@nypl/design-system-react-components 0.28.0 → 1.0.2
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 +39 -0
- package/README.md +10 -10
- package/dist/components/Checkbox/Checkbox.d.ts +0 -1
- package/dist/components/ComponentWrapper/ComponentWrapper.d.ts +8 -0
- package/dist/components/Heading/Heading.d.ts +2 -0
- package/dist/components/Logo/Logo.d.ts +1 -1
- package/dist/components/Logo/LogoSvgs.d.ts +4 -0
- package/dist/design-system-react-components.cjs.development.js +1021 -683
- 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 +1022 -684
- package/dist/design-system-react-components.esm.js.map +1 -1
- package/dist/theme/components/button.d.ts +1 -0
- package/dist/theme/components/card.d.ts +98 -13
- package/dist/theme/components/checkboxGroup.d.ts +1 -1
- package/dist/theme/components/global.d.ts +1 -1
- package/dist/theme/components/heading.d.ts +4 -16
- package/dist/theme/components/image.d.ts +6 -0
- package/dist/theme/components/radioGroup.d.ts +1 -1
- package/dist/theme/components/skipNavigation.d.ts +3 -0
- package/dist/theme/components/structuredContent.d.ts +0 -5
- package/dist/utils/utils.d.ts +15 -0
- package/package.json +6 -6
- package/src/components/Accordion/Accordion.stories.mdx +18 -46
- package/src/components/Accordion/Accordion.tsx +3 -2
- package/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +12 -12
- package/src/components/Button/Button.stories.mdx +1 -1
- package/src/components/ButtonGroup/ButtonGroup.stories.mdx +33 -2
- package/src/components/ButtonGroup/ButtonGroup.tsx +2 -1
- package/src/components/Card/Card.stories.mdx +2 -4
- package/src/components/Card/Card.tsx +2 -1
- package/src/components/Chakra/Box.stories.mdx +1 -1
- package/src/components/Chakra/Center.stories.mdx +1 -1
- package/src/components/Chakra/Flex.stories.mdx +1 -1
- package/src/components/Chakra/Grid.stories.mdx +1 -1
- package/src/components/Chakra/Stack.stories.mdx +1 -1
- package/src/components/Checkbox/Checkbox.stories.mdx +1 -1
- package/src/components/Checkbox/Checkbox.test.tsx +42 -11
- package/src/components/Checkbox/Checkbox.tsx +25 -39
- package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +589 -544
- package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +1 -1
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +1 -1
- package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +1540 -1420
- package/src/components/ComponentWrapper/ComponentWrapper.tsx +12 -3
- package/src/components/ComponentWrapper/__snapshots__/ComponentWrapper.test.tsx.snap +5 -0
- package/src/components/DatePicker/__snapshots__/DatePicker.test.tsx.snap +36 -17
- package/src/components/Grid/SimpleGrid.stories.mdx +1 -3
- package/src/components/Heading/Heading.stories.mdx +4 -1
- package/src/components/Heading/Heading.tsx +4 -1
- package/src/components/Image/Image.stories.mdx +1 -1
- package/src/components/Logo/Logo.stories.mdx +10 -5
- package/src/components/Logo/Logo.tsx +4 -0
- package/src/components/Logo/LogoSvgs.tsx +8 -0
- package/src/components/Modal/Modal.stories.mdx +83 -90
- package/src/components/Pagination/Pagination.stories.mdx +1 -1
- package/src/components/Radio/Radio.stories.mdx +1 -1
- package/src/components/Radio/Radio.tsx +22 -31
- package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +405 -365
- package/src/components/RadioGroup/RadioGroup.stories.mdx +2 -1
- package/src/components/RadioGroup/RadioGroup.tsx +2 -1
- package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +1236 -1116
- package/src/components/SearchBar/SearchBar.stories.mdx +3 -3
- package/src/components/SearchBar/__snapshots__/SearchBar.test.tsx.snap +32 -10
- package/src/components/Select/Select.stories.mdx +1 -1
- package/src/components/Select/Select.tsx +24 -22
- package/src/components/Select/__snapshots__/Select.test.tsx.snap +21 -11
- package/src/components/SkipNavigation/SkipNavigation.stories.mdx +2 -2
- package/src/components/Slider/Slider.stories.mdx +1 -1
- package/src/components/Slider/Slider.tsx +14 -14
- package/src/components/Slider/__snapshots__/Slider.test.tsx.snap +66 -33
- package/src/components/StyleGuide/Buttons.stories.mdx +1 -1
- package/src/components/StyleGuide/Colors.stories.mdx +2 -2
- package/src/components/StyleGuide/Forms.stories.mdx +2 -1
- package/src/components/StyleGuide/Iconography.stories.mdx +2 -2
- package/src/components/StyleGuide/Spacing.stories.mdx +1 -1
- package/src/components/StyleGuide/Typography.stories.mdx +1 -1
- package/src/components/Table/Table.stories.mdx +1 -5
- package/src/components/Table/Table.test.tsx +33 -0
- package/src/components/Table/Table.tsx +21 -0
- package/src/components/Template/Template.stories.mdx +9 -5
- package/src/components/TextInput/TextInput.stories.mdx +1 -1
- package/src/components/TextInput/TextInput.tsx +21 -21
- package/src/components/TextInput/__snapshots__/TextInput.test.tsx.snap +19 -9
- package/src/components/Toggle/Toggle.stories.mdx +1 -1
- package/src/components/Toggle/Toggle.tsx +22 -20
- package/src/components/Toggle/__snapshots__/Toggle.test.tsx.snap +400 -372
- package/src/components/VideoPlayer/VideoPlayer.stories.mdx +1 -0
- package/src/components/VideoPlayer/__snapshots__/VideoPlayer.test.tsx.snap +5 -0
- package/src/docs/Chakra.stories.mdx +2 -2
- package/src/theme/components/button.ts +1 -0
- package/src/theme/components/card.ts +9 -3
- package/src/theme/components/componentWrapper.ts +1 -1
- package/src/theme/components/global.ts +1 -1
- package/src/theme/components/heading.ts +3 -3
- package/src/theme/components/image.ts +1 -0
- package/src/theme/components/skipNavigation.ts +3 -0
- package/src/theme/foundations/colors.ts +6 -9
- package/src/utils/utils.ts +40 -0
|
@@ -11,7 +11,7 @@ exports[`Accordion Renders the UI snapshot correctly 1`] = `
|
|
|
11
11
|
<button
|
|
12
12
|
aria-controls="accordion-panel-accordian-item-0"
|
|
13
13
|
aria-expanded={false}
|
|
14
|
-
className="chakra-accordion__button css-
|
|
14
|
+
className="chakra-accordion__button css-ilurlz"
|
|
15
15
|
disabled={false}
|
|
16
16
|
id="accordion-button-accordian-item-0"
|
|
17
17
|
onClick={[Function]}
|
|
@@ -20,7 +20,7 @@ exports[`Accordion Renders the UI snapshot correctly 1`] = `
|
|
|
20
20
|
type="button"
|
|
21
21
|
>
|
|
22
22
|
<div
|
|
23
|
-
className="css-
|
|
23
|
+
className="css-ox82o1"
|
|
24
24
|
>
|
|
25
25
|
Gerry Kellman
|
|
26
26
|
</div>
|
|
@@ -133,7 +133,7 @@ exports[`Accordion Renders the UI snapshot correctly 2`] = `
|
|
|
133
133
|
<button
|
|
134
134
|
aria-controls="accordion-panel-accordian-item-0"
|
|
135
135
|
aria-expanded={false}
|
|
136
|
-
className="chakra-accordion__button css-
|
|
136
|
+
className="chakra-accordion__button css-ilurlz"
|
|
137
137
|
disabled={false}
|
|
138
138
|
id="accordion-button-accordian-item-0"
|
|
139
139
|
onClick={[Function]}
|
|
@@ -142,7 +142,7 @@ exports[`Accordion Renders the UI snapshot correctly 2`] = `
|
|
|
142
142
|
type="button"
|
|
143
143
|
>
|
|
144
144
|
<div
|
|
145
|
-
className="css-
|
|
145
|
+
className="css-ox82o1"
|
|
146
146
|
>
|
|
147
147
|
Gerry Kellman
|
|
148
148
|
</div>
|
|
@@ -255,7 +255,7 @@ exports[`Accordion Renders the UI snapshot correctly 3`] = `
|
|
|
255
255
|
<button
|
|
256
256
|
aria-controls="accordion-panel-accordian-item-0"
|
|
257
257
|
aria-expanded={false}
|
|
258
|
-
className="chakra-accordion__button css-
|
|
258
|
+
className="chakra-accordion__button css-ilurlz"
|
|
259
259
|
disabled={false}
|
|
260
260
|
id="accordion-button-accordian-item-0"
|
|
261
261
|
onClick={[Function]}
|
|
@@ -264,7 +264,7 @@ exports[`Accordion Renders the UI snapshot correctly 3`] = `
|
|
|
264
264
|
type="button"
|
|
265
265
|
>
|
|
266
266
|
<div
|
|
267
|
-
className="css-
|
|
267
|
+
className="css-ox82o1"
|
|
268
268
|
>
|
|
269
269
|
Gerry Kellman
|
|
270
270
|
</div>
|
|
@@ -378,7 +378,7 @@ exports[`Accordion Renders the UI snapshot correctly 4`] = `
|
|
|
378
378
|
<button
|
|
379
379
|
aria-controls="accordion-panel-accordian-item-0"
|
|
380
380
|
aria-expanded={false}
|
|
381
|
-
className="chakra-accordion__button css-
|
|
381
|
+
className="chakra-accordion__button css-ilurlz"
|
|
382
382
|
disabled={false}
|
|
383
383
|
id="accordion-button-accordian-item-0"
|
|
384
384
|
onClick={[Function]}
|
|
@@ -387,7 +387,7 @@ exports[`Accordion Renders the UI snapshot correctly 4`] = `
|
|
|
387
387
|
type="button"
|
|
388
388
|
>
|
|
389
389
|
<div
|
|
390
|
-
className="css-
|
|
390
|
+
className="css-ox82o1"
|
|
391
391
|
>
|
|
392
392
|
Gerry Kellman
|
|
393
393
|
</div>
|
|
@@ -500,7 +500,7 @@ exports[`Accordion Renders the UI snapshot correctly 5`] = `
|
|
|
500
500
|
<button
|
|
501
501
|
aria-controls="accordion-panel-accordian-item-0"
|
|
502
502
|
aria-expanded={false}
|
|
503
|
-
className="chakra-accordion__button css-
|
|
503
|
+
className="chakra-accordion__button css-gne4sq"
|
|
504
504
|
disabled={false}
|
|
505
505
|
id="accordion-button-accordian-item-0"
|
|
506
506
|
onClick={[Function]}
|
|
@@ -509,7 +509,7 @@ exports[`Accordion Renders the UI snapshot correctly 5`] = `
|
|
|
509
509
|
type="button"
|
|
510
510
|
>
|
|
511
511
|
<div
|
|
512
|
-
className="css-
|
|
512
|
+
className="css-ox82o1"
|
|
513
513
|
>
|
|
514
514
|
Gerry Kellman
|
|
515
515
|
</div>
|
|
@@ -622,7 +622,7 @@ exports[`Accordion Renders the UI snapshot correctly 6`] = `
|
|
|
622
622
|
<button
|
|
623
623
|
aria-controls="accordion-panel-accordian-item-0"
|
|
624
624
|
aria-expanded={false}
|
|
625
|
-
className="chakra-accordion__button css-
|
|
625
|
+
className="chakra-accordion__button css-11hvvs4"
|
|
626
626
|
disabled={false}
|
|
627
627
|
id="accordion-button-accordian-item-0"
|
|
628
628
|
onClick={[Function]}
|
|
@@ -631,7 +631,7 @@ exports[`Accordion Renders the UI snapshot correctly 6`] = `
|
|
|
631
631
|
type="button"
|
|
632
632
|
>
|
|
633
633
|
<div
|
|
634
|
-
className="css-
|
|
634
|
+
className="css-ox82o1"
|
|
635
635
|
>
|
|
636
636
|
Gerry Kellman
|
|
637
637
|
</div>
|
|
@@ -35,7 +35,7 @@ import DSProvider from "../../theme/provider";
|
|
|
35
35
|
| Component Version | DS Version |
|
|
36
36
|
| ----------------- | ---------- |
|
|
37
37
|
| Added | `0.28.0` |
|
|
38
|
-
| Latest | `0.
|
|
38
|
+
| Latest | `1.0.2` |
|
|
39
39
|
|
|
40
40
|
## Table of Contents
|
|
41
41
|
|
|
@@ -44,6 +44,7 @@ import DSProvider from "../../theme/provider";
|
|
|
44
44
|
- [Accessibility](#accessibility)
|
|
45
45
|
- [Button Width](#button-width)
|
|
46
46
|
- [Layout](#layout)
|
|
47
|
+
- [isDisabled](#isDisabled)
|
|
47
48
|
|
|
48
49
|
## Overview
|
|
49
50
|
|
|
@@ -83,7 +84,7 @@ width.
|
|
|
83
84
|
|
|
84
85
|
This component is a wrapper around the `Button` component. For accessibility
|
|
85
86
|
information on the `Button` component, see the
|
|
86
|
-
[Button Accessibility](https://nypl.github.io/nypl-design-system/reservoir/
|
|
87
|
+
[Button Accessibility](https://nypl.github.io/nypl-design-system/reservoir/v1/?path=/docs/components-form-elements-button--button-with-controls#accessibility)
|
|
87
88
|
documentation.
|
|
88
89
|
|
|
89
90
|
## Button Width
|
|
@@ -145,3 +146,33 @@ The `layout` prop can be used to set the layout to either `row` or `column`.
|
|
|
145
146
|
</SimpleGrid>
|
|
146
147
|
</DSProvider>
|
|
147
148
|
</Canvas>
|
|
149
|
+
|
|
150
|
+
## isDisabled
|
|
151
|
+
|
|
152
|
+
The `isDisabled` prop can be used to disable all the `Button` children at once.
|
|
153
|
+
Individual `Button`s can still be disabled with their own `isDisabled` prop.
|
|
154
|
+
|
|
155
|
+
<Canvas>
|
|
156
|
+
<DSProvider>
|
|
157
|
+
<SimpleGrid columns={1}>
|
|
158
|
+
<Heading level="three">ButtonGroup isDisabled</Heading>
|
|
159
|
+
<ButtonGroup isDisabled>
|
|
160
|
+
<Button buttonType="secondary" id="group-disabled-1">
|
|
161
|
+
Button disabled
|
|
162
|
+
</Button>
|
|
163
|
+
<Button buttonType="secondary" id="group-disabled-2">
|
|
164
|
+
Button disabled
|
|
165
|
+
</Button>
|
|
166
|
+
</ButtonGroup>
|
|
167
|
+
<Heading level="three">Individual Button isDisabled</Heading>
|
|
168
|
+
<ButtonGroup>
|
|
169
|
+
<Button buttonType="secondary" id="individual-disabled-1">
|
|
170
|
+
Button not disabled
|
|
171
|
+
</Button>
|
|
172
|
+
<Button buttonType="secondary" id="individual-disabled-2" isDisabled>
|
|
173
|
+
Button disabled
|
|
174
|
+
</Button>
|
|
175
|
+
</ButtonGroup>
|
|
176
|
+
</SimpleGrid>
|
|
177
|
+
</DSProvider>
|
|
178
|
+
</Canvas>
|
|
@@ -76,7 +76,8 @@ export const ButtonGroup = chakra(
|
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
const disabledProps = isDisabled ? { isDisabled } : {};
|
|
80
|
+
newChildren.push(React.cloneElement(child, { key, ...disabledProps }));
|
|
80
81
|
}
|
|
81
82
|
);
|
|
82
83
|
|
|
@@ -75,7 +75,7 @@ import DSProvider from "../../theme/provider";
|
|
|
75
75
|
| Component Version | DS Version |
|
|
76
76
|
| ----------------- | ---------- |
|
|
77
77
|
| Added | `0.24.0` |
|
|
78
|
-
| Latest | `0.
|
|
78
|
+
| Latest | `1.0.2` |
|
|
79
79
|
|
|
80
80
|
## Table of Contents
|
|
81
81
|
|
|
@@ -107,7 +107,7 @@ grouped together and displayed in some type of grid layout.
|
|
|
107
107
|
### CardHeading
|
|
108
108
|
|
|
109
109
|
The `CardHeading` component mirrors the standard Reservoir Design System (DS)
|
|
110
|
-
`Heading` component and accepts the [same props](https://nypl.github.io/nypl-design-system/
|
|
110
|
+
`Heading` component and accepts the [same props](https://nypl.github.io/nypl-design-system/reservoir/v1/?path=/story/components-typography-styles-heading--heading-with-controls).
|
|
111
111
|
|
|
112
112
|
### CardActions
|
|
113
113
|
|
|
@@ -612,11 +612,9 @@ image component in using the `imageProps.component` prop.
|
|
|
612
612
|
<Card
|
|
613
613
|
imageProps={{
|
|
614
614
|
alt: "Alt text",
|
|
615
|
-
aspectRatio: "sixteenByNine",
|
|
616
615
|
component: (
|
|
617
616
|
<Image src="https://placeimg.com/400/400/animals" alt="Alt text" />
|
|
618
617
|
),
|
|
619
|
-
src: "https://placeimg.com/400/200/animals",
|
|
620
618
|
}}
|
|
621
619
|
>
|
|
622
620
|
<CardHeading level="two" id="img1-heading1">
|
|
@@ -222,7 +222,7 @@ export const Card = chakra((props: React.PropsWithChildren<CardProps>) => {
|
|
|
222
222
|
const windowDimensions = useWindowSize();
|
|
223
223
|
let cardHeadingCount = 0;
|
|
224
224
|
|
|
225
|
-
if (imageProps.component && imageProps.aspectRatio
|
|
225
|
+
if (imageProps.component && imageProps.aspectRatio) {
|
|
226
226
|
console.warn(
|
|
227
227
|
"NYPL Reservoir Card: Both the `imageProps.component` and `imageProps.aspectRatio` " +
|
|
228
228
|
"props were set but `imageProps.aspectRatio` will be ignored in favor " +
|
|
@@ -248,6 +248,7 @@ export const Card = chakra((props: React.PropsWithChildren<CardProps>) => {
|
|
|
248
248
|
const styles = useMultiStyleConfig("Card", {
|
|
249
249
|
hasImage,
|
|
250
250
|
imageIsAtEnd: imageProps.isAtEnd,
|
|
251
|
+
isAlignedRightActions,
|
|
251
252
|
isBordered,
|
|
252
253
|
isCentered,
|
|
253
254
|
layout,
|
|
@@ -14,7 +14,7 @@ import DSProvider from "../../theme/provider";
|
|
|
14
14
|
| Added | `0.24.0` |
|
|
15
15
|
|
|
16
16
|
Note: This needs the use of the `DSProvider` component. See the
|
|
17
|
-
[README](https://nypl.github.io/nypl-design-system/
|
|
17
|
+
[README](https://nypl.github.io/nypl-design-system/reservoir/v1/?path=/story/chakra-ui--page#dsprovider)
|
|
18
18
|
for more information.
|
|
19
19
|
|
|
20
20
|
This component is directly exported from Chakra UI. The `Box` is a simple and
|
|
@@ -15,7 +15,7 @@ import DSProvider from "../../theme/provider";
|
|
|
15
15
|
| Added | `0.24.0` |
|
|
16
16
|
|
|
17
17
|
Note: This needs the use of the `DSProvider` component. See the
|
|
18
|
-
[README](https://nypl.github.io/nypl-design-system/
|
|
18
|
+
[README](https://nypl.github.io/nypl-design-system/reservoir/v1/?path=/story/chakra-ui--page#dsprovider)
|
|
19
19
|
for more information.
|
|
20
20
|
|
|
21
21
|
These components are directly exported from Chakra UI. The `Center`, `Circle`,
|
|
@@ -16,7 +16,7 @@ import DSProvider from "../../theme/provider";
|
|
|
16
16
|
| Latest | `0.25.10` |
|
|
17
17
|
|
|
18
18
|
Note: This needs the use of the `DSProvider` component. See the
|
|
19
|
-
[README](https://nypl.github.io/nypl-design-system/
|
|
19
|
+
[README](https://nypl.github.io/nypl-design-system/reservoir/v1/?path=/story/chakra-ui--page#dsprovider)
|
|
20
20
|
for more information.
|
|
21
21
|
|
|
22
22
|
This component is directly exported from Chakra UI. The `Flex` component is
|
|
@@ -14,7 +14,7 @@ import DSProvider from "../../theme/provider";
|
|
|
14
14
|
| Latest | `0.25.1` |
|
|
15
15
|
|
|
16
16
|
Note: This needs the use of the `DSProvider` component. See the
|
|
17
|
-
[README](https://nypl.github.io/nypl-design-system/
|
|
17
|
+
[README](https://nypl.github.io/nypl-design-system/reservoir/v1/?path=/story/chakra-ui--page#dsprovider)
|
|
18
18
|
for more information.
|
|
19
19
|
|
|
20
20
|
This component is directly exported from Chakra UI. The `Grid` component is
|
|
@@ -14,7 +14,7 @@ import DSProvider from "../../theme/provider";
|
|
|
14
14
|
| Added | `0.24.0` |
|
|
15
15
|
|
|
16
16
|
Note: This needs the use of the `DSProvider` component. See the
|
|
17
|
-
[README](https://nypl.github.io/nypl-design-system/
|
|
17
|
+
[README](https://nypl.github.io/nypl-design-system/reservoir/v1/?path=/story/chakra-ui--page#dsprovider)
|
|
18
18
|
for more information.
|
|
19
19
|
|
|
20
20
|
These components are directly exported from Chakra UI. The `Stack`, `HStack`,
|
|
@@ -39,12 +39,6 @@ describe("Checkbox Accessibility", () => {
|
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
describe("Checkbox", () => {
|
|
42
|
-
let changeHandler: jest.MockedFunction<() => void>;
|
|
43
|
-
|
|
44
|
-
beforeEach(() => {
|
|
45
|
-
changeHandler = jest.fn();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
42
|
it("Renders with a checkbox input and label", () => {
|
|
49
43
|
render(<Checkbox id="inputID" labelText="Test Label" />);
|
|
50
44
|
expect(screen.getByLabelText("Test Label")).toBeInTheDocument();
|
|
@@ -189,20 +183,57 @@ describe("Checkbox", () => {
|
|
|
189
183
|
).not.toBeInTheDocument();
|
|
190
184
|
});
|
|
191
185
|
|
|
186
|
+
it("should call onChange only once when checkbox is clicked", () => {
|
|
187
|
+
const onChangeMock = jest.fn();
|
|
188
|
+
|
|
189
|
+
render(
|
|
190
|
+
<Checkbox
|
|
191
|
+
id="onChangeCalledOnce"
|
|
192
|
+
onChange={onChangeMock}
|
|
193
|
+
labelText="onChangeTest"
|
|
194
|
+
showLabel={true}
|
|
195
|
+
isChecked={false}
|
|
196
|
+
/>
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
expect(
|
|
200
|
+
screen.getByRole("checkbox", { name: /onchangetest/i })
|
|
201
|
+
).toBeInTheDocument();
|
|
202
|
+
userEvent.click(screen.getByRole("checkbox", { name: /onchangetest/i }));
|
|
203
|
+
expect(onChangeMock).toBeCalledTimes(1);
|
|
204
|
+
});
|
|
205
|
+
|
|
192
206
|
it("Changing the value calls the onChange handler", () => {
|
|
207
|
+
let isChecked = false;
|
|
208
|
+
const onChange = (e) => {
|
|
209
|
+
isChecked = e.target.checked;
|
|
210
|
+
};
|
|
193
211
|
const utils = render(
|
|
194
212
|
<Checkbox
|
|
195
213
|
id="onChangeTest"
|
|
196
|
-
onChange={
|
|
214
|
+
onChange={onChange}
|
|
197
215
|
labelText="onChangeTest Lab"
|
|
198
216
|
showLabel={true}
|
|
199
|
-
isChecked
|
|
217
|
+
isChecked={isChecked}
|
|
218
|
+
/>
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
expect(isChecked).toEqual(false);
|
|
222
|
+
userEvent.click(utils.getByText("onChangeTest Lab"));
|
|
223
|
+
expect(isChecked).toEqual(true);
|
|
224
|
+
|
|
225
|
+
utils.rerender(
|
|
226
|
+
<Checkbox
|
|
227
|
+
id="onChangeTest"
|
|
228
|
+
onChange={onChange}
|
|
229
|
+
labelText="onChangeTest Lab"
|
|
230
|
+
showLabel={true}
|
|
231
|
+
isChecked={isChecked}
|
|
200
232
|
/>
|
|
201
233
|
);
|
|
202
234
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
expect(changeHandler).toHaveBeenCalledTimes(1);
|
|
235
|
+
userEvent.click(utils.getByText("onChangeTest Lab"));
|
|
236
|
+
expect(isChecked).toEqual(false);
|
|
206
237
|
});
|
|
207
238
|
|
|
208
239
|
it("logs a warning if `labelText` is not a string and `showLabel` is false", () => {
|
|
@@ -5,11 +5,10 @@ import {
|
|
|
5
5
|
useMultiStyleConfig,
|
|
6
6
|
} from "@chakra-ui/react";
|
|
7
7
|
import * as React from "react";
|
|
8
|
-
import { AriaAttributes } from "../../utils/interfaces";
|
|
9
8
|
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
} from "
|
|
9
|
+
import ComponentWrapper from "../ComponentWrapper/ComponentWrapper";
|
|
10
|
+
import { HelperErrorTextType } from "../HelperErrorText/HelperErrorText";
|
|
11
|
+
import { getAriaAttrs } from "../../utils/utils";
|
|
13
12
|
|
|
14
13
|
interface CheckboxIconProps {
|
|
15
14
|
/** When using the Checkbox as a "controlled" form element, you can specify
|
|
@@ -56,10 +55,6 @@ export interface CheckboxProps extends CheckboxIconProps {
|
|
|
56
55
|
value?: string;
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
export const onChangeDefault = () => {
|
|
60
|
-
return;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
58
|
function CheckboxIcon(props: CheckboxIconProps) {
|
|
64
59
|
// We don't need the `isIndeterminate` or `isChecked` props but it
|
|
65
60
|
// causes rendering issues on the SVG element, so we remove them
|
|
@@ -90,6 +85,7 @@ export const Checkbox = chakra(
|
|
|
90
85
|
isRequired = false,
|
|
91
86
|
labelText,
|
|
92
87
|
name,
|
|
88
|
+
onChange,
|
|
93
89
|
showHelperInvalidText = true,
|
|
94
90
|
showLabel = true,
|
|
95
91
|
value,
|
|
@@ -97,10 +93,15 @@ export const Checkbox = chakra(
|
|
|
97
93
|
} = props;
|
|
98
94
|
const styles = useMultiStyleConfig("Checkbox", {});
|
|
99
95
|
const footnote = isInvalid ? invalidText : helperText;
|
|
100
|
-
const ariaAttributes: AriaAttributes = {};
|
|
101
|
-
const onChange = props.onChange || onChangeDefault;
|
|
102
96
|
// Use Chakra's default indeterminate icon.
|
|
103
97
|
const icon = !isIndeterminate ? <CheckboxIcon /> : undefined;
|
|
98
|
+
const ariaAttributes = getAriaAttrs({
|
|
99
|
+
footnote,
|
|
100
|
+
id,
|
|
101
|
+
labelText,
|
|
102
|
+
name: "Checkbox",
|
|
103
|
+
showLabel,
|
|
104
|
+
});
|
|
104
105
|
|
|
105
106
|
if (!id) {
|
|
106
107
|
console.warn(
|
|
@@ -108,30 +109,25 @@ export const Checkbox = chakra(
|
|
|
108
109
|
);
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
if (!showLabel) {
|
|
112
|
-
if (typeof labelText !== "string") {
|
|
113
|
-
console.warn(
|
|
114
|
-
"NYPL Reservoir Checkbox: `labelText` must be a string when `showLabel` is false."
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
ariaAttributes["aria-label"] =
|
|
118
|
-
labelText && footnote
|
|
119
|
-
? `${labelText} - ${footnote}`
|
|
120
|
-
: (labelText as string);
|
|
121
|
-
} else {
|
|
122
|
-
if (footnote) ariaAttributes["aria-describedby"] = `${id}-helperText`;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
112
|
return (
|
|
126
|
-
|
|
113
|
+
<ComponentWrapper
|
|
114
|
+
helperText={helperText}
|
|
115
|
+
helperTextStyles={styles.helperErrorText}
|
|
116
|
+
id={id}
|
|
117
|
+
invalidText={invalidText}
|
|
118
|
+
isInvalid={isInvalid}
|
|
119
|
+
showHelperInvalidText={showHelperInvalidText}
|
|
120
|
+
{...rest}
|
|
121
|
+
>
|
|
127
122
|
<ChakraCheckbox
|
|
128
|
-
id={id}
|
|
129
123
|
className={className}
|
|
130
|
-
|
|
124
|
+
icon={icon}
|
|
125
|
+
id={id}
|
|
131
126
|
isDisabled={isDisabled}
|
|
127
|
+
isIndeterminate={isIndeterminate}
|
|
132
128
|
isInvalid={isInvalid}
|
|
133
129
|
isRequired={isRequired}
|
|
134
|
-
|
|
130
|
+
name={name || "default"}
|
|
135
131
|
ref={ref}
|
|
136
132
|
value={value}
|
|
137
133
|
{...(isChecked !== undefined
|
|
@@ -142,23 +138,13 @@ export const Checkbox = chakra(
|
|
|
142
138
|
: {
|
|
143
139
|
defaultIsChecked: false,
|
|
144
140
|
})}
|
|
145
|
-
icon={icon}
|
|
146
141
|
alignItems="flex-start"
|
|
147
142
|
__css={styles}
|
|
148
143
|
{...ariaAttributes}
|
|
149
|
-
{...rest}
|
|
150
144
|
>
|
|
151
145
|
{showLabel && labelText}
|
|
152
146
|
</ChakraCheckbox>
|
|
153
|
-
|
|
154
|
-
<HelperErrorText
|
|
155
|
-
id={`${id}-helperText`}
|
|
156
|
-
isInvalid={isInvalid}
|
|
157
|
-
text={footnote}
|
|
158
|
-
__css={styles.helperErrorText}
|
|
159
|
-
/>
|
|
160
|
-
)}
|
|
161
|
-
</>
|
|
147
|
+
</ComponentWrapper>
|
|
162
148
|
);
|
|
163
149
|
})
|
|
164
150
|
);
|