@edvisor/product-language 0.2.0 → 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.
Files changed (94) hide show
  1. package/.eslintrc.json +14 -6
  2. package/package.json +2 -3
  3. package/project.json +18 -7
  4. package/src/README.md +61 -0
  5. package/src/helpers/index.ts +2 -1
  6. package/src/helpers/playground.ts +16 -0
  7. package/src/lib/components/badge/badge.tsx +8 -17
  8. package/src/lib/components/badge/stories/badge.stories.mdx +44 -0
  9. package/src/lib/components/badge/stories/components.tsx +49 -0
  10. package/src/lib/components/card/card.test.tsx +4 -5
  11. package/src/lib/components/card/card.tsx +2 -2
  12. package/src/lib/components/card/components/card-section-slot.tsx +2 -2
  13. package/src/lib/components/card/storybook/card.stories.mdx +1 -1
  14. package/src/lib/components/card/storybook/components.tsx +6 -23
  15. package/src/lib/components/checkbox/checkbox.tsx +34 -95
  16. package/src/lib/components/checkbox/helpers.tsx +100 -0
  17. package/src/lib/components/checkbox/stories/checkbox.stories.mdx +27 -24
  18. package/src/lib/components/checkbox/stories/components.tsx +63 -15
  19. package/src/lib/components/divider/stories/divider.stories.mdx +7 -13
  20. package/src/lib/components/flag/flag-size-flags.tsx +55 -0
  21. package/src/lib/components/flag/flag.list.tsx +788 -0
  22. package/src/lib/components/flag/flag.test.tsx +65 -0
  23. package/src/lib/components/flag/flag.tsx +97 -0
  24. package/src/lib/components/flag/index.tsx +1 -0
  25. package/src/lib/components/flag/stories/components.tsx +403 -0
  26. package/src/lib/components/flag/stories/flag.stories.mdx +48 -0
  27. package/src/lib/components/flag/stories/playGround-select.tsx +145 -0
  28. package/src/lib/components/icon/icon-list.tsx +135 -0
  29. package/src/lib/components/icon/icon.test.tsx +48 -0
  30. package/src/lib/components/icon/icon.tsx +181 -0
  31. package/src/lib/components/icon/index.tsx +1 -0
  32. package/src/lib/components/icon/stories/components.tsx +282 -0
  33. package/src/lib/components/icon/stories/icon.stories.mdx +65 -0
  34. package/src/lib/components/index.ts +5 -0
  35. package/src/lib/components/input-field/components/labeled-input.tsx +7 -14
  36. package/src/lib/components/input-field/components/stepper.tsx +4 -3
  37. package/src/lib/components/input-field/input-field.test.tsx +5 -6
  38. package/src/lib/components/input-field/input-field.tsx +8 -8
  39. package/src/lib/components/input-field/storybook/components.tsx +9 -16
  40. package/src/lib/components/link/storybook/link.stories.mdx +1 -0
  41. package/src/lib/components/molecules/avatar/avatar-size-flags.tsx +3 -3
  42. package/src/lib/components/molecules/avatar/avatar.tsx +2 -2
  43. package/src/lib/components/molecules/avatar/stories/avatar.stories.mdx +18 -21
  44. package/src/lib/components/molecules/button/button-flags.tsx +120 -15
  45. package/src/lib/components/molecules/button/button.test.tsx +9 -9
  46. package/src/lib/components/molecules/button/button.tsx +61 -78
  47. package/src/lib/components/molecules/button/stories/button.stories.mdx +43 -42
  48. package/src/lib/components/molecules/button/stories/components.tsx +6 -8
  49. package/src/lib/components/molecules/input-checkbox/input-checkbox.tsx +23 -24
  50. package/src/lib/components/molecules/input-checkbox/stories/components.tsx +32 -15
  51. package/src/lib/components/molecules/input-checkbox/stories/input-checkbox.stories.mdx +6 -8
  52. package/src/lib/components/organisms/multi-choice-list/multi-choice-list.tsx +7 -8
  53. package/src/lib/components/organisms/multi-choice-list/stories/components.tsx +3 -5
  54. package/src/lib/components/organisms/multi-choice-list/stories/multi-choice-list.stories.mdx +4 -4
  55. package/src/lib/components/spinner/spinner.test.tsx +2 -2
  56. package/src/lib/components/spinner/spinner.tsx +15 -28
  57. package/src/lib/components/spinner/stories/components.tsx +33 -2
  58. package/src/lib/components/spinner/stories/spinner.stories.mdx +3 -10
  59. package/src/lib/components/tabs/components/index.ts +1 -0
  60. package/src/lib/components/tabs/components/tab.tsx +62 -0
  61. package/src/lib/components/tabs/index.tsx +1 -0
  62. package/src/lib/components/tabs/storybook/components.tsx +282 -0
  63. package/src/lib/components/tabs/storybook/tabs.stories.mdx +97 -0
  64. package/src/lib/components/tabs/tabs.test.tsx +86 -0
  65. package/src/lib/components/tabs/tabs.tsx +101 -0
  66. package/src/lib/components/tag/components/close-button.tsx +85 -0
  67. package/src/lib/components/tag/components/index.ts +2 -0
  68. package/src/lib/components/tag/components/tag-label.tsx +44 -0
  69. package/src/lib/components/tag/index.tsx +1 -0
  70. package/src/lib/components/tag/stories/components.tsx +86 -0
  71. package/src/lib/components/tag/stories/tag.stories.mdx +42 -0
  72. package/src/lib/components/tag/tag.test.tsx +36 -0
  73. package/src/lib/components/tag/tag.tsx +33 -0
  74. package/src/lib/components/thumbnail/thumbnail.tsx +7 -2
  75. package/src/lib/components/typography/storybook/components.tsx +47 -15
  76. package/src/lib/components/typography/storybook/typography.stories.mdx +6 -4
  77. package/src/lib/components/typography/typography.test.tsx +34 -30
  78. package/src/lib/components/typography/typography.tsx +61 -19
  79. package/src/lib/foundations/color-system/base-palette/base-palette.ts +0 -1
  80. package/src/lib/foundations/color-system/color-guidelines/color-guidelines.ts +5 -4
  81. package/src/lib/foundations/color-system/components/color-sample.tsx +3 -3
  82. package/src/lib/foundations/typography/fonts.ts +205 -0
  83. package/src/lib/foundations/typography/text-aspect-flags.ts +11 -4
  84. package/src/lib/foundations/typography/typography.tsx +38 -33
  85. package/src/lib/helpers/numbers.ts +14 -0
  86. package/src/lib/helpers/safe-navigation.ts +10 -0
  87. package/src/lib/helpers/slots.test.tsx +98 -0
  88. package/src/lib/helpers/slots.tsx +93 -12
  89. package/.storybook/preview-head.html +0 -1
  90. package/src/lib/components/badge/badge.stories.tsx +0 -16
  91. package/src/lib/components/checkbox/components/components.tsx +0 -59
  92. package/src/lib/components/checkbox/stories/index.tsx +0 -1
  93. package/src/lib/components/molecules/input-checkbox/stories/index.tsx +0 -1
  94. package/src/lib/components/organisms/multi-choice-list/stories/index.tsx +0 -1
@@ -1,25 +1,30 @@
1
1
  import styled from 'styled-components'
2
- import { FC, is, isDefined } from '@helpers'
2
+ import { FC, is, isDefined, Nothing } from '@helpers'
3
3
  import { Focused } from '@foundations'
4
4
  import {
5
5
  ButtonSizeProps,
6
6
  getBackgroundColorByType,
7
7
  getIsDisabled,
8
8
  getTextColorByType,
9
+ getIconColorByType,
9
10
  getTextColorIfDisabled,
10
11
  getCursor,
11
12
  getPaddingBySize,
12
13
  getBackgroundColorHoverByType,
14
+ getTextDecorationHoverByType,
13
15
  getTextColorOnHoverByType,
16
+ getIconColorOnHoverByType,
14
17
  getBorderByType,
15
18
  getPaddingByType,
16
19
  getBackgroundColorDisabledByType,
17
20
  getBorderDisabledByType,
18
21
  ButtonType,
19
22
  getBackgroundColorPressedByType,
23
+ getButtonType,
24
+ ButtonTypeProps,
20
25
  } from './button-flags'
21
26
  import { ComponentType } from 'react'
22
- import { Label1 } from 'components/typography'
27
+ import { Label } from 'components/typography'
23
28
  import { Spinner } from 'components/spinner'
24
29
 
25
30
  const ButtonFrame = styled.button<{
@@ -27,10 +32,13 @@ const ButtonFrame = styled.button<{
27
32
  buttonSize: string
28
33
  cursor: string
29
34
  backgroundHover: string
35
+ textDecorationHover: string,
30
36
  backgroundPressed: string
31
37
  textColorHover: string
32
38
  buttonBorder: string
33
39
  isDisabled: boolean
40
+ iconColor: string
41
+ iconColorHover: string
34
42
  }>`
35
43
  padding: ${(props) => props.buttonSize};
36
44
  border: ${(props) => props.buttonBorder};
@@ -43,16 +51,27 @@ const ButtonFrame = styled.button<{
43
51
  gap: 8px;
44
52
  align-items: center;
45
53
  position: relative;
54
+ svg[role='icon'] {
55
+ path {
56
+ fill: ${(props) => props.iconColor};
57
+ }
58
+ }
59
+
46
60
 
47
61
  ${(props) =>
48
62
  !props.isDisabled
49
63
  ? `
50
64
  &:hover {
51
65
  background: ${props.backgroundHover};
52
-
66
+ text-decoration: ${props.textDecorationHover};
53
67
  div {
54
68
  color: ${props.textColorHover};
55
69
  }
70
+ svg[role='icon'] {
71
+ path {
72
+ fill: ${props.iconColorHover};
73
+ }
74
+ }
56
75
  }
57
76
 
58
77
  &:focus {
@@ -64,17 +83,14 @@ const ButtonFrame = styled.button<{
64
83
  }
65
84
 
66
85
  &:active {
86
+ text-decoration: 'none'
67
87
  background: ${props.backgroundPressed}
68
88
  }
69
89
  `
70
90
  : ''}
71
91
  `
72
92
 
73
- const ButtonText = styled(Label1)<{
74
- textColor: string
75
- textColorDisabled: string
76
- isLoading: boolean
77
- }>`
93
+ const ButtonText = styled(Label)<{ textColor: string, textColorDisabled: string, isLoading: boolean }>`
78
94
  color: ${(props) =>
79
95
  props.textColorDisabled !== '' ? props.textColorDisabled : props.textColor};
80
96
 
@@ -86,37 +102,29 @@ const ButtonText = styled(Label1)<{
86
102
  : ''}
87
103
  `
88
104
 
89
- const Loading = styled(Spinner)`
90
- position: absolute;
105
+ const IconContainer = styled.div<{ isLoading: boolean }>`
106
+ width: 20px;
107
+ ${(props) =>
108
+ props.isLoading
109
+ ? 'visibility: hidden;'
110
+ : ''
111
+ }
91
112
  `
92
113
 
93
- interface DummyIconProps {
94
- type: ButtonType
95
- }
114
+ const Loading = styled(Spinner)`
115
+ position: absolute;
116
+ `
96
117
 
97
- interface IButtonProps {
118
+ interface IButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
98
119
  loading?: boolean
99
- IconPrefix?: ComponentType<DummyIconProps>
100
- IconSuffix?: ComponentType<DummyIconProps>
120
+ IconPrefix?: ComponentType
121
+ IconSuffix?: ComponentType
101
122
  children?: string
102
- }
103
-
104
- interface IButtonDestructiveProps extends IButtonProps {
105
- primary?: boolean
106
- }
107
-
108
- interface IButtonPlainProps extends IButtonProps {
109
123
  subtle?: boolean
110
124
  }
111
125
 
112
- interface ISecretInnerButtonProps
113
- extends IButtonPlainProps,
114
- IButtonDestructiveProps {
115
- buttonType: ButtonType
116
- }
117
-
118
- function makeButtonConfig(props: ISecretInnerButtonProps & ButtonSizeProps) {
119
- const { buttonType } = props
126
+ function makeButtonConfig(props: IButtonProps & ButtonTypeProps & ButtonSizeProps) {
127
+ const buttonType = getButtonType(props)
120
128
  const isDisabled = getIsDisabled(props)
121
129
  const backgroundColor = isDisabled
122
130
  ? getBackgroundColorDisabledByType(buttonType)
@@ -125,14 +133,17 @@ function makeButtonConfig(props: ISecretInnerButtonProps & ButtonSizeProps) {
125
133
  const buttonOverridePadding = getPaddingByType(buttonType)
126
134
  const cursor = getCursor(props)
127
135
  const backgroundHover = getBackgroundColorHoverByType(buttonType)
136
+ const textDecorationHover = getTextDecorationHoverByType(buttonType)
128
137
  const backgroundPressed = getBackgroundColorPressedByType(buttonType)
129
138
  const textColorHover = getTextColorOnHoverByType(buttonType)
139
+ const iconColorHover = getIconColorOnHoverByType(buttonType)
130
140
  const buttonBorder = isDisabled
131
141
  ? getBorderDisabledByType(buttonType)
132
142
  : getBorderByType(buttonType)
133
143
  const buttonSize =
134
144
  buttonOverridePadding !== '' ? buttonOverridePadding : buttonPadding
135
145
  const textColor = getTextColorByType(buttonType)
146
+ const iconColor = getIconColorByType(buttonType)
136
147
  const textColorDisabled = getTextColorIfDisabled(props)
137
148
 
138
149
  return {
@@ -140,33 +151,39 @@ function makeButtonConfig(props: ISecretInnerButtonProps & ButtonSizeProps) {
140
151
  buttonSize,
141
152
  cursor,
142
153
  backgroundHover,
154
+ textDecorationHover,
143
155
  backgroundPressed,
144
156
  textColorHover,
157
+ iconColorHover,
145
158
  buttonBorder,
146
159
  isDisabled,
147
160
  textColor,
161
+ iconColor,
148
162
  textColorDisabled,
163
+ buttonType,
149
164
  }
150
165
  }
151
166
 
152
- const SecretInnerButton: FC<ISecretInnerButtonProps & ButtonSizeProps> = (
167
+ export const Button: FC<IButtonProps & ButtonTypeProps & ButtonSizeProps> = (
153
168
  props
154
169
  ) => {
155
170
  const {
156
171
  children,
157
- buttonType,
158
172
  loading,
159
173
  IconPrefix,
160
174
  IconSuffix,
175
+ type = 'button',
161
176
  ...htmlProps
162
177
  } = props
163
- const { textColor, textColorDisabled, ...buttonConfig } =
178
+ const { textColor, textColorDisabled, buttonType, ...buttonConfig } =
164
179
  makeButtonConfig(props)
165
-
166
180
  return (
167
- <ButtonFrame {...htmlProps} {...buttonConfig} data-testid="button-test">
168
- {isDefined(IconPrefix) ? <IconPrefix type={buttonType} /> : ''}
169
-
181
+ <ButtonFrame {...htmlProps} type={type} {...buttonConfig} data-testid="button-test">
182
+ {isDefined(IconPrefix) ? (
183
+ <IconContainer isLoading={is(loading)}>
184
+ <IconPrefix />
185
+ </IconContainer>
186
+ ) : <Nothing />}
170
187
  <ButtonText
171
188
  textColor={textColor}
172
189
  textColorDisabled={textColorDisabled}
@@ -179,53 +196,19 @@ const SecretInnerButton: FC<ISecretInnerButtonProps & ButtonSizeProps> = (
179
196
  small
180
197
  onPrimary={
181
198
  buttonType === ButtonType.primary ||
182
- buttonType === ButtonType.primaryDestructive
199
+ buttonType === ButtonType.destructivePrimary
183
200
  }
184
201
  />
185
202
  ) : (
186
203
  ''
187
204
  )}
188
205
 
189
- {isDefined(IconSuffix) ? <IconSuffix type={buttonType} /> : ''}
206
+ {isDefined(IconSuffix) ? (
207
+ <IconContainer isLoading={is(loading)}>
208
+ <IconSuffix />
209
+ </IconContainer>
210
+ ) : <Nothing />}
190
211
  </ButtonFrame>
191
212
  )
192
213
  }
193
214
 
194
- export const ButtonBasic: FC<IButtonProps> = (props) => {
195
- return <SecretInnerButton buttonType={ButtonType.basic} {...props} />
196
- }
197
-
198
- export const ButtonPrimary: FC<IButtonProps> = (props) => {
199
- return <SecretInnerButton buttonType={ButtonType.primary} {...props} />
200
- }
201
-
202
- export const ButtonDestructive: FC<IButtonDestructiveProps> = (props) => {
203
- const { primary } = props
204
- return (
205
- <SecretInnerButton
206
- buttonType={
207
- isDefined(primary) && primary
208
- ? ButtonType.primaryDestructive
209
- : ButtonType.destructive
210
- }
211
- {...props}
212
- />
213
- )
214
- }
215
-
216
- export const ButtonOutline: FC<IButtonProps> = (props) => {
217
- return <SecretInnerButton buttonType={ButtonType.outline} {...props} />
218
- }
219
-
220
- export const ButtonPlain: FC<IButtonPlainProps> = (props) => {
221
- const { subtle } = props
222
-
223
- return (
224
- <SecretInnerButton
225
- buttonType={
226
- isDefined(subtle) && subtle ? ButtonType.plainSubtle : ButtonType.plain
227
- }
228
- {...props}
229
- />
230
- )
231
- }
@@ -1,10 +1,11 @@
1
1
  import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';
2
- import { ButtonPrimary, ButtonBasic, ButtonDestructive, ButtonOutline, ButtonPlain, DummyIcon } from '../index'
2
+ import { Button } from '../index'
3
+ import { IconMinor } from 'components/icon'
3
4
  import { PlainHTMLFormExample, DisabledLoadingExample } from './components'
4
5
 
5
6
  <Meta
6
7
  title="Components/Button"
7
- component={ButtonPrimary}
8
+ component={Button}
8
9
  />
9
10
 
10
11
  # Button
@@ -15,11 +16,11 @@ For more details, check out the component page on [Figma](https://www.figma.com/
15
16
 
16
17
  ```javascript
17
18
  // Import the component
18
- import { ButtonPrimary } from './index'
19
+ import { Button } from './index'
19
20
 
20
21
 
21
22
  // Render the component sending the required parameters
22
- <ButtonPrimary label="SOME-label-HERE" />
23
+ <Button primary label="SOME-label-HERE" />
23
24
  ```
24
25
 
25
26
  ## Properties
@@ -44,61 +45,61 @@ The available optional properties are as follows, try them out in the editable c
44
45
  ## Examples
45
46
 
46
47
  <Canvas>
47
- <ButtonBasic type="submit">Basic</ButtonBasic>
48
- <ButtonPrimary>Primary</ButtonPrimary>
49
- <ButtonDestructive>Destructive</ButtonDestructive>
50
- <ButtonDestructive primary>Primary Destructive</ButtonDestructive>
51
- <ButtonOutline>Outline</ButtonOutline>
52
- <ButtonPlain>Plain</ButtonPlain>
53
- <ButtonPlain subtle >Plain Subtle</ButtonPlain>
48
+ <Button type="submit">Basic</Button>
49
+ <Button primary>Primary</Button>
50
+ <Button destructive>Destructive</Button>
51
+ <Button destructive primary>Destructive Primary</Button>
52
+ <Button outline>Outline</Button>
53
+ <Button plain>Plain</Button>
54
+ <Button plain subtle >Plain Subtle</Button>
54
55
  </Canvas>
55
56
 
56
57
  Disabled
57
58
  <Canvas>
58
- <ButtonBasic disabled>Basic</ButtonBasic>
59
- <ButtonPrimary disabled>Primary</ButtonPrimary>
60
- <ButtonDestructive disabled>Destructive</ButtonDestructive>
61
- <ButtonDestructive primary disabled>Primary Destructive</ButtonDestructive>
62
- <ButtonOutline disabled>Outline</ButtonOutline>
63
- <ButtonPlain disabled>Plain</ButtonPlain>
64
- <ButtonPlain subtle disabled>Plain Subtle</ButtonPlain>
59
+ <Button disabled>Basic</Button>
60
+ <Button primary disabled>Primary</Button>
61
+ <Button destructive disabled>Destructive</Button>
62
+ <Button destructive primary disabled>Destructive Primary</Button>
63
+ <Button outline disabled>Outline</Button>
64
+ <Button plain disabled>Plain</Button>
65
+ <Button plain subtle disabled>Plain Subtle</Button>
65
66
  </Canvas>
66
67
 
67
68
  Loading
68
69
  <Canvas>
69
- <ButtonBasic loading>Basic</ButtonBasic>
70
- <ButtonPrimary loading>Primary</ButtonPrimary>
71
- <ButtonDestructive loading>Destructive</ButtonDestructive>
72
- <ButtonDestructive primary loading>Primary Destructive</ButtonDestructive>
73
- <ButtonOutline loading>Outline</ButtonOutline>
74
- <ButtonPlain loading>Plain</ButtonPlain>
75
- <ButtonPlain subtle loading>Plain Subtle</ButtonPlain>
70
+ <Button loading>Basic</Button>
71
+ <Button primary loading>Primary</Button>
72
+ <Button destructive loading>Destructive</Button>
73
+ <Button destructive primary loading>Destructive Primary</Button>
74
+ <Button outline loading>Outline</Button>
75
+ <Button plain loading>Plain</Button>
76
+ <Button plain subtle loading>Plain Subtle</Button>
76
77
  </Canvas>
77
78
 
78
79
  Icons
79
80
  <Canvas>
80
- <ButtonBasic IconPrefix={DummyIcon}>Basic</ButtonBasic>
81
- <ButtonPrimary IconPrefix={DummyIcon}>Primary</ButtonPrimary>
82
- <ButtonDestructive IconPrefix={DummyIcon}>Destructive</ButtonDestructive>
83
- <ButtonDestructive primary IconPrefix={DummyIcon}>Primary Destructive</ButtonDestructive>
84
- <ButtonOutline IconPrefix={DummyIcon}>Outline</ButtonOutline>
85
- <ButtonPlain IconPrefix={DummyIcon}>Plain</ButtonPlain>
86
- <ButtonPlain subtle IconPrefix={DummyIcon}>Plain Subtle</ButtonPlain>
81
+ <Button IconPrefix={IconMinor.Fire}>Basic</Button>
82
+ <Button primary IconPrefix={IconMinor.Fire}>Primary</Button>
83
+ <Button destructive IconPrefix={IconMinor.Fire}>Destructive</Button>
84
+ <Button destructive primary IconPrefix={IconMinor.Fire}>Destructive Primary</Button>
85
+ <Button outline IconPrefix={IconMinor.Fire}>Outline</Button>
86
+ <Button plain IconPrefix={IconMinor.Fire}>Plain</Button>
87
+ <Button plain subtle IconPrefix={IconMinor.Fire}>Plain Subtle</Button>
87
88
  </Canvas>
88
89
 
89
90
  <Canvas>
90
- <ButtonBasic IconSuffix={DummyIcon}>Basic</ButtonBasic>
91
- <ButtonPrimary IconSuffix={DummyIcon}>Primary</ButtonPrimary>
92
- <ButtonDestructive IconSuffix={DummyIcon}>Destructive</ButtonDestructive>
93
- <ButtonDestructive primary IconSuffix={DummyIcon}>Primary Destructive</ButtonDestructive>
94
- <ButtonOutline IconSuffix={DummyIcon}>Outline</ButtonOutline>
95
- <ButtonPlain IconSuffix={DummyIcon}>Plain</ButtonPlain>
96
- <ButtonPlain subtle IconSuffix={DummyIcon}>Plain Subtle</ButtonPlain>
91
+ <Button IconSuffix={IconMinor.Fire}>Basic</Button>
92
+ <Button primary IconSuffix={IconMinor.Fire}>Primary</Button>
93
+ <Button destructive IconSuffix={IconMinor.Fire}>Destructive</Button>
94
+ <Button destructive primary IconSuffix={IconMinor.Fire}>Destructive Primary</Button>
95
+ <Button outline IconSuffix={IconMinor.Fire}>Outline</Button>
96
+ <Button plain IconSuffix={IconMinor.Fire}>Plain</Button>
97
+ <Button plain subtle IconSuffix={IconMinor.Fire}>Plain Subtle</Button>
97
98
  </Canvas>
98
99
 
99
100
  <Canvas>
100
- <ButtonBasic large>Large</ButtonBasic>
101
- <ButtonBasic>Default</ButtonBasic>
102
- <ButtonBasic small>Small</ButtonBasic>
101
+ <Button large>Large</Button>
102
+ <Button>Default</Button>
103
+ <Button small>Small</Button>
103
104
  </Canvas>
104
105
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  import { Playground } from 'storybook-addon-jarle-monaco'
3
3
  import { InputField } from '../../../input-field'
4
- import { Button, ButtonPrimary } from '../button'
4
+ import { Button } from '../button'
5
5
 
6
6
  export const PlainHTMLFormExample = () => (
7
7
  <Playground
@@ -24,8 +24,8 @@ const [invalid, setInvalid] = useState(false);
24
24
  required
25
25
  />
26
26
  <div style={{display:'flex', gap:'8px'}}>
27
- <ButtonBasic type="reset">Clear</ButtonBasic>
28
- <ButtonPrimary type="submit">Send</ButtonPrimary>
27
+ <Button type="reset">Clear</Button>
28
+ <Button primary type="submit">Send</Button>
29
29
  </div>
30
30
  </form>
31
31
  `}
@@ -33,8 +33,7 @@ const [invalid, setInvalid] = useState(false);
33
33
  renderAsComponent: true,
34
34
  scope: {
35
35
  InputField,
36
- ButtonBasic: Button,
37
- ButtonPrimary
36
+ Button
38
37
  },
39
38
  }}
40
39
  />
@@ -70,7 +69,7 @@ const [loading, setLoading] = useState(false);
70
69
  required
71
70
  />
72
71
  <div style={{display:'flex', gap:'8px'}}>
73
- <ButtonPrimary type="submit" disabled={disabled} loading={loading}>Send</ButtonPrimary>
72
+ <Button primary type="submit" disabled={disabled} loading={loading}>Send</Button>
74
73
  </div>
75
74
  </form>
76
75
  `}
@@ -78,8 +77,7 @@ const [loading, setLoading] = useState(false);
78
77
  renderAsComponent: true,
79
78
  scope: {
80
79
  InputField,
81
- ButtonBasic: Button,
82
- ButtonPrimary
80
+ Button
83
81
  },
84
82
  }}
85
83
  />
@@ -1,48 +1,47 @@
1
- import { useState } from 'react'
1
+ import { InputHTMLAttributes } from 'react'
2
2
  import styled from 'styled-components'
3
3
  import { FC, isDefined, isEmpty, Nothing } from '@helpers'
4
4
  import { Margin } from '@foundations'
5
- import { Checkbox, ICheckboxProps } from '../../checkbox'
6
- import { Label1 } from 'components/typography'
7
- import { Flex } from 'components/layout'
5
+ import { Checkbox } from '../../checkbox'
6
+ import { Label } from 'components/typography'
8
7
 
9
- const Text = styled(Label1)`
10
- margin-left: ${Margin.s};
8
+ const Text = styled(Label)`
9
+ margin-left: ${Margin.xs};
11
10
  user-select: none;
12
11
  `
13
- const Wrapper = styled(Flex)`
12
+
13
+ const Wrapper = styled.label`
14
+ display: flex;
14
15
  width: 100%;
15
16
  align-items: center;
16
17
  `
17
- interface IInputCheckboxProps {
18
+
19
+ export type IInputCheckboxProps = InputHTMLAttributes<HTMLInputElement> & {
18
20
  label: string
21
+ error?: boolean
22
+ onChange?: (change: boolean) => void
19
23
  }
20
24
 
21
- export type IInputCheckbox = IInputCheckboxProps & ICheckboxProps
25
+ export const InputCheckbox: FC<IInputCheckboxProps> = (props) => {
26
+ const {
27
+ onChange,
28
+ label = '',
29
+ } = props
22
30
 
23
- export const InputCheckbox: FC<IInputCheckbox> = (props) => {
24
- const { onChange, label = '', disabled = false, error = false, checked = false } = props
25
- const [isChecked, setIsChecked] = useState(checked)
26
31
  if (isEmpty(label)) {
27
32
  return <Nothing />
28
33
  }
29
34
 
30
- const handleOnChange = () => {
31
- setIsChecked(!isChecked)
32
- if(isDefined(onChange)){
33
- onChange(!isChecked)
34
- }
35
- }
36
-
37
35
  return (
38
36
  <Wrapper>
39
37
  <Checkbox
40
38
  {...props}
41
- onChange={handleOnChange}
42
- onClick={handleOnChange}
43
- disabled={disabled}
44
- error={error}
45
- checked={isChecked}
39
+ onChange={(e) => {
40
+ if (isDefined(onChange)) {
41
+ onChange(e.target.checked)
42
+ }
43
+ }}
44
+ name={isDefined(props.name) ? props.name : label}
46
45
  />
47
46
  <Text>{label}</Text>
48
47
  </Wrapper>
@@ -1,36 +1,53 @@
1
1
  import { Playground } from 'storybook-addon-jarle-monaco'
2
- import { InputCheckbox } from '../index'
2
+ import styled from 'styled-components'
3
+ import { Margin } from '@foundations'
4
+ import { If } from '@helpers'
5
+ import { Button } from 'components/molecules/button'
6
+ import { Caption } from 'components/typography'
7
+ import { InputCheckbox } from '../input-checkbox'
3
8
 
4
- export const PlainHTMLFormExample = () => (
9
+ const Fields = styled.div`
10
+ margin-bottom: ${Margin.s};
11
+ `
12
+
13
+ export const InputCheckboxExample = () => (
5
14
  <Playground
6
15
  code={`
7
16
  /* Edit this code sample! */
8
17
  const [withError, setWithError] = useState(false);
18
+ const [accepted, setAccepted] = useState(false);
9
19
 
10
20
  <form onSubmit={(e) => {
11
21
  e.preventDefault()
12
- console.log('form submitted')
13
22
  }}
14
23
  >
15
- <InputCheckbox
16
- onInvalid={(e) => {
17
- setWithError(true)
18
- }}
19
- error={withError}
20
- onChange={(e) => {
21
- console.log('at stories', e)
22
- setWithError(false)
23
- }}
24
- label="My label"
25
- required />
26
- <input type="submit"/>
24
+ <Fields>
25
+ <InputCheckbox
26
+ onInvalid={(e) => {
27
+ setWithError(true)
28
+ }}
29
+ error={withError}
30
+ onChange={(e) => {
31
+ setAccepted(!accepted)
32
+ setWithError(false)
33
+ }}
34
+ label="I accept the terms."
35
+ required />
36
+ <If is={accepted}><Caption subdued>You have accepted the terms.</Caption></If>
37
+ </Fields>
38
+ <Button primary type="submit">Submit</Button>
27
39
  </form>
28
40
  `}
29
41
  providerProps={{
30
42
  renderAsComponent: true,
31
43
  scope: {
32
44
  InputCheckbox,
45
+ Caption,
46
+ Button,
47
+ If,
48
+ Fields,
33
49
  },
34
50
  }}
35
51
  />
36
52
  )
53
+
@@ -1,6 +1,6 @@
1
1
  import { Canvas, Meta, Story } from '@storybook/addon-docs';
2
- import { InputCheckbox } from '../index'
3
- import { PlainHTMLFormExample } from './index'
2
+ import { InputCheckbox } from '../input-checkbox'
3
+ import { InputCheckboxExample } from './components'
4
4
 
5
5
  <Meta
6
6
  title="Components/InputCheckbox"
@@ -27,11 +27,9 @@ import { InputCheckbox } from './index'
27
27
  ## Examples
28
28
 
29
29
  <Canvas>
30
- <InputCheckbox label="My label" onChange={(e) => console.log('at stories', e)} />
31
- <InputCheckbox label="My label" disabled />
32
- <InputCheckbox label="My label" error />
33
- <InputCheckbox label="My label" checked />
34
- <InputCheckbox label="My label" error checked />
30
+ <InputCheckbox label="Burger" />
31
+ <InputCheckbox label="Fries" disabled />
32
+ <InputCheckbox label="Drink" error />
35
33
  </Canvas>
36
34
 
37
35
 
@@ -48,4 +46,4 @@ Also, you can sen this parameters:
48
46
 
49
47
  ## Playground
50
48
 
51
- <PlainHTMLFormExample />
49
+ <InputCheckboxExample />
@@ -1,14 +1,13 @@
1
1
  import styled from 'styled-components'
2
2
  import { FC, isDefined, isEmpty, Nothing } from '@helpers'
3
- import { Text , Margin } from '@foundations'
3
+ import { Margin } from '@foundations'
4
4
  import { Flex } from 'components/layout'
5
- import { Label1 } from 'components/typography'
6
- import { InputCheckbox, IInputCheckbox } from '../../molecules/input-checkbox'
5
+ import { Label } from 'components/typography'
6
+ import { IInputCheckboxProps, InputCheckbox } from 'components/molecules/input-checkbox'
7
7
 
8
- const HelpfulMessage = styled(Label1)`
8
+ const HelpfulMessage = styled(Label)`
9
9
  margin-top: ${Margin.xxs};
10
10
  margin-left: ${Margin.xl};
11
- color: ${Text.Subdued};
12
11
  user-select: none;
13
12
  `
14
13
  const Group = styled(Flex)`
@@ -16,8 +15,7 @@ const Group = styled(Flex)`
16
15
  flex-direction: column;
17
16
  gap: 18px;
18
17
  `
19
- interface IOption extends IInputCheckbox {
20
- id: string
18
+ interface IOption extends IInputCheckboxProps {
21
19
  helpfulMessage?: string
22
20
  }
23
21
  interface IMultiChoiceList {
@@ -30,6 +28,7 @@ export const MultiChoiceList: FC<IMultiChoiceList> = (props: IMultiChoiceList) =
30
28
  if (isEmpty(options)) {
31
29
  return <Nothing />
32
30
  }
31
+
33
32
  return (
34
33
  <Group role="group">
35
34
  {options.map((option:IOption) => (
@@ -42,7 +41,7 @@ export const MultiChoiceList: FC<IMultiChoiceList> = (props: IMultiChoiceList) =
42
41
  {...option}
43
42
  />
44
43
  {isDefined(option.helpfulMessage) && (
45
- <HelpfulMessage id={`${option.id}-id`}>
44
+ <HelpfulMessage subdued id={`${option.id}-id`}>
46
45
  {option.helpfulMessage}
47
46
  </HelpfulMessage>
48
47
  )}