@edvisor/product-language 0.1.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 (150) hide show
  1. package/.babelrc +12 -0
  2. package/.eslintrc.json +139 -0
  3. package/.storybook/main.js +57 -0
  4. package/.storybook/manager.js +7 -0
  5. package/.storybook/preview-head.html +1 -0
  6. package/.storybook/preview.js +15 -0
  7. package/.storybook/tsconfig.json +30 -0
  8. package/README.md +33 -0
  9. package/jest.config.ts +15 -0
  10. package/jest.setup.ts +2 -0
  11. package/package.json +30 -0
  12. package/project.json +75 -0
  13. package/src/assets/svg/example_icon.svg +3 -0
  14. package/src/assets/svg/example_icon_white.svg +3 -0
  15. package/src/assets/svg/spinner.svg +3 -0
  16. package/src/assets/svg/spinner_white.svg +3 -0
  17. package/src/helpers/index.ts +3 -0
  18. package/src/helpers/talesOf.tsx +42 -0
  19. package/src/index.ts +2 -0
  20. package/src/lib/components/README.md +49 -0
  21. package/src/lib/components/alert-banner/alert-banner.tsx +34 -0
  22. package/src/lib/components/alert-banner/alert-level-flags.ts +77 -0
  23. package/src/lib/components/alert-banner/index.ts +1 -0
  24. package/src/lib/components/badge/badge-type-flags.ts +72 -0
  25. package/src/lib/components/badge/badge.stories.tsx +16 -0
  26. package/src/lib/components/badge/badge.test.tsx +29 -0
  27. package/src/lib/components/badge/badge.tsx +31 -0
  28. package/src/lib/components/badge/index.ts +1 -0
  29. package/src/lib/components/card/atoms/card-frame.tsx +17 -0
  30. package/src/lib/components/card/atoms/index.ts +1 -0
  31. package/src/lib/components/card/card.test.tsx +163 -0
  32. package/src/lib/components/card/card.tsx +78 -0
  33. package/src/lib/components/card/components/card-alert-banner-slot.tsx +16 -0
  34. package/src/lib/components/card/components/card-controls-slot.tsx +19 -0
  35. package/src/lib/components/card/components/card-section-slot.tsx +51 -0
  36. package/src/lib/components/card/components/index.ts +3 -0
  37. package/src/lib/components/card/index.ts +2 -0
  38. package/src/lib/components/card/molecules/index.ts +1 -0
  39. package/src/lib/components/card/molecules/left-right-card.test.tsx +89 -0
  40. package/src/lib/components/card/molecules/left-right-card.tsx +63 -0
  41. package/src/lib/components/card/storybook/card.stories.mdx +100 -0
  42. package/src/lib/components/card/storybook/components.tsx +240 -0
  43. package/src/lib/components/checkbox/checkbox.test.tsx +39 -0
  44. package/src/lib/components/checkbox/checkbox.tsx +124 -0
  45. package/src/lib/components/checkbox/components/components.tsx +59 -0
  46. package/src/lib/components/checkbox/index.tsx +1 -0
  47. package/src/lib/components/checkbox/stories/checkbox.stories.mdx +54 -0
  48. package/src/lib/components/checkbox/stories/components.tsx +36 -0
  49. package/src/lib/components/checkbox/stories/index.tsx +1 -0
  50. package/src/lib/components/divider/divider-type-flags.tsx +37 -0
  51. package/src/lib/components/divider/divider.test.tsx +34 -0
  52. package/src/lib/components/divider/divider.tsx +37 -0
  53. package/src/lib/components/divider/index.tsx +1 -0
  54. package/src/lib/components/divider/stories/components.tsx +13 -0
  55. package/src/lib/components/divider/stories/divider.stories.mdx +50 -0
  56. package/src/lib/components/index.ts +14 -0
  57. package/src/lib/components/input-field/components/index.ts +2 -0
  58. package/src/lib/components/input-field/components/labeled-input.tsx +61 -0
  59. package/src/lib/components/input-field/components/stepper.tsx +59 -0
  60. package/src/lib/components/input-field/index.ts +6 -0
  61. package/src/lib/components/input-field/input-field.test.tsx +108 -0
  62. package/src/lib/components/input-field/input-field.tsx +126 -0
  63. package/src/lib/components/input-field/input-number.tsx +41 -0
  64. package/src/lib/components/input-field/input-text.tsx +30 -0
  65. package/src/lib/components/input-field/storybook/components.tsx +334 -0
  66. package/src/lib/components/input-field/storybook/input-field.stories.mdx +113 -0
  67. package/src/lib/components/layout/flex.tsx +22 -0
  68. package/src/lib/components/layout/grid-layout.tsx +40 -0
  69. package/src/lib/components/layout/index.ts +3 -0
  70. package/src/lib/components/layout/left-right-layout.tsx +67 -0
  71. package/src/lib/components/link/index.ts +1 -0
  72. package/src/lib/components/link/link.test.tsx +29 -0
  73. package/src/lib/components/link/link.tsx +56 -0
  74. package/src/lib/components/link/storybook/link.stories.mdx +51 -0
  75. package/src/lib/components/molecules/avatar/avatar-size-flags.tsx +55 -0
  76. package/src/lib/components/molecules/avatar/avatar.test.tsx +114 -0
  77. package/src/lib/components/molecules/avatar/avatar.tsx +80 -0
  78. package/src/lib/components/molecules/avatar/index.tsx +1 -0
  79. package/src/lib/components/molecules/avatar/stories/avatar.stories.mdx +55 -0
  80. package/src/lib/components/molecules/avatar/stories/components.tsx +36 -0
  81. package/src/lib/components/molecules/button/button-flags.tsx +235 -0
  82. package/src/lib/components/molecules/button/button.test.tsx +77 -0
  83. package/src/lib/components/molecules/button/button.tsx +231 -0
  84. package/src/lib/components/molecules/button/index.tsx +1 -0
  85. package/src/lib/components/molecules/button/stories/button.stories.mdx +104 -0
  86. package/src/lib/components/molecules/button/stories/components.tsx +86 -0
  87. package/src/lib/components/molecules/index.ts +3 -0
  88. package/src/lib/components/molecules/input-checkbox/index.tsx +1 -0
  89. package/src/lib/components/molecules/input-checkbox/input-checkbox.test.tsx +34 -0
  90. package/src/lib/components/molecules/input-checkbox/input-checkbox.tsx +50 -0
  91. package/src/lib/components/molecules/input-checkbox/stories/components.tsx +36 -0
  92. package/src/lib/components/molecules/input-checkbox/stories/index.tsx +1 -0
  93. package/src/lib/components/molecules/input-checkbox/stories/input-checkbox.stories.mdx +51 -0
  94. package/src/lib/components/organisms/index.ts +1 -0
  95. package/src/lib/components/organisms/multi-choice-list/index.tsx +1 -0
  96. package/src/lib/components/organisms/multi-choice-list/multi-choice-list.test.tsx +33 -0
  97. package/src/lib/components/organisms/multi-choice-list/multi-choice-list.tsx +53 -0
  98. package/src/lib/components/organisms/multi-choice-list/stories/components.tsx +126 -0
  99. package/src/lib/components/organisms/multi-choice-list/stories/index.tsx +1 -0
  100. package/src/lib/components/organisms/multi-choice-list/stories/multi-choice-list.stories.mdx +99 -0
  101. package/src/lib/components/spinner/index.tsx +1 -0
  102. package/src/lib/components/spinner/spinner-size-flags.tsx +39 -0
  103. package/src/lib/components/spinner/spinner.test.tsx +31 -0
  104. package/src/lib/components/spinner/spinner.tsx +67 -0
  105. package/src/lib/components/spinner/stories/components.tsx +8 -0
  106. package/src/lib/components/spinner/stories/spinner.stories.mdx +42 -0
  107. package/src/lib/components/thumbnail/index.tsx +1 -0
  108. package/src/lib/components/thumbnail/stories/thumbnail.stories.mdx +34 -0
  109. package/src/lib/components/thumbnail/thumbnail-size-flags.tsx +41 -0
  110. package/src/lib/components/thumbnail/thumbnail.test.tsx +51 -0
  111. package/src/lib/components/thumbnail/thumbnail.tsx +40 -0
  112. package/src/lib/components/typography/index.ts +1 -0
  113. package/src/lib/components/typography/storybook/components.tsx +256 -0
  114. package/src/lib/components/typography/storybook/typography.stories.mdx +88 -0
  115. package/src/lib/components/typography/typography.test.tsx +93 -0
  116. package/src/lib/components/typography/typography.tsx +57 -0
  117. package/src/lib/foundations/color-system/base-palette/base-palette.stories.tsx +123 -0
  118. package/src/lib/foundations/color-system/base-palette/base-palette.ts +94 -0
  119. package/src/lib/foundations/color-system/base-palette/index.ts +1 -0
  120. package/src/lib/foundations/color-system/color-guidelines/color-guidelines.stories.mdx +85 -0
  121. package/src/lib/foundations/color-system/color-guidelines/color-guidelines.stories.tsx +231 -0
  122. package/src/lib/foundations/color-system/color-guidelines/color-guidelines.ts +159 -0
  123. package/src/lib/foundations/color-system/color-guidelines/index.ts +1 -0
  124. package/src/lib/foundations/color-system/components/color-sample.tsx +99 -0
  125. package/src/lib/foundations/color-system/components/index.ts +1 -0
  126. package/src/lib/foundations/color-system/index.ts +1 -0
  127. package/src/lib/foundations/index.ts +4 -0
  128. package/src/lib/foundations/shadows/components.tsx +59 -0
  129. package/src/lib/foundations/shadows/index.ts +1 -0
  130. package/src/lib/foundations/shadows/shadows.stories.mdx +71 -0
  131. package/src/lib/foundations/shadows/shadows.tsx +47 -0
  132. package/src/lib/foundations/spacing/index.ts +1 -0
  133. package/src/lib/foundations/spacing/spacing-guidelines.ts +24 -0
  134. package/src/lib/foundations/spacing/spacing.stories.mdx +51 -0
  135. package/src/lib/foundations/spacing/spacing.ts +18 -0
  136. package/src/lib/foundations/typography/constants.ts +25 -0
  137. package/src/lib/foundations/typography/index.tsx +1 -0
  138. package/src/lib/foundations/typography/text-aspect-flags.ts +54 -0
  139. package/src/lib/foundations/typography/typography.tsx +97 -0
  140. package/src/lib/helpers/generic-types.ts +44 -0
  141. package/src/lib/helpers/index.ts +6 -0
  142. package/src/lib/helpers/nothing.tsx +18 -0
  143. package/src/lib/helpers/numbers.ts +53 -0
  144. package/src/lib/helpers/safe-navigation.ts +34 -0
  145. package/src/lib/helpers/slots.tsx +76 -0
  146. package/src/lib/helpers/strings.test.ts +47 -0
  147. package/src/lib/helpers/strings.ts +16 -0
  148. package/tsconfig.json +35 -0
  149. package/tsconfig.lib.json +28 -0
  150. package/tsconfig.spec.json +21 -0
@@ -0,0 +1,77 @@
1
+ import { Actions } from '@foundations'
2
+ import {render, screen } from '@testing-library/react'
3
+ import { ButtonBasic, ButtonPrimary, ButtonDestructive, ButtonOutline, ButtonPlain } from './index'
4
+
5
+ describe('Button Tests', () => {
6
+ describe('ButtonBasic Tests', () => {
7
+ it('should render Button with given Text', async () => {
8
+ render(
9
+ <ButtonBasic>Test Button</ButtonBasic>
10
+ )
11
+
12
+ expect(screen.getByText('Test Button')).toBeInTheDocument()
13
+ expect(screen.queryByRole('button')).toBeInTheDocument()
14
+ })
15
+
16
+ })
17
+
18
+ describe('ButtonPrimary Tests', () => {
19
+ it('should render Button with given Text', async () => {
20
+ render(
21
+ <ButtonPrimary>Test Button</ButtonPrimary>
22
+ )
23
+
24
+ expect(screen.getByText('Test Button')).toBeInTheDocument()
25
+ expect(screen.queryByRole('button')).toBeInTheDocument()
26
+ })
27
+
28
+ })
29
+
30
+ describe('ButtonDestructive Tests', () => {
31
+ it('should render Button with given Text', async () => {
32
+ render(
33
+ <ButtonDestructive>Test Button</ButtonDestructive>
34
+ )
35
+
36
+ expect(screen.getByText('Test Button')).toBeInTheDocument()
37
+ expect(screen.queryByRole('button')).toBeInTheDocument()
38
+ expect(screen.getByTestId('button-test')).toHaveStyle('background: none')
39
+ })
40
+
41
+ it('should render Button with given Text', async () => {
42
+ render(
43
+ <ButtonDestructive primary>Test Button</ButtonDestructive>
44
+ )
45
+
46
+ expect(screen.getByText('Test Button')).toBeInTheDocument()
47
+ expect(screen.queryByRole('button')).toBeInTheDocument()
48
+ expect(screen.getByTestId('button-test')).toHaveStyle(`background: ${Actions.Critical.Default}`)
49
+ })
50
+
51
+
52
+ })
53
+
54
+ describe('ButtonOutline Tests', () => {
55
+ it('should render Button with given Text', async () => {
56
+ render(
57
+ <ButtonOutline>Test Button</ButtonOutline>
58
+ )
59
+
60
+ expect(screen.getByText('Test Button')).toBeInTheDocument()
61
+ expect(screen.queryByRole('button')).toBeInTheDocument()
62
+ })
63
+
64
+ })
65
+
66
+ describe('ButtonPlain Tests', () => {
67
+ it('should render Button with given Text', async () => {
68
+ render(
69
+ <ButtonPlain>Test Button</ButtonPlain>
70
+ )
71
+
72
+ expect(screen.getByText('Test Button')).toBeInTheDocument()
73
+ expect(screen.queryByRole('button')).toBeInTheDocument()
74
+ })
75
+ })
76
+
77
+ })
@@ -0,0 +1,231 @@
1
+ import styled from 'styled-components'
2
+ import { FC, is, isDefined } from '@helpers'
3
+ import { Focused } from '@foundations'
4
+ import {
5
+ ButtonSizeProps,
6
+ getBackgroundColorByType,
7
+ getIsDisabled,
8
+ getTextColorByType,
9
+ getTextColorIfDisabled,
10
+ getCursor,
11
+ getPaddingBySize,
12
+ getBackgroundColorHoverByType,
13
+ getTextColorOnHoverByType,
14
+ getBorderByType,
15
+ getPaddingByType,
16
+ getBackgroundColorDisabledByType,
17
+ getBorderDisabledByType,
18
+ ButtonType,
19
+ getBackgroundColorPressedByType,
20
+ } from './button-flags'
21
+ import { ComponentType } from 'react'
22
+ import { Label1 } from 'components/typography'
23
+ import { Spinner } from 'components/spinner'
24
+
25
+ const ButtonFrame = styled.button<{
26
+ backgroundColor: string
27
+ buttonSize: string
28
+ cursor: string
29
+ backgroundHover: string
30
+ backgroundPressed: string
31
+ textColorHover: string
32
+ buttonBorder: string
33
+ isDisabled: boolean
34
+ }>`
35
+ padding: ${(props) => props.buttonSize};
36
+ border: ${(props) => props.buttonBorder};
37
+ border-radius: 6px;
38
+ background: ${(props) => props.backgroundColor};
39
+ cursor: ${(props) => props.cursor};
40
+ display: flex;
41
+ flex-direction: row;
42
+ justify-content: center;
43
+ gap: 8px;
44
+ align-items: center;
45
+ position: relative;
46
+
47
+ ${(props) =>
48
+ !props.isDisabled
49
+ ? `
50
+ &:hover {
51
+ background: ${props.backgroundHover};
52
+
53
+ div {
54
+ color: ${props.textColorHover};
55
+ }
56
+ }
57
+
58
+ &:focus {
59
+ outline: 2px solid ${Focused.Default}
60
+ }
61
+
62
+ &:focus-visible {
63
+ border: 2px solid ${Focused.Default}
64
+ }
65
+
66
+ &:active {
67
+ background: ${props.backgroundPressed}
68
+ }
69
+ `
70
+ : ''}
71
+ `
72
+
73
+ const ButtonText = styled(Label1)<{
74
+ textColor: string
75
+ textColorDisabled: string
76
+ isLoading: boolean
77
+ }>`
78
+ color: ${(props) =>
79
+ props.textColorDisabled !== '' ? props.textColorDisabled : props.textColor};
80
+
81
+ ${(props) =>
82
+ props.isLoading
83
+ ? `
84
+ opacity: 0;
85
+ `
86
+ : ''}
87
+ `
88
+
89
+ const Loading = styled(Spinner)`
90
+ position: absolute;
91
+ `
92
+
93
+ interface DummyIconProps {
94
+ type: ButtonType
95
+ }
96
+
97
+ interface IButtonProps {
98
+ loading?: boolean
99
+ IconPrefix?: ComponentType<DummyIconProps>
100
+ IconSuffix?: ComponentType<DummyIconProps>
101
+ children?: string
102
+ }
103
+
104
+ interface IButtonDestructiveProps extends IButtonProps {
105
+ primary?: boolean
106
+ }
107
+
108
+ interface IButtonPlainProps extends IButtonProps {
109
+ subtle?: boolean
110
+ }
111
+
112
+ interface ISecretInnerButtonProps
113
+ extends IButtonPlainProps,
114
+ IButtonDestructiveProps {
115
+ buttonType: ButtonType
116
+ }
117
+
118
+ function makeButtonConfig(props: ISecretInnerButtonProps & ButtonSizeProps) {
119
+ const { buttonType } = props
120
+ const isDisabled = getIsDisabled(props)
121
+ const backgroundColor = isDisabled
122
+ ? getBackgroundColorDisabledByType(buttonType)
123
+ : getBackgroundColorByType(buttonType)
124
+ const buttonPadding = getPaddingBySize(props)
125
+ const buttonOverridePadding = getPaddingByType(buttonType)
126
+ const cursor = getCursor(props)
127
+ const backgroundHover = getBackgroundColorHoverByType(buttonType)
128
+ const backgroundPressed = getBackgroundColorPressedByType(buttonType)
129
+ const textColorHover = getTextColorOnHoverByType(buttonType)
130
+ const buttonBorder = isDisabled
131
+ ? getBorderDisabledByType(buttonType)
132
+ : getBorderByType(buttonType)
133
+ const buttonSize =
134
+ buttonOverridePadding !== '' ? buttonOverridePadding : buttonPadding
135
+ const textColor = getTextColorByType(buttonType)
136
+ const textColorDisabled = getTextColorIfDisabled(props)
137
+
138
+ return {
139
+ backgroundColor,
140
+ buttonSize,
141
+ cursor,
142
+ backgroundHover,
143
+ backgroundPressed,
144
+ textColorHover,
145
+ buttonBorder,
146
+ isDisabled,
147
+ textColor,
148
+ textColorDisabled,
149
+ }
150
+ }
151
+
152
+ const SecretInnerButton: FC<ISecretInnerButtonProps & ButtonSizeProps> = (
153
+ props
154
+ ) => {
155
+ const {
156
+ children,
157
+ buttonType,
158
+ loading,
159
+ IconPrefix,
160
+ IconSuffix,
161
+ ...htmlProps
162
+ } = props
163
+ const { textColor, textColorDisabled, ...buttonConfig } =
164
+ makeButtonConfig(props)
165
+
166
+ return (
167
+ <ButtonFrame {...htmlProps} {...buttonConfig} data-testid="button-test">
168
+ {isDefined(IconPrefix) ? <IconPrefix type={buttonType} /> : ''}
169
+
170
+ <ButtonText
171
+ textColor={textColor}
172
+ textColorDisabled={textColorDisabled}
173
+ isLoading={is(loading)}
174
+ >
175
+ {children}
176
+ </ButtonText>
177
+ {is(loading) ? (
178
+ <Loading
179
+ small
180
+ onPrimary={
181
+ buttonType === ButtonType.primary ||
182
+ buttonType === ButtonType.primaryDestructive
183
+ }
184
+ />
185
+ ) : (
186
+ ''
187
+ )}
188
+
189
+ {isDefined(IconSuffix) ? <IconSuffix type={buttonType} /> : ''}
190
+ </ButtonFrame>
191
+ )
192
+ }
193
+
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
+ }
@@ -0,0 +1 @@
1
+ export * from './button'
@@ -0,0 +1,104 @@
1
+ import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';
2
+ import { ButtonPrimary, ButtonBasic, ButtonDestructive, ButtonOutline, ButtonPlain, DummyIcon } from '../index'
3
+ import { PlainHTMLFormExample, DisabledLoadingExample } from './components'
4
+
5
+ <Meta
6
+ title="Components/Button"
7
+ component={ButtonPrimary}
8
+ />
9
+
10
+ # Button
11
+
12
+ For more details, check out the component page on [Figma](https://www.figma.com/file/ue1CurHfZ426o2T2l8Dk64/Edvisor-Product-Language?node-id=1008%3A1257)
13
+
14
+ ## How to use
15
+
16
+ ```javascript
17
+ // Import the component
18
+ import { ButtonPrimary } from './index'
19
+
20
+
21
+ // Render the component sending the required parameters
22
+ <ButtonPrimary label="SOME-label-HERE" />
23
+ ```
24
+
25
+ ## Properties
26
+
27
+ The Buttons accepts the same properties as a normal button and has some additional ones.
28
+
29
+ The available optional properties are as follows, try them out in the editable code sample below!
30
+
31
+ | Prop | Type | Description |
32
+ | ---------- | --------- | ------------------------------------------------------------------------ |
33
+ | `IconPrefix?` | `Icon` | It will add the given Icon before the text |
34
+ | `IconSuffix?` | `Icon` | It will add the given Icon after the text |
35
+ | `loading?` | `boolean` | Replaces the text for a loading icon |
36
+ | `size?` | `small / large` | Changes the size of the button. Leave it empty for the default size |
37
+
38
+ ### Using as form controls
39
+ <PlainHTMLFormExample />
40
+
41
+ ### Disabled until something is typed then loading until response
42
+ <DisabledLoadingExample />
43
+
44
+ ## Examples
45
+
46
+ <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>
54
+ </Canvas>
55
+
56
+ Disabled
57
+ <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>
65
+ </Canvas>
66
+
67
+ Loading
68
+ <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>
76
+ </Canvas>
77
+
78
+ Icons
79
+ <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>
87
+ </Canvas>
88
+
89
+ <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>
97
+ </Canvas>
98
+
99
+ <Canvas>
100
+ <ButtonBasic large>Large</ButtonBasic>
101
+ <ButtonBasic>Default</ButtonBasic>
102
+ <ButtonBasic small>Small</ButtonBasic>
103
+ </Canvas>
104
+
@@ -0,0 +1,86 @@
1
+
2
+ import { Playground } from 'storybook-addon-jarle-monaco'
3
+ import { InputField } from '../../../input-field'
4
+ import { Button, ButtonPrimary } from '../button'
5
+
6
+ export const PlainHTMLFormExample = () => (
7
+ <Playground
8
+ code={`
9
+ /* Edit this code sample! */
10
+ const [invalid, setInvalid] = useState(false);
11
+
12
+ <form onSubmit={(e) => e.preventDefault()}>
13
+ <label htmlFor="country_code">Country code:</label>
14
+ <InputField
15
+ type="text"
16
+ placeholder="Enter a country code..."
17
+ id="country_code"
18
+ name="country_code"
19
+ pattern="[A-Za-z]{3}"
20
+ onInvalid={setInvalid}
21
+ invalid={invalid}
22
+ onChange={() => setInvalid(false)}
23
+ title="Three letter country code"
24
+ required
25
+ />
26
+ <div style={{display:'flex', gap:'8px'}}>
27
+ <ButtonBasic type="reset">Clear</ButtonBasic>
28
+ <ButtonPrimary type="submit">Send</ButtonPrimary>
29
+ </div>
30
+ </form>
31
+ `}
32
+ providerProps={{
33
+ renderAsComponent: true,
34
+ scope: {
35
+ InputField,
36
+ ButtonBasic: Button,
37
+ ButtonPrimary
38
+ },
39
+ }}
40
+ />
41
+ )
42
+
43
+ export const DisabledLoadingExample = () => (
44
+ <Playground
45
+ code={`
46
+ /* Edit this code sample! */
47
+ const [invalid, setInvalid] = useState(false);
48
+ const [disabled, setDisabled] = useState(true);
49
+ const [loading, setLoading] = useState(false);
50
+
51
+ <form onSubmit={(e) => {
52
+ e.preventDefault();
53
+ setLoading(true)
54
+ setTimeout(() => setLoading(false), 2000)
55
+ }}>
56
+ <label htmlFor="country_code">Country code:</label>
57
+ <InputField
58
+ type="text"
59
+ placeholder="Enter a country code..."
60
+ id="country_code"
61
+ name="country_code"
62
+ pattern="[A-Za-z]{3}"
63
+ onInvalid={setInvalid}
64
+ invalid={invalid}
65
+ onChange={() => {
66
+ setInvalid(false);
67
+ setDisabled(false);
68
+ }}
69
+ title="Three letter country code"
70
+ required
71
+ />
72
+ <div style={{display:'flex', gap:'8px'}}>
73
+ <ButtonPrimary type="submit" disabled={disabled} loading={loading}>Send</ButtonPrimary>
74
+ </div>
75
+ </form>
76
+ `}
77
+ providerProps={{
78
+ renderAsComponent: true,
79
+ scope: {
80
+ InputField,
81
+ ButtonBasic: Button,
82
+ ButtonPrimary
83
+ },
84
+ }}
85
+ />
86
+ )
@@ -0,0 +1,3 @@
1
+ export * from './avatar'
2
+ export * from './button'
3
+ export * from './input-checkbox'
@@ -0,0 +1 @@
1
+ export * from './input-checkbox'
@@ -0,0 +1,34 @@
1
+ import {render, screen } from '@testing-library/react'
2
+ import userEvent from '@testing-library/user-event'
3
+ import { InputCheckbox } from './input-checkbox'
4
+
5
+ describe('InputCheckbox Tests', () => {
6
+ it('should render the component and handle event after click', async () => {
7
+ const spyOnChange = jest.fn()
8
+ render(
9
+ <InputCheckbox
10
+ label='My Checkbox'
11
+ onChange={spyOnChange}
12
+ />
13
+ )
14
+
15
+ expect(spyOnChange).not.toHaveBeenCalled()
16
+ const myComponent = screen.getByRole('checkbox')
17
+ expect(screen.getByText('My Checkbox')).toBeInTheDocument()
18
+ expect(myComponent).toBeInTheDocument()
19
+
20
+ await userEvent.click(myComponent)
21
+
22
+ expect(spyOnChange).toHaveBeenCalled()
23
+ })
24
+ it('should not render the component if dont receive a label', async () => {
25
+ const { container } = render(
26
+ <InputCheckbox
27
+ label=''
28
+ />
29
+ )
30
+
31
+
32
+ expect(container).toBeEmptyDOMElement()
33
+ })
34
+ })
@@ -0,0 +1,50 @@
1
+ import { useState } from 'react'
2
+ import styled from 'styled-components'
3
+ import { FC, isDefined, isEmpty, Nothing } from '@helpers'
4
+ import { Margin } from '@foundations'
5
+ import { Checkbox, ICheckboxProps } from '../../checkbox'
6
+ import { Label1 } from 'components/typography'
7
+ import { Flex } from 'components/layout'
8
+
9
+ const Text = styled(Label1)`
10
+ margin-left: ${Margin.s};
11
+ user-select: none;
12
+ `
13
+ const Wrapper = styled(Flex)`
14
+ width: 100%;
15
+ align-items: center;
16
+ `
17
+ interface IInputCheckboxProps {
18
+ label: string
19
+ }
20
+
21
+ export type IInputCheckbox = IInputCheckboxProps & ICheckboxProps
22
+
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
+ if (isEmpty(label)) {
27
+ return <Nothing />
28
+ }
29
+
30
+ const handleOnChange = () => {
31
+ setIsChecked(!isChecked)
32
+ if(isDefined(onChange)){
33
+ onChange(!isChecked)
34
+ }
35
+ }
36
+
37
+ return (
38
+ <Wrapper>
39
+ <Checkbox
40
+ {...props}
41
+ onChange={handleOnChange}
42
+ onClick={handleOnChange}
43
+ disabled={disabled}
44
+ error={error}
45
+ checked={isChecked}
46
+ />
47
+ <Text>{label}</Text>
48
+ </Wrapper>
49
+ )
50
+ }
@@ -0,0 +1,36 @@
1
+ import { Playground } from 'storybook-addon-jarle-monaco'
2
+ import { InputCheckbox } from '../index'
3
+
4
+ export const PlainHTMLFormExample = () => (
5
+ <Playground
6
+ code={`
7
+ /* Edit this code sample! */
8
+ const [withError, setWithError] = useState(false);
9
+
10
+ <form onSubmit={(e) => {
11
+ e.preventDefault()
12
+ console.log('form submitted')
13
+ }}
14
+ >
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"/>
27
+ </form>
28
+ `}
29
+ providerProps={{
30
+ renderAsComponent: true,
31
+ scope: {
32
+ InputCheckbox,
33
+ },
34
+ }}
35
+ />
36
+ )
@@ -0,0 +1 @@
1
+ export * from './components'
@@ -0,0 +1,51 @@
1
+ import { Canvas, Meta, Story } from '@storybook/addon-docs';
2
+ import { InputCheckbox } from '../index'
3
+ import { PlainHTMLFormExample } from './index'
4
+
5
+ <Meta
6
+ title="Components/InputCheckbox"
7
+ component={InputCheckbox}
8
+ />
9
+
10
+ # InputCheckbox
11
+
12
+ This is a molecule, composed by the atoms checkbox input and typography as well.
13
+
14
+ For more details, check out the component page on [Figma](https://www.figma.com/file/ue1CurHfZ426o2T2l8Dk64/Edvisor-Product-Language?node-id=1008%3A1257)
15
+
16
+ ## How to use
17
+
18
+ ```javascript
19
+ // Import the component
20
+ import { InputCheckbox } from './index'
21
+
22
+
23
+ // Render the component sending the required parameters
24
+ <InputCheckbox label="MY-TEXT-HERE" />
25
+ ```
26
+
27
+ ## Examples
28
+
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 />
35
+ </Canvas>
36
+
37
+
38
+ ## API
39
+ You can send all the possible values from Checkbox component.
40
+ Also, you can sen this parameters:
41
+
42
+
43
+ | Name | Type | Description | Required (Y/N)|
44
+ | ---- | ----- | ------ | ------- |
45
+ | `label` | `string` | `The label from the checkbox` | `Y` |
46
+ | `onChange` | `event` | `You can listen the changes from the component` | `N` |
47
+
48
+
49
+ ## Playground
50
+
51
+ <PlainHTMLFormExample />
@@ -0,0 +1 @@
1
+ export * from './multi-choice-list'
@@ -0,0 +1 @@
1
+ export * from './multi-choice-list'