@nypl/design-system-react-components 0.23.4 → 0.25.1
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 +98 -1
- package/README.md +46 -11
- package/dist/components/Accordion/Accordion.d.ts +14 -14
- package/dist/components/Autosuggest/Autosuggest.stories.d.ts +1 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +11 -14
- package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +6 -0
- package/dist/components/Button/Button.d.ts +6 -13
- package/dist/components/Button/ButtonTypes.d.ts +5 -3
- package/dist/components/Card/Card.d.ts +59 -10
- package/dist/components/Card/CardTypes.d.ts +19 -0
- package/dist/components/CardEdition/CardEdition.d.ts +21 -0
- package/dist/components/{StyleGuide/Colors.stories.d.ts → CardEdition/CardEdition.stories.d.ts} +5 -2
- package/dist/components/Checkbox/Checkbox.d.ts +21 -16
- package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +43 -0
- package/dist/components/CheckboxGroup/CheckboxGroupLayoutTypes.d.ts +4 -0
- package/dist/components/DatePicker/DatePicker.d.ts +79 -0
- package/dist/components/DatePicker/DatePickerTypes.d.ts +5 -0
- package/dist/components/Form/Form.d.ts +16 -8
- package/dist/components/Form/FormTypes.d.ts +2 -0
- package/dist/components/Grid/GridTypes.d.ts +9 -0
- package/dist/components/Grid/SimpleGrid.d.ts +14 -0
- package/dist/components/Heading/Heading.d.ts +9 -11
- package/dist/components/Heading/{HeadingDisplaySizes.d.ts → HeadingTypes.d.ts} +8 -0
- package/dist/components/HelperErrorText/HelperErrorText.stories.d.ts +2 -1
- package/dist/components/Hero/Hero.d.ts +19 -14
- package/dist/components/Hero/HeroTypes.d.ts +10 -5
- package/dist/components/Icons/Icon.d.ts +13 -16
- package/dist/components/Icons/IconSvgs.d.ts +4 -0
- package/dist/components/Icons/IconTypes.d.ts +78 -60
- package/dist/components/Image/Image.stories.d.ts +2 -1
- package/dist/components/Label/Label.d.ts +10 -26
- package/dist/components/Link/Link.d.ts +8 -12
- package/dist/components/List/List.stories.d.ts +1 -0
- package/dist/components/Radio/Radio.d.ts +30 -24
- package/dist/components/RadioGroup/RadioGroup.d.ts +40 -0
- package/dist/components/RadioGroup/RadioGroupLayoutTypes.d.ts +4 -0
- package/dist/components/SearchBar/SearchBar.d.ts +45 -27
- package/dist/components/Select/Select.d.ts +34 -35
- package/dist/components/Select/SelectTypes.d.ts +4 -0
- package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +1 -1
- package/dist/components/SkeletonLoader/SkeletonLoaderTypes.d.ts +2 -2
- package/dist/components/StatusBadge/StatusBadge.d.ts +8 -6
- package/dist/components/StatusBadge/StatusBadgeTypes.d.ts +5 -0
- package/dist/components/Tabs/Tabs.d.ts +25 -0
- package/dist/components/Template/Template.d.ts +91 -0
- package/dist/components/Text/Text.d.ts +16 -0
- package/dist/components/Text/TextTypes.d.ts +6 -0
- package/dist/components/TextInput/TextInput.d.ts +37 -30
- package/dist/components/TextInput/TextInputTypes.d.ts +5 -0
- package/dist/design-system-react-components.cjs.development.js +4102 -917
- 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 +4023 -920
- package/dist/design-system-react-components.esm.js.map +1 -1
- package/dist/index.d.ts +23 -5
- package/dist/resources.scss +133 -24
- package/dist/styles.css +1 -1
- package/dist/theme/components/accordion.d.ts +25 -0
- package/dist/theme/components/breadcrumb.d.ts +90 -0
- package/dist/theme/components/button.d.ts +109 -0
- package/dist/theme/components/checkbox.d.ts +91 -0
- package/dist/theme/components/customCheckboxGroup.d.ts +18 -0
- package/dist/theme/components/customRadioGroup.d.ts +18 -0
- package/dist/theme/components/global.d.ts +55 -0
- package/dist/theme/components/globalMixins.d.ts +15 -0
- package/dist/theme/components/heading.d.ts +110 -0
- package/dist/theme/components/hero.d.ts +492 -0
- package/dist/theme/components/icon.d.ts +13 -0
- package/dist/theme/components/label.d.ts +16 -0
- package/dist/theme/components/link.d.ts +45 -0
- package/dist/theme/components/radio.d.ts +95 -0
- package/dist/theme/components/searchBar.d.ts +20 -0
- package/dist/theme/components/select.d.ts +58 -0
- package/dist/theme/components/statusBadge.d.ts +25 -0
- package/dist/theme/components/tabs.d.ts +85 -0
- package/dist/theme/components/template.d.ts +105 -0
- package/dist/theme/components/text.d.ts +20 -0
- package/dist/theme/components/textInput.d.ts +105 -0
- package/dist/theme/foundations/breakpoints.d.ts +23 -0
- package/dist/theme/foundations/colors.d.ts +3 -0
- package/dist/theme/foundations/global.d.ts +23 -0
- package/dist/theme/foundations/shadows.d.ts +4 -0
- package/dist/theme/foundations/spacing.d.ts +77 -0
- package/dist/theme/foundations/typography.d.ts +8 -0
- package/dist/theme/index.d.ts +20 -0
- package/dist/theme/provider.d.ts +5 -0
- package/dist/theme/types.d.ts +1 -0
- package/dist/utils/utils.d.ts +6 -0
- package/package.json +9 -2
- package/src/components/Accordion/Accordion.stories.mdx +233 -33
- package/src/components/Accordion/Accordion.test.tsx +135 -19
- package/src/components/Accordion/Accordion.tsx +81 -56
- package/src/components/Autosuggest/Autosuggest.stories.mdx +4 -3
- package/src/components/Autosuggest/Autosuggest.stories.tsx +1 -1
- package/src/components/Autosuggest/_Autosuggest.scss +2 -2
- package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +57 -56
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +31 -25
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +71 -73
- package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +6 -0
- package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +100 -0
- package/src/components/Button/Button.stories.mdx +125 -138
- package/src/components/Button/Button.test.tsx +65 -11
- package/src/components/Button/Button.tsx +72 -68
- package/src/components/Button/ButtonTypes.tsx +4 -2
- package/src/components/Button/_Button.scss +7 -92
- package/src/components/Button/__snapshots__/Button.test.tsx.snap +58 -3
- package/src/components/Card/Card.stories.mdx +694 -0
- package/src/components/Card/Card.test.tsx +97 -102
- package/src/components/Card/Card.tsx +182 -31
- package/src/components/Card/CardTypes.tsx +21 -0
- package/src/components/Card/_Card.scss +234 -49
- package/src/components/{Card/Card.stories.tsx → CardEdition/CardEdition.stories.tsx} +32 -22
- package/src/components/CardEdition/CardEdition.test.tsx +395 -0
- package/src/components/CardEdition/CardEdition.tsx +60 -0
- package/src/components/CardEdition/_CardEdition.scss +138 -0
- package/src/components/Chakra/Box.stories.mdx +57 -0
- package/src/components/Chakra/Center.stories.mdx +99 -0
- package/src/components/Chakra/Grid.stories.mdx +79 -0
- package/src/components/Chakra/Stack.stories.mdx +93 -0
- package/src/components/Checkbox/Checkbox.stories.mdx +57 -35
- package/src/components/Checkbox/Checkbox.test.tsx +117 -147
- package/src/components/Checkbox/Checkbox.tsx +76 -50
- package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +325 -0
- package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +249 -0
- package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +345 -0
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +148 -0
- package/src/components/CheckboxGroup/CheckboxGroupLayoutTypes.tsx +4 -0
- package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +1360 -0
- package/src/components/DatePicker/DatePicker.stories.mdx +284 -0
- package/src/components/DatePicker/DatePicker.test.tsx +657 -0
- package/src/components/DatePicker/DatePicker.tsx +396 -0
- package/src/components/DatePicker/DatePickerTypes.tsx +5 -0
- package/src/components/DatePicker/_DatePicker.scss +76 -0
- package/src/components/Form/Form.stories.mdx +130 -27
- package/src/components/Form/Form.test.tsx +78 -36
- package/src/components/Form/Form.tsx +53 -19
- package/src/components/Form/FormTypes.tsx +3 -0
- package/src/components/Form/__snapshots__/Form.test.tsx.snap +38 -0
- package/src/components/Grid/GridTypes.tsx +9 -0
- package/src/components/Grid/SimpleGrid.stories.mdx +275 -0
- package/src/components/Grid/SimpleGrid.test.tsx +66 -0
- package/src/components/Grid/SimpleGrid.tsx +37 -0
- package/src/components/Grid/__snapshots__/SimpleGrid.test.tsx.snap +8 -0
- package/src/components/Heading/Heading.stories.mdx +63 -33
- package/src/components/Heading/Heading.test.tsx +24 -16
- package/src/components/Heading/Heading.tsx +54 -38
- package/src/components/Heading/{HeadingDisplaySizes.tsx → HeadingTypes.tsx} +9 -0
- package/src/components/HelperErrorText/HelperErrorText.stories.tsx +2 -1
- package/src/components/HelperErrorText/_HelperErrorText.scss +1 -1
- package/src/components/Hero/Hero.stories.mdx +195 -85
- package/src/components/Hero/Hero.test.tsx +544 -113
- package/src/components/Hero/Hero.tsx +80 -93
- package/src/components/Hero/HeroTypes.tsx +17 -5
- package/src/components/Hero/__snapshots__/Hero.test.tsx.snap +307 -0
- package/src/components/HorizontalRule/HorizontalRule.stories.mdx +6 -1
- package/src/components/HorizontalRule/_HorizontalRule.scss +1 -1
- package/src/components/Icons/Icon.stories.mdx +89 -74
- package/src/components/Icons/Icon.test.tsx +30 -22
- package/src/components/Icons/Icon.tsx +63 -61
- package/src/components/Icons/IconSvgs.tsx +8 -0
- package/src/components/Icons/IconTypes.tsx +80 -60
- package/src/components/Image/Image.stories.tsx +2 -1
- package/src/components/Input/_Input.scss +2 -2
- package/src/components/Label/Label.stories.mdx +77 -0
- package/src/components/Label/Label.test.tsx +43 -12
- package/src/components/Label/Label.tsx +28 -45
- package/src/components/Label/__snapshots__/Label.test.tsx.snap +41 -0
- package/src/components/Link/Link.stories.mdx +47 -41
- package/src/components/Link/Link.test.tsx +33 -44
- package/src/components/Link/Link.tsx +114 -100
- package/src/components/List/List.stories.mdx +7 -3
- package/src/components/List/List.stories.tsx +14 -9
- package/src/components/List/List.test.tsx +12 -8
- package/src/components/List/List.tsx +9 -7
- package/src/components/List/_List.scss +3 -3
- package/src/components/Modal/Modal.stories.mdx +7 -3
- package/src/components/Modal/_Modal.scss +1 -1
- package/src/components/Notification/Notification.stories.mdx +99 -65
- package/src/components/Notification/Notification.test.tsx +3 -16
- package/src/components/Notification/Notification.tsx +12 -12
- package/src/components/Notification/_Notification.scss +5 -4
- package/src/components/Notification/__snapshots__/Notification.test.tsx.snap +1 -1
- package/src/components/Pagination/Pagination.stories.mdx +7 -1
- package/src/components/Pagination/Pagination.test.tsx +16 -10
- package/src/components/Radio/Radio.stories.mdx +57 -46
- package/src/components/Radio/Radio.test.tsx +92 -138
- package/src/components/Radio/Radio.tsx +70 -69
- package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +250 -0
- package/src/components/RadioGroup/RadioGroup.stories.mdx +247 -0
- package/src/components/RadioGroup/RadioGroup.test.tsx +327 -0
- package/src/components/RadioGroup/RadioGroup.tsx +154 -0
- package/src/components/RadioGroup/RadioGroupLayoutTypes.tsx +4 -0
- package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +1101 -0
- package/src/components/SearchBar/SearchBar.Test.tsx +151 -16
- package/src/components/SearchBar/SearchBar.stories.mdx +196 -224
- package/src/components/SearchBar/SearchBar.tsx +151 -46
- package/src/components/Select/Select.stories.mdx +193 -168
- package/src/components/Select/Select.test.tsx +129 -324
- package/src/components/Select/Select.tsx +120 -160
- package/src/components/Select/SelectTypes.tsx +4 -0
- package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +18 -29
- package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +7 -7
- package/src/components/SkeletonLoader/SkeletonLoader.tsx +4 -2
- package/src/components/SkeletonLoader/SkeletonLoaderTypes.tsx +2 -2
- package/src/components/SkeletonLoader/_SkeletonLoader.scss +3 -3
- package/src/components/StatusBadge/StatusBadge.stories.mdx +91 -0
- package/src/components/StatusBadge/StatusBadge.test.tsx +35 -7
- package/src/components/StatusBadge/StatusBadge.tsx +24 -25
- package/src/components/StatusBadge/StatusBadgeTypes.tsx +5 -0
- package/src/components/StatusBadge/__snapshots__/StatusBadge.test.tsx.snap +28 -0
- package/src/components/StyleGuide/Bidirectionality.stories.mdx +112 -90
- package/src/components/StyleGuide/Buttons.stories.mdx +98 -100
- package/src/components/StyleGuide/Colors.stories.mdx +336 -0
- package/src/components/StyleGuide/Forms.stories.mdx +85 -0
- package/src/components/StyleGuide/Iconography.stories.mdx +86 -93
- package/src/components/StyleGuide/Spacing.stories.mdx +0 -1
- package/src/components/StyleGuide/Typography.stories.mdx +164 -166
- package/src/components/StyleGuide/UIDocCard.tsx +4 -4
- package/src/components/Tabs/Tabs.stories.mdx +221 -0
- package/src/components/Tabs/Tabs.test.tsx +264 -0
- package/src/components/Tabs/Tabs.tsx +220 -0
- package/src/components/Template/Template.stories.mdx +574 -0
- package/src/components/Template/Template.test.tsx +124 -0
- package/src/components/Template/Template.tsx +226 -0
- package/src/components/Text/Text.stories.mdx +70 -0
- package/src/components/Text/Text.test.tsx +63 -0
- package/src/components/Text/Text.tsx +55 -0
- package/src/components/Text/TextTypes.tsx +6 -0
- package/src/components/Text/__snapshots__/Text.test.tsx.snap +33 -0
- package/src/components/TextInput/TextInput.stories.mdx +90 -90
- package/src/components/TextInput/TextInput.test.tsx +103 -83
- package/src/components/TextInput/TextInput.tsx +108 -91
- package/src/components/TextInput/TextInputTypes.tsx +6 -0
- package/src/components/VideoPlayer/VideoPlayer.stories.mdx +2 -1
- package/src/components/VideoPlayer/VideoPlayer.tsx +4 -2
- package/src/components/VideoPlayer/_VideoPlayer.scss +1 -1
- package/src/docs/Chakra.stories.mdx +341 -0
- package/src/docs/Intro.stories.mdx +31 -24
- package/src/index.ts +70 -5
- package/src/styles/01-colors/_colors-brand.scss +6 -4
- package/src/styles/01-colors/_colors-utility.scss +14 -15
- package/src/styles/03-space/_space-inline.scss +47 -7
- package/src/styles/03-space/_space-inset.scss +33 -5
- package/src/styles/03-space/_space-stack.scss +48 -8
- package/src/styles/base/_02-breakpoints.scss +5 -4
- package/src/styles/base/_04-base.scss +2 -1
- package/src/styles/base/_place-holder.scss +1 -1
- package/src/styles/base/_typography.scss +1 -29
- package/src/styles.scss +22 -25
- package/src/theme/components/accordion.ts +30 -0
- package/src/theme/components/breadcrumb.ts +77 -0
- package/src/theme/components/button.ts +125 -0
- package/src/theme/components/checkbox.ts +107 -0
- package/src/theme/components/customCheckboxGroup.ts +12 -0
- package/src/theme/components/customRadioGroup.ts +12 -0
- package/src/theme/components/global.ts +71 -0
- package/src/theme/components/globalMixins.ts +16 -0
- package/src/theme/components/heading.ts +72 -0
- package/src/theme/components/hero.ts +239 -0
- package/src/theme/components/icon.ts +79 -0
- package/src/theme/components/label.ts +17 -0
- package/src/theme/components/link.ts +47 -0
- package/src/theme/components/radio.ts +106 -0
- package/src/theme/components/searchBar.ts +21 -0
- package/src/theme/components/select.ts +50 -0
- package/src/theme/components/statusBadge.ts +27 -0
- package/src/theme/components/tabs.ts +79 -0
- package/src/theme/components/template.ts +114 -0
- package/src/theme/components/text.ts +31 -0
- package/src/theme/components/textInput.ts +61 -0
- package/src/theme/foundations/breakpoints.ts +24 -0
- package/src/theme/foundations/colors.ts +208 -0
- package/src/theme/foundations/global.ts +26 -0
- package/src/theme/foundations/shadows.ts +5 -0
- package/src/theme/foundations/spacing.ts +85 -0
- package/src/theme/foundations/typography.ts +35 -0
- package/src/theme/index.ts +88 -0
- package/src/theme/provider.tsx +9 -0
- package/src/theme/types.ts +1 -0
- package/src/utils/componentCategories.ts +56 -21
- package/src/utils/utils.ts +13 -0
- package/dist/components/Accordion/Accordion.stories.d.ts +0 -5
- package/dist/components/Card/Card.stories.d.ts +0 -27
- package/dist/components/Label/Label.stories.d.ts +0 -12
- package/dist/components/StatusBadge/StatusBadge.stories.d.ts +0 -8
- package/dist/components/Template/Template.stories.d.ts +0 -29
- package/src/components/Accordion/Accordion.stories.tsx +0 -65
- package/src/components/Accordion/_Accordion.scss +0 -81
- package/src/components/Breadcrumbs/_Breadcrumbs.scss +0 -97
- package/src/components/Checkbox/_Checkbox.scss +0 -97
- package/src/components/Form/_Form.scss +0 -28
- package/src/components/Heading/_Heading.scss +0 -163
- package/src/components/Hero/_Hero.scss +0 -256
- package/src/components/Icons/_Icons.scss +0 -116
- package/src/components/Label/Label.stories.tsx +0 -30
- package/src/components/Label/_Label.scss +0 -22
- package/src/components/Link/_Link.scss +0 -73
- package/src/components/Radio/_Radio.scss +0 -84
- package/src/components/SearchBar/_SearchBar.scss +0 -16
- package/src/components/Select/_Select.scss +0 -82
- package/src/components/StatusBadge/StatusBadge.stories.tsx +0 -33
- package/src/components/StatusBadge/_StatusBadge.scss +0 -23
- package/src/components/StyleGuide/Colors.stories.tsx +0 -288
- package/src/components/Template/Template.stories.tsx +0 -85
- package/src/components/Template/_Template.scss +0 -63
- package/src/components/TextInput/_TextInput.scss +0 -59
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
import { axe } from "jest-axe";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
4
3
|
import userEvent from "@testing-library/user-event";
|
|
5
|
-
|
|
4
|
+
import { axe } from "jest-axe";
|
|
5
|
+
import renderer from "react-test-renderer";
|
|
6
6
|
import * as generateUUID from "../../helpers/generateUUID";
|
|
7
7
|
import Checkbox from "./Checkbox";
|
|
8
8
|
|
|
9
9
|
describe("Checkbox Accessibility", () => {
|
|
10
|
-
it("
|
|
10
|
+
it("Passes axe accessibility test", async () => {
|
|
11
11
|
const { container } = render(
|
|
12
12
|
<Checkbox
|
|
13
13
|
id="inputID"
|
|
14
|
-
attributes={{ onClick: jest.fn() }}
|
|
15
14
|
onChange={jest.fn()}
|
|
16
15
|
labelText="Test Label"
|
|
17
16
|
showLabel={false}
|
|
@@ -22,204 +21,175 @@ describe("Checkbox Accessibility", () => {
|
|
|
22
21
|
});
|
|
23
22
|
|
|
24
23
|
describe("Checkbox", () => {
|
|
25
|
-
let utils;
|
|
26
24
|
let changeHandler;
|
|
27
|
-
let clickHander;
|
|
28
25
|
let generateUUIDSpy;
|
|
29
26
|
|
|
30
27
|
beforeEach(() => {
|
|
31
|
-
clickHander = jest.fn();
|
|
32
28
|
changeHandler = jest.fn();
|
|
33
29
|
generateUUIDSpy = jest.spyOn(generateUUID, "default");
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
showLabel={false}
|
|
41
|
-
/>
|
|
42
|
-
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("Renders with a checkbox input and label", () => {
|
|
33
|
+
render(<Checkbox id="inputID" labelText="Test Label" />);
|
|
34
|
+
expect(screen.getByLabelText("Test Label")).toBeInTheDocument();
|
|
35
|
+
expect(screen.getByRole("checkbox")).toBeInTheDocument();
|
|
43
36
|
});
|
|
44
37
|
|
|
45
38
|
it("Renders with appropriate 'aria-label' attribute and value when 'showLabel' prop is set to false", () => {
|
|
46
|
-
|
|
47
|
-
expect(
|
|
39
|
+
render(<Checkbox id="inputID" labelText="Test Label" showLabel={false} />);
|
|
40
|
+
expect(screen.getByLabelText("Test Label")).toHaveAttribute(
|
|
48
41
|
"aria-label",
|
|
49
42
|
"Test Label"
|
|
50
43
|
);
|
|
51
44
|
});
|
|
52
45
|
|
|
53
|
-
it("Renders
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"checkbox"
|
|
46
|
+
it("Renders with appropriate 'aria-label' attribute and value when 'showLabel' prop is set to false and 'helperText' has been passed", () => {
|
|
47
|
+
render(
|
|
48
|
+
<Checkbox
|
|
49
|
+
id="inputID"
|
|
50
|
+
labelText="Test Label"
|
|
51
|
+
showLabel={false}
|
|
52
|
+
helperText="This is the helper text."
|
|
53
|
+
/>
|
|
62
54
|
);
|
|
55
|
+
expect(
|
|
56
|
+
screen.getByLabelText("Test Label - This is the helper text.")
|
|
57
|
+
).toBeInTheDocument();
|
|
63
58
|
});
|
|
64
59
|
|
|
65
|
-
it("
|
|
66
|
-
|
|
67
|
-
userEvent.click(screen.getByLabelText("Test Label"));
|
|
68
|
-
expect(clickHander.mock.calls.length).toEqual(1);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("Changing the value calls the onChange handler", () => {
|
|
72
|
-
const utils = render(
|
|
60
|
+
it("Renders visible helper or error text", () => {
|
|
61
|
+
const { rerender } = render(
|
|
73
62
|
<Checkbox
|
|
74
|
-
id="
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
checked
|
|
63
|
+
id="inputID"
|
|
64
|
+
labelText="Test Label"
|
|
65
|
+
helperText="This is the helper text."
|
|
66
|
+
errorText="This is the error text :("
|
|
79
67
|
/>
|
|
80
68
|
);
|
|
69
|
+
expect(screen.getByText("This is the helper text.")).toBeVisible();
|
|
70
|
+
expect(
|
|
71
|
+
screen.queryByText("This is the error text :(")
|
|
72
|
+
).not.toBeInTheDocument();
|
|
81
73
|
|
|
82
|
-
|
|
83
|
-
userEvent.type(utils.getByText("onChangeTest Lab"), "Hello");
|
|
84
|
-
expect(changeHandler).toHaveBeenCalledTimes(1);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("Renders with appropriate 'aria-label' attribute and value when 'showLabel' prop is set to false and 'helperText' has been passed", () => {
|
|
88
|
-
const utils = render(
|
|
74
|
+
rerender(
|
|
89
75
|
<Checkbox
|
|
90
|
-
id="
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
checked
|
|
76
|
+
id="inputID"
|
|
77
|
+
labelText="Test Label"
|
|
78
|
+
isInvalid
|
|
79
|
+
helperText="This is the helper text."
|
|
80
|
+
errorText="This is the error text :("
|
|
96
81
|
/>
|
|
97
82
|
);
|
|
98
|
-
|
|
83
|
+
expect(screen.getByText("This is the error text :(")).toBeVisible();
|
|
84
|
+
expect(
|
|
85
|
+
screen.queryByText("This is the helper text.")
|
|
86
|
+
).not.toBeInTheDocument();
|
|
87
|
+
});
|
|
99
88
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
);
|
|
89
|
+
it("Sets the checkbox's ID", () => {
|
|
90
|
+
render(<Checkbox id="inputID" labelText="Test Label" />);
|
|
91
|
+
expect(screen.getByRole("checkbox")).toHaveAttribute("id", "inputID");
|
|
104
92
|
});
|
|
105
93
|
|
|
106
|
-
it("
|
|
107
|
-
|
|
94
|
+
it("Calls the UUID generation function if no id prop value is passed", () => {
|
|
95
|
+
expect(generateUUIDSpy).toHaveBeenCalledTimes(0);
|
|
96
|
+
render(<Checkbox labelText="Test Label" />);
|
|
97
|
+
expect(generateUUIDSpy).toHaveBeenCalledTimes(1);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("Sets the 'checked' attribute", () => {
|
|
101
|
+
render(
|
|
108
102
|
<Checkbox
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
labelText="Hello"
|
|
103
|
+
id="inputID"
|
|
104
|
+
labelText="Test Label"
|
|
112
105
|
showLabel={true}
|
|
106
|
+
isChecked
|
|
113
107
|
/>
|
|
114
108
|
);
|
|
115
|
-
|
|
116
|
-
expect(utils.getByLabelText("Hello")).toBeInTheDocument();
|
|
117
|
-
expect(container.querySelector(".input__checkbox")).not.toHaveAttribute(
|
|
118
|
-
"aria-label"
|
|
119
|
-
);
|
|
120
|
-
expect(utils.getByText("Hello")).toHaveAttribute("for", "test_id");
|
|
109
|
+
expect(screen.getByRole("checkbox")).toHaveAttribute("checked");
|
|
121
110
|
});
|
|
122
111
|
|
|
123
|
-
it("
|
|
124
|
-
|
|
112
|
+
it("Sets the 'disabled' attribute", () => {
|
|
113
|
+
render(
|
|
125
114
|
<Checkbox
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
labelText="Hello"
|
|
115
|
+
id="inputID"
|
|
116
|
+
labelText="Test Label"
|
|
129
117
|
showLabel={true}
|
|
130
|
-
|
|
131
|
-
errorText="The error text."
|
|
132
|
-
errored={false}
|
|
118
|
+
isDisabled
|
|
133
119
|
/>
|
|
134
120
|
);
|
|
135
|
-
expect(
|
|
121
|
+
expect(screen.getByRole("checkbox")).toHaveAttribute("disabled");
|
|
136
122
|
});
|
|
137
123
|
|
|
138
|
-
it("
|
|
139
|
-
|
|
124
|
+
it("Sets the 'required' attribute", () => {
|
|
125
|
+
render(
|
|
140
126
|
<Checkbox
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
labelText="Hello"
|
|
127
|
+
id="inputID"
|
|
128
|
+
labelText="Test Label"
|
|
144
129
|
showLabel={true}
|
|
145
|
-
|
|
146
|
-
errorText="The error text."
|
|
147
|
-
errored={true}
|
|
130
|
+
isRequired
|
|
148
131
|
/>
|
|
149
132
|
);
|
|
150
|
-
expect(
|
|
133
|
+
expect(screen.getByRole("checkbox")).toHaveAttribute("required");
|
|
151
134
|
});
|
|
152
135
|
|
|
153
|
-
it("
|
|
154
|
-
render(
|
|
155
|
-
|
|
156
|
-
expect(generateUUIDSpy).toHaveBeenCalledTimes(1);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it("The 'checked' attribute can be set properly", () => {
|
|
160
|
-
const onChange = jest.fn();
|
|
161
|
-
const utils = render(
|
|
136
|
+
it("Sets the error state", () => {
|
|
137
|
+
render(
|
|
162
138
|
<Checkbox
|
|
163
139
|
id="inputID-attributes"
|
|
164
|
-
labelText="
|
|
165
|
-
showLabel={
|
|
166
|
-
|
|
167
|
-
checked: true,
|
|
168
|
-
"aria-checked": true,
|
|
169
|
-
onChange,
|
|
170
|
-
}}
|
|
140
|
+
labelText="onChange test"
|
|
141
|
+
showLabel={true}
|
|
142
|
+
isInvalid
|
|
171
143
|
/>
|
|
172
144
|
);
|
|
173
|
-
|
|
174
|
-
const container = utils.container;
|
|
175
|
-
expect(container.querySelector(".input__checkbox")).toHaveAttribute(
|
|
176
|
-
"checked"
|
|
177
|
-
);
|
|
178
|
-
expect(container.querySelector(".input__checkbox")).toHaveAttribute(
|
|
179
|
-
"aria-checked"
|
|
180
|
-
);
|
|
145
|
+
expect(screen.getByRole("checkbox")).toHaveAttribute("aria-invalid");
|
|
181
146
|
});
|
|
182
147
|
|
|
183
|
-
|
|
184
|
-
// it("Passes the ref to the input element", () => {
|
|
185
|
-
// const ref = React.createRef<HTMLInputElement>();
|
|
186
|
-
// const container = render(
|
|
187
|
-
// <Checkbox
|
|
188
|
-
// id="inputID-attributes"
|
|
189
|
-
// ref={ref}
|
|
190
|
-
// labelText="Hello"
|
|
191
|
-
// showLabel={false}
|
|
192
|
-
// />
|
|
193
|
-
// );
|
|
194
|
-
// });
|
|
195
|
-
|
|
196
|
-
it("Renders HTML attributes passed through the `attributes` prop", () => {
|
|
197
|
-
const onChangeSpy = jest.fn();
|
|
198
|
-
const onBlurSpy = jest.fn();
|
|
148
|
+
it("Changing the value calls the onChange handler", () => {
|
|
199
149
|
const utils = render(
|
|
200
150
|
<Checkbox
|
|
201
|
-
id="
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
onBlur: onBlurSpy,
|
|
205
|
-
tabIndex: 0,
|
|
206
|
-
}}
|
|
207
|
-
labelText="Hello"
|
|
151
|
+
id="onChangeTest"
|
|
152
|
+
onChange={changeHandler}
|
|
153
|
+
labelText="onChangeTest Lab"
|
|
208
154
|
showLabel={true}
|
|
209
|
-
|
|
155
|
+
isChecked
|
|
156
|
+
/>
|
|
210
157
|
);
|
|
211
|
-
const container = utils.container;
|
|
212
158
|
|
|
213
|
-
expect(
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
159
|
+
expect(changeHandler).toHaveBeenCalledTimes(0);
|
|
160
|
+
userEvent.type(utils.getByText("onChangeTest Lab"), "Hello");
|
|
161
|
+
expect(changeHandler).toHaveBeenCalledTimes(1);
|
|
162
|
+
});
|
|
217
163
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
164
|
+
it("Renders the UI snapshot correctly", () => {
|
|
165
|
+
const primary = renderer
|
|
166
|
+
.create(<Checkbox id="inputID" labelText="Test Label" />)
|
|
167
|
+
.toJSON();
|
|
168
|
+
const isChecked = renderer
|
|
169
|
+
.create(
|
|
170
|
+
<Checkbox id="checkbox-checked" labelText="Test Label" isChecked />
|
|
171
|
+
)
|
|
172
|
+
.toJSON();
|
|
173
|
+
const isRequired = renderer
|
|
174
|
+
.create(
|
|
175
|
+
<Checkbox id="checkbox-required" labelText="Test Label" isRequired />
|
|
176
|
+
)
|
|
177
|
+
.toJSON();
|
|
178
|
+
const isInvalid = renderer
|
|
179
|
+
.create(
|
|
180
|
+
<Checkbox id="checkbox-invalid" labelText="Test Label" isInvalid />
|
|
181
|
+
)
|
|
182
|
+
.toJSON();
|
|
183
|
+
const isDisabled = renderer
|
|
184
|
+
.create(
|
|
185
|
+
<Checkbox id="checkbox-disabled" labelText="Test Label" isDisabled />
|
|
186
|
+
)
|
|
187
|
+
.toJSON();
|
|
188
|
+
|
|
189
|
+
expect(primary).toMatchSnapshot();
|
|
190
|
+
expect(isChecked).toMatchSnapshot();
|
|
191
|
+
expect(isRequired).toMatchSnapshot();
|
|
192
|
+
expect(isInvalid).toMatchSnapshot();
|
|
193
|
+
expect(isDisabled).toMatchSnapshot();
|
|
224
194
|
});
|
|
225
195
|
});
|
|
@@ -1,36 +1,47 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
Box,
|
|
4
|
+
Checkbox as ChakraCheckbox,
|
|
5
|
+
Icon,
|
|
6
|
+
useMultiStyleConfig,
|
|
7
|
+
} from "@chakra-ui/react";
|
|
3
8
|
import HelperErrorText from "../HelperErrorText/HelperErrorText";
|
|
4
|
-
import Label from "../Label/Label";
|
|
5
9
|
import generateUUID from "../../helpers/generateUUID";
|
|
6
10
|
|
|
7
11
|
export interface CheckboxProps {
|
|
8
|
-
/** The checkbox's label. This will serve as the text content for a `<label>` element if `showlabel` is true, or an "aria-label" if `showLabel` is false. */
|
|
9
|
-
labelText: string;
|
|
10
|
-
/** Additional attributes to pass to the `<input>` tag */
|
|
11
|
-
attributes?: { [key: string]: any };
|
|
12
|
-
/** When using the Checkbox as a "controlled" form element, you can specify the Checkbox's checked state using this prop. Learn more about controlled and uncontrolled form fields: https://goshakkk.name/controlled-vs-uncontrolled-inputs-react/ */
|
|
13
|
-
checked?: boolean;
|
|
14
12
|
/** className you can add in addition to 'input' */
|
|
15
13
|
className?: string;
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
errored?: boolean;
|
|
20
|
-
/** Optional string to populate the HelperErrorText for error state */
|
|
14
|
+
/** Optional string to populate the HelperErrorText for the error state
|
|
15
|
+
* when `isInvalid` is true.
|
|
16
|
+
*/
|
|
21
17
|
errorText?: string;
|
|
22
18
|
/** Optional string to populate the HelperErrorText for standard state */
|
|
23
19
|
helperText?: string;
|
|
24
20
|
/** ID that other components can cross reference for accessibility purposes */
|
|
25
21
|
id?: string;
|
|
26
|
-
/**
|
|
27
|
-
|
|
22
|
+
/** When using the Checkbox as a "controlled" form element, you can specify the
|
|
23
|
+
* Checkbox's checked state using this prop.
|
|
24
|
+
* Learn more about controlled and uncontrolled form fields:
|
|
25
|
+
* https://goshakkk.name/controlled-vs-uncontrolled-inputs-react/ */
|
|
26
|
+
isChecked?: boolean;
|
|
27
|
+
/** Adds the 'disabled' and `aria-disabled` attributes to the input when true.
|
|
28
|
+
* This also makes the text italic and color scheme gray.
|
|
29
|
+
*/
|
|
30
|
+
isDisabled?: boolean;
|
|
31
|
+
/** Adds the 'aria-invalid' attribute to the input when true. This also makes
|
|
32
|
+
* the color theme "NYPL error" red for the button and text.
|
|
33
|
+
*/
|
|
34
|
+
isInvalid?: boolean;
|
|
35
|
+
/** Adds the 'required' attribute to the input when true. */
|
|
36
|
+
isRequired?: boolean;
|
|
37
|
+
/** The checkbox's label. This will serve as the text content for a `<label>` element if `showlabel` is true, or an "aria-label" if `showLabel` is false. */
|
|
38
|
+
labelText: string;
|
|
28
39
|
/** The name prop indicates into which group of checkboxes this checkbox belongs. If none is specified, 'default' will be used */
|
|
29
40
|
name?: string;
|
|
30
41
|
/** The action to perform on the `<input>`'s onChange function */
|
|
31
42
|
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
32
43
|
/** Offers the ability to show the checkbox's label onscreen or hide it. Refer to the `labelText` property for more information. */
|
|
33
|
-
showLabel
|
|
44
|
+
showLabel?: boolean;
|
|
34
45
|
/** Populates the value of the input */
|
|
35
46
|
value?: string;
|
|
36
47
|
}
|
|
@@ -39,67 +50,82 @@ export const onChangeDefault = () => {
|
|
|
39
50
|
return;
|
|
40
51
|
};
|
|
41
52
|
|
|
53
|
+
function CheckboxIcon(props) {
|
|
54
|
+
// Don't need the `isChecked` prop but it causes
|
|
55
|
+
// rendering issues on the SVG element.
|
|
56
|
+
const { isIndeterminate, isChecked, ...rest } = props;
|
|
57
|
+
|
|
58
|
+
const d = isIndeterminate
|
|
59
|
+
? "M12,0A12,12,0,1,0,24,12,12.013,12.013,0,0,0,12,0Zm0,19a1.5,1.5,0,1,1,1.5-1.5A1.5,1.5,0,0,1,12,19Zm1.6-6.08a1,1,0,0,0-.6.917,1,1,0,1,1-2,0,3,3,0,0,1,1.8-2.75A2,2,0,1,0,10,9.255a1,1,0,1,1-2,0,4,4,0,1,1,5.6,3.666Z"
|
|
60
|
+
: "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";
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<Icon viewBox="0 0 24 24" {...rest}>
|
|
64
|
+
<path fill="currentColor" d={d} />
|
|
65
|
+
</Icon>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
42
69
|
const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
|
|
43
70
|
(props, ref?) => {
|
|
44
71
|
const {
|
|
45
|
-
checked,
|
|
46
72
|
className,
|
|
47
|
-
disabled,
|
|
48
|
-
errored,
|
|
49
73
|
errorText,
|
|
50
74
|
helperText,
|
|
51
|
-
id,
|
|
75
|
+
id = generateUUID(),
|
|
76
|
+
isChecked,
|
|
77
|
+
isDisabled = false,
|
|
78
|
+
isInvalid = false,
|
|
79
|
+
isRequired = false,
|
|
52
80
|
labelText,
|
|
53
81
|
name,
|
|
54
|
-
showLabel,
|
|
82
|
+
showLabel = true,
|
|
55
83
|
value,
|
|
56
84
|
} = props;
|
|
57
85
|
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
const
|
|
86
|
+
const styles = useMultiStyleConfig("Checkbox", {});
|
|
87
|
+
const footnote = isInvalid ? errorText : helperText;
|
|
88
|
+
const attributes = {};
|
|
61
89
|
const onChange = props.onChange || onChangeDefault;
|
|
62
90
|
|
|
63
|
-
const footnote = errored ? errorText : helperText;
|
|
64
|
-
|
|
65
91
|
if (!showLabel) {
|
|
66
92
|
attributes["aria-label"] =
|
|
67
93
|
labelText && footnote ? `${labelText} - ${footnote}` : labelText;
|
|
68
94
|
} else {
|
|
69
|
-
if (footnote) attributes["aria-describedby"] = `${
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (errored) {
|
|
73
|
-
modifiers.push("error");
|
|
95
|
+
if (footnote) attributes["aria-describedby"] = `${id}-helperText`;
|
|
74
96
|
}
|
|
75
97
|
|
|
76
98
|
return (
|
|
77
99
|
<>
|
|
78
|
-
<
|
|
79
|
-
{
|
|
100
|
+
<ChakraCheckbox
|
|
101
|
+
id={id}
|
|
102
|
+
className={className}
|
|
103
|
+
name={name || "default"}
|
|
104
|
+
isDisabled={isDisabled}
|
|
105
|
+
isInvalid={isInvalid}
|
|
106
|
+
isRequired={isRequired}
|
|
107
|
+
ref={ref}
|
|
108
|
+
value={value}
|
|
109
|
+
{...(isChecked !== undefined
|
|
80
110
|
? {
|
|
81
|
-
|
|
82
|
-
onChange
|
|
111
|
+
isChecked,
|
|
112
|
+
onChange,
|
|
83
113
|
}
|
|
84
114
|
: {
|
|
85
|
-
|
|
115
|
+
defaultIsChecked: false,
|
|
86
116
|
})}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
id={checkboxID}
|
|
90
|
-
name={name || "default"}
|
|
91
|
-
ref={ref}
|
|
92
|
-
type="checkbox"
|
|
93
|
-
value={value}
|
|
117
|
+
icon={<CheckboxIcon />}
|
|
118
|
+
__css={styles}
|
|
94
119
|
{...attributes}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
)}
|
|
120
|
+
>
|
|
121
|
+
{showLabel && labelText}
|
|
122
|
+
</ChakraCheckbox>
|
|
99
123
|
{footnote && showLabel && (
|
|
100
|
-
<
|
|
101
|
-
{
|
|
102
|
-
|
|
124
|
+
<Box __css={styles.helper} aria-disabled={isDisabled}>
|
|
125
|
+
<HelperErrorText isError={isInvalid} id={`${id}-helperText`}>
|
|
126
|
+
{footnote}
|
|
127
|
+
</HelperErrorText>
|
|
128
|
+
</Box>
|
|
103
129
|
)}
|
|
104
130
|
</>
|
|
105
131
|
);
|