@nypl/design-system-react-components 0.25.12 → 0.25.13
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/CHANGELOG.md +63 -1
- package/dist/components/Accordion/Accordion.d.ts +5 -3
- package/dist/components/Accordion/AccordionTypes.d.ts +5 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +3 -3
- package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +1 -1
- package/dist/components/Card/Card.d.ts +11 -20
- package/dist/components/Checkbox/Checkbox.d.ts +1 -1
- package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +4 -2
- package/dist/components/Heading/Heading.d.ts +4 -4
- package/dist/components/Heading/HeadingTypes.d.ts +1 -1
- package/dist/components/Hero/Hero.d.ts +7 -4
- package/dist/components/Icons/IconTypes.d.ts +1 -0
- package/dist/components/Image/Image.d.ts +25 -7
- package/dist/components/Image/ImageTypes.d.ts +4 -4
- package/dist/components/Logo/LogoTypes.d.ts +2 -2
- package/dist/components/Notification/Notification.d.ts +4 -4
- package/dist/components/Radio/Radio.d.ts +1 -1
- package/dist/components/RadioGroup/RadioGroup.d.ts +4 -2
- package/dist/components/Select/Select.d.ts +2 -2
- package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +4 -3
- package/dist/components/SkeletonLoader/SkeletonLoaderTypes.d.ts +0 -4
- package/dist/components/StructuredContent/StructuredContent.d.ts +9 -22
- package/dist/components/Tabs/Tabs.d.ts +3 -3
- package/dist/components/Template/Template.d.ts +13 -5
- package/dist/components/Text/Text.d.ts +3 -3
- package/dist/components/Text/TextTypes.d.ts +1 -1
- package/dist/components/TextInput/TextInput.d.ts +2 -2
- package/dist/components/Toggle/Toggle.d.ts +6 -7
- package/dist/components/Toggle/{ToggleSizes.d.ts → ToggleTypes.d.ts} +1 -1
- package/dist/design-system-react-components.cjs.development.js +505 -422
- package/dist/design-system-react-components.cjs.development.js.map +1 -1
- package/dist/design-system-react-components.cjs.production.min.js +1 -1
- package/dist/design-system-react-components.cjs.production.min.js.map +1 -1
- package/dist/design-system-react-components.esm.js +514 -435
- package/dist/design-system-react-components.esm.js.map +1 -1
- package/dist/helpers/enums.d.ts +4 -0
- package/dist/index.d.ts +7 -8
- package/dist/theme/components/accordion.d.ts +7 -12
- package/dist/theme/components/breadcrumb.d.ts +3 -0
- package/dist/theme/components/card.d.ts +4 -4
- package/dist/theme/components/checkbox.d.ts +1 -0
- package/dist/theme/components/checkboxGroup.d.ts +3 -1
- package/dist/theme/components/global.d.ts +2 -1
- package/dist/theme/components/hero.d.ts +1 -1
- package/dist/theme/components/image.d.ts +1 -1
- package/dist/theme/components/notification.d.ts +4 -4
- package/dist/theme/components/pagination.d.ts +2 -5
- package/dist/theme/components/radio.d.ts +1 -0
- package/dist/theme/components/radioGroup.d.ts +3 -1
- package/dist/theme/components/select.d.ts +3 -0
- package/dist/theme/components/toggle.d.ts +13 -1
- package/package.json +1 -1
- package/src/components/AccessibilityGuide/SkipNavigation.stories.mdx +34 -0
- package/src/components/Accordion/Accordion.stories.mdx +150 -66
- package/src/components/Accordion/Accordion.test.tsx +44 -17
- package/src/components/Accordion/Accordion.tsx +50 -20
- package/src/components/Accordion/AccordionTypes.tsx +5 -0
- package/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +244 -2
- package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +17 -15
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +6 -6
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +6 -6
- package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +1 -1
- package/src/components/Card/Card.stories.mdx +236 -165
- package/src/components/Card/Card.test.tsx +36 -18
- package/src/components/Card/Card.tsx +84 -59
- package/src/components/Card/__snapshots__/Card.test.tsx.snap +25 -65
- package/src/components/Chakra/Center.stories.mdx +2 -2
- package/src/components/Checkbox/Checkbox.stories.mdx +13 -1
- package/src/components/Checkbox/Checkbox.test.tsx +58 -2
- package/src/components/Checkbox/Checkbox.tsx +6 -1
- package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +76 -0
- package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +73 -9
- package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +79 -9
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +10 -7
- package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +169 -0
- package/src/components/ComponentWrapper/ComponentWrapper.tsx +1 -1
- package/src/components/DatePicker/DatePicker.test.tsx +5 -2
- package/src/components/DatePicker/DatePicker.tsx +5 -2
- package/src/components/Form/Form.stories.mdx +47 -9
- package/src/components/Form/Form.test.tsx +1 -1
- package/src/components/Form/Form.tsx +3 -1
- package/src/components/Grid/SimpleGrid.stories.mdx +53 -35
- package/src/components/Grid/SimpleGrid.test.tsx +15 -9
- package/src/components/Heading/Heading.stories.mdx +21 -23
- package/src/components/Heading/Heading.test.tsx +7 -7
- package/src/components/Heading/Heading.tsx +10 -14
- package/src/components/Heading/HeadingTypes.tsx +1 -1
- package/src/components/Heading/__snapshots__/Heading.test.tsx.snap +1 -1
- package/src/components/Hero/Hero.stories.mdx +27 -27
- package/src/components/Hero/Hero.test.tsx +113 -58
- package/src/components/Hero/Hero.tsx +43 -20
- package/src/components/HorizontalRule/HorizontalRule.test.tsx +6 -4
- package/src/components/HorizontalRule/HorizontalRule.tsx +3 -2
- package/src/components/Icons/Icon.stories.mdx +50 -18
- package/src/components/Icons/Icon.test.tsx +13 -2
- package/src/components/Icons/Icon.tsx +11 -6
- package/src/components/Icons/IconTypes.tsx +1 -0
- package/src/components/Image/Image.stories.mdx +133 -68
- package/src/components/Image/Image.test.tsx +32 -48
- package/src/components/Image/Image.tsx +46 -26
- package/src/components/Image/ImageTypes.ts +4 -4
- package/src/components/Image/__snapshots__/Image.test.tsx.snap +60 -13
- package/src/components/Link/Link.tsx +8 -1
- package/src/components/List/List.stories.mdx +1 -1
- package/src/components/List/List.test.tsx +7 -4
- package/src/components/List/List.tsx +7 -4
- package/src/components/Logo/Logo.stories.mdx +13 -13
- package/src/components/Logo/Logo.test.tsx +12 -2
- package/src/components/Logo/Logo.tsx +10 -5
- package/src/components/Logo/LogoTypes.tsx +1 -1
- package/src/components/Notification/Notification.stories.mdx +5 -5
- package/src/components/Notification/Notification.tsx +10 -10
- package/src/components/Pagination/Pagination.stories.mdx +4 -3
- package/src/components/Pagination/Pagination.test.tsx +30 -2
- package/src/components/Pagination/Pagination.tsx +6 -3
- package/src/components/ProgressIndicator/ProgressIndicator.stories.mdx +1 -1
- package/src/components/ProgressIndicator/ProgressIndicator.test.tsx +6 -2
- package/src/components/ProgressIndicator/ProgressIndicator.tsx +3 -1
- package/src/components/Radio/Radio.stories.mdx +13 -1
- package/src/components/Radio/Radio.test.tsx +56 -2
- package/src/components/Radio/Radio.tsx +6 -1
- package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +61 -0
- package/src/components/RadioGroup/RadioGroup.stories.mdx +73 -9
- package/src/components/RadioGroup/RadioGroup.test.tsx +72 -7
- package/src/components/RadioGroup/RadioGroup.tsx +10 -7
- package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +140 -0
- package/src/components/SearchBar/SearchBar.stories.mdx +1 -1
- package/src/components/SearchBar/SearchBar.tsx +3 -3
- package/src/components/Select/Select.stories.mdx +26 -16
- package/src/components/Select/Select.test.tsx +1 -36
- package/src/components/Select/Select.tsx +4 -16
- package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +12 -14
- package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +6 -8
- package/src/components/SkeletonLoader/SkeletonLoader.tsx +5 -7
- package/src/components/SkeletonLoader/SkeletonLoaderTypes.tsx +0 -5
- package/src/components/Slider/Slider.stories.mdx +41 -8
- package/src/components/Slider/Slider.tsx +4 -4
- package/src/components/StatusBadge/StatusBadge.test.tsx +3 -1
- package/src/components/StatusBadge/StatusBadge.tsx +1 -1
- package/src/components/StructuredContent/StructuredContent.stories.mdx +103 -54
- package/src/components/StructuredContent/StructuredContent.test.tsx +129 -102
- package/src/components/StructuredContent/StructuredContent.tsx +43 -53
- package/src/components/StyleGuide/ColorCard.tsx +3 -3
- package/src/components/StyleGuide/Typography.stories.mdx +17 -12
- package/src/components/Table/Table.test.tsx +1 -1
- package/src/components/Table/Table.tsx +3 -1
- package/src/components/Tabs/Tabs.stories.mdx +8 -8
- package/src/components/Tabs/Tabs.test.tsx +13 -11
- package/src/components/Tabs/Tabs.tsx +18 -15
- package/src/components/Template/Template.stories.mdx +62 -25
- package/src/components/Template/Template.test.tsx +35 -5
- package/src/components/Template/Template.tsx +26 -13
- package/src/components/Template/__snapshots__/Template.test.tsx.snap +4 -2
- package/src/components/Text/Text.stories.mdx +13 -15
- package/src/components/Text/Text.test.tsx +6 -15
- package/src/components/Text/Text.tsx +7 -12
- package/src/components/Text/TextTypes.tsx +1 -1
- package/src/components/TextInput/TextInput.stories.mdx +9 -9
- package/src/components/TextInput/TextInput.test.tsx +28 -27
- package/src/components/TextInput/TextInput.tsx +4 -4
- package/src/components/Toggle/Toggle.stories.mdx +12 -22
- package/src/components/Toggle/Toggle.test.tsx +15 -2
- package/src/components/Toggle/Toggle.tsx +8 -9
- package/src/components/Toggle/{ToggleSizes.tsx → ToggleTypes.tsx} +1 -1
- package/src/components/Toggle/__snapshots__/Toggle.test.tsx.snap +64 -0
- package/src/components/VideoPlayer/VideoPlayer.test.tsx +18 -6
- package/src/components/VideoPlayer/VideoPlayer.tsx +14 -7
- package/src/docs/{Intro.stories.mdx → Welcome.stories.mdx} +5 -9
- package/src/{components/Card/CardTypes.tsx → helpers/enums.ts} +2 -2
- package/src/hooks/tests/useNYPLTheme.test.tsx +1 -1
- package/src/hooks/useCarouselStyles.stories.mdx +10 -0
- package/src/hooks/useNYPLTheme.ts +1 -1
- package/src/index.ts +7 -14
- package/src/theme/components/accordion.ts +7 -12
- package/src/theme/components/breadcrumb.ts +3 -0
- package/src/theme/components/card.ts +29 -20
- package/src/theme/components/checkboxGroup.ts +3 -1
- package/src/theme/components/global.ts +4 -3
- package/src/theme/components/hero.ts +1 -1
- package/src/theme/components/icon.ts +5 -2
- package/src/theme/components/image.ts +1 -1
- package/src/theme/components/list.ts +1 -1
- package/src/theme/components/notification.ts +5 -5
- package/src/theme/components/pagination.ts +2 -5
- package/src/theme/components/progressIndicator.ts +3 -3
- package/src/theme/components/radioGroup.ts +3 -1
- package/src/theme/components/select.ts +6 -0
- package/src/theme/components/toggle.ts +26 -3
- package/src/utils/componentCategories.ts +27 -19
- package/dist/components/Card/CardTypes.d.ts +0 -4
- package/dist/components/CheckboxGroup/CheckboxGroupLayoutTypes.d.ts +0 -4
- package/dist/components/RadioGroup/RadioGroupLayoutTypes.d.ts +0 -4
- package/src/components/CheckboxGroup/CheckboxGroupLayoutTypes.tsx +0 -4
- package/src/components/RadioGroup/RadioGroupLayoutTypes.tsx +0 -4
|
@@ -411,3 +411,79 @@ exports[`Checkbox Renders the UI snapshot correctly 6`] = `
|
|
|
411
411
|
</span>
|
|
412
412
|
</label>
|
|
413
413
|
`;
|
|
414
|
+
|
|
415
|
+
exports[`Checkbox Renders the UI snapshot correctly 7`] = `
|
|
416
|
+
<label
|
|
417
|
+
className="chakra-checkbox css-g8du1g"
|
|
418
|
+
onClick={[Function]}
|
|
419
|
+
>
|
|
420
|
+
<input
|
|
421
|
+
aria-disabled={false}
|
|
422
|
+
aria-invalid={false}
|
|
423
|
+
checked={false}
|
|
424
|
+
className="chakra-checkbox__input"
|
|
425
|
+
disabled={false}
|
|
426
|
+
id="jsxLabel"
|
|
427
|
+
name="default"
|
|
428
|
+
onBlur={[Function]}
|
|
429
|
+
onChange={[Function]}
|
|
430
|
+
onFocus={[Function]}
|
|
431
|
+
onKeyDown={[Function]}
|
|
432
|
+
onKeyUp={[Function]}
|
|
433
|
+
required={false}
|
|
434
|
+
style={
|
|
435
|
+
Object {
|
|
436
|
+
"border": "0px",
|
|
437
|
+
"clip": "rect(0px, 0px, 0px, 0px)",
|
|
438
|
+
"height": "1px",
|
|
439
|
+
"margin": "-1px",
|
|
440
|
+
"overflow": "hidden",
|
|
441
|
+
"padding": "0px",
|
|
442
|
+
"position": "absolute",
|
|
443
|
+
"whiteSpace": "nowrap",
|
|
444
|
+
"width": "1px",
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
type="checkbox"
|
|
448
|
+
value="arts"
|
|
449
|
+
/>
|
|
450
|
+
<span
|
|
451
|
+
aria-hidden={true}
|
|
452
|
+
className="chakra-checkbox__control css-dnty2r"
|
|
453
|
+
onMouseDown={[Function]}
|
|
454
|
+
onMouseEnter={[Function]}
|
|
455
|
+
onMouseLeave={[Function]}
|
|
456
|
+
onMouseUp={[Function]}
|
|
457
|
+
>
|
|
458
|
+
<svg
|
|
459
|
+
className="chakra-icon css-1vfv7ic"
|
|
460
|
+
focusable={false}
|
|
461
|
+
viewBox="0 0 24 24"
|
|
462
|
+
>
|
|
463
|
+
<path
|
|
464
|
+
d="M8.795 15.875l-4.17-4.17-1.42 1.41 5.59 5.59 12-12-1.41-1.41-10.59 10.58z"
|
|
465
|
+
fill="currentColor"
|
|
466
|
+
/>
|
|
467
|
+
</svg>
|
|
468
|
+
</span>
|
|
469
|
+
<span
|
|
470
|
+
className="chakra-checkbox__label css-1oeb2oe"
|
|
471
|
+
onMouseDown={[Function]}
|
|
472
|
+
onTouchStart={[Function]}
|
|
473
|
+
>
|
|
474
|
+
<div
|
|
475
|
+
className="css-k008qs"
|
|
476
|
+
>
|
|
477
|
+
<span>
|
|
478
|
+
Arts
|
|
479
|
+
</span>
|
|
480
|
+
<div
|
|
481
|
+
className="css-17xejub"
|
|
482
|
+
/>
|
|
483
|
+
<span>
|
|
484
|
+
4
|
|
485
|
+
</span>
|
|
486
|
+
</div>
|
|
487
|
+
</span>
|
|
488
|
+
</label>
|
|
489
|
+
`;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Flex, Spacer } from "@chakra-ui/react";
|
|
1
2
|
import {
|
|
2
3
|
ArgsTable,
|
|
3
4
|
Canvas,
|
|
@@ -9,15 +10,12 @@ import { withDesign } from "storybook-addon-designs";
|
|
|
9
10
|
|
|
10
11
|
import Checkbox from "../Checkbox/Checkbox";
|
|
11
12
|
import CheckboxGroup from "./CheckboxGroup";
|
|
12
|
-
import {
|
|
13
|
+
import { LayoutTypes } from "../../helpers/enums";
|
|
13
14
|
import { getCategory } from "../../utils/componentCategories";
|
|
14
15
|
import DSProvider from "../../theme/provider";
|
|
15
16
|
import { getStorybookEnumValues } from "../../utils/utils";
|
|
16
17
|
|
|
17
|
-
export const enumValues = getStorybookEnumValues(
|
|
18
|
-
CheckboxGroupLayoutTypes,
|
|
19
|
-
"CheckboxGroupLayoutTypes"
|
|
20
|
-
);
|
|
18
|
+
export const enumValues = getStorybookEnumValues(LayoutTypes, "LayoutTypes");
|
|
21
19
|
|
|
22
20
|
<Meta
|
|
23
21
|
title={getCategory("CheckboxGroup")}
|
|
@@ -37,6 +35,9 @@ export const enumValues = getStorybookEnumValues(
|
|
|
37
35
|
isDisabled: {
|
|
38
36
|
table: { defaultValue: { summary: false } },
|
|
39
37
|
},
|
|
38
|
+
isFullWidth: {
|
|
39
|
+
table: { defaultValue: { summary: true } },
|
|
40
|
+
},
|
|
40
41
|
isInvalid: {
|
|
41
42
|
table: { defaultValue: { summary: false } },
|
|
42
43
|
},
|
|
@@ -46,7 +47,7 @@ export const enumValues = getStorybookEnumValues(
|
|
|
46
47
|
key: { table: { disable: true } },
|
|
47
48
|
layout: {
|
|
48
49
|
control: { type: "select" },
|
|
49
|
-
table: { defaultValue: { summary: "
|
|
50
|
+
table: { defaultValue: { summary: "LayoutTypes.Column" } },
|
|
50
51
|
options: enumValues.options,
|
|
51
52
|
},
|
|
52
53
|
name: { control: false },
|
|
@@ -69,7 +70,7 @@ export const enumValues = getStorybookEnumValues(
|
|
|
69
70
|
| Component Version | DS Version |
|
|
70
71
|
| ----------------- | ---------- |
|
|
71
72
|
| Added | `0.25.1` |
|
|
72
|
-
| Latest | `0.25.
|
|
73
|
+
| Latest | `0.25.13` |
|
|
73
74
|
|
|
74
75
|
<Description of={CheckboxGroup} />
|
|
75
76
|
|
|
@@ -82,10 +83,11 @@ export const enumValues = getStorybookEnumValues(
|
|
|
82
83
|
id: "checkboxGroup-id",
|
|
83
84
|
invalidText: "This is the error text :(",
|
|
84
85
|
isDisabled: false,
|
|
86
|
+
isFullWidth: false,
|
|
85
87
|
isInvalid: false,
|
|
86
88
|
isRequired: false,
|
|
87
89
|
labelText: "Standard Checkbox Group",
|
|
88
|
-
layout: "
|
|
90
|
+
layout: "LayoutTypes.Column",
|
|
89
91
|
name: "checkbox-story",
|
|
90
92
|
onChange: undefined,
|
|
91
93
|
optReqFlag: true,
|
|
@@ -127,7 +129,7 @@ a row.
|
|
|
127
129
|
<CheckboxGroup
|
|
128
130
|
labelText="Row"
|
|
129
131
|
name="row-example"
|
|
130
|
-
layout={
|
|
132
|
+
layout={LayoutTypes.Row}
|
|
131
133
|
optReqFlag={false}
|
|
132
134
|
>
|
|
133
135
|
<Checkbox value="2" labelText="Checkbox 2" />
|
|
@@ -176,6 +178,68 @@ a row.
|
|
|
176
178
|
</DSProvider>
|
|
177
179
|
</Canvas>
|
|
178
180
|
|
|
181
|
+
## With JSX Element labels
|
|
182
|
+
|
|
183
|
+
React elements can be passed to the `labelText` prop of the `Checkbox` component.
|
|
184
|
+
This is useful if you need to pass information as part of the label. For example,
|
|
185
|
+
if a `Checkbox` label needs to display how many items that option has, it can be
|
|
186
|
+
displayed with the help of the `Flex` and `Spacer` components.
|
|
187
|
+
|
|
188
|
+
Note: the width of `CheckboxGroup` is _not_ set to full width by default. In
|
|
189
|
+
order to make this work, pass in the `isFullWidth` prop.
|
|
190
|
+
|
|
191
|
+
<Canvas>
|
|
192
|
+
<DSProvider>
|
|
193
|
+
<CheckboxGroup
|
|
194
|
+
labelText="Checkbox Group"
|
|
195
|
+
name="checkbox-example"
|
|
196
|
+
optReqFlag={false}
|
|
197
|
+
isFullWidth
|
|
198
|
+
>
|
|
199
|
+
<Checkbox
|
|
200
|
+
labelText={
|
|
201
|
+
<Flex>
|
|
202
|
+
<span>Arts</span>
|
|
203
|
+
<Spacer />
|
|
204
|
+
<span>4</span>
|
|
205
|
+
</Flex>
|
|
206
|
+
}
|
|
207
|
+
value="arts"
|
|
208
|
+
/>
|
|
209
|
+
<Checkbox
|
|
210
|
+
labelText={
|
|
211
|
+
<Flex>
|
|
212
|
+
<span>English</span>
|
|
213
|
+
<Spacer />
|
|
214
|
+
<span>23</span>
|
|
215
|
+
</Flex>
|
|
216
|
+
}
|
|
217
|
+
value="English"
|
|
218
|
+
/>
|
|
219
|
+
<Checkbox
|
|
220
|
+
labelText={
|
|
221
|
+
<Flex>
|
|
222
|
+
<span>Science</span>
|
|
223
|
+
<Spacer />
|
|
224
|
+
<span>10</span>
|
|
225
|
+
</Flex>
|
|
226
|
+
}
|
|
227
|
+
value="Science"
|
|
228
|
+
/>
|
|
229
|
+
<Checkbox
|
|
230
|
+
labelText={
|
|
231
|
+
<Flex>
|
|
232
|
+
<span>Math</span>
|
|
233
|
+
<Spacer />
|
|
234
|
+
<span>3</span>
|
|
235
|
+
</Flex>
|
|
236
|
+
}
|
|
237
|
+
value="Math"
|
|
238
|
+
/>
|
|
239
|
+
</CheckboxGroup>
|
|
240
|
+
</DSProvider>
|
|
241
|
+
</Canvas>
|
|
242
|
+
|
|
179
243
|
## Indeterminate Example
|
|
180
244
|
|
|
181
245
|
The "indeterminate" state can be used when a group of checkboxes are not all
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Flex, Spacer } from "@chakra-ui/react";
|
|
2
2
|
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
3
4
|
import { axe } from "jest-axe";
|
|
5
|
+
import * as React from "react";
|
|
4
6
|
import renderer from "react-test-renderer";
|
|
5
7
|
|
|
6
8
|
import * as generateUUID from "../../helpers/generateUUID";
|
|
7
9
|
import CheckboxGroup from "./CheckboxGroup";
|
|
8
10
|
import Checkbox from "../Checkbox/Checkbox";
|
|
9
|
-
import {
|
|
10
|
-
import userEvent from "@testing-library/user-event";
|
|
11
|
+
import { LayoutTypes } from "../../helpers/enums";
|
|
11
12
|
|
|
12
|
-
describe("
|
|
13
|
-
it("passes axe accessibility", async () => {
|
|
13
|
+
describe("CheckboxGroup Accessibility", () => {
|
|
14
|
+
it("passes axe accessibility with string labels ", async () => {
|
|
14
15
|
const { container } = render(
|
|
15
16
|
<CheckboxGroup labelText="CheckboxGroup example" name="a11y-test">
|
|
16
17
|
<Checkbox value="2" labelText="Checkbox 2" />
|
|
@@ -21,6 +22,40 @@ describe("Checkbox Accessibility", () => {
|
|
|
21
22
|
);
|
|
22
23
|
expect(await axe(container)).toHaveNoViolations();
|
|
23
24
|
});
|
|
25
|
+
it("passes axe accessibility with jsx labels", async () => {
|
|
26
|
+
const { container } = render(
|
|
27
|
+
<CheckboxGroup
|
|
28
|
+
labelText="jsxLabels"
|
|
29
|
+
name="jsxLabels"
|
|
30
|
+
id="jsxLabels"
|
|
31
|
+
isFullWidth
|
|
32
|
+
>
|
|
33
|
+
<Checkbox
|
|
34
|
+
id="arts"
|
|
35
|
+
labelText={
|
|
36
|
+
<Flex>
|
|
37
|
+
<span>Arts</span>
|
|
38
|
+
<Spacer />
|
|
39
|
+
<span>4</span>
|
|
40
|
+
</Flex>
|
|
41
|
+
}
|
|
42
|
+
value="arts"
|
|
43
|
+
/>
|
|
44
|
+
<Checkbox
|
|
45
|
+
id="English"
|
|
46
|
+
labelText={
|
|
47
|
+
<Flex>
|
|
48
|
+
<span>English</span>
|
|
49
|
+
<Spacer />
|
|
50
|
+
<span>23</span>
|
|
51
|
+
</Flex>
|
|
52
|
+
}
|
|
53
|
+
value="English"
|
|
54
|
+
/>
|
|
55
|
+
</CheckboxGroup>
|
|
56
|
+
);
|
|
57
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
58
|
+
});
|
|
24
59
|
});
|
|
25
60
|
|
|
26
61
|
describe("Checkbox", () => {
|
|
@@ -119,8 +154,8 @@ describe("Checkbox", () => {
|
|
|
119
154
|
});
|
|
120
155
|
|
|
121
156
|
it("sets the next value through the onChange function", () => {
|
|
122
|
-
let newValue = [];
|
|
123
|
-
const onChange = (value) => {
|
|
157
|
+
let newValue: string[] = [];
|
|
158
|
+
const onChange = (value: string[]) => {
|
|
124
159
|
newValue = value;
|
|
125
160
|
};
|
|
126
161
|
render(
|
|
@@ -248,7 +283,7 @@ describe("Checkbox", () => {
|
|
|
248
283
|
labelText="row"
|
|
249
284
|
name="row"
|
|
250
285
|
id="row"
|
|
251
|
-
layout={
|
|
286
|
+
layout={LayoutTypes.Row}
|
|
252
287
|
>
|
|
253
288
|
<Checkbox value="2" labelText="Checkbox 2" />
|
|
254
289
|
<Checkbox value="3" labelText="Checkbox 3" />
|
|
@@ -346,6 +381,39 @@ describe("Checkbox", () => {
|
|
|
346
381
|
</CheckboxGroup>
|
|
347
382
|
)
|
|
348
383
|
.toJSON();
|
|
384
|
+
const withJSXCheckboxLabels = renderer
|
|
385
|
+
.create(
|
|
386
|
+
<CheckboxGroup
|
|
387
|
+
id="jsxLabels"
|
|
388
|
+
isFullWidth
|
|
389
|
+
labelText="jsxLabels"
|
|
390
|
+
name="jsxLabels"
|
|
391
|
+
>
|
|
392
|
+
<Checkbox
|
|
393
|
+
id="arts"
|
|
394
|
+
labelText={
|
|
395
|
+
<Flex>
|
|
396
|
+
<span>Arts</span>
|
|
397
|
+
<Spacer />
|
|
398
|
+
<span>4</span>
|
|
399
|
+
</Flex>
|
|
400
|
+
}
|
|
401
|
+
value="arts"
|
|
402
|
+
/>
|
|
403
|
+
<Checkbox
|
|
404
|
+
id="English"
|
|
405
|
+
labelText={
|
|
406
|
+
<Flex>
|
|
407
|
+
<span>English</span>
|
|
408
|
+
<Spacer />
|
|
409
|
+
<span>23</span>
|
|
410
|
+
</Flex>
|
|
411
|
+
}
|
|
412
|
+
value="English"
|
|
413
|
+
/>
|
|
414
|
+
</CheckboxGroup>
|
|
415
|
+
)
|
|
416
|
+
.toJSON();
|
|
349
417
|
|
|
350
418
|
expect(column).toMatchSnapshot();
|
|
351
419
|
expect(row).toMatchSnapshot();
|
|
@@ -356,6 +424,7 @@ describe("Checkbox", () => {
|
|
|
356
424
|
expect(isRequired).toMatchSnapshot();
|
|
357
425
|
expect(isInvalid).toMatchSnapshot();
|
|
358
426
|
expect(isDisabled).toMatchSnapshot();
|
|
427
|
+
expect(withJSXCheckboxLabels).toMatchSnapshot();
|
|
359
428
|
});
|
|
360
429
|
|
|
361
430
|
it("should throw warning when a non-Checkbox component is used as a child", () => {
|
|
@@ -366,7 +435,8 @@ describe("Checkbox", () => {
|
|
|
366
435
|
</CheckboxGroup>
|
|
367
436
|
);
|
|
368
437
|
expect(warn).toHaveBeenCalledWith(
|
|
369
|
-
"Only `Checkbox` components are
|
|
438
|
+
"NYPL Reservoir CheckboxGroup: Only `Checkbox` components are " +
|
|
439
|
+
"allowed as children."
|
|
370
440
|
);
|
|
371
441
|
});
|
|
372
442
|
});
|
|
@@ -7,11 +7,11 @@ import {
|
|
|
7
7
|
} from "@chakra-ui/react";
|
|
8
8
|
|
|
9
9
|
import Checkbox from "../Checkbox/Checkbox";
|
|
10
|
-
import { CheckboxGroupLayoutTypes } from "./CheckboxGroupLayoutTypes";
|
|
11
10
|
import Fieldset from "../Fieldset/Fieldset";
|
|
12
11
|
import HelperErrorText, {
|
|
13
12
|
HelperErrorTextType,
|
|
14
13
|
} from "../HelperErrorText/HelperErrorText";
|
|
14
|
+
import { LayoutTypes } from "../../helpers/enums";
|
|
15
15
|
import { spacing } from "../../theme/foundations/spacing";
|
|
16
16
|
import generateUUID from "../../helpers/generateUUID";
|
|
17
17
|
|
|
@@ -28,6 +28,8 @@ export interface CheckboxGroupProps {
|
|
|
28
28
|
invalidText?: HelperErrorTextType;
|
|
29
29
|
/** Adds the 'disabled' prop to the input when true. */
|
|
30
30
|
isDisabled?: boolean;
|
|
31
|
+
/** Set's the `Checkbox`s' wrapper to be full width. */
|
|
32
|
+
isFullWidth?: boolean;
|
|
31
33
|
/** A`dds the 'aria-invalid' attribute to the input and
|
|
32
34
|
* sets the error state when true. */
|
|
33
35
|
isInvalid?: boolean;
|
|
@@ -37,7 +39,7 @@ export interface CheckboxGroupProps {
|
|
|
37
39
|
* true, or an "aria-label" if `showLabel` is false. */
|
|
38
40
|
labelText: string;
|
|
39
41
|
/** Renders the checkbox buttons in a row or column (default). */
|
|
40
|
-
layout?:
|
|
42
|
+
layout?: LayoutTypes;
|
|
41
43
|
/** The `name` prop indicates the form group for all the `Checkbox` children. */
|
|
42
44
|
name: string;
|
|
43
45
|
/** The action to perform on the `<input>`'s onChange function */
|
|
@@ -68,10 +70,11 @@ const CheckboxGroup = React.forwardRef<HTMLInputElement, CheckboxGroupProps>(
|
|
|
68
70
|
id = generateUUID(),
|
|
69
71
|
invalidText,
|
|
70
72
|
isDisabled = false,
|
|
73
|
+
isFullWidth = false,
|
|
71
74
|
isInvalid = false,
|
|
72
75
|
isRequired = false,
|
|
73
76
|
labelText,
|
|
74
|
-
layout =
|
|
77
|
+
layout = LayoutTypes.Column,
|
|
75
78
|
name,
|
|
76
79
|
onChange,
|
|
77
80
|
optReqFlag = true,
|
|
@@ -79,8 +82,7 @@ const CheckboxGroup = React.forwardRef<HTMLInputElement, CheckboxGroupProps>(
|
|
|
79
82
|
showLabel = true,
|
|
80
83
|
} = props;
|
|
81
84
|
const footnote: HelperErrorTextType = isInvalid ? invalidText : helperText;
|
|
82
|
-
const spacingProp =
|
|
83
|
-
layout === CheckboxGroupLayoutTypes.Column ? spacing.s : spacing.l;
|
|
85
|
+
const spacingProp = layout === LayoutTypes.Column ? spacing.s : spacing.l;
|
|
84
86
|
const newChildren = [];
|
|
85
87
|
const checkboxProps =
|
|
86
88
|
defaultValue && onChange
|
|
@@ -98,7 +100,8 @@ const CheckboxGroup = React.forwardRef<HTMLInputElement, CheckboxGroupProps>(
|
|
|
98
100
|
noop();
|
|
99
101
|
} else {
|
|
100
102
|
console.warn(
|
|
101
|
-
"Only `Checkbox` components are
|
|
103
|
+
"NYPL Reservoir CheckboxGroup: Only `Checkbox` components are " +
|
|
104
|
+
"allowed as children."
|
|
102
105
|
);
|
|
103
106
|
}
|
|
104
107
|
}
|
|
@@ -117,7 +120,7 @@ const CheckboxGroup = React.forwardRef<HTMLInputElement, CheckboxGroupProps>(
|
|
|
117
120
|
});
|
|
118
121
|
|
|
119
122
|
// Get the Chakra-based styles for the custom elements in this component.
|
|
120
|
-
const styles = useMultiStyleConfig("CheckboxGroup", {});
|
|
123
|
+
const styles = useMultiStyleConfig("CheckboxGroup", { isFullWidth });
|
|
121
124
|
|
|
122
125
|
return (
|
|
123
126
|
<Fieldset
|
|
@@ -1327,3 +1327,172 @@ exports[`Checkbox renders the UI snapshot correctly 9`] = `
|
|
|
1327
1327
|
</div>
|
|
1328
1328
|
</fieldset>
|
|
1329
1329
|
`;
|
|
1330
|
+
|
|
1331
|
+
exports[`Checkbox renders the UI snapshot correctly 10`] = `
|
|
1332
|
+
<fieldset
|
|
1333
|
+
className="css-0"
|
|
1334
|
+
id="jsxLabels-checkbox-group"
|
|
1335
|
+
>
|
|
1336
|
+
<legend>
|
|
1337
|
+
jsxLabels
|
|
1338
|
+
<div
|
|
1339
|
+
className="css-0"
|
|
1340
|
+
>
|
|
1341
|
+
Optional
|
|
1342
|
+
</div>
|
|
1343
|
+
</legend>
|
|
1344
|
+
<div
|
|
1345
|
+
aria-label={null}
|
|
1346
|
+
className="chakra-stack css-1wdv1uh"
|
|
1347
|
+
data-testid="checkbox-group"
|
|
1348
|
+
id="jsxLabels"
|
|
1349
|
+
>
|
|
1350
|
+
<label
|
|
1351
|
+
className="chakra-checkbox css-g8du1g"
|
|
1352
|
+
onClick={[Function]}
|
|
1353
|
+
>
|
|
1354
|
+
<input
|
|
1355
|
+
aria-disabled={false}
|
|
1356
|
+
aria-invalid={false}
|
|
1357
|
+
checked={false}
|
|
1358
|
+
className="chakra-checkbox__input"
|
|
1359
|
+
disabled={false}
|
|
1360
|
+
id="jsxLabels-0"
|
|
1361
|
+
name="jsxLabels"
|
|
1362
|
+
onBlur={[Function]}
|
|
1363
|
+
onChange={[Function]}
|
|
1364
|
+
onFocus={[Function]}
|
|
1365
|
+
onKeyDown={[Function]}
|
|
1366
|
+
onKeyUp={[Function]}
|
|
1367
|
+
required={false}
|
|
1368
|
+
style={
|
|
1369
|
+
Object {
|
|
1370
|
+
"border": "0px",
|
|
1371
|
+
"clip": "rect(0px, 0px, 0px, 0px)",
|
|
1372
|
+
"height": "1px",
|
|
1373
|
+
"margin": "-1px",
|
|
1374
|
+
"overflow": "hidden",
|
|
1375
|
+
"padding": "0px",
|
|
1376
|
+
"position": "absolute",
|
|
1377
|
+
"whiteSpace": "nowrap",
|
|
1378
|
+
"width": "1px",
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
type="checkbox"
|
|
1382
|
+
value="arts"
|
|
1383
|
+
/>
|
|
1384
|
+
<span
|
|
1385
|
+
aria-hidden={true}
|
|
1386
|
+
className="chakra-checkbox__control css-dnty2r"
|
|
1387
|
+
onMouseDown={[Function]}
|
|
1388
|
+
onMouseEnter={[Function]}
|
|
1389
|
+
onMouseLeave={[Function]}
|
|
1390
|
+
onMouseUp={[Function]}
|
|
1391
|
+
>
|
|
1392
|
+
<svg
|
|
1393
|
+
className="chakra-icon css-1vfv7ic"
|
|
1394
|
+
focusable={false}
|
|
1395
|
+
viewBox="0 0 24 24"
|
|
1396
|
+
>
|
|
1397
|
+
<path
|
|
1398
|
+
d="M8.795 15.875l-4.17-4.17-1.42 1.41 5.59 5.59 12-12-1.41-1.41-10.59 10.58z"
|
|
1399
|
+
fill="currentColor"
|
|
1400
|
+
/>
|
|
1401
|
+
</svg>
|
|
1402
|
+
</span>
|
|
1403
|
+
<span
|
|
1404
|
+
className="chakra-checkbox__label css-1oeb2oe"
|
|
1405
|
+
onMouseDown={[Function]}
|
|
1406
|
+
onTouchStart={[Function]}
|
|
1407
|
+
>
|
|
1408
|
+
<div
|
|
1409
|
+
className="css-k008qs"
|
|
1410
|
+
>
|
|
1411
|
+
<span>
|
|
1412
|
+
Arts
|
|
1413
|
+
</span>
|
|
1414
|
+
<div
|
|
1415
|
+
className="css-17xejub"
|
|
1416
|
+
/>
|
|
1417
|
+
<span>
|
|
1418
|
+
4
|
|
1419
|
+
</span>
|
|
1420
|
+
</div>
|
|
1421
|
+
</span>
|
|
1422
|
+
</label>
|
|
1423
|
+
<label
|
|
1424
|
+
className="chakra-checkbox css-g8du1g"
|
|
1425
|
+
onClick={[Function]}
|
|
1426
|
+
>
|
|
1427
|
+
<input
|
|
1428
|
+
aria-disabled={false}
|
|
1429
|
+
aria-invalid={false}
|
|
1430
|
+
checked={false}
|
|
1431
|
+
className="chakra-checkbox__input"
|
|
1432
|
+
disabled={false}
|
|
1433
|
+
id="jsxLabels-1"
|
|
1434
|
+
name="jsxLabels"
|
|
1435
|
+
onBlur={[Function]}
|
|
1436
|
+
onChange={[Function]}
|
|
1437
|
+
onFocus={[Function]}
|
|
1438
|
+
onKeyDown={[Function]}
|
|
1439
|
+
onKeyUp={[Function]}
|
|
1440
|
+
required={false}
|
|
1441
|
+
style={
|
|
1442
|
+
Object {
|
|
1443
|
+
"border": "0px",
|
|
1444
|
+
"clip": "rect(0px, 0px, 0px, 0px)",
|
|
1445
|
+
"height": "1px",
|
|
1446
|
+
"margin": "-1px",
|
|
1447
|
+
"overflow": "hidden",
|
|
1448
|
+
"padding": "0px",
|
|
1449
|
+
"position": "absolute",
|
|
1450
|
+
"whiteSpace": "nowrap",
|
|
1451
|
+
"width": "1px",
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
type="checkbox"
|
|
1455
|
+
value="English"
|
|
1456
|
+
/>
|
|
1457
|
+
<span
|
|
1458
|
+
aria-hidden={true}
|
|
1459
|
+
className="chakra-checkbox__control css-dnty2r"
|
|
1460
|
+
onMouseDown={[Function]}
|
|
1461
|
+
onMouseEnter={[Function]}
|
|
1462
|
+
onMouseLeave={[Function]}
|
|
1463
|
+
onMouseUp={[Function]}
|
|
1464
|
+
>
|
|
1465
|
+
<svg
|
|
1466
|
+
className="chakra-icon css-1vfv7ic"
|
|
1467
|
+
focusable={false}
|
|
1468
|
+
viewBox="0 0 24 24"
|
|
1469
|
+
>
|
|
1470
|
+
<path
|
|
1471
|
+
d="M8.795 15.875l-4.17-4.17-1.42 1.41 5.59 5.59 12-12-1.41-1.41-10.59 10.58z"
|
|
1472
|
+
fill="currentColor"
|
|
1473
|
+
/>
|
|
1474
|
+
</svg>
|
|
1475
|
+
</span>
|
|
1476
|
+
<span
|
|
1477
|
+
className="chakra-checkbox__label css-1oeb2oe"
|
|
1478
|
+
onMouseDown={[Function]}
|
|
1479
|
+
onTouchStart={[Function]}
|
|
1480
|
+
>
|
|
1481
|
+
<div
|
|
1482
|
+
className="css-k008qs"
|
|
1483
|
+
>
|
|
1484
|
+
<span>
|
|
1485
|
+
English
|
|
1486
|
+
</span>
|
|
1487
|
+
<div
|
|
1488
|
+
className="css-17xejub"
|
|
1489
|
+
/>
|
|
1490
|
+
<span>
|
|
1491
|
+
23
|
|
1492
|
+
</span>
|
|
1493
|
+
</div>
|
|
1494
|
+
</span>
|
|
1495
|
+
</label>
|
|
1496
|
+
</div>
|
|
1497
|
+
</fieldset>
|
|
1498
|
+
`;
|
|
@@ -46,7 +46,7 @@ function ComponentWrapper(
|
|
|
46
46
|
// Note: Typescript warns when there are no children passed and
|
|
47
47
|
// doesn't compile. This is meant to log in non-Typescript apps.
|
|
48
48
|
if (!hasChildren) {
|
|
49
|
-
console.warn("
|
|
49
|
+
console.warn("NYPL Reservoir ComponentWrapper: No children were passed.");
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
return (
|
|
@@ -344,7 +344,8 @@ describe("DatePicker", () => {
|
|
|
344
344
|
/>
|
|
345
345
|
);
|
|
346
346
|
expect(warn).toHaveBeenCalledWith(
|
|
347
|
-
"A `ref` or `refTo` prop was passed but
|
|
347
|
+
"NYPL Reservoir DatePicker: A `ref` or `refTo` prop was passed but " +
|
|
348
|
+
"not the equivalent `nameFrom` or `nameTo` prop."
|
|
348
349
|
);
|
|
349
350
|
});
|
|
350
351
|
|
|
@@ -361,7 +362,9 @@ describe("DatePicker", () => {
|
|
|
361
362
|
/>
|
|
362
363
|
);
|
|
363
364
|
expect(warn).toHaveBeenCalledWith(
|
|
364
|
-
"
|
|
365
|
+
"NYPL Reservoir DatePicker: A `ref`, `refTo`, `nameFrom`, or `nameTo` " +
|
|
366
|
+
"prop was passed and an `onChange` prop as well. Use whichever is best " +
|
|
367
|
+
"for your app but not both."
|
|
365
368
|
);
|
|
366
369
|
});
|
|
367
370
|
|
|
@@ -327,12 +327,15 @@ const DatePicker = React.forwardRef<TextInputRefType, DatePickerProps>(
|
|
|
327
327
|
|
|
328
328
|
if ((ref && !nameFrom) || (refTo && !nameTo)) {
|
|
329
329
|
console.warn(
|
|
330
|
-
"A `ref` or `refTo` prop was passed but
|
|
330
|
+
"NYPL Reservoir DatePicker: A `ref` or `refTo` prop was passed but " +
|
|
331
|
+
"not the equivalent `nameFrom` or `nameTo` prop."
|
|
331
332
|
);
|
|
332
333
|
}
|
|
333
334
|
if (onChange && (ref || refTo || nameFrom || nameTo)) {
|
|
334
335
|
console.warn(
|
|
335
|
-
"
|
|
336
|
+
"NYPL Reservoir DatePicker: A `ref`, `refTo`, `nameFrom`, or `nameTo` " +
|
|
337
|
+
"prop was passed and an `onChange` prop as well. Use whichever is best " +
|
|
338
|
+
"for your app but not both."
|
|
336
339
|
);
|
|
337
340
|
}
|
|
338
341
|
|