@edvisor/product-language 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +12 -0
- package/.eslintrc.json +147 -0
- package/.storybook/main.js +57 -0
- package/.storybook/manager.js +7 -0
- package/.storybook/preview.js +15 -0
- package/.storybook/tsconfig.json +30 -0
- package/jest.config.ts +15 -0
- package/jest.setup.ts +2 -0
- package/package.json +21 -10
- package/project.json +96 -0
- package/src/README.md +61 -0
- package/src/assets/svg/example_icon.svg +3 -0
- package/src/assets/svg/example_icon_white.svg +3 -0
- package/src/assets/svg/spinner.svg +3 -0
- package/src/assets/svg/spinner_white.svg +3 -0
- package/src/helpers/index.ts +4 -0
- package/src/helpers/playground.ts +16 -0
- package/src/helpers/talesOf.tsx +42 -0
- package/src/index.ts +2 -0
- package/src/lib/components/README.md +49 -0
- package/src/lib/components/alert-banner/alert-banner.tsx +34 -0
- package/src/lib/components/alert-banner/alert-level-flags.ts +77 -0
- package/src/lib/components/alert-banner/index.ts +1 -0
- package/src/lib/components/badge/badge-type-flags.ts +72 -0
- package/src/lib/components/badge/badge.test.tsx +29 -0
- package/src/lib/components/badge/badge.tsx +22 -0
- package/src/lib/components/badge/index.ts +1 -0
- package/src/lib/components/badge/stories/badge.stories.mdx +44 -0
- package/src/lib/components/badge/stories/components.tsx +49 -0
- package/{lib/components/card/atoms/card-frame.d.ts → src/lib/components/card/atoms/card-frame.tsx} +17 -7
- package/src/lib/components/card/atoms/index.ts +1 -0
- package/src/lib/components/card/card.test.tsx +162 -0
- package/src/lib/components/card/card.tsx +78 -0
- package/src/lib/components/card/components/card-alert-banner-slot.tsx +16 -0
- package/src/lib/components/card/components/card-controls-slot.tsx +19 -0
- package/src/lib/components/card/components/card-section-slot.tsx +51 -0
- package/src/lib/components/card/components/index.ts +3 -0
- package/src/lib/components/card/index.ts +2 -0
- package/src/lib/components/card/molecules/index.ts +1 -0
- package/src/lib/components/card/molecules/left-right-card.test.tsx +89 -0
- package/src/lib/components/card/molecules/left-right-card.tsx +63 -0
- package/src/lib/components/card/storybook/card.stories.mdx +100 -0
- package/src/lib/components/card/storybook/components.tsx +223 -0
- package/src/lib/components/checkbox/checkbox.test.tsx +39 -0
- package/src/lib/components/checkbox/checkbox.tsx +63 -0
- package/src/lib/components/checkbox/helpers.tsx +100 -0
- package/src/lib/components/checkbox/index.tsx +1 -0
- package/src/lib/components/checkbox/stories/checkbox.stories.mdx +57 -0
- package/src/lib/components/checkbox/stories/components.tsx +84 -0
- package/src/lib/components/divider/divider-type-flags.tsx +37 -0
- package/src/lib/components/divider/divider.test.tsx +34 -0
- package/src/lib/components/divider/divider.tsx +37 -0
- package/src/lib/components/divider/index.tsx +1 -0
- package/src/lib/components/divider/stories/components.tsx +13 -0
- package/src/lib/components/divider/stories/divider.stories.mdx +44 -0
- package/src/lib/components/flag/flag-size-flags.tsx +55 -0
- package/src/lib/components/flag/flag.list.tsx +788 -0
- package/src/lib/components/flag/flag.test.tsx +65 -0
- package/src/lib/components/flag/flag.tsx +97 -0
- package/src/lib/components/flag/index.tsx +1 -0
- package/src/lib/components/flag/stories/components.tsx +403 -0
- package/src/lib/components/flag/stories/flag.stories.mdx +48 -0
- package/src/lib/components/flag/stories/playGround-select.tsx +145 -0
- package/src/lib/components/icon/icon-list.tsx +135 -0
- package/src/lib/components/icon/icon.test.tsx +48 -0
- package/src/lib/components/icon/icon.tsx +181 -0
- package/src/lib/components/icon/index.tsx +1 -0
- package/src/lib/components/icon/stories/components.tsx +282 -0
- package/src/lib/components/icon/stories/icon.stories.mdx +65 -0
- package/src/lib/components/index.ts +19 -0
- package/src/lib/components/input-field/components/index.ts +2 -0
- package/src/lib/components/input-field/components/labeled-input.tsx +54 -0
- package/src/lib/components/input-field/components/stepper.tsx +60 -0
- package/src/lib/components/input-field/index.ts +6 -0
- package/src/lib/components/input-field/input-field.test.tsx +107 -0
- package/src/lib/components/input-field/input-field.tsx +126 -0
- package/src/lib/components/input-field/input-number.tsx +41 -0
- package/src/lib/components/input-field/input-text.tsx +30 -0
- package/src/lib/components/input-field/storybook/components.tsx +327 -0
- package/src/lib/components/input-field/storybook/input-field.stories.mdx +113 -0
- package/src/lib/components/layout/flex.tsx +22 -0
- package/src/lib/components/layout/grid-layout.tsx +40 -0
- package/src/lib/components/layout/index.ts +3 -0
- package/src/lib/components/layout/left-right-layout.tsx +67 -0
- package/src/lib/components/link/index.ts +1 -0
- package/src/lib/components/link/link.test.tsx +29 -0
- package/src/lib/components/link/link.tsx +56 -0
- package/src/lib/components/link/storybook/link.stories.mdx +52 -0
- package/src/lib/components/molecules/avatar/avatar-size-flags.tsx +55 -0
- package/src/lib/components/molecules/avatar/avatar.test.tsx +114 -0
- package/src/lib/components/molecules/avatar/avatar.tsx +80 -0
- package/src/lib/components/molecules/avatar/index.tsx +1 -0
- package/src/lib/components/molecules/avatar/stories/avatar.stories.mdx +52 -0
- package/src/lib/components/molecules/avatar/stories/components.tsx +36 -0
- package/src/lib/components/molecules/button/button-flags.tsx +340 -0
- package/src/lib/components/molecules/button/button.test.tsx +77 -0
- package/src/lib/components/molecules/button/button.tsx +214 -0
- package/src/lib/components/molecules/button/index.tsx +1 -0
- package/src/lib/components/molecules/button/stories/button.stories.mdx +105 -0
- package/src/lib/components/molecules/button/stories/components.tsx +84 -0
- package/src/lib/components/molecules/index.ts +3 -0
- package/src/lib/components/molecules/input-checkbox/index.tsx +1 -0
- package/src/lib/components/molecules/input-checkbox/input-checkbox.test.tsx +34 -0
- package/src/lib/components/molecules/input-checkbox/input-checkbox.tsx +49 -0
- package/src/lib/components/molecules/input-checkbox/stories/components.tsx +53 -0
- package/src/lib/components/molecules/input-checkbox/stories/input-checkbox.stories.mdx +49 -0
- package/src/lib/components/organisms/index.ts +1 -0
- package/src/lib/components/organisms/multi-choice-list/index.tsx +1 -0
- package/src/lib/components/organisms/multi-choice-list/multi-choice-list.test.tsx +33 -0
- package/src/lib/components/organisms/multi-choice-list/multi-choice-list.tsx +52 -0
- package/src/lib/components/organisms/multi-choice-list/stories/components.tsx +124 -0
- package/src/lib/components/organisms/multi-choice-list/stories/multi-choice-list.stories.mdx +99 -0
- package/src/lib/components/spinner/index.tsx +1 -0
- package/src/lib/components/spinner/spinner-size-flags.tsx +39 -0
- package/src/lib/components/spinner/spinner.test.tsx +31 -0
- package/src/lib/components/spinner/spinner.tsx +54 -0
- package/src/lib/components/spinner/stories/components.tsx +39 -0
- package/src/lib/components/spinner/stories/spinner.stories.mdx +35 -0
- package/src/lib/components/tabs/components/index.ts +1 -0
- package/src/lib/components/tabs/components/tab.tsx +62 -0
- package/src/lib/components/tabs/index.tsx +1 -0
- package/src/lib/components/tabs/storybook/components.tsx +282 -0
- package/src/lib/components/tabs/storybook/tabs.stories.mdx +97 -0
- package/src/lib/components/tabs/tabs.test.tsx +86 -0
- package/src/lib/components/tabs/tabs.tsx +101 -0
- package/src/lib/components/tag/components/close-button.tsx +85 -0
- package/src/lib/components/tag/components/index.ts +2 -0
- package/src/lib/components/tag/components/tag-label.tsx +44 -0
- package/src/lib/components/tag/index.tsx +1 -0
- package/src/lib/components/tag/stories/components.tsx +86 -0
- package/src/lib/components/tag/stories/tag.stories.mdx +42 -0
- package/src/lib/components/tag/tag.test.tsx +36 -0
- package/src/lib/components/tag/tag.tsx +33 -0
- package/src/lib/components/thumbnail/index.tsx +1 -0
- package/src/lib/components/thumbnail/stories/thumbnail.stories.mdx +34 -0
- package/src/lib/components/thumbnail/thumbnail-size-flags.tsx +41 -0
- package/src/lib/components/thumbnail/thumbnail.test.tsx +51 -0
- package/src/lib/components/thumbnail/thumbnail.tsx +45 -0
- package/src/lib/components/typography/index.ts +1 -0
- package/src/lib/components/typography/storybook/components.tsx +288 -0
- package/src/lib/components/typography/storybook/typography.stories.mdx +90 -0
- package/src/lib/components/typography/typography.test.tsx +97 -0
- package/src/lib/components/typography/typography.tsx +99 -0
- package/src/lib/foundations/color-system/base-palette/base-palette.stories.tsx +123 -0
- package/src/lib/foundations/color-system/base-palette/base-palette.ts +93 -0
- package/src/lib/foundations/color-system/base-palette/index.ts +1 -0
- package/src/lib/foundations/color-system/color-guidelines/color-guidelines.stories.mdx +85 -0
- package/src/lib/foundations/color-system/color-guidelines/color-guidelines.stories.tsx +231 -0
- package/src/lib/foundations/color-system/color-guidelines/color-guidelines.ts +160 -0
- package/src/lib/foundations/color-system/color-guidelines/index.ts +1 -0
- package/src/lib/foundations/color-system/components/color-sample.tsx +99 -0
- package/src/lib/foundations/color-system/components/index.ts +1 -0
- package/src/lib/foundations/color-system/index.ts +1 -0
- package/src/lib/foundations/index.ts +4 -0
- package/src/lib/foundations/shadows/components.tsx +59 -0
- package/src/lib/foundations/shadows/index.ts +1 -0
- package/src/lib/foundations/shadows/shadows.stories.mdx +71 -0
- package/src/lib/foundations/shadows/shadows.tsx +47 -0
- package/src/lib/foundations/spacing/index.ts +1 -0
- package/src/lib/foundations/spacing/spacing-guidelines.ts +24 -0
- package/src/lib/foundations/spacing/spacing.stories.mdx +51 -0
- package/src/lib/foundations/spacing/spacing.ts +18 -0
- package/src/lib/foundations/typography/constants.ts +25 -0
- package/src/lib/foundations/typography/fonts.ts +205 -0
- package/src/lib/foundations/typography/index.tsx +1 -0
- package/src/lib/foundations/typography/text-aspect-flags.ts +61 -0
- package/src/lib/foundations/typography/typography.tsx +102 -0
- package/src/lib/helpers/generic-types.ts +44 -0
- package/src/lib/helpers/index.ts +6 -0
- package/src/lib/helpers/nothing.tsx +18 -0
- package/src/lib/helpers/numbers.ts +67 -0
- package/src/lib/helpers/safe-navigation.ts +44 -0
- package/src/lib/helpers/slots.test.tsx +98 -0
- package/src/lib/helpers/slots.tsx +157 -0
- package/src/lib/helpers/strings.test.ts +47 -0
- package/src/lib/helpers/strings.ts +16 -0
- package/tsconfig.json +35 -0
- package/tsconfig.lib.json +28 -0
- package/tsconfig.spec.json +21 -0
- package/index.d.ts +0 -2
- package/index.js +0 -6078
- package/lib/components/alert-banner/alert-banner.d.ts +0 -11
- package/lib/components/alert-banner/alert-level-flags.d.ts +0 -13
- package/lib/components/alert-banner/index.d.ts +0 -1
- package/lib/components/badge/badge-type-flags.d.ts +0 -18
- package/lib/components/badge/badge.d.ts +0 -5
- package/lib/components/badge/index.d.ts +0 -1
- package/lib/components/card/atoms/index.d.ts +0 -1
- package/lib/components/card/card.d.ts +0 -14
- package/lib/components/card/components/card-alert-banner-slot.d.ts +0 -5
- package/lib/components/card/components/card-controls-slot.d.ts +0 -4
- package/lib/components/card/components/card-section-slot.d.ts +0 -11
- package/lib/components/card/components/index.d.ts +0 -3
- package/lib/components/card/index.d.ts +0 -2
- package/lib/components/card/molecules/index.d.ts +0 -1
- package/lib/components/card/molecules/left-right-card.d.ts +0 -16
- package/lib/components/checkbox/checkbox.d.ts +0 -11
- package/lib/components/checkbox/components/components.d.ts +0 -12
- package/lib/components/checkbox/index.d.ts +0 -1
- package/lib/components/divider/divider-type-flags.d.ts +0 -9
- package/lib/components/divider/divider.d.ts +0 -7
- package/lib/components/divider/index.d.ts +0 -1
- package/lib/components/index.d.ts +0 -12
- package/lib/components/input-field/components/index.d.ts +0 -2
- package/lib/components/input-field/components/labeled-input.d.ts +0 -11
- package/lib/components/input-field/components/stepper.d.ts +0 -7
- package/lib/components/input-field/index.d.ts +0 -3
- package/lib/components/input-field/input-field.d.ts +0 -25
- package/lib/components/input-field/input-number.d.ts +0 -18
- package/lib/components/input-field/input-text.d.ts +0 -14
- package/lib/components/layout/flex.d.ts +0 -16
- package/lib/components/layout/grid-layout.d.ts +0 -11
- package/lib/components/layout/index.d.ts +0 -3
- package/lib/components/layout/left-right-layout.d.ts +0 -70
- package/lib/components/link/index.d.ts +0 -1
- package/lib/components/link/link.d.ts +0 -14
- package/lib/components/molecules/avatar/avatar-size-flags.d.ts +0 -12
- package/lib/components/molecules/avatar/avatar.d.ts +0 -12
- package/lib/components/molecules/avatar/index.d.ts +0 -1
- package/lib/components/molecules/button/button-flags.d.ts +0 -39
- package/lib/components/molecules/button/button.d.ts +0 -24
- package/lib/components/molecules/button/index.d.ts +0 -1
- package/lib/components/molecules/index.d.ts +0 -3
- package/lib/components/molecules/input-checkbox/index.d.ts +0 -1
- package/lib/components/molecules/input-checkbox/input-checkbox.d.ts +0 -8
- package/lib/components/organisms/index.d.ts +0 -1
- package/lib/components/organisms/multi-choice-list/index.d.ts +0 -1
- package/lib/components/organisms/multi-choice-list/multi-choice-list.d.ts +0 -11
- package/lib/components/spinner/index.d.ts +0 -1
- package/lib/components/spinner/spinner-size-flags.d.ts +0 -10
- package/lib/components/spinner/spinner.d.ts +0 -9
- package/lib/components/thumbnail/index.d.ts +0 -1
- package/lib/components/thumbnail/thumbnail-size-flags.d.ts +0 -10
- package/lib/components/thumbnail/thumbnail.d.ts +0 -9
- package/lib/components/typography/index.d.ts +0 -1
- package/lib/components/typography/typography.d.ts +0 -23
- package/lib/foundations/color-system/base-palette/base-palette.d.ts +0 -77
- package/lib/foundations/color-system/base-palette/index.d.ts +0 -1
- package/lib/foundations/color-system/color-guidelines/color-guidelines.d.ts +0 -131
- package/lib/foundations/color-system/color-guidelines/index.d.ts +0 -1
- package/lib/foundations/color-system/components/color-sample.d.ts +0 -17
- package/lib/foundations/color-system/components/index.d.ts +0 -1
- package/lib/foundations/color-system/index.d.ts +0 -1
- package/lib/foundations/index.d.ts +0 -4
- package/lib/foundations/shadows/components.d.ts +0 -8
- package/lib/foundations/shadows/index.d.ts +0 -1
- package/lib/foundations/shadows/shadows.d.ts +0 -8
- package/lib/foundations/spacing/index.d.ts +0 -1
- package/lib/foundations/spacing/spacing-guidelines.d.ts +0 -22
- package/lib/foundations/spacing/spacing.d.ts +0 -18
- package/lib/foundations/typography/constants.d.ts +0 -22
- package/lib/foundations/typography/index.d.ts +0 -1
- package/lib/foundations/typography/text-aspect-flags.d.ts +0 -14
- package/lib/foundations/typography/typography.d.ts +0 -19
- package/lib/helpers/generic-types.d.ts +0 -21
- package/lib/helpers/index.d.ts +0 -6
- package/lib/helpers/nothing.d.ts +0 -8
- package/lib/helpers/numbers.d.ts +0 -41
- package/lib/helpers/safe-navigation.d.ts +0 -14
- package/lib/helpers/slots.d.ts +0 -8
- package/lib/helpers/strings.d.ts +0 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Margin, Padding, Surface, Icons } from '@foundations'
|
|
2
|
+
import { FC } from '@helpers'
|
|
3
|
+
import { Center } from 'components/layout'
|
|
4
|
+
import styled from 'styled-components'
|
|
5
|
+
|
|
6
|
+
const Controls = styled.div`
|
|
7
|
+
height: 34px;
|
|
8
|
+
width: 26px;
|
|
9
|
+
padding: ${Padding.xxxs} ${Padding.xxxs};
|
|
10
|
+
box-sizing: border-box;
|
|
11
|
+
`
|
|
12
|
+
|
|
13
|
+
const Up = styled(Center)`
|
|
14
|
+
background: ${Surface.Neutral.Default};
|
|
15
|
+
width: 22px;
|
|
16
|
+
height: 14px;
|
|
17
|
+
border-radius: 3px 3px 0px 0px;
|
|
18
|
+
margin-bottom: ${Margin.xxxs};
|
|
19
|
+
display: flex;
|
|
20
|
+
align-items: center;
|
|
21
|
+
justify-content: center;
|
|
22
|
+
margin-top: ${Margin.xs}
|
|
23
|
+
`
|
|
24
|
+
|
|
25
|
+
const TriangleUp = styled.div`
|
|
26
|
+
width: 0px;
|
|
27
|
+
height: 0px;
|
|
28
|
+
border-left: 5px solid transparent;
|
|
29
|
+
border-right: 5px solid transparent;
|
|
30
|
+
border-bottom: 5px solid ${Icons.Default};
|
|
31
|
+
`
|
|
32
|
+
|
|
33
|
+
const TriangleDown = styled.div`
|
|
34
|
+
width: 0px;
|
|
35
|
+
height: 0px;
|
|
36
|
+
border-left: 5px solid transparent;
|
|
37
|
+
border-right: 5px solid transparent;
|
|
38
|
+
border-top: 5px solid ${Icons.Default};
|
|
39
|
+
`
|
|
40
|
+
|
|
41
|
+
const Down = styled(Center)`
|
|
42
|
+
background: ${Surface.Neutral.Default};
|
|
43
|
+
width: 22px;
|
|
44
|
+
height: 14px;
|
|
45
|
+
border-radius: 0px 0px 3px 3px;
|
|
46
|
+
`
|
|
47
|
+
|
|
48
|
+
interface IStepperProps {
|
|
49
|
+
onUpClick?: () => void
|
|
50
|
+
onDownClick?: () => void
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const Stepper: FC<IStepperProps> = (props: IStepperProps) => {
|
|
54
|
+
return (
|
|
55
|
+
<Controls>
|
|
56
|
+
<Up onClick={props.onUpClick}><TriangleUp /></Up>
|
|
57
|
+
<Down onClick={props.onDownClick}><TriangleDown /></Down>
|
|
58
|
+
</Controls>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react'
|
|
2
|
+
import userEvent from '@testing-library/user-event'
|
|
3
|
+
import { InputField } from './index'
|
|
4
|
+
|
|
5
|
+
describe('InputField', () => {
|
|
6
|
+
describe('the inner input element', () => {
|
|
7
|
+
it('should receive nice html props', async () => {
|
|
8
|
+
render(
|
|
9
|
+
<InputField
|
|
10
|
+
value="value"
|
|
11
|
+
onChange={() => undefined}
|
|
12
|
+
type="text"
|
|
13
|
+
label="Label"
|
|
14
|
+
placeholder="placeholder"
|
|
15
|
+
/>
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
expect(screen.getByRole('textbox')).toBeInTheDocument()
|
|
19
|
+
expect(screen.getByPlaceholderText('placeholder')).toBeInTheDocument()
|
|
20
|
+
expect(screen.getByDisplayValue('value')).toBeInTheDocument()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('should call the onChange callback on change events', async () => {
|
|
24
|
+
const handleChange = jest.fn()
|
|
25
|
+
|
|
26
|
+
render(<InputField value="value" onChange={handleChange} />)
|
|
27
|
+
|
|
28
|
+
await userEvent.type(screen.getByRole('textbox'), 'hello')
|
|
29
|
+
|
|
30
|
+
expect(handleChange).toHaveBeenCalledTimes(5)
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
describe('Label', () => {
|
|
35
|
+
it('should render when given', async () => {
|
|
36
|
+
render(<InputField label="Label" />)
|
|
37
|
+
|
|
38
|
+
expect(screen.getByLabelText('Label')).toBeInTheDocument()
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('should not render when not given', async () => {
|
|
42
|
+
render(<InputField />)
|
|
43
|
+
|
|
44
|
+
expect(screen.queryByLabelText('Label')).not.toBeInTheDocument()
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
describe('Prefix', () => {
|
|
49
|
+
it('should render when given', async () => {
|
|
50
|
+
render(<InputField prefix="$" />)
|
|
51
|
+
|
|
52
|
+
expect(screen.getByText('$')).toBeInTheDocument()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('should not render when not given', async () => {
|
|
56
|
+
render(<InputField />)
|
|
57
|
+
|
|
58
|
+
expect(screen.queryByText('$')).not.toBeInTheDocument()
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
describe('Suffix', () => {
|
|
63
|
+
it('should render when given', async () => {
|
|
64
|
+
render(<InputField suffix="%" />)
|
|
65
|
+
|
|
66
|
+
expect(screen.getByText('%')).toBeInTheDocument()
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('should not render when not given', async () => {
|
|
70
|
+
render(<InputField />)
|
|
71
|
+
|
|
72
|
+
expect(screen.queryByText('&')).not.toBeInTheDocument()
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
describe('Slots', () => {
|
|
77
|
+
it('should render the Icon slot', async () => {
|
|
78
|
+
render(
|
|
79
|
+
<InputField>
|
|
80
|
+
<InputField.Icon>Icon</InputField.Icon>
|
|
81
|
+
</InputField>
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
expect(screen.getByText('Icon')).toBeInTheDocument()
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('should render the Controls slot', async () => {
|
|
88
|
+
render(
|
|
89
|
+
<InputField>
|
|
90
|
+
<InputField.Controls>Controls</InputField.Controls>
|
|
91
|
+
</InputField>
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
expect(screen.getByText('Controls')).toBeInTheDocument()
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('should not render other kinds of children', () => {
|
|
98
|
+
render(
|
|
99
|
+
<InputField>
|
|
100
|
+
<div>Other Children</div>
|
|
101
|
+
</InputField>
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
expect(screen.queryByText('Other Children')).not.toBeInTheDocument()
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
})
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import styled from 'styled-components'
|
|
2
|
+
import { InputHTMLAttributes } from 'react'
|
|
3
|
+
|
|
4
|
+
import { Borders, Focused, Margin, Padding, Surface, Typography, _Typography } from '@foundations'
|
|
5
|
+
import { getSlot, Slot, is, forwardRef, If } from '@helpers'
|
|
6
|
+
import { Flex, SpaceBetween } from '../layout'
|
|
7
|
+
|
|
8
|
+
import { LabeledInput } from './components'
|
|
9
|
+
import { Label } from 'components/typography'
|
|
10
|
+
|
|
11
|
+
const FancyBorder = styled(SpaceBetween)<{ invalid?: boolean }>`
|
|
12
|
+
background: ${({ invalid }) => is(invalid) ? Surface.Critical.Subdued : Surface.Default.Default };
|
|
13
|
+
border: 1px solid ${({ invalid }) => is(invalid) ? Borders.Critical.Default : Borders.Default.Default };
|
|
14
|
+
border-radius: 6px;
|
|
15
|
+
box-sizing: border-box;
|
|
16
|
+
margin-bottom: ${Margin.xxs};
|
|
17
|
+
padding-left: ${Padding.s};
|
|
18
|
+
|
|
19
|
+
user-select: none;
|
|
20
|
+
|
|
21
|
+
:focus, :focus-within, :active {
|
|
22
|
+
border: ${({ invalid }) => is(invalid)
|
|
23
|
+
? `1px solid ${Borders.Critical.Default}`
|
|
24
|
+
: `2px solid ${Focused.Default}`
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
`
|
|
28
|
+
|
|
29
|
+
const InputLayout = styled(Flex)`
|
|
30
|
+
width: 100%;
|
|
31
|
+
`
|
|
32
|
+
|
|
33
|
+
export const HTMLInput = styled.input`
|
|
34
|
+
all: unset;
|
|
35
|
+
|
|
36
|
+
padding: ${Padding.none} ${Padding.none} ${Padding.xs} ${Padding.none};
|
|
37
|
+
|
|
38
|
+
width: 100%;
|
|
39
|
+
|
|
40
|
+
::-webkit-inner-spin-button {
|
|
41
|
+
-webkit-appearance: none;
|
|
42
|
+
margin: ${Margin.none};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
${Typography.Body}
|
|
46
|
+
|
|
47
|
+
::placeholder {
|
|
48
|
+
${_Typography.LightText}
|
|
49
|
+
}
|
|
50
|
+
`
|
|
51
|
+
|
|
52
|
+
const PrefixFrame = styled(Label)`
|
|
53
|
+
margin-right: ${Margin.xs};
|
|
54
|
+
`
|
|
55
|
+
|
|
56
|
+
const SuffixFrame = styled(Label)`
|
|
57
|
+
margin-right: ${Margin.xs};
|
|
58
|
+
`
|
|
59
|
+
|
|
60
|
+
class IconSlot extends Slot {}
|
|
61
|
+
class ControlsSlot extends Slot {}
|
|
62
|
+
|
|
63
|
+
export type InputFieldSlots = {
|
|
64
|
+
Icon: typeof IconSlot,
|
|
65
|
+
Controls: typeof ControlsSlot,
|
|
66
|
+
Label: typeof LabeledInput,
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface IInputFieldProps extends InputHTMLAttributes<HTMLInputElement> {
|
|
70
|
+
invalid?: boolean
|
|
71
|
+
prefix?: string
|
|
72
|
+
suffix?: string
|
|
73
|
+
label?: string
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const InputFrame = styled.label`
|
|
77
|
+
width: 100%;
|
|
78
|
+
padding: ${Padding.xs} ${Padding.none} ${Padding.none} ${Padding.none};
|
|
79
|
+
flex-direction: column;
|
|
80
|
+
display: flex;
|
|
81
|
+
`
|
|
82
|
+
|
|
83
|
+
const ControlsFrame = Flex
|
|
84
|
+
|
|
85
|
+
const InputLabel = styled(Label)`
|
|
86
|
+
margin-bottom: ${Margin.xxs};
|
|
87
|
+
`
|
|
88
|
+
|
|
89
|
+
export const InputField = forwardRef<
|
|
90
|
+
HTMLInputElement,
|
|
91
|
+
IInputFieldProps,
|
|
92
|
+
InputFieldSlots
|
|
93
|
+
>((props: IInputFieldProps, ref) => {
|
|
94
|
+
const { children, prefix, suffix, label, className, ...inputProps } = props
|
|
95
|
+
const icon = getSlot(IconSlot, children)
|
|
96
|
+
const controls = getSlot(ControlsSlot, children)
|
|
97
|
+
const required = is(props.required) ? '*' : ''
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<FancyBorder invalid={props.invalid} className={className}>
|
|
101
|
+
<InputFrame>
|
|
102
|
+
<If is={label}>
|
|
103
|
+
<InputLabel subtle subdued>
|
|
104
|
+
{label}
|
|
105
|
+
{required}
|
|
106
|
+
</InputLabel>
|
|
107
|
+
</If>
|
|
108
|
+
<InputLayout>
|
|
109
|
+
{icon}
|
|
110
|
+
<If is={prefix}>
|
|
111
|
+
<PrefixFrame subtle subdued>{prefix}</PrefixFrame>
|
|
112
|
+
</If>
|
|
113
|
+
<HTMLInput ref={ref} {...inputProps} />
|
|
114
|
+
<If is={suffix}>
|
|
115
|
+
<SuffixFrame subtle subdued>{suffix}</SuffixFrame>
|
|
116
|
+
</If>
|
|
117
|
+
</InputLayout>
|
|
118
|
+
</InputFrame>
|
|
119
|
+
<ControlsFrame center>{controls}</ControlsFrame>
|
|
120
|
+
</FancyBorder>
|
|
121
|
+
)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
InputField.Icon = IconSlot
|
|
125
|
+
InputField.Controls = ControlsSlot
|
|
126
|
+
InputField.Label = LabeledInput
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { FC, isNil } from '@helpers'
|
|
2
|
+
import { InputField, InputFieldSlots } from './input-field'
|
|
3
|
+
import { Stepper } from './components'
|
|
4
|
+
|
|
5
|
+
interface IInputNumberProps {
|
|
6
|
+
value?: number
|
|
7
|
+
onChange: (change?: number) => void
|
|
8
|
+
|
|
9
|
+
label?: string
|
|
10
|
+
placeholder?: string
|
|
11
|
+
invalid?: boolean
|
|
12
|
+
prefix?: string
|
|
13
|
+
suffix?: string
|
|
14
|
+
required?: boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type IInputNumberSlots = InputFieldSlots & {
|
|
18
|
+
Stepper: typeof Stepper
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const InputNumber: FC<IInputNumberProps, IInputNumberSlots> = (props) => {
|
|
22
|
+
const { onChange, value, ...inputFieldProps } = props
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<InputField
|
|
26
|
+
type='number'
|
|
27
|
+
value={isNil(value) || isNaN(value) ? '' : value}
|
|
28
|
+
onChange={(e) => {
|
|
29
|
+
const next = e.target.value === '' ? undefined : parseFloat(e.target.value)
|
|
30
|
+
|
|
31
|
+
onChange(next)
|
|
32
|
+
}}
|
|
33
|
+
{...inputFieldProps}
|
|
34
|
+
/>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
InputNumber.Icon = InputField.Icon
|
|
39
|
+
InputNumber.Controls = InputField.Controls
|
|
40
|
+
InputNumber.Label = InputField.Label
|
|
41
|
+
InputNumber.Stepper = Stepper
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FC } from '@helpers'
|
|
2
|
+
import { InputField, InputFieldSlots } from './input-field'
|
|
3
|
+
|
|
4
|
+
interface IInputTextProps {
|
|
5
|
+
value: string
|
|
6
|
+
onChange: (change: string) => void
|
|
7
|
+
|
|
8
|
+
label?: string
|
|
9
|
+
invalid?: boolean
|
|
10
|
+
placeholder?: string
|
|
11
|
+
prefix?: string
|
|
12
|
+
suffix?: string
|
|
13
|
+
required?: boolean
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const InputText: FC<IInputTextProps, InputFieldSlots> = (props) => {
|
|
17
|
+
const { onChange, ...inputFieldProps } = props
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<InputField
|
|
21
|
+
type='text'
|
|
22
|
+
onChange={(e) => onChange(e.target.value)}
|
|
23
|
+
{...inputFieldProps}
|
|
24
|
+
/>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
InputText.Icon = InputField.Icon
|
|
29
|
+
InputText.Controls = InputField.Controls
|
|
30
|
+
InputText.Label = InputField.Label
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import styled from 'styled-components'
|
|
2
|
+
import { useForm } from 'react-hook-form'
|
|
3
|
+
|
|
4
|
+
import { SpaceBetween } from 'components/layout'
|
|
5
|
+
import { InputField } from '../input-field'
|
|
6
|
+
|
|
7
|
+
import { IconMinor } from 'components/icon'
|
|
8
|
+
|
|
9
|
+
import { Playground } from 'storybook-addon-jarle-monaco'
|
|
10
|
+
import { InputNumber } from '../input-number'
|
|
11
|
+
import { InputText } from '../input-text'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export const PlainHTMLFormExample = () => (
|
|
15
|
+
<Playground
|
|
16
|
+
code={`
|
|
17
|
+
/* Edit this code sample! */
|
|
18
|
+
const [invalid, setInvalid] = useState(false);
|
|
19
|
+
|
|
20
|
+
<form onSubmit={(e) => e.preventDefault()}>
|
|
21
|
+
<label htmlFor="country_code">Country code*</label>
|
|
22
|
+
{/* try replacing this element with an <input /> */}
|
|
23
|
+
<InputField
|
|
24
|
+
// try setting the prefix, suffix, and invalid props
|
|
25
|
+
type="text"
|
|
26
|
+
placeholder="Enter a country code..."
|
|
27
|
+
id="country_code"
|
|
28
|
+
name="country_code"
|
|
29
|
+
pattern="[A-Za-z]{3}"
|
|
30
|
+
onInvalid={setInvalid}
|
|
31
|
+
invalid={invalid}
|
|
32
|
+
onChange={() => setInvalid(false)}
|
|
33
|
+
title="Three letter country code"
|
|
34
|
+
required
|
|
35
|
+
/>
|
|
36
|
+
<input type="submit"/>
|
|
37
|
+
</form>
|
|
38
|
+
`}
|
|
39
|
+
providerProps={{
|
|
40
|
+
renderAsComponent: true,
|
|
41
|
+
scope: {
|
|
42
|
+
InputField,
|
|
43
|
+
},
|
|
44
|
+
}}
|
|
45
|
+
/>
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
export const InnerLabelExample = () => (
|
|
49
|
+
<Playground
|
|
50
|
+
code={`
|
|
51
|
+
<InputField
|
|
52
|
+
type="text"
|
|
53
|
+
label="Country Code"
|
|
54
|
+
placeholder="Enter a country code..."
|
|
55
|
+
/>
|
|
56
|
+
`}
|
|
57
|
+
providerProps={{
|
|
58
|
+
renderAsComponent: true,
|
|
59
|
+
scope: {
|
|
60
|
+
InputField,
|
|
61
|
+
},
|
|
62
|
+
}}
|
|
63
|
+
/>
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
export const ReactFormHookExample = () => (
|
|
67
|
+
<Playground
|
|
68
|
+
code={`
|
|
69
|
+
const { register, formState: { errors }, handleSubmit } = useForm();
|
|
70
|
+
const onSubmit = data => alert(data);
|
|
71
|
+
|
|
72
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
73
|
+
<InputField
|
|
74
|
+
label="First name"
|
|
75
|
+
invalid={errors.firstName}
|
|
76
|
+
required
|
|
77
|
+
{...register("firstName", { required: true, maxLength: 20 })}
|
|
78
|
+
/>
|
|
79
|
+
<InputField
|
|
80
|
+
label="Last name"
|
|
81
|
+
invalid={errors.lastName}
|
|
82
|
+
{...register("lastName", { pattern: /^[A-Za-z]+$/i })}
|
|
83
|
+
/>
|
|
84
|
+
<InputField
|
|
85
|
+
label="Age"
|
|
86
|
+
type="number"
|
|
87
|
+
invalid={errors.age}
|
|
88
|
+
{...register("age", { min: 18, max: 99 })}
|
|
89
|
+
/>
|
|
90
|
+
<input type="submit" />
|
|
91
|
+
</form>
|
|
92
|
+
`}
|
|
93
|
+
providerProps={{
|
|
94
|
+
renderAsComponent: true,
|
|
95
|
+
scope: {
|
|
96
|
+
InputField,
|
|
97
|
+
useForm,
|
|
98
|
+
},
|
|
99
|
+
}}
|
|
100
|
+
/>
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
export const SimpleInputExample = () => (
|
|
104
|
+
<Playground
|
|
105
|
+
code={`
|
|
106
|
+
const [state, setState] = useState({
|
|
107
|
+
firstName: '',
|
|
108
|
+
lastName: '',
|
|
109
|
+
age: 18
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const onChange = (change) => setState({
|
|
113
|
+
...state,
|
|
114
|
+
...change
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
<>
|
|
118
|
+
<InputText
|
|
119
|
+
label="First name"
|
|
120
|
+
value={state.firstName}
|
|
121
|
+
onChange={(firstName) => onChange({ firstName })}
|
|
122
|
+
/>
|
|
123
|
+
<InputText
|
|
124
|
+
label="Last name"
|
|
125
|
+
value={state.lastName}
|
|
126
|
+
onChange={(lastName) => onChange({ lastName })}
|
|
127
|
+
/>
|
|
128
|
+
<InputNumber
|
|
129
|
+
label="Age"
|
|
130
|
+
value={state.age}
|
|
131
|
+
onChange={(age) => onChange({ age })}
|
|
132
|
+
required
|
|
133
|
+
/>
|
|
134
|
+
</>
|
|
135
|
+
`}
|
|
136
|
+
providerProps={{
|
|
137
|
+
renderAsComponent: true,
|
|
138
|
+
scope: {
|
|
139
|
+
InputNumber,
|
|
140
|
+
InputText,
|
|
141
|
+
},
|
|
142
|
+
}}
|
|
143
|
+
/>
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
export const IconExample = () => (
|
|
147
|
+
<Playground
|
|
148
|
+
code={`
|
|
149
|
+
<InputField
|
|
150
|
+
label="Search"
|
|
151
|
+
type="text"
|
|
152
|
+
prefix="🍺"
|
|
153
|
+
>
|
|
154
|
+
<InputField.Icon>
|
|
155
|
+
<IconMinor.FolderOpen title="Icons render before the input" />
|
|
156
|
+
</InputField.Icon>
|
|
157
|
+
</InputField>
|
|
158
|
+
`}
|
|
159
|
+
providerProps={{
|
|
160
|
+
renderAsComponent: true,
|
|
161
|
+
scope: {
|
|
162
|
+
InputField,
|
|
163
|
+
IconMinor,
|
|
164
|
+
},
|
|
165
|
+
}}
|
|
166
|
+
/>
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
export const ControlsExample = () => (
|
|
170
|
+
<Playground
|
|
171
|
+
code={`
|
|
172
|
+
const [likes, setLikes] = useState(0);
|
|
173
|
+
|
|
174
|
+
const onLike = () => setLikes(likes + 1);
|
|
175
|
+
const onDislike = () => setLikes(Math.max(likes - 1, 0));
|
|
176
|
+
|
|
177
|
+
<InputField
|
|
178
|
+
label="Do you like this storybook?"
|
|
179
|
+
value={likes}
|
|
180
|
+
onChange={() => undefined}
|
|
181
|
+
type="number"
|
|
182
|
+
suffix="🍺"
|
|
183
|
+
>
|
|
184
|
+
<InputField.Controls>
|
|
185
|
+
<SpaceBetween>
|
|
186
|
+
<div onClick={onLike}>️👍</div>
|
|
187
|
+
<div>/</div>
|
|
188
|
+
<div onClick={onDislike}>👎️</div>
|
|
189
|
+
</SpaceBetween>
|
|
190
|
+
</InputField.Controls>
|
|
191
|
+
</InputField>
|
|
192
|
+
`}
|
|
193
|
+
providerProps={{
|
|
194
|
+
renderAsComponent: true,
|
|
195
|
+
scope: {
|
|
196
|
+
InputField,
|
|
197
|
+
IconMinor,
|
|
198
|
+
styled,
|
|
199
|
+
SpaceBetween,
|
|
200
|
+
},
|
|
201
|
+
}}
|
|
202
|
+
/>
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
export const OuterLabelExample = () => (
|
|
206
|
+
<Playground
|
|
207
|
+
code={`
|
|
208
|
+
const [value, setValue] = useState('');
|
|
209
|
+
const [errors, setErrors] = useState([]);
|
|
210
|
+
|
|
211
|
+
const handleChange = (change: string) => {
|
|
212
|
+
const errors = [];
|
|
213
|
+
|
|
214
|
+
if (!change) {
|
|
215
|
+
errors.push({ message: 'This field is required' });
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (!change.match(/[A-Za-z]{3}/)) {
|
|
219
|
+
errors.push({ message: 'Input was not a 3 letter country code' });
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
setValue(change);
|
|
223
|
+
setErrors(errors);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
<InputText.Label
|
|
227
|
+
label="Country Code"
|
|
228
|
+
helpText="Please enter a 3 letter country code"
|
|
229
|
+
errors={errors}
|
|
230
|
+
>
|
|
231
|
+
<InputText
|
|
232
|
+
value={value}
|
|
233
|
+
invalid={errors.length > 0}
|
|
234
|
+
placeholder="e.g. AUD"
|
|
235
|
+
onChange={handleChange}
|
|
236
|
+
/>
|
|
237
|
+
</InputText.Label>
|
|
238
|
+
`}
|
|
239
|
+
providerProps={{
|
|
240
|
+
renderAsComponent: true,
|
|
241
|
+
scope: {
|
|
242
|
+
InputText,
|
|
243
|
+
IconMinor,
|
|
244
|
+
},
|
|
245
|
+
}}
|
|
246
|
+
/>
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
export const StepperExample = () => (
|
|
250
|
+
<Playground
|
|
251
|
+
code={`
|
|
252
|
+
const [age, setAge] = useState(0);
|
|
253
|
+
const onUp = () => setAge(Math.min(age + 1, 99));
|
|
254
|
+
const onDown = () => setAge(Math.max(age - 1, 0));
|
|
255
|
+
const errors = []
|
|
256
|
+
|
|
257
|
+
if (0 > age || age > 100) {
|
|
258
|
+
errors.push({ message: 'Please choose an age between 0 and 99' })
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
<form onSubmit={(e) => e.preventDefault()}>
|
|
262
|
+
<InputNumber.Label
|
|
263
|
+
helpText='Age should be a number between 0 and 99'
|
|
264
|
+
errors={errors}
|
|
265
|
+
>
|
|
266
|
+
<InputNumber
|
|
267
|
+
label='Age'
|
|
268
|
+
onChange={setAge}
|
|
269
|
+
value={age}
|
|
270
|
+
invalid={errors.length > 0}
|
|
271
|
+
placeholder="Enter your age..."
|
|
272
|
+
>
|
|
273
|
+
<InputNumber.Controls>
|
|
274
|
+
<InputNumber.Stepper onUpClick={onUp} onDownClick={onDown} />
|
|
275
|
+
</InputNumber.Controls>
|
|
276
|
+
</InputNumber>
|
|
277
|
+
</InputNumber.Label>
|
|
278
|
+
<input type="submit"/>
|
|
279
|
+
</form>
|
|
280
|
+
`}
|
|
281
|
+
providerProps={{
|
|
282
|
+
renderAsComponent: true,
|
|
283
|
+
scope: {
|
|
284
|
+
InputNumber,
|
|
285
|
+
styled,
|
|
286
|
+
},
|
|
287
|
+
}}
|
|
288
|
+
/>
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
export const AllDressedExample = () => (
|
|
292
|
+
<Playground
|
|
293
|
+
code={`
|
|
294
|
+
<InputField.Label
|
|
295
|
+
label='Price'
|
|
296
|
+
helpText='Enter a price in AUD'
|
|
297
|
+
errors={[{ message: 'Too many UI decorations!' }]}
|
|
298
|
+
>
|
|
299
|
+
<InputField
|
|
300
|
+
type="number"
|
|
301
|
+
label='Price'
|
|
302
|
+
// prefix and suffix render immediately
|
|
303
|
+
// before and after the input field
|
|
304
|
+
prefix="$"
|
|
305
|
+
suffix="AUD"
|
|
306
|
+
step={0.01}
|
|
307
|
+
min={0.00}
|
|
308
|
+
placeholder="Enter an amount..."
|
|
309
|
+
>
|
|
310
|
+
<InputField.Icon>
|
|
311
|
+
<IconMinor.CircleDollar title="Icons render before the input" />
|
|
312
|
+
</InputField.Icon>
|
|
313
|
+
<InputField.Controls>
|
|
314
|
+
<IconMinor.CircleDollar title="Controls render after the input" />
|
|
315
|
+
</InputField.Controls>
|
|
316
|
+
</InputField>
|
|
317
|
+
</InputField.Label>
|
|
318
|
+
`}
|
|
319
|
+
providerProps={{
|
|
320
|
+
renderAsComponent: true,
|
|
321
|
+
scope: {
|
|
322
|
+
InputField,
|
|
323
|
+
IconMinor,
|
|
324
|
+
},
|
|
325
|
+
}}
|
|
326
|
+
/>
|
|
327
|
+
)
|