@nypl/design-system-react-components 0.25.12 → 0.26.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 +131 -1
- package/README.md +10 -10
- package/dist/components/Accordion/Accordion.d.ts +6 -4
- package/dist/components/Accordion/AccordionTypes.d.ts +5 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +4 -4
- package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +1 -1
- package/dist/components/Button/Button.d.ts +2 -2
- package/dist/components/Card/Card.d.ts +22 -29
- package/dist/components/Checkbox/Checkbox.d.ts +3 -3
- package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +9 -6
- package/dist/components/ComponentWrapper/ComponentWrapper.d.ts +1 -1
- package/dist/components/DatePicker/DatePicker.d.ts +5 -6
- package/dist/components/Fieldset/Fieldset.d.ts +5 -6
- package/dist/components/Form/Form.d.ts +6 -6
- package/dist/components/Grid/GridTypes.d.ts +7 -7
- package/dist/components/Grid/SimpleGrid.d.ts +1 -1
- package/dist/components/Heading/Heading.d.ts +5 -5
- package/dist/components/Heading/HeadingTypes.d.ts +1 -1
- package/dist/components/HelperErrorText/HelperErrorText.d.ts +9 -8
- package/dist/components/Hero/Hero.d.ts +9 -5
- package/dist/components/HorizontalRule/HorizontalRule.d.ts +2 -10
- package/dist/components/Icons/Icon.d.ts +2 -1
- package/dist/components/Icons/IconTypes.d.ts +1 -0
- package/dist/components/Image/Image.d.ts +27 -9
- package/dist/components/Image/ImageTypes.d.ts +4 -4
- package/dist/components/Label/Label.d.ts +7 -4
- package/dist/components/Link/Link.d.ts +1 -1
- package/dist/components/List/List.d.ts +11 -11
- package/dist/components/List/ListTypes.d.ts +1 -1
- package/dist/components/Logo/Logo.d.ts +2 -1
- package/dist/components/Logo/LogoSvgs.d.ts +2 -0
- package/dist/components/Logo/LogoTypes.d.ts +4 -2
- package/dist/components/Notification/Notification.d.ts +7 -7
- package/dist/components/Pagination/Pagination.d.ts +2 -2
- package/dist/components/ProgressIndicator/ProgressIndicator.d.ts +3 -3
- package/dist/components/Radio/Radio.d.ts +5 -7
- package/dist/components/RadioGroup/RadioGroup.d.ts +16 -8
- package/dist/components/SearchBar/SearchBar.d.ts +4 -4
- package/dist/components/Select/Select.d.ts +12 -8
- package/dist/components/Select/SelectTypes.d.ts +4 -0
- package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +8 -6
- package/dist/components/SkeletonLoader/SkeletonLoaderTypes.d.ts +0 -4
- package/dist/components/Slider/Slider.d.ts +6 -4
- package/dist/components/StatusBadge/StatusBadge.d.ts +5 -1
- package/dist/components/StructuredContent/StructuredContent.d.ts +10 -23
- package/dist/components/Table/Table.d.ts +1 -1
- package/dist/components/Tabs/Tabs.d.ts +7 -6
- package/dist/components/Template/Template.d.ts +17 -8
- package/dist/components/Text/Text.d.ts +4 -4
- package/dist/components/Text/TextTypes.d.ts +1 -1
- package/dist/components/TextInput/TextInput.d.ts +7 -7
- package/dist/components/Toggle/Toggle.d.ts +8 -10
- package/dist/components/Toggle/{ToggleSizes.d.ts → ToggleTypes.d.ts} +1 -1
- package/dist/components/VideoPlayer/VideoPlayer.d.ts +2 -1
- package/dist/design-system-react-components.cjs.development.js +2075 -1468
- 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 +2086 -1483
- package/dist/design-system-react-components.esm.js.map +1 -1
- package/dist/helpers/enums.d.ts +4 -0
- package/dist/hooks/useCarouselStyles.d.ts +3 -2
- package/dist/hooks/useNYPLTheme.d.ts +12 -0
- package/dist/index.d.ts +11 -9
- package/dist/styles.css +1 -1
- package/dist/theme/components/accordion.d.ts +7 -12
- package/dist/theme/components/breadcrumb.d.ts +3 -0
- package/dist/theme/components/button.d.ts +10 -2
- package/dist/theme/components/card.d.ts +44 -24
- package/dist/theme/components/checkbox.d.ts +6 -4
- package/dist/theme/components/checkboxGroup.d.ts +4 -2
- package/dist/theme/components/componentWrapper.d.ts +2 -2
- package/dist/theme/components/customTable.d.ts +84 -1
- package/dist/theme/components/fieldset.d.ts +4 -14
- package/dist/theme/components/global.d.ts +25 -18
- package/dist/theme/components/heading.d.ts +53 -0
- package/dist/theme/components/helperErrorText.d.ts +1 -0
- package/dist/theme/components/hero.d.ts +21 -15
- package/dist/theme/components/image.d.ts +1 -1
- package/dist/theme/components/label.d.ts +9 -10
- package/dist/theme/components/list.d.ts +99 -9
- 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 +7 -4
- package/dist/theme/components/radioGroup.d.ts +4 -2
- package/dist/theme/components/select.d.ts +37 -5
- package/dist/theme/components/skeletonLoader.d.ts +2 -2
- package/dist/theme/components/slider.d.ts +6 -3
- package/dist/theme/components/structuredContent.d.ts +197 -0
- package/dist/theme/components/textInput.d.ts +18 -6
- package/dist/theme/components/toggle.d.ts +20 -5
- package/dist/theme/foundations/global.d.ts +2 -0
- package/dist/theme/foundations/radii.d.ts +1 -0
- package/dist/theme/foundations/spacing.d.ts +46 -43
- package/package.json +5 -6
- 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 +65 -17
- package/src/components/Accordion/Accordion.tsx +61 -27
- package/src/components/Accordion/AccordionTypes.tsx +5 -0
- package/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +505 -14
- package/src/components/Autosuggest/Autosuggest.stories.mdx +4 -3
- package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +37 -19
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +57 -36
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +14 -13
- package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +1 -1
- package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +211 -12
- package/src/components/Button/Button.stories.mdx +87 -23
- package/src/components/Button/Button.test.tsx +25 -0
- package/src/components/Button/Button.tsx +18 -7
- package/src/components/Button/__snapshots__/Button.test.tsx.snap +27 -7
- package/src/components/Card/Card.stories.mdx +493 -329
- package/src/components/Card/Card.test.tsx +138 -18
- package/src/components/Card/Card.tsx +151 -85
- package/src/components/Card/__snapshots__/Card.test.tsx.snap +221 -101
- package/src/components/Chakra/Center.stories.mdx +2 -2
- package/src/components/Chakra/Grid.stories.mdx +4 -4
- package/src/components/Checkbox/Checkbox.stories.mdx +73 -9
- package/src/components/Checkbox/Checkbox.test.tsx +89 -10
- package/src/components/Checkbox/Checkbox.tsx +26 -16
- package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +209 -6
- package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +135 -23
- package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +216 -90
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +39 -26
- package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +493 -89
- package/src/components/ComponentWrapper/ComponentWrapper.test.tsx +12 -0
- package/src/components/ComponentWrapper/ComponentWrapper.tsx +39 -41
- package/src/components/ComponentWrapper/__snapshots__/ComponentWrapper.test.tsx.snap +47 -34
- package/src/components/DatePicker/DatePicker.stories.mdx +63 -27
- package/src/components/DatePicker/DatePicker.test.tsx +94 -15
- package/src/components/DatePicker/DatePicker.tsx +67 -58
- package/src/components/DatePicker/_DatePicker.scss +71 -13
- package/src/components/DatePicker/__snapshots__/DatePicker.test.tsx.snap +250 -206
- package/src/components/Fieldset/Fieldset.stories.mdx +33 -3
- package/src/components/Fieldset/Fieldset.test.tsx +58 -28
- package/src/components/Fieldset/Fieldset.tsx +35 -30
- package/src/components/Fieldset/__snapshots__/Fieldset.test.tsx.snap +40 -19
- package/src/components/Form/Form.stories.mdx +118 -47
- package/src/components/Form/Form.test.tsx +59 -16
- package/src/components/Form/Form.tsx +89 -65
- package/src/components/Form/__snapshots__/Form.test.tsx.snap +83 -5
- package/src/components/Grid/GridTypes.tsx +7 -7
- package/src/components/Grid/SimpleGrid.stories.mdx +87 -41
- package/src/components/Grid/SimpleGrid.test.tsx +24 -9
- package/src/components/Grid/SimpleGrid.tsx +29 -20
- package/src/components/Grid/__snapshots__/SimpleGrid.test.tsx.snap +16 -1
- package/src/components/Heading/Heading.stories.mdx +56 -25
- package/src/components/Heading/Heading.test.tsx +17 -7
- package/src/components/Heading/Heading.tsx +60 -58
- package/src/components/Heading/HeadingTypes.tsx +1 -1
- package/src/components/Heading/__snapshots__/Heading.test.tsx.snap +27 -8
- package/src/components/HelperErrorText/HelperErrorText.stories.mdx +64 -42
- package/src/components/HelperErrorText/HelperErrorText.test.tsx +15 -0
- package/src/components/HelperErrorText/HelperErrorText.tsx +40 -35
- package/src/components/HelperErrorText/__snapshots__/HelperErrorText.test.tsx.snap +35 -4
- package/src/components/Hero/Hero.stories.mdx +143 -113
- package/src/components/Hero/Hero.test.tsx +146 -58
- package/src/components/Hero/Hero.tsx +144 -112
- package/src/components/Hero/__snapshots__/Hero.test.tsx.snap +89 -17
- package/src/components/HorizontalRule/HorizontalRule.stories.mdx +26 -4
- package/src/components/HorizontalRule/HorizontalRule.test.tsx +9 -17
- package/src/components/HorizontalRule/HorizontalRule.tsx +9 -25
- package/src/components/HorizontalRule/__snapshots__/HorizontalRule.test.tsx.snap +18 -5
- package/src/components/Icons/Icon.stories.mdx +80 -23
- package/src/components/Icons/Icon.test.tsx +51 -2
- package/src/components/Icons/Icon.tsx +93 -71
- package/src/components/Icons/IconTypes.tsx +1 -0
- package/src/components/Icons/__snapshots__/Icon.test.tsx.snap +129 -0
- package/src/components/Image/Image.stories.mdx +160 -71
- package/src/components/Image/Image.test.tsx +40 -48
- package/src/components/Image/Image.tsx +80 -48
- package/src/components/Image/ImageTypes.ts +4 -4
- package/src/components/Image/__snapshots__/Image.test.tsx.snap +84 -21
- package/src/components/Label/Label.stories.mdx +42 -20
- package/src/components/Label/Label.test.tsx +42 -17
- package/src/components/Label/Label.tsx +22 -13
- package/src/components/Label/__snapshots__/Label.test.tsx.snap +19 -15
- package/src/components/Link/Link.stories.mdx +25 -1
- package/src/components/Link/Link.test.tsx +21 -0
- package/src/components/Link/Link.tsx +16 -9
- package/src/components/Link/__snapshots__/Link.test.tsx.snap +37 -11
- package/src/components/List/List.stories.mdx +75 -40
- package/src/components/List/List.test.tsx +73 -22
- package/src/components/List/List.tsx +44 -28
- package/src/components/List/ListTypes.tsx +1 -1
- package/src/components/List/__snapshots__/List.test.tsx.snap +110 -8
- package/src/components/Logo/Logo.stories.mdx +40 -16
- package/src/components/Logo/Logo.test.tsx +29 -2
- package/src/components/Logo/Logo.tsx +28 -11
- package/src/components/Logo/LogoSvgs.tsx +4 -0
- package/src/components/Logo/LogoTypes.tsx +3 -1
- package/src/components/Logo/__snapshots__/Logo.test.tsx.snap +73 -2
- package/src/components/Modal/Modal.stories.mdx +13 -0
- package/src/components/Notification/Notification.stories.mdx +29 -5
- package/src/components/Notification/Notification.test.tsx +23 -0
- package/src/components/Notification/Notification.tsx +53 -51
- package/src/components/Notification/__snapshots__/Notification.test.tsx.snap +158 -29
- package/src/components/Pagination/Pagination.stories.mdx +27 -6
- package/src/components/Pagination/Pagination.test.tsx +55 -2
- package/src/components/Pagination/Pagination.tsx +12 -9
- package/src/components/Pagination/__snapshots__/Pagination.test.tsx.snap +244 -27
- package/src/components/Placeholder/Placeholder.tsx +3 -1
- package/src/components/ProgressIndicator/ProgressIndicator.stories.mdx +76 -10
- package/src/components/ProgressIndicator/ProgressIndicator.test.tsx +87 -13
- package/src/components/ProgressIndicator/ProgressIndicator.tsx +20 -10
- package/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap +101 -14
- package/src/components/Radio/Radio.stories.mdx +75 -11
- package/src/components/Radio/Radio.test.tsx +83 -9
- package/src/components/Radio/Radio.tsx +70 -62
- package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +163 -5
- package/src/components/RadioGroup/RadioGroup.stories.mdx +293 -94
- package/src/components/RadioGroup/RadioGroup.test.tsx +193 -68
- package/src/components/RadioGroup/RadioGroup.tsx +110 -101
- package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +1258 -902
- package/src/components/SearchBar/SearchBar.stories.mdx +101 -36
- package/src/components/SearchBar/{SearchBar.Test.tsx → SearchBar.test.tsx} +46 -4
- package/src/components/SearchBar/SearchBar.tsx +20 -11
- package/src/components/SearchBar/__snapshots__/SearchBar.test.tsx.snap +1039 -0
- package/src/components/Select/Select.stories.mdx +151 -62
- package/src/components/Select/Select.test.tsx +56 -44
- package/src/components/Select/Select.tsx +125 -104
- package/src/components/Select/SelectTypes.tsx +5 -0
- package/src/components/Select/__snapshots__/Select.test.tsx.snap +749 -409
- package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +53 -23
- package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +14 -8
- package/src/components/SkeletonLoader/SkeletonLoader.tsx +80 -78
- package/src/components/SkeletonLoader/SkeletonLoaderTypes.tsx +0 -5
- package/src/components/SkeletonLoader/__snapshots__/SkeletonLoader.test.tsx.snap +169 -10
- package/src/components/Slider/Slider.stories.mdx +123 -41
- package/src/components/Slider/Slider.test.tsx +65 -17
- package/src/components/Slider/Slider.tsx +30 -23
- package/src/components/Slider/__snapshots__/Slider.test.tsx.snap +403 -226
- package/src/components/StatusBadge/StatusBadge.stories.mdx +19 -1
- package/src/components/StatusBadge/StatusBadge.test.tsx +19 -1
- package/src/components/StatusBadge/StatusBadge.tsx +25 -20
- package/src/components/StatusBadge/__snapshots__/StatusBadge.test.tsx.snap +22 -3
- package/src/components/StructuredContent/StructuredContent.stories.mdx +229 -61
- package/src/components/StructuredContent/StructuredContent.test.tsx +162 -101
- package/src/components/StructuredContent/StructuredContent.tsx +98 -103
- package/src/components/StructuredContent/__snapshots__/StructuredContent.test.tsx.snap +102 -17
- package/src/components/StyleGuide/Bidirectionality.stories.mdx +5 -5
- package/src/components/StyleGuide/Breakpoints.stories.mdx +6 -6
- package/src/components/StyleGuide/Buttons.stories.mdx +2 -12
- package/src/components/StyleGuide/ColorCard.tsx +4 -4
- package/src/components/StyleGuide/Colors.stories.mdx +1 -2
- package/src/components/StyleGuide/DesignTokens.stories.mdx +56 -26
- package/src/components/StyleGuide/Forms.stories.mdx +27 -12
- package/src/components/StyleGuide/Iconography.stories.mdx +2 -12
- package/src/components/StyleGuide/Spacing.stories.mdx +80 -41
- package/src/components/StyleGuide/Typography.stories.mdx +47 -33
- package/src/components/Table/Table.stories.mdx +38 -11
- package/src/components/Table/Table.test.tsx +16 -1
- package/src/components/Table/Table.tsx +10 -8
- package/src/components/Table/__snapshots__/Table.test.tsx.snap +408 -5
- package/src/components/Tabs/Tabs.stories.mdx +59 -10
- package/src/components/Tabs/Tabs.test.tsx +29 -11
- package/src/components/Tabs/Tabs.tsx +28 -21
- package/src/components/Tabs/__snapshots__/Tabs.test.tsx.snap +394 -5
- package/src/components/Template/Template.stories.mdx +73 -32
- package/src/components/Template/Template.test.tsx +68 -5
- package/src/components/Template/Template.tsx +89 -71
- package/src/components/Template/__snapshots__/Template.test.tsx.snap +195 -22
- package/src/components/Text/Text.stories.mdx +32 -15
- package/src/components/Text/Text.test.tsx +14 -11
- package/src/components/Text/Text.tsx +13 -16
- package/src/components/Text/TextTypes.tsx +1 -1
- package/src/components/Text/__snapshots__/Text.test.tsx.snap +21 -4
- package/src/components/TextInput/TextInput.stories.mdx +73 -27
- package/src/components/TextInput/TextInput.test.tsx +65 -50
- package/src/components/TextInput/TextInput.tsx +123 -115
- package/src/components/TextInput/__snapshots__/TextInput.test.tsx.snap +96 -73
- package/src/components/Toggle/Toggle.stories.mdx +74 -26
- package/src/components/Toggle/Toggle.test.tsx +41 -10
- package/src/components/Toggle/Toggle.tsx +29 -26
- package/src/components/Toggle/{ToggleSizes.tsx → ToggleTypes.tsx} +1 -1
- package/src/components/Toggle/__snapshots__/Toggle.test.tsx.snap +191 -4
- package/src/components/VideoPlayer/VideoPlayer.stories.mdx +52 -4
- package/src/components/VideoPlayer/VideoPlayer.test.tsx +41 -6
- package/src/components/VideoPlayer/VideoPlayer.tsx +134 -120
- package/src/components/VideoPlayer/__snapshots__/VideoPlayer.test.tsx.snap +81 -39
- package/src/docs/Chakra.stories.mdx +50 -9
- package/src/docs/Welcome.stories.mdx +168 -0
- 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 +30 -0
- package/src/hooks/useCarouselStyles.ts +3 -2
- package/src/hooks/useNYPLTheme.stories.mdx +101 -0
- package/src/hooks/useNYPLTheme.ts +31 -7
- package/src/hooks/useWindowSize.stories.mdx +23 -0
- package/src/index.ts +11 -15
- package/src/styles/base/_place-holder.scss +1 -1
- package/src/theme/components/accordion.ts +7 -12
- package/src/theme/components/breadcrumb.ts +3 -0
- package/src/theme/components/button.ts +15 -7
- package/src/theme/components/card.ts +56 -36
- package/src/theme/components/checkbox.ts +10 -8
- package/src/theme/components/checkboxGroup.ts +4 -2
- package/src/theme/components/componentWrapper.ts +2 -2
- package/src/theme/components/customTable.ts +39 -31
- package/src/theme/components/fieldset.ts +1 -2
- package/src/theme/components/global.ts +29 -23
- package/src/theme/components/heading.ts +1 -1
- package/src/theme/components/helperErrorText.ts +1 -0
- package/src/theme/components/hero.ts +14 -16
- package/src/theme/components/icon.ts +5 -2
- package/src/theme/components/image.ts +1 -1
- package/src/theme/components/label.ts +4 -3
- package/src/theme/components/list.ts +73 -66
- package/src/theme/components/notification.ts +7 -7
- package/src/theme/components/pagination.ts +2 -5
- package/src/theme/components/progressIndicator.ts +3 -3
- package/src/theme/components/radio.ts +9 -9
- package/src/theme/components/radioGroup.ts +4 -2
- package/src/theme/components/select.ts +35 -16
- package/src/theme/components/skeletonLoader.ts +3 -3
- package/src/theme/components/slider.ts +8 -7
- package/src/theme/components/statusBadge.ts +2 -2
- package/src/theme/components/structuredContent.ts +66 -1
- package/src/theme/components/tabs.ts +2 -2
- package/src/theme/components/template.ts +9 -9
- package/src/theme/components/textInput.ts +13 -12
- package/src/theme/components/toggle.ts +43 -13
- package/src/theme/components/videoPlayer.ts +1 -1
- package/src/theme/foundations/colors.ts +1 -1
- package/src/theme/foundations/radii.ts +1 -0
- package/src/theme/foundations/spacing.ts +70 -22
- package/src/theme/foundations/typography.ts +2 -2
- package/src/utils/componentCategories.ts +28 -21
- 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/dist/components/SearchBar/SearchBar.Test.d.ts +0 -1
- package/dist/helpers/generateUUID.d.ts +0 -1
- package/src/components/CheckboxGroup/CheckboxGroupLayoutTypes.tsx +0 -4
- package/src/components/RadioGroup/RadioGroupLayoutTypes.tsx +0 -4
- package/src/docs/Intro.stories.mdx +0 -53
- package/src/helpers/generateUUID.tsx +0 -5
|
@@ -28,7 +28,10 @@ const monthArray = [
|
|
|
28
28
|
describe("DatePicker Accessibility", () => {
|
|
29
29
|
it("passes axe accessibility for a single date input", async () => {
|
|
30
30
|
const { container } = render(
|
|
31
|
-
<DatePicker
|
|
31
|
+
<DatePicker
|
|
32
|
+
id="datePicker"
|
|
33
|
+
labelText="Select the date you want to visit NYPL"
|
|
34
|
+
/>
|
|
32
35
|
);
|
|
33
36
|
expect(await axe(container)).toHaveNoViolations();
|
|
34
37
|
});
|
|
@@ -36,6 +39,7 @@ describe("DatePicker Accessibility", () => {
|
|
|
36
39
|
it("passes axe accessibility for a date range", async () => {
|
|
37
40
|
const { container } = render(
|
|
38
41
|
<DatePicker
|
|
42
|
+
id="datePicker"
|
|
39
43
|
labelText="Select the date range you want to visit NYPL"
|
|
40
44
|
isDateRange
|
|
41
45
|
/>
|
|
@@ -67,7 +71,10 @@ describe("DatePicker", () => {
|
|
|
67
71
|
describe("Single input", () => {
|
|
68
72
|
it("should render the basic date input field including a date", () => {
|
|
69
73
|
render(
|
|
70
|
-
<DatePicker
|
|
74
|
+
<DatePicker
|
|
75
|
+
id="datePicker"
|
|
76
|
+
labelText="Select the full date you want to visit NYPL"
|
|
77
|
+
/>
|
|
71
78
|
);
|
|
72
79
|
const [year, month, day] = getTodaysValues();
|
|
73
80
|
const date = getTodaysDateDisplay();
|
|
@@ -85,6 +92,7 @@ describe("DatePicker", () => {
|
|
|
85
92
|
it("should render with an initial date", () => {
|
|
86
93
|
render(
|
|
87
94
|
<DatePicker
|
|
95
|
+
id="datePicker"
|
|
88
96
|
labelText="Select the full date you want to visit NYPL"
|
|
89
97
|
initialDate="1/2/1988"
|
|
90
98
|
/>
|
|
@@ -97,6 +105,7 @@ describe("DatePicker", () => {
|
|
|
97
105
|
it("should render the 'month' DatePicker type", () => {
|
|
98
106
|
render(
|
|
99
107
|
<DatePicker
|
|
108
|
+
id="datePicker"
|
|
100
109
|
dateType={DatePickerTypes.Month}
|
|
101
110
|
labelText="Select the month you want to visit NYPL"
|
|
102
111
|
/>
|
|
@@ -115,6 +124,7 @@ describe("DatePicker", () => {
|
|
|
115
124
|
it("should render the 'year' DatePicker type", () => {
|
|
116
125
|
render(
|
|
117
126
|
<DatePicker
|
|
127
|
+
id="datePicker"
|
|
118
128
|
dateType={DatePickerTypes.Year}
|
|
119
129
|
labelText="Select the month you want to visit NYPL"
|
|
120
130
|
/>
|
|
@@ -135,6 +145,7 @@ describe("DatePicker", () => {
|
|
|
135
145
|
const customDateFormat2 = "MM/dd/yyyy";
|
|
136
146
|
const { rerender } = render(
|
|
137
147
|
<DatePicker
|
|
148
|
+
id="datePicker"
|
|
138
149
|
labelText="Select the date you want to visit NYPL"
|
|
139
150
|
dateFormat={customDateFormat1}
|
|
140
151
|
/>
|
|
@@ -147,6 +158,7 @@ describe("DatePicker", () => {
|
|
|
147
158
|
const dateFormat2 = `${month}/${day}/${year}`;
|
|
148
159
|
rerender(
|
|
149
160
|
<DatePicker
|
|
161
|
+
id="datePicker"
|
|
150
162
|
labelText="Select the date you want to visit NYPL"
|
|
151
163
|
dateFormat={customDateFormat2}
|
|
152
164
|
/>
|
|
@@ -157,6 +169,7 @@ describe("DatePicker", () => {
|
|
|
157
169
|
it("should hide the input label but add an aria-label", () => {
|
|
158
170
|
render(
|
|
159
171
|
<DatePicker
|
|
172
|
+
id="datePicker"
|
|
160
173
|
labelText="Select the date you want to visit NYPL"
|
|
161
174
|
showLabel={false}
|
|
162
175
|
/>
|
|
@@ -174,6 +187,7 @@ describe("DatePicker", () => {
|
|
|
174
187
|
it("should render with helper text and error text", () => {
|
|
175
188
|
const { rerender } = render(
|
|
176
189
|
<DatePicker
|
|
190
|
+
id="datePicker"
|
|
177
191
|
labelText="Select the date you want to visit NYPL"
|
|
178
192
|
helperText="Note that the Library may be closed on Sundays."
|
|
179
193
|
invalidText="Please select a valid date."
|
|
@@ -193,6 +207,7 @@ describe("DatePicker", () => {
|
|
|
193
207
|
|
|
194
208
|
rerender(
|
|
195
209
|
<DatePicker
|
|
210
|
+
id="datePicker"
|
|
196
211
|
labelText="Select the date you want to visit NYPL"
|
|
197
212
|
helperText="Note that the Library may be closed on Sundays."
|
|
198
213
|
invalidText="Please select a valid date."
|
|
@@ -211,6 +226,7 @@ describe("DatePicker", () => {
|
|
|
211
226
|
it("should not render the helper text or invalid text when 'showHelperInvalidText' is false", () => {
|
|
212
227
|
const { rerender } = render(
|
|
213
228
|
<DatePicker
|
|
229
|
+
id="datePicker"
|
|
214
230
|
labelText="Select the date you want to visit NYPL"
|
|
215
231
|
helperText="Note that the Library may be closed on Sundays."
|
|
216
232
|
invalidText="Please select a valid date."
|
|
@@ -226,6 +242,7 @@ describe("DatePicker", () => {
|
|
|
226
242
|
|
|
227
243
|
rerender(
|
|
228
244
|
<DatePicker
|
|
245
|
+
id="datePicker"
|
|
229
246
|
labelText="Select the date you want to visit NYPL"
|
|
230
247
|
helperText="Note that the Library may be closed on Sundays."
|
|
231
248
|
invalidText="Please select a valid date."
|
|
@@ -244,6 +261,7 @@ describe("DatePicker", () => {
|
|
|
244
261
|
it("should render a disabled input field", () => {
|
|
245
262
|
render(
|
|
246
263
|
<DatePicker
|
|
264
|
+
id="datePicker"
|
|
247
265
|
labelText="Select the date you want to visit NYPL"
|
|
248
266
|
helperText="Note that the Library may be closed on Sundays."
|
|
249
267
|
isDisabled
|
|
@@ -258,6 +276,7 @@ describe("DatePicker", () => {
|
|
|
258
276
|
it("should render a required label", () => {
|
|
259
277
|
render(
|
|
260
278
|
<DatePicker
|
|
279
|
+
id="datePicker"
|
|
261
280
|
labelText="Select the date you want to visit NYPL"
|
|
262
281
|
helperText="Note that the Library may be closed on Sundays."
|
|
263
282
|
isRequired
|
|
@@ -267,22 +286,18 @@ describe("DatePicker", () => {
|
|
|
267
286
|
expect(screen.getByText(/required/i)).toBeInTheDocument();
|
|
268
287
|
});
|
|
269
288
|
|
|
270
|
-
it("should hide the
|
|
289
|
+
it("should hide the (Required) text in the label with `showRequiredLabel`", () => {
|
|
271
290
|
const { rerender } = render(
|
|
272
|
-
<DatePicker labelText="Select the date you want to visit NYPL" />
|
|
273
|
-
);
|
|
274
|
-
expect(screen.getByText(/Optional/i)).toBeInTheDocument();
|
|
275
|
-
|
|
276
|
-
rerender(
|
|
277
291
|
<DatePicker
|
|
292
|
+
id="datePicker"
|
|
278
293
|
labelText="Select the date you want to visit NYPL"
|
|
279
|
-
showOptReqLabel={false}
|
|
280
294
|
/>
|
|
281
295
|
);
|
|
282
|
-
expect(screen.queryByText(/
|
|
296
|
+
expect(screen.queryByText(/Required/i)).not.toBeInTheDocument();
|
|
283
297
|
|
|
284
298
|
rerender(
|
|
285
299
|
<DatePicker
|
|
300
|
+
id="datePicker"
|
|
286
301
|
labelText="Select the date you want to visit NYPL"
|
|
287
302
|
isRequired
|
|
288
303
|
/>
|
|
@@ -291,8 +306,9 @@ describe("DatePicker", () => {
|
|
|
291
306
|
|
|
292
307
|
rerender(
|
|
293
308
|
<DatePicker
|
|
309
|
+
id="datePicker"
|
|
294
310
|
labelText="Select the date you want to visit NYPL"
|
|
295
|
-
|
|
311
|
+
showRequiredLabel={false}
|
|
296
312
|
isRequired
|
|
297
313
|
/>
|
|
298
314
|
);
|
|
@@ -306,6 +322,7 @@ describe("DatePicker", () => {
|
|
|
306
322
|
};
|
|
307
323
|
render(
|
|
308
324
|
<DatePicker
|
|
325
|
+
id="datePicker"
|
|
309
326
|
labelText="Select the date you want to visit NYPL"
|
|
310
327
|
helperText="Note that the Library may be closed on Sundays."
|
|
311
328
|
onChange={onChange}
|
|
@@ -339,12 +356,14 @@ describe("DatePicker", () => {
|
|
|
339
356
|
const ref = React.createRef<TextInputRefType>();
|
|
340
357
|
render(
|
|
341
358
|
<DatePicker
|
|
359
|
+
id="datePicker"
|
|
342
360
|
labelText="Select the date you want to visit NYPL"
|
|
343
361
|
ref={ref}
|
|
344
362
|
/>
|
|
345
363
|
);
|
|
346
364
|
expect(warn).toHaveBeenCalledWith(
|
|
347
|
-
"A `ref` or `refTo` prop was passed but
|
|
365
|
+
"NYPL Reservoir DatePicker: A `ref` or `refTo` prop was passed but " +
|
|
366
|
+
"not the equivalent `nameFrom` or `nameTo` prop."
|
|
348
367
|
);
|
|
349
368
|
});
|
|
350
369
|
|
|
@@ -354,6 +373,7 @@ describe("DatePicker", () => {
|
|
|
354
373
|
const onChange = (_data) => {};
|
|
355
374
|
render(
|
|
356
375
|
<DatePicker
|
|
376
|
+
id="datePicker"
|
|
357
377
|
labelText="Select the date you want to visit NYPL"
|
|
358
378
|
ref={ref}
|
|
359
379
|
nameFrom="start-date"
|
|
@@ -361,7 +381,9 @@ describe("DatePicker", () => {
|
|
|
361
381
|
/>
|
|
362
382
|
);
|
|
363
383
|
expect(warn).toHaveBeenCalledWith(
|
|
364
|
-
"
|
|
384
|
+
"NYPL Reservoir DatePicker: A `ref`, `refTo`, `nameFrom`, or `nameTo` " +
|
|
385
|
+
"prop was passed and an `onChange` prop as well. Use whichever is best " +
|
|
386
|
+
"for your app but not both."
|
|
365
387
|
);
|
|
366
388
|
});
|
|
367
389
|
|
|
@@ -422,11 +444,39 @@ describe("DatePicker", () => {
|
|
|
422
444
|
/>
|
|
423
445
|
)
|
|
424
446
|
.toJSON();
|
|
447
|
+
const withChakraProps = renderer
|
|
448
|
+
.create(
|
|
449
|
+
<DatePicker
|
|
450
|
+
id="chakra"
|
|
451
|
+
labelText="Select the date you want to visit NYPL"
|
|
452
|
+
helperText="Note that the Library may be closed on Sundays."
|
|
453
|
+
invalidText="Please select a valid date."
|
|
454
|
+
initialDate="1/2/1988"
|
|
455
|
+
p="20px"
|
|
456
|
+
color="ui.error.primary"
|
|
457
|
+
/>
|
|
458
|
+
)
|
|
459
|
+
.toJSON();
|
|
460
|
+
const withOtherProps = renderer
|
|
461
|
+
.create(
|
|
462
|
+
<DatePicker
|
|
463
|
+
id="props"
|
|
464
|
+
labelText="Select the date you want to visit NYPL"
|
|
465
|
+
helperText="Note that the Library may be closed on Sundays."
|
|
466
|
+
invalidText="Please select a valid date."
|
|
467
|
+
initialDate="1/2/1988"
|
|
468
|
+
data-testid="datepicker"
|
|
469
|
+
/>
|
|
470
|
+
)
|
|
471
|
+
.toJSON();
|
|
472
|
+
|
|
425
473
|
expect(basic).toMatchSnapshot();
|
|
426
474
|
expect(withoutLabel).toMatchSnapshot();
|
|
427
475
|
expect(withCustomFormat).toMatchSnapshot();
|
|
428
476
|
expect(invalid).toMatchSnapshot();
|
|
429
477
|
expect(disabled).toMatchSnapshot();
|
|
478
|
+
expect(withChakraProps).toMatchSnapshot();
|
|
479
|
+
expect(withOtherProps).toMatchSnapshot();
|
|
430
480
|
});
|
|
431
481
|
});
|
|
432
482
|
|
|
@@ -434,6 +484,7 @@ describe("DatePicker", () => {
|
|
|
434
484
|
it("should render the date range with two input fields", () => {
|
|
435
485
|
render(
|
|
436
486
|
<DatePicker
|
|
487
|
+
id="datePicker"
|
|
437
488
|
labelText="Select the date range you want to visit NYPL"
|
|
438
489
|
isDateRange
|
|
439
490
|
/>
|
|
@@ -453,6 +504,7 @@ describe("DatePicker", () => {
|
|
|
453
504
|
it("should render the initial dates", () => {
|
|
454
505
|
render(
|
|
455
506
|
<DatePicker
|
|
507
|
+
id="datePicker"
|
|
456
508
|
labelText="Select the full date you want to visit NYPL"
|
|
457
509
|
isDateRange
|
|
458
510
|
initialDate="1/2/1988"
|
|
@@ -469,6 +521,7 @@ describe("DatePicker", () => {
|
|
|
469
521
|
it("should render two input labels and three separate helper text", () => {
|
|
470
522
|
render(
|
|
471
523
|
<DatePicker
|
|
524
|
+
id="datePicker"
|
|
472
525
|
labelText="Select the date range you want to visit NYPL"
|
|
473
526
|
helperText="Note that the Library may be closed on Sundays."
|
|
474
527
|
helperTextFrom="Note for the 'from' field."
|
|
@@ -495,6 +548,7 @@ describe("DatePicker", () => {
|
|
|
495
548
|
it("should render different states based on respective props", () => {
|
|
496
549
|
const { rerender } = render(
|
|
497
550
|
<DatePicker
|
|
551
|
+
id="datePicker"
|
|
498
552
|
labelText="Select the date range you want to visit NYPL"
|
|
499
553
|
helperText="Note that the Library may be closed on Sundays."
|
|
500
554
|
helperTextTo="Note for the 'to' field."
|
|
@@ -511,6 +565,7 @@ describe("DatePicker", () => {
|
|
|
511
565
|
|
|
512
566
|
rerender(
|
|
513
567
|
<DatePicker
|
|
568
|
+
id="datePicker"
|
|
514
569
|
labelText="Select the date range you want to visit NYPL"
|
|
515
570
|
helperText="Note that the Library may be closed on Sundays."
|
|
516
571
|
helperTextTo="Note for the 'to' field."
|
|
@@ -525,6 +580,7 @@ describe("DatePicker", () => {
|
|
|
525
580
|
|
|
526
581
|
rerender(
|
|
527
582
|
<DatePicker
|
|
583
|
+
id="datePicker"
|
|
528
584
|
labelText="Select the date range you want to visit NYPL"
|
|
529
585
|
helperText="Note that the Library may be closed on Sundays."
|
|
530
586
|
helperTextTo="Note for the 'to' field."
|
|
@@ -535,7 +591,7 @@ describe("DatePicker", () => {
|
|
|
535
591
|
);
|
|
536
592
|
// Both input fields are required.
|
|
537
593
|
// The "Required" text is only displayed once in the `legend`.
|
|
538
|
-
expect(screen.getAllByText(/
|
|
594
|
+
expect(screen.getAllByText(/Required/i)).toHaveLength(1);
|
|
539
595
|
expect(screen.getByLabelText(/From/i)).toHaveAttribute("required");
|
|
540
596
|
expect(screen.getByLabelText(/To/i)).toHaveAttribute("required");
|
|
541
597
|
});
|
|
@@ -617,6 +673,7 @@ describe("DatePicker", () => {
|
|
|
617
673
|
it("should select two new dates", () => {
|
|
618
674
|
render(
|
|
619
675
|
<DatePicker
|
|
676
|
+
id="datePicker"
|
|
620
677
|
initialDate="3/2/1988"
|
|
621
678
|
initialDateTo="3/28/1988"
|
|
622
679
|
isDateRange
|
|
@@ -659,7 +716,12 @@ describe("DatePicker", () => {
|
|
|
659
716
|
|
|
660
717
|
describe("Popup Calendar", () => {
|
|
661
718
|
it("should render a popup calendar for the full date", () => {
|
|
662
|
-
render(
|
|
719
|
+
render(
|
|
720
|
+
<DatePicker
|
|
721
|
+
id="datePicker"
|
|
722
|
+
labelText="Select the date you want to visit NYPL"
|
|
723
|
+
/>
|
|
724
|
+
);
|
|
663
725
|
const input = screen.getByLabelText(
|
|
664
726
|
/Select the date you want to visit NYPL/i
|
|
665
727
|
);
|
|
@@ -689,6 +751,7 @@ describe("DatePicker", () => {
|
|
|
689
751
|
it("should select a new date from the calendar", () => {
|
|
690
752
|
render(
|
|
691
753
|
<DatePicker
|
|
754
|
+
id="datePicker"
|
|
692
755
|
labelText="Select the date you want to visit NYPL"
|
|
693
756
|
initialDate="08/01/2021"
|
|
694
757
|
/>
|
|
@@ -733,6 +796,7 @@ describe("DatePicker", () => {
|
|
|
733
796
|
it("should render a popup calendar for the month date", () => {
|
|
734
797
|
render(
|
|
735
798
|
<DatePicker
|
|
799
|
+
id="datePicker"
|
|
736
800
|
dateType={DatePickerTypes.Month}
|
|
737
801
|
labelText="Select the month you want to visit NYPL"
|
|
738
802
|
/>
|
|
@@ -759,6 +823,7 @@ describe("DatePicker", () => {
|
|
|
759
823
|
it("should select a new month from the calendar", () => {
|
|
760
824
|
render(
|
|
761
825
|
<DatePicker
|
|
826
|
+
id="datePicker"
|
|
762
827
|
dateType={DatePickerTypes.Month}
|
|
763
828
|
initialDate="4/1/1988"
|
|
764
829
|
labelText="Select the month you want to visit NYPL"
|
|
@@ -798,6 +863,7 @@ describe("DatePicker", () => {
|
|
|
798
863
|
it("should render a popup calendar for the year date", () => {
|
|
799
864
|
render(
|
|
800
865
|
<DatePicker
|
|
866
|
+
id="datePicker"
|
|
801
867
|
dateType={DatePickerTypes.Year}
|
|
802
868
|
labelText="Select the year you want to visit NYPL"
|
|
803
869
|
/>
|
|
@@ -835,6 +901,7 @@ describe("DatePicker", () => {
|
|
|
835
901
|
it("should select a new year from the calendar", () => {
|
|
836
902
|
render(
|
|
837
903
|
<DatePicker
|
|
904
|
+
id="datePicker"
|
|
838
905
|
dateType={DatePickerTypes.Year}
|
|
839
906
|
labelText="Select the year you want to visit NYPL"
|
|
840
907
|
/>
|
|
@@ -855,5 +922,17 @@ describe("DatePicker", () => {
|
|
|
855
922
|
|
|
856
923
|
expect(screen.getByDisplayValue("2024")).toBeInTheDocument();
|
|
857
924
|
});
|
|
925
|
+
|
|
926
|
+
it("logs a warning when there is no `id` passed", () => {
|
|
927
|
+
const warn = jest.spyOn(console, "warn");
|
|
928
|
+
render(
|
|
929
|
+
// @ts-ignore: Typescript complains when a required prop is not passed, but
|
|
930
|
+
// here we don't want to pass the required prop to make sure the warning appears.
|
|
931
|
+
<DatePicker labelText="Select the year you want to visit NYPL" />
|
|
932
|
+
);
|
|
933
|
+
expect(warn).toHaveBeenCalledWith(
|
|
934
|
+
"NYPL Reservoir DatePicker: This component's required `id` prop was not passed."
|
|
935
|
+
);
|
|
936
|
+
});
|
|
858
937
|
});
|
|
859
938
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { chakra, useMultiStyleConfig } from "@chakra-ui/react";
|
|
1
2
|
import React, { useState, forwardRef } from "react";
|
|
2
3
|
import ReactDatePicker from "react-datepicker";
|
|
3
4
|
|
|
@@ -8,13 +9,10 @@ import { FormGaps } from "../Form/FormTypes";
|
|
|
8
9
|
import HelperErrorText, {
|
|
9
10
|
HelperErrorTextType,
|
|
10
11
|
} from "../HelperErrorText/HelperErrorText";
|
|
11
|
-
import { helperTextMargin } from "../../theme/components/global";
|
|
12
12
|
import TextInput, {
|
|
13
13
|
InputProps,
|
|
14
14
|
TextInputRefType,
|
|
15
15
|
} from "../TextInput/TextInput";
|
|
16
|
-
import generateUUID from "../../helpers/generateUUID";
|
|
17
|
-
import { Box, useMultiStyleConfig } from "@chakra-ui/react";
|
|
18
16
|
|
|
19
17
|
// The object shape for the DatePicker's start and end date state values.
|
|
20
18
|
export interface FullDateType {
|
|
@@ -28,7 +26,7 @@ export interface FullDateType {
|
|
|
28
26
|
// Used for the input fields' parent wrapper. Internal use only.
|
|
29
27
|
interface DateRangeRowProps {
|
|
30
28
|
/** ID that other components can cross reference for accessibility purposes. */
|
|
31
|
-
id
|
|
29
|
+
id: string;
|
|
32
30
|
/** Whether to render a single date input or two for a range of two dates. */
|
|
33
31
|
isDateRange?: boolean;
|
|
34
32
|
}
|
|
@@ -44,16 +42,17 @@ interface DatePickerWrapperProps extends DateRangeRowProps {
|
|
|
44
42
|
labelText: string;
|
|
45
43
|
/** Offers the ability to show the label onscreen or hide it. */
|
|
46
44
|
showLabel?: boolean;
|
|
47
|
-
/** Whether or not to display the "Required"
|
|
48
|
-
|
|
45
|
+
/** Whether or not to display the "(Required)" text in the label text.
|
|
46
|
+
* True by default. */
|
|
47
|
+
showRequiredLabel?: boolean;
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
// Interface used by the internal DS `TextInput` component as a custom
|
|
52
51
|
// component for the ReactDatePicker plugin component. Internal use only.
|
|
53
|
-
interface CustomTextInputProps extends InputProps {
|
|
52
|
+
interface CustomTextInputProps extends Partial<InputProps> {
|
|
54
53
|
/** The ReactDatePicker plugin has its own `id` prop so we use this to pass the
|
|
55
54
|
* value from the parent `DatePicker` component. */
|
|
56
|
-
dsId
|
|
55
|
+
dsId: string;
|
|
57
56
|
/** The ReactDatePicker plugin manipulates the ref value so we declare our
|
|
58
57
|
* own for some cases. */
|
|
59
58
|
dsRef?: React.Ref<TextInputRefType>;
|
|
@@ -62,8 +61,6 @@ interface CustomTextInputProps extends InputProps {
|
|
|
62
61
|
isRequired?: boolean;
|
|
63
62
|
/** Event handler used by the ReactDatePicker plugin to open the popup calendar. */
|
|
64
63
|
onClick?: (data: any) => any;
|
|
65
|
-
/** Whether or not to display the "Required"/"Optional" text in the label text. */
|
|
66
|
-
showOptReqLabel?: boolean;
|
|
67
64
|
/** Data value used by the ReactDatePicker plugin and the custom TextInput component. */
|
|
68
65
|
value?: string;
|
|
69
66
|
}
|
|
@@ -114,8 +111,6 @@ export interface DatePickerProps extends DatePickerWrapperProps {
|
|
|
114
111
|
refTo?: React.Ref<TextInputRefType>;
|
|
115
112
|
/** Offers the ability to hide the helper/invalid text. */
|
|
116
113
|
showHelperInvalidText?: boolean;
|
|
117
|
-
/** Whether or not to display the "Required"/"Optional" text in the label text. */
|
|
118
|
-
showOptReqLabel?: boolean;
|
|
119
114
|
}
|
|
120
115
|
|
|
121
116
|
/**
|
|
@@ -143,7 +138,7 @@ const CustomTextInput = forwardRef<TextInputRefType, CustomTextInputProps>(
|
|
|
143
138
|
onClick,
|
|
144
139
|
showLabel,
|
|
145
140
|
showHelperInvalidText,
|
|
146
|
-
|
|
141
|
+
showRequiredLabel,
|
|
147
142
|
value,
|
|
148
143
|
},
|
|
149
144
|
ref: React.Ref<TextInputRefType>
|
|
@@ -157,7 +152,7 @@ const CustomTextInput = forwardRef<TextInputRefType, CustomTextInputProps>(
|
|
|
157
152
|
isDisabled={isDisabled}
|
|
158
153
|
isRequired={isRequired}
|
|
159
154
|
showHelperInvalidText={showHelperInvalidText}
|
|
160
|
-
|
|
155
|
+
showRequiredLabel={showRequiredLabel}
|
|
161
156
|
isInvalid={isInvalid}
|
|
162
157
|
helperText={helperText}
|
|
163
158
|
invalidText={invalidText}
|
|
@@ -177,32 +172,36 @@ const CustomTextInput = forwardRef<TextInputRefType, CustomTextInputProps>(
|
|
|
177
172
|
* for a date range we render a "fieldset".
|
|
178
173
|
* @note This is only used internally for this file.
|
|
179
174
|
*/
|
|
180
|
-
const DatePickerWrapper: React.FC<DatePickerWrapperProps> = (
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
175
|
+
const DatePickerWrapper: React.FC<DatePickerWrapperProps> = chakra(
|
|
176
|
+
({
|
|
177
|
+
children,
|
|
178
|
+
className,
|
|
179
|
+
id,
|
|
180
|
+
isDateRange,
|
|
181
|
+
isRequired,
|
|
182
|
+
labelText,
|
|
183
|
+
showLabel,
|
|
184
|
+
showRequiredLabel,
|
|
185
|
+
...rest
|
|
186
|
+
}) => (
|
|
187
|
+
<FormField id={`${id}-form-field`} {...rest}>
|
|
188
|
+
{isDateRange ? (
|
|
189
|
+
<Fieldset
|
|
190
|
+
className={className}
|
|
191
|
+
id={id}
|
|
192
|
+
isLegendHidden={!showLabel}
|
|
193
|
+
isRequired={isRequired}
|
|
194
|
+
legendText={labelText}
|
|
195
|
+
showRequiredLabel={showRequiredLabel}
|
|
196
|
+
>
|
|
197
|
+
{children}
|
|
198
|
+
</Fieldset>
|
|
199
|
+
) : (
|
|
200
|
+
children
|
|
201
|
+
)}
|
|
202
|
+
</FormField>
|
|
203
|
+
),
|
|
204
|
+
{ shouldForwardProp: () => true }
|
|
206
205
|
);
|
|
207
206
|
|
|
208
207
|
/**
|
|
@@ -227,8 +226,8 @@ const DateRangeRow: React.FC<DateRangeRowProps> = ({
|
|
|
227
226
|
/**
|
|
228
227
|
* Returns a single date input field or two date input fields for a date range.
|
|
229
228
|
*/
|
|
230
|
-
const DatePicker =
|
|
231
|
-
(props, ref?) => {
|
|
229
|
+
export const DatePicker = chakra(
|
|
230
|
+
React.forwardRef<TextInputRefType, DatePickerProps>((props, ref?) => {
|
|
232
231
|
const {
|
|
233
232
|
className,
|
|
234
233
|
dateFormat = "yyyy-MM-dd",
|
|
@@ -236,7 +235,7 @@ const DatePicker = React.forwardRef<TextInputRefType, DatePickerProps>(
|
|
|
236
235
|
helperText,
|
|
237
236
|
helperTextFrom,
|
|
238
237
|
helperTextTo,
|
|
239
|
-
id
|
|
238
|
+
id,
|
|
240
239
|
initialDate,
|
|
241
240
|
initialDateTo,
|
|
242
241
|
invalidText,
|
|
@@ -253,7 +252,8 @@ const DatePicker = React.forwardRef<TextInputRefType, DatePickerProps>(
|
|
|
253
252
|
refTo,
|
|
254
253
|
showHelperInvalidText = true,
|
|
255
254
|
showLabel = true,
|
|
256
|
-
|
|
255
|
+
showRequiredLabel = true,
|
|
256
|
+
...rest
|
|
257
257
|
} = props;
|
|
258
258
|
const styles = useMultiStyleConfig("DatePicker", {});
|
|
259
259
|
const finalStyles = isDateRange ? styles : {};
|
|
@@ -294,9 +294,9 @@ const DatePicker = React.forwardRef<TextInputRefType, DatePickerProps>(
|
|
|
294
294
|
let baseCustomTextInputAttrs = {
|
|
295
295
|
dsId: `${id}-start`,
|
|
296
296
|
isRequired,
|
|
297
|
-
// In the date range type, don't display the "
|
|
298
|
-
//
|
|
299
|
-
|
|
297
|
+
// In the date range type, don't display the "(Required)" text in
|
|
298
|
+
// individual input labels. It'll display in the legend element.
|
|
299
|
+
showRequiredLabel: isDateRange ? false : showRequiredLabel,
|
|
300
300
|
// Always display the labels for the input fields when
|
|
301
301
|
// the DatePicker component is a date range type.
|
|
302
302
|
showLabel: isDateRange ? true : showLabel,
|
|
@@ -325,14 +325,23 @@ const DatePicker = React.forwardRef<TextInputRefType, DatePickerProps>(
|
|
|
325
325
|
baseDatePickerAttrs.dateFormat = "yyyy";
|
|
326
326
|
}
|
|
327
327
|
|
|
328
|
+
if (!id) {
|
|
329
|
+
console.warn(
|
|
330
|
+
"NYPL Reservoir DatePicker: This component's required `id` prop was not passed."
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
328
334
|
if ((ref && !nameFrom) || (refTo && !nameTo)) {
|
|
329
335
|
console.warn(
|
|
330
|
-
"A `ref` or `refTo` prop was passed but
|
|
336
|
+
"NYPL Reservoir DatePicker: A `ref` or `refTo` prop was passed but " +
|
|
337
|
+
"not the equivalent `nameFrom` or `nameTo` prop."
|
|
331
338
|
);
|
|
332
339
|
}
|
|
333
340
|
if (onChange && (ref || refTo || nameFrom || nameTo)) {
|
|
334
341
|
console.warn(
|
|
335
|
-
"
|
|
342
|
+
"NYPL Reservoir DatePicker: A `ref`, `refTo`, `nameFrom`, or `nameTo` " +
|
|
343
|
+
"prop was passed and an `onChange` prop as well. Use whichever is best " +
|
|
344
|
+
"for your app but not both."
|
|
336
345
|
);
|
|
337
346
|
}
|
|
338
347
|
|
|
@@ -405,7 +414,8 @@ const DatePicker = React.forwardRef<TextInputRefType, DatePickerProps>(
|
|
|
405
414
|
labelText={labelText}
|
|
406
415
|
className={className}
|
|
407
416
|
isRequired={isRequired}
|
|
408
|
-
|
|
417
|
+
showRequiredLabel={showRequiredLabel}
|
|
418
|
+
{...rest}
|
|
409
419
|
>
|
|
410
420
|
<DateRangeRow id={id} isDateRange={isDateRange}>
|
|
411
421
|
<FormField id={`${id}-start-form`}>
|
|
@@ -417,17 +427,16 @@ const DatePicker = React.forwardRef<TextInputRefType, DatePickerProps>(
|
|
|
417
427
|
)}
|
|
418
428
|
</DateRangeRow>
|
|
419
429
|
{helperText && isDateRange && showHelperInvalidText && (
|
|
420
|
-
<
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
/>
|
|
426
|
-
</Box>
|
|
430
|
+
<HelperErrorText
|
|
431
|
+
id={`${id}-helper-text`}
|
|
432
|
+
isInvalid={false}
|
|
433
|
+
text={helperText}
|
|
434
|
+
/>
|
|
427
435
|
)}
|
|
428
436
|
</DatePickerWrapper>
|
|
429
437
|
);
|
|
430
|
-
}
|
|
438
|
+
}),
|
|
439
|
+
{ shouldForwardProp: () => true }
|
|
431
440
|
);
|
|
432
441
|
|
|
433
442
|
export default DatePicker;
|