@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,100 @@
1
+ import { Meta, Canvas } from '@storybook/addon-docs';
2
+ import { AlertBanner } from 'components/alert-banner'
3
+ import {
4
+ CardExample,
5
+ SectionsExample,
6
+ AlertBannerExample,
7
+ LeftRightLayoutExample,
8
+ CardControlsExample,
9
+ SectionsHeadingActionsExample,
10
+ } from './components'
11
+
12
+ <Meta title="Components/Card"/>
13
+
14
+ # Card
15
+
16
+ Cards are used to group similar things together.
17
+
18
+ ## How to Use It
19
+
20
+ ```tsx
21
+ import { Card } from '@edvisor/product-language'
22
+
23
+ <Card heading='Heading'>
24
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit.
25
+ </Card>
26
+ ```
27
+
28
+ ### Card
29
+
30
+ A simple card with a heading and content.
31
+
32
+ <CardExample />
33
+
34
+ ### Card with Sections
35
+
36
+ You can divide a card's body up into sections.
37
+
38
+ <SectionsExample />
39
+
40
+ ### Card with Heading Actions
41
+
42
+ Any heading in a Card can have an action
43
+
44
+ <AlertBanner warning>
45
+ HeadingAction is a slots, so its children will always render in the same place regardless of where you use it.
46
+ </AlertBanner>
47
+
48
+ <SectionsHeadingActionsExample />
49
+
50
+ ### Card with Controls
51
+
52
+ Primary controls go on the bottom of the card.
53
+
54
+ <AlertBanner warning>
55
+ Controls is a slot, so its children will always render in the same place regardless of where you use it.
56
+ </AlertBanner>
57
+
58
+ <CardControlsExample />
59
+
60
+ ### Card with Alert Banner
61
+
62
+ You can grab the user's attention with a banner.
63
+
64
+ <AlertBanner warning>
65
+ AlertBanner is a slot, so its children will always render in the same place regardless of where you use it.
66
+ </AlertBanner>
67
+
68
+ <AlertBannerExample />
69
+
70
+ ### Card with a Layout
71
+
72
+ You can add a layout to a card. In this case we've added a 1:2 ratio "left/right" layout.
73
+
74
+ <LeftRightLayoutExample />
75
+
76
+ ## API
77
+
78
+ ### `Card`
79
+
80
+ Extends `HTMLAttributes<HTMLDivElement>`
81
+
82
+ | Prop | Type | Description |
83
+ | --------- | ---------- | -------------------------- |
84
+ | `heading` | `boolean?` | Adds a heading to the card |
85
+
86
+ ### `Card.Section`
87
+
88
+ Extends `HTMLAttributes<HTMLDivElement>`
89
+
90
+ | Prop | Type | Description |
91
+ | --------- | ---------- | ------------------------------- |
92
+ | `heading` | `boolean?` | Adds a heading to the section |
93
+
94
+ ### Slots
95
+
96
+ | Slot | Description |
97
+ | --------------- | ----------------------------------------------------------- |
98
+ | `Controls` | Adds controls to the bottom of the card |
99
+ | `HeadingAction` | Adds UI directly across from the card or sections's heading |
100
+ | `AlertBanner` | Adds an alert banner above the heading |
@@ -0,0 +1,240 @@
1
+ import styled from 'styled-components'
2
+ import { Playground } from 'storybook-addon-jarle-monaco'
3
+ import { Margin, Surface, Text } from '@foundations'
4
+ import { leftRightLayoutGenerator } from 'components/layout'
5
+ import { Body, Heading3 } from 'components/typography'
6
+ import { Divider } from 'components/divider'
7
+ import { Card } from '../card'
8
+ import { LeftRightCard } from '../molecules/left-right-card'
9
+ import { InputField } from 'components/input-field'
10
+
11
+ const CardPlayground = styled(Playground)`
12
+ background: ${Surface.Neutral.Default};
13
+
14
+ margin-bottom: ${Margin.xxl};
15
+
16
+ > div:nth-of-type(2) {
17
+ background: ${Surface.Default.Inverse}; // Surface.Inverse
18
+ color: ${Text.OnPrimary};
19
+ }
20
+ `
21
+
22
+ const Bar = styled(Divider)`
23
+ margin-bottom: ${Margin.l};
24
+ margin-top: ${Margin.l};
25
+ `
26
+
27
+ export const CardExample = () => (
28
+ <CardPlayground
29
+ code={`
30
+ <Card heading='Heading'>
31
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit.
32
+ <Bar />
33
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit.
34
+ </Card>
35
+ `}
36
+ providerProps={{
37
+ renderAsComponent: true,
38
+ scope: {
39
+ Card,
40
+ Bar,
41
+ },
42
+ }}
43
+ />
44
+ )
45
+
46
+ export const SectionsExample = () => (
47
+ <CardPlayground
48
+ code={`
49
+ <Card heading='Sections!'>
50
+ If you include section slots, plain children won't render.
51
+ <Card.Section heading='Subheading 1'>
52
+ This is a section.
53
+ </Card.Section>
54
+ <Card.Section heading='Subheading 2'>
55
+ This is another section.
56
+ </Card.Section>
57
+ </Card>
58
+ `}
59
+ providerProps={{
60
+ renderAsComponent: true,
61
+ scope: {
62
+ Card,
63
+ },
64
+ }}
65
+ />
66
+ )
67
+
68
+ export const CardControlsExample = () => (
69
+ <CardPlayground
70
+ code={`
71
+ const handleCancel = () => alert('Cancel');
72
+ const handleConfirm = () => alert('Confirm');
73
+
74
+ <Card heading='Controls!'>
75
+ <Card.Controls>
76
+ <button onClick={handleCancel}>Cancel</button>
77
+ <button onClick={handleConfirm}>Confirm</button>
78
+ </Card.Controls>
79
+ Notice that the controls render below this text, even though they are above this text in the JSX. That's because Controls is a slot, it is only telling Card what we want to render, not where we want to render it.
80
+ </Card>
81
+ `}
82
+ providerProps={{
83
+ renderAsComponent: true,
84
+ scope: {
85
+ Card,
86
+ },
87
+ }}
88
+ />
89
+ )
90
+
91
+ export const CardHeadingActionExample = () => (
92
+ <CardPlayground
93
+ code={`
94
+ <Card heading='Heading Actions!'>
95
+ If you include section slots, plain children won't render.
96
+ <Card.HeadingAction><button>Activate</button></Card.HeadingAction>
97
+ </Card>
98
+ `}
99
+ providerProps={{
100
+ renderAsComponent: true,
101
+ scope: {
102
+ Card,
103
+ },
104
+ }}
105
+ />
106
+ )
107
+
108
+ export const SectionsHeadingActionsExample = () => (
109
+ <CardPlayground
110
+ code={`
111
+ <Card heading='Heading Actions'>
112
+ <Card.HeadingAction><button>Action</button></Card.HeadingAction>
113
+
114
+ <Card.Section heading='Subheading 1'>
115
+ This is a section.
116
+ <Card.HeadingAction><button>Action</button></Card.HeadingAction>
117
+ </Card.Section>
118
+
119
+ <Card.Section heading='Subheading 2'>
120
+ This is another section.
121
+ <Card.HeadingAction><button>Action</button></Card.HeadingAction>
122
+ </Card.Section>
123
+ </Card>
124
+ `}
125
+ providerProps={{
126
+ renderAsComponent: true,
127
+ scope: {
128
+ Card,
129
+ },
130
+ }}
131
+ />
132
+ )
133
+
134
+ export const AlertBannerExample = () => (
135
+ <CardPlayground
136
+ code={`
137
+ <Card heading='Heading'>
138
+ <Card.AlertBanner info>Seriously though, if you change the student's age or nationality you will regret it.</Card.AlertBanner>
139
+ Disaster can strike at any moment.
140
+ </Card>
141
+ `}
142
+ providerProps={{
143
+ renderAsComponent: true,
144
+ scope: {
145
+ Card,
146
+ },
147
+ }}
148
+ />
149
+ )
150
+
151
+ const { Layout } = leftRightLayoutGenerator()
152
+
153
+ const GreyBox = styled.div`
154
+ background-color: ${Surface.Neutral};
155
+ height: 100%;
156
+ `
157
+
158
+ export const LeftRightLayoutExample = () => (
159
+ <CardPlayground
160
+ code={`
161
+ <Card>
162
+ <Layout>
163
+ <Layout.Left>
164
+ <Heading3>Personal Information</Heading3>
165
+ <Body subdued>This information will be seen by your colleagues and students.</Body>
166
+ </Layout.Left>
167
+ <Layout.Right>
168
+ <form id='my-form' onSubmit={(e) => e.preventDefault()}>
169
+ <InputField
170
+ label='First name'
171
+ />
172
+ <InputField
173
+ label='Last name'
174
+ />
175
+ <InputField
176
+ type='email'
177
+ required
178
+ label='Email'
179
+ />
180
+ </form>
181
+ </Layout.Right>
182
+ </Layout>
183
+ <Card.Controls>
184
+ <button>Cancel</button>
185
+ <button form='my-form' type='submit'>Confirm</button>
186
+ </Card.Controls>
187
+ </Card>
188
+ `}
189
+ providerProps={{
190
+ renderAsComponent: true,
191
+ scope: {
192
+ Card,
193
+ Layout,
194
+ InputField,
195
+ Heading3,
196
+ Body,
197
+ },
198
+ }}
199
+ />
200
+ )
201
+
202
+ export const LeftRightCardExample = () => (
203
+ <CardPlayground
204
+ code={`
205
+ <LeftRightCard
206
+ heading='Personal Information'
207
+ helpText='This information will be seen by your colleagues and students.'
208
+ >
209
+ <LeftRightCard.Right>
210
+ <form id='my-form-2' onSubmit={(e) => e.preventDefault()}>
211
+ <InputField
212
+ label='First name'
213
+ />
214
+ <InputField
215
+ label='Last name'
216
+ />
217
+ <InputField
218
+ type='email'
219
+ required
220
+ label='Email'
221
+ />
222
+ </form>
223
+ </LeftRightCard.Right>
224
+ <LeftRightCard.Controls>
225
+ <button>Cancel</button>
226
+ <button form='my-form-2' type='submit'>Confirm</button>
227
+ </LeftRightCard.Controls>
228
+ </LeftRightCard>
229
+ `}
230
+ providerProps={{
231
+ renderAsComponent: true,
232
+ scope: {
233
+ LeftRightCard,
234
+ GreyBox,
235
+ Body,
236
+ InputField,
237
+ },
238
+ }}
239
+ />
240
+ )
@@ -0,0 +1,39 @@
1
+ import { render, screen } from '@testing-library/react'
2
+ import userEvent from '@testing-library/user-event'
3
+ import { Checkbox } from './checkbox'
4
+
5
+ describe('Checkbox Input Tests', () => {
6
+ it('should render the component and handle event after click', async () => {
7
+ const spyOnChange = jest.fn()
8
+ render(
9
+ <Checkbox
10
+ onChange={spyOnChange}
11
+ />
12
+ )
13
+
14
+ expect(spyOnChange).not.toHaveBeenCalled()
15
+ const myComponent = screen.getByRole('checkbox')
16
+
17
+ expect(myComponent).toBeInTheDocument()
18
+
19
+ await userEvent.click(myComponent)
20
+ expect(spyOnChange).toHaveBeenCalled()
21
+ })
22
+
23
+ it('should not handle event after click if checkbox has disabled', async () => {
24
+ const spyOnChange = jest.fn()
25
+ render(
26
+ <Checkbox
27
+ disabled
28
+ onChange={spyOnChange}
29
+ />
30
+ )
31
+
32
+ expect(spyOnChange).not.toHaveBeenCalled()
33
+ const myComponent = screen.getByRole('checkbox')
34
+
35
+ userEvent.click(myComponent)
36
+
37
+ expect(spyOnChange).not.toHaveBeenCalled()
38
+ })
39
+ })
@@ -0,0 +1,124 @@
1
+ import { InputHTMLAttributes, useState } from 'react'
2
+ import styled, { css } from 'styled-components'
3
+ import { Surface, Borders, Margin, Padding, Interactive, Actions, Focused } from '@foundations'
4
+ import { FC, is, isDefined } from '@helpers'
5
+ import {
6
+ getHoverStyles,
7
+ getDisabledStyles,
8
+ getInvalidStyles,
9
+ getTabIndexValue,
10
+ getCheckedIcon,
11
+ HiddenCheckbox,
12
+ Icon,
13
+ Wrapper,
14
+ } from './components/components'
15
+
16
+ const CustomizedCheckbox = styled.div<{
17
+ checked: boolean;
18
+ disabled: boolean;
19
+ error: boolean;
20
+ }>`
21
+ display: inline-block;
22
+ width: 18px;
23
+ height: 18px;
24
+ margin: ${Margin.none};
25
+ padding: ${Padding.none};
26
+ border-radius: 4px;
27
+
28
+ ${props => is(props.checked)
29
+ ? css`
30
+ background: ${Interactive.Default.Default};
31
+ border: 2px solid ${Interactive.Default.Default};
32
+ &:hover {
33
+ background: ${Actions.Primary.Pressed};
34
+ border: 2px solid ${Interactive.Default.Hover};
35
+ }
36
+ `
37
+ : css`
38
+ background: ${Surface.Default.Default};
39
+ border: 2px solid ${Interactive.Default.Disabled};
40
+ &:hover {
41
+ ${getHoverStyles}
42
+ }
43
+ `
44
+ }
45
+
46
+ ${props => is(props.disabled) ? getDisabledStyles() : ''}
47
+ ${props => is(props.error)
48
+ ? css`
49
+ ${getInvalidStyles()}
50
+ &:hover {
51
+ background: ${({ checked }) => (is(checked)
52
+ ? `${Actions.Critical.Pressed}`
53
+ : `${Surface.Default.Default}`
54
+ )};
55
+ border: 2px solid ${Borders.Critical.Default};
56
+ }
57
+ ${HiddenCheckbox}:invalid {
58
+ ${getInvalidStyles()}
59
+ }
60
+ `
61
+ : ''
62
+ }
63
+
64
+ ${HiddenCheckbox}:focus + & {
65
+ outline: 2px solid ${Focused.Default};
66
+ outline-offset: 1px;
67
+ }
68
+ ${Icon} {
69
+ visibility: ${(props) => (is(props.checked) ? 'visible' : 'hidden')};
70
+ }
71
+ `
72
+
73
+ export interface ICheckboxProps {
74
+ disabled?: boolean;
75
+ checked?: boolean;
76
+ error?: boolean;
77
+ className?: string;
78
+ onChange?: (value: boolean) => void;
79
+ }
80
+
81
+ export type IProps = ICheckboxProps & InputHTMLAttributes<HTMLInputElement>
82
+
83
+ export const Checkbox: FC<IProps> = (props: IProps) => {
84
+ const {
85
+ className,
86
+ onChange,
87
+ disabled = false,
88
+ error = false,
89
+ checked = false,
90
+ } = props
91
+ const [isChecked, setIsChecked] = useState<boolean>(checked)
92
+ const handleOnChange = () => {
93
+ const newCheckedValue = !isChecked
94
+ setIsChecked(newCheckedValue)
95
+ if(isDefined(onChange)){
96
+ onChange(newCheckedValue)
97
+ }
98
+ }
99
+
100
+ return (
101
+ <Wrapper
102
+ className={className}
103
+ >
104
+ <HiddenCheckbox
105
+ {...props}
106
+ tabIndex={getTabIndexValue(disabled)}
107
+ checked={isChecked}
108
+ disabled={disabled}
109
+ onChange={handleOnChange}
110
+ type='checkbox'
111
+ />
112
+ <CustomizedCheckbox
113
+ {...props}
114
+ data-testid='checkbox-id'
115
+ checked={isChecked}
116
+ disabled={disabled}
117
+ error={error}
118
+ onClick={handleOnChange}
119
+ >
120
+ {getCheckedIcon()}
121
+ </CustomizedCheckbox>
122
+ </Wrapper>
123
+ )
124
+ }
@@ -0,0 +1,59 @@
1
+ import styled, { css } from 'styled-components'
2
+ import { Padding, Surface, Borders, Actions } from '@foundations'
3
+
4
+ interface ICheckedProps {
5
+ checked: boolean;
6
+ }
7
+
8
+ export const getHoverStyles = () => css`
9
+ background: ${Surface.Default.Hover};
10
+ `
11
+
12
+ export const getDisabledStyles = () => css`
13
+ pointer-events: none;
14
+ background: ${(props: ICheckedProps) => (props.checked === true ? `${Borders.Default.Default}`: `${Surface.Default.Subdued}` )};
15
+ border-color: ${Borders.Default.Default};
16
+ `
17
+
18
+ export const getInvalidStyles = () => css`
19
+ background: ${(props: ICheckedProps) => (props.checked === true ? `${Actions.Critical.Default}`: `${Surface.Critical.Subdued}`)};
20
+ border: 2px solid ${Borders.Critical.Default};
21
+ `
22
+
23
+ export const HiddenCheckbox = styled.input`
24
+ border: 0;
25
+ clip: rect(0 0 0 0);
26
+ clippath: inset(50%);
27
+ height: 1px;
28
+ margin: -1px;
29
+ overflow: hidden;
30
+ padding: ${Padding.none};
31
+ position: absolute;
32
+ white-space: nowrap;
33
+ width: 1px;
34
+ `
35
+
36
+ export const Icon = styled.svg`
37
+ width: 100%;
38
+ height: 50%;
39
+ `
40
+
41
+ export const Wrapper = styled.div`
42
+ width: 18px;
43
+ height: 100%;
44
+ `
45
+
46
+ export const getTabIndexValue = (
47
+ disabled: boolean
48
+ ): number => {
49
+ return disabled ? -1 : 0
50
+ }
51
+
52
+ export const getCheckedIcon = () => (
53
+ <Icon width="10" height="8" viewBox="0 0 10 8">
54
+ <path
55
+ d="M4.50846 7.37941C4.0689 7.81898 3.35108 7.81898 2.91151 7.37941L0.330581 4.79848C-0.110194 4.35892 -0.110194 3.64109 0.330581 3.20153C0.770146 2.76196 1.48797 2.76196 1.92753 3.20153L3.70999 4.98399L8.07338 0.620598C8.51294 0.181033 9.23076 0.181033 9.67033 0.620598C10.1099 1.06016 10.1099 1.77798 9.67033 2.21755L4.50846 7.37941Z"
56
+ fill="white"
57
+ />
58
+ </Icon>
59
+ )
@@ -0,0 +1 @@
1
+ export * from './checkbox'
@@ -0,0 +1,54 @@
1
+ import { Canvas, Meta, Story } from '@storybook/addon-docs';
2
+ import { Checkbox } from '../index'
3
+ import { PlainHTMLFormExample } from './index'
4
+
5
+ <Meta
6
+ title="Components/Checkbox"
7
+ component={Checkbox}
8
+ />
9
+
10
+ # Checkbox
11
+
12
+ This is an atom.
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 { Checkbox } from './index'
21
+
22
+
23
+ // Render the component sending the required parameters
24
+ <Checkbox />
25
+ ```
26
+
27
+ ## Examples
28
+
29
+ <Canvas>
30
+ <Checkbox onChange={(e) => console.log('at stories', e)} />
31
+ <Checkbox disabled />
32
+ <Checkbox error />
33
+ <Checkbox checked />
34
+ <Checkbox error checked />
35
+ </Canvas>
36
+
37
+
38
+ ## API
39
+
40
+ | Name | Type | Description | Required (Y/N)|
41
+ | ---- | ----- | ------ | ------- |
42
+ | `checked` | `boolean` | `Set checkbox as filled` | `N` |
43
+ | `disabled` | `boolean` | `Set checkbox as a disabled way (can't click or interact with that)` | `N` |
44
+ | `error` | `boolean` | `Useful to work inside a form or show some feedback from user action` | `N` |
45
+ | `onChange` | `event` | `You can listen the changes from the component` | `N` |
46
+
47
+
48
+ ## Playground
49
+
50
+ <PlainHTMLFormExample />
51
+
52
+ ## Changelog
53
+ - Offer the "indeterminate" style
54
+ - Get feedback from the component usage (we can migrate to just rendering with css pseudo elements if necessary)
@@ -0,0 +1,36 @@
1
+ import { Playground } from 'storybook-addon-jarle-monaco'
2
+ import { Checkbox } from '../checkbox'
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
+ <label htmlFor="accept_terms">Accept the terms:</label>
16
+ <Checkbox
17
+ onInvalid={(e) => {
18
+ setWithError(true)
19
+ }}
20
+ error={withError}
21
+ onChange={(e) => {
22
+ console.log('at stories', e)
23
+ setWithError(false)
24
+ }}
25
+ required />
26
+ <input type="submit"/>
27
+ </form>
28
+ `}
29
+ providerProps={{
30
+ renderAsComponent: true,
31
+ scope: {
32
+ Checkbox,
33
+ },
34
+ }}
35
+ />
36
+ )
@@ -0,0 +1 @@
1
+ export * from './components'
@@ -0,0 +1,37 @@
1
+ // this file was generated, but it is safe to modify
2
+ import { bitwiseOr, MappedEnum, RequireOnlyOne, PropsWithChildren } from '@helpers'
3
+ import { Borders } from '@foundations'
4
+
5
+ const enum DividerType {
6
+ default = 1,
7
+ subdued = 2,
8
+ }
9
+
10
+ type DividerTypes<T> = MappedEnum<typeof DividerType, T>
11
+
12
+ function toDividerType(n: number): DividerType {
13
+ switch (n) {
14
+ case DividerType.default:
15
+ return DividerType.default
16
+ case DividerType.subdued:
17
+ return DividerType.subdued
18
+ default:
19
+ return DividerType.default
20
+ }
21
+ }
22
+
23
+ const DividerTypeColor = {
24
+ [DividerType.default]: Borders.Default.Default,
25
+ [DividerType.subdued]: Borders.Default.Subdued,
26
+ }
27
+
28
+ export type DivideTypeProps = Partial<RequireOnlyOne<DividerTypes<boolean>>> &
29
+ PropsWithChildren
30
+
31
+ export function getColor(props: DivideTypeProps): string {
32
+ return DividerTypeColor[
33
+ toDividerType(
34
+ bitwiseOr([props.default, props.subdued])
35
+ )
36
+ ]
37
+ }