-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from Altalogy/launchpad/feature/83/a_box
feat(primitive): implement standard box
- Loading branch information
Showing
12 changed files
with
230 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import { ThemeProvider } from 'styled-components' | ||
|
||
import themes from '../../styles/themes' | ||
import Box from '.' | ||
|
||
describe('Box', () => { | ||
it('should render box and children without crash', () => { | ||
render( | ||
<ThemeProvider theme={themes.light}> | ||
<Box> | ||
<p>box children</p> | ||
</Box> | ||
</ThemeProvider>, | ||
) | ||
|
||
const el = screen.getByText('box children') | ||
expect(el).toBeInTheDocument() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { StyledBox } from './styles' | ||
|
||
import { BoxProps } from './types' | ||
|
||
/** | ||
* A box with standardized border radius, padding etc. | ||
* | ||
* @prop {ReactNode} children - elements to render inside the box | ||
* @prop {Gradient} gradient - optional gradient definition for box background | ||
* @prop {boolean} border - whether to show box border or not | ||
* @prop {CSSProperties} style - prop allowing to override all styles of the box | ||
* | ||
* @typedef Gradient | ||
* @prop {string} start - color of gradient start | ||
* @prop {string} end - color on gradient end | ||
* @prop {number} rotation - gradient rotation in degress (45 by default) | ||
*/ | ||
const Box = ({ children, gradient, border, style: inlineStyle }: BoxProps) => { | ||
const style = { | ||
border: border === false ? 'none' : undefined, | ||
background: | ||
gradient && | ||
` | ||
linear-gradient( | ||
${gradient.rotation || 45}deg, | ||
${gradient.start} 0%, | ||
${gradient.end} 100% | ||
)`, | ||
...inlineStyle, | ||
} | ||
|
||
return <StyledBox style={style}>{children}</StyledBox> | ||
} | ||
|
||
export default Box |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import styled from 'styled-components' | ||
|
||
export const StyledBox = styled.div` | ||
color: ${({ theme }) => theme.primary}; | ||
background: ${({ theme }) => theme.background}; | ||
padding: ${({ theme }) => theme.spacing()}; | ||
margin: ${({ theme }) => theme.spacing()} 0; | ||
border-radius: ${({ theme }) => theme.borderRadius()}; | ||
border: 1px solid ${({ theme }) => theme.borderColor}; | ||
min-width: 416px; | ||
width: 416px; | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ReactNode, CSSProperties } from 'react' | ||
|
||
type Gradient = { | ||
start: string | ||
end: string | ||
rotation?: number | ||
} | ||
|
||
export type BoxProps = { | ||
children: ReactNode | ||
border?: boolean | ||
style?: CSSProperties | ||
gradient?: Gradient | ||
} |
103 changes: 52 additions & 51 deletions
103
applications/launchpad_v2/src/components/Select/Select.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,65 @@ | ||
import React from 'react' | ||
import { act, render, screen } from '@testing-library/react' | ||
import { ThemeProvider } from 'styled-components' | ||
|
||
import themes from '../../styles/themes' | ||
import Select from './' | ||
|
||
test('renders label with select', async () => { | ||
// given | ||
const options = [ | ||
{ | ||
value: 'Test value', | ||
key: 'test', | ||
label: 'Test label', | ||
}, | ||
] | ||
describe('Select', () => { | ||
it('should render label with select', async () => { | ||
// given | ||
const options = [ | ||
{ | ||
value: 'Test value', | ||
key: 'test', | ||
label: 'Test label', | ||
}, | ||
] | ||
|
||
// when | ||
await act(async () => { | ||
render( | ||
<ThemeProvider theme={themes.light}> | ||
<Select | ||
label='Test select label' | ||
value={options[0]} | ||
options={options} | ||
onChange={() => null} | ||
/> | ||
</ThemeProvider>, | ||
) | ||
// when | ||
await act(async () => { | ||
render( | ||
<ThemeProvider theme={themes.light}> | ||
<Select | ||
label='Test select label' | ||
value={options[0]} | ||
options={options} | ||
onChange={() => null} | ||
/> | ||
</ThemeProvider>, | ||
) | ||
}) | ||
|
||
// then | ||
const label = screen.getByText(/Test select label/i) | ||
expect(label).toBeInTheDocument() | ||
}) | ||
|
||
// then | ||
const label = screen.getByText(/Test select label/i) | ||
expect(label).toBeInTheDocument() | ||
}) | ||
it('should render selected option', async () => { | ||
// given | ||
const options = [ | ||
{ | ||
value: 'Test value', | ||
key: 'test', | ||
label: 'Test label', | ||
}, | ||
] | ||
|
||
test('render selected option', async () => { | ||
// given | ||
const options = [ | ||
{ | ||
value: 'Test value', | ||
key: 'test', | ||
label: 'Test label', | ||
}, | ||
] | ||
// when | ||
await act(async () => { | ||
render( | ||
<ThemeProvider theme={themes.light}> | ||
<Select | ||
label='Test select label' | ||
value={options[0]} | ||
options={options} | ||
onChange={() => null} | ||
/> | ||
</ThemeProvider>, | ||
) | ||
}) | ||
|
||
// when | ||
await act(async () => { | ||
render( | ||
<ThemeProvider theme={themes.light}> | ||
<Select | ||
label='Test select label' | ||
value={options[0]} | ||
options={options} | ||
onChange={() => null} | ||
/> | ||
</ThemeProvider>, | ||
) | ||
// then | ||
const label = screen.getByText(/Test label/i) | ||
expect(label).toBeInTheDocument() | ||
}) | ||
|
||
// then | ||
const label = screen.getByText(/Test label/i) | ||
expect(label).toBeInTheDocument() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import styled from 'styled-components' | ||
|
||
export const StyledText = styled.p`` | ||
export const StyledText = styled.p` | ||
color: ${({ theme }) => theme.primary}; | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,46 @@ | ||
import 'styled-components' | ||
|
||
declare module '*.svg' { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const content: any | ||
export default content | ||
} | ||
|
||
declare module '*.otf' | ||
|
||
declare module 'styled-components' { | ||
export interface DefaultTheme { | ||
spacing: (count?: number) => string | ||
spacingHorizontal: (count?: number) => string | ||
spacingVertical: (count?: number) => string | ||
borderRadius: (count?: number) => string | ||
primary: string | ||
secondary: string | ||
background: string | ||
backgroundSecondary: string | ||
backgroundImage: string | ||
accent: string | ||
accentDark: string | ||
disabledText: string | ||
tariGradient: string | ||
borderColor: string | ||
actionBackground: string | ||
|
||
titleBar: string | ||
|
||
controlBackground: string | ||
|
||
inverted: { | ||
controlBackground: string | ||
primary: string | ||
secondary: string | ||
background: string | ||
backgroundSecondary: string | ||
backgroundImage: string | ||
accent: string | ||
accentDark: string | ||
disabledText: string | ||
tariGradient: string | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.