@nypl/design-system-react-components 0.25.13 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -0
- package/README.md +10 -10
- package/dist/components/Accordion/Accordion.d.ts +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +1 -1
- package/dist/components/Button/Button.d.ts +2 -2
- package/dist/components/Card/Card.d.ts +11 -9
- package/dist/components/Checkbox/Checkbox.d.ts +2 -2
- package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +5 -4
- 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 +1 -1
- package/dist/components/HelperErrorText/HelperErrorText.d.ts +9 -8
- package/dist/components/Hero/Hero.d.ts +2 -1
- package/dist/components/HorizontalRule/HorizontalRule.d.ts +2 -10
- package/dist/components/Icons/Icon.d.ts +2 -1
- package/dist/components/Image/Image.d.ts +2 -2
- 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 +2 -0
- package/dist/components/Notification/Notification.d.ts +4 -4
- 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 +4 -6
- package/dist/components/RadioGroup/RadioGroup.d.ts +12 -6
- package/dist/components/SearchBar/SearchBar.d.ts +4 -4
- package/dist/components/Select/Select.d.ts +10 -6
- package/dist/components/Select/SelectTypes.d.ts +4 -0
- package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +4 -3
- 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 +2 -2
- package/dist/components/Table/Table.d.ts +1 -1
- package/dist/components/Tabs/Tabs.d.ts +4 -3
- package/dist/components/Template/Template.d.ts +4 -3
- package/dist/components/Text/Text.d.ts +1 -1
- package/dist/components/TextInput/TextInput.d.ts +5 -5
- package/dist/components/Toggle/Toggle.d.ts +3 -4
- package/dist/components/VideoPlayer/VideoPlayer.d.ts +2 -1
- package/dist/design-system-react-components.cjs.development.js +1663 -1139
- 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 +1667 -1143
- package/dist/design-system-react-components.esm.js.map +1 -1
- package/dist/hooks/useCarouselStyles.d.ts +3 -2
- package/dist/hooks/useNYPLTheme.d.ts +12 -0
- package/dist/index.d.ts +4 -1
- package/dist/styles.css +1 -1
- package/dist/theme/components/button.d.ts +10 -2
- package/dist/theme/components/card.d.ts +42 -22
- package/dist/theme/components/checkbox.d.ts +5 -4
- package/dist/theme/components/checkboxGroup.d.ts +1 -1
- 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 +23 -17
- 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 +20 -14
- package/dist/theme/components/label.d.ts +9 -10
- package/dist/theme/components/list.d.ts +99 -9
- package/dist/theme/components/radio.d.ts +6 -4
- package/dist/theme/components/radioGroup.d.ts +1 -1
- package/dist/theme/components/select.d.ts +34 -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 +7 -4
- 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/Accordion/Accordion.stories.mdx +9 -9
- package/src/components/Accordion/Accordion.test.tsx +21 -0
- package/src/components/Accordion/Accordion.tsx +13 -9
- package/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +276 -27
- package/src/components/Autosuggest/Autosuggest.stories.mdx +4 -3
- package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +21 -5
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +52 -31
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +8 -7
- 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 +287 -194
- package/src/components/Card/Card.test.tsx +102 -0
- package/src/components/Card/Card.tsx +73 -32
- package/src/components/Card/__snapshots__/Card.test.tsx.snap +195 -35
- package/src/components/Chakra/Grid.stories.mdx +4 -4
- package/src/components/Checkbox/Checkbox.stories.mdx +62 -10
- package/src/components/Checkbox/Checkbox.test.tsx +32 -9
- package/src/components/Checkbox/Checkbox.tsx +20 -15
- package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +134 -7
- package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +65 -17
- package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +137 -81
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +31 -21
- package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +332 -97
- 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 +89 -13
- package/src/components/DatePicker/DatePicker.tsx +62 -56
- 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 +72 -39
- package/src/components/Form/Form.test.tsx +58 -15
- package/src/components/Form/Form.tsx +89 -67
- 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 +34 -6
- package/src/components/Grid/SimpleGrid.test.tsx +9 -0
- 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 +36 -3
- package/src/components/Heading/Heading.test.tsx +10 -0
- package/src/components/Heading/Heading.tsx +56 -50
- package/src/components/Heading/__snapshots__/Heading.test.tsx.snap +26 -7
- 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 +125 -95
- package/src/components/Hero/Hero.test.tsx +33 -0
- package/src/components/Hero/Hero.tsx +135 -126
- 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 -19
- package/src/components/HorizontalRule/HorizontalRule.tsx +9 -26
- package/src/components/HorizontalRule/__snapshots__/HorizontalRule.test.tsx.snap +18 -5
- package/src/components/Icons/Icon.stories.mdx +31 -6
- package/src/components/Icons/Icon.test.tsx +38 -0
- package/src/components/Icons/Icon.tsx +93 -76
- package/src/components/Icons/__snapshots__/Icon.test.tsx.snap +129 -0
- package/src/components/Image/Image.stories.mdx +29 -5
- package/src/components/Image/Image.test.tsx +8 -0
- package/src/components/Image/Image.tsx +38 -26
- package/src/components/Image/__snapshots__/Image.test.tsx.snap +24 -8
- 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 +8 -8
- 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 +67 -19
- package/src/components/List/List.tsx +38 -25
- 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 +30 -6
- package/src/components/Logo/Logo.test.tsx +17 -0
- package/src/components/Logo/Logo.tsx +18 -6
- package/src/components/Logo/LogoSvgs.tsx +4 -0
- package/src/components/Logo/LogoTypes.tsx +2 -0
- 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 +25 -1
- package/src/components/Notification/Notification.test.tsx +23 -0
- package/src/components/Notification/Notification.tsx +46 -44
- package/src/components/Notification/__snapshots__/Notification.test.tsx.snap +158 -29
- package/src/components/Pagination/Pagination.stories.mdx +24 -4
- package/src/components/Pagination/Pagination.test.tsx +25 -0
- package/src/components/Pagination/Pagination.tsx +6 -6
- 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 +81 -11
- package/src/components/ProgressIndicator/ProgressIndicator.tsx +17 -9
- package/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap +101 -14
- package/src/components/Radio/Radio.stories.mdx +64 -12
- package/src/components/Radio/Radio.test.tsx +28 -8
- package/src/components/Radio/Radio.tsx +66 -63
- package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +103 -6
- package/src/components/RadioGroup/RadioGroup.stories.mdx +224 -89
- package/src/components/RadioGroup/RadioGroup.test.tsx +122 -62
- package/src/components/RadioGroup/RadioGroup.tsx +106 -100
- package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +1236 -1020
- 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 +17 -8
- package/src/components/SearchBar/__snapshots__/SearchBar.test.tsx.snap +1039 -0
- package/src/components/Select/Select.stories.mdx +128 -49
- package/src/components/Select/Select.test.tsx +63 -16
- package/src/components/Select/Select.tsx +125 -92
- 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 +42 -10
- package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +8 -0
- package/src/components/SkeletonLoader/SkeletonLoader.tsx +76 -72
- package/src/components/SkeletonLoader/__snapshots__/SkeletonLoader.test.tsx.snap +169 -10
- package/src/components/Slider/Slider.stories.mdx +91 -42
- package/src/components/Slider/Slider.test.tsx +65 -17
- package/src/components/Slider/Slider.tsx +26 -19
- 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 +16 -0
- 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 +131 -12
- package/src/components/StructuredContent/StructuredContent.test.tsx +34 -0
- package/src/components/StructuredContent/StructuredContent.tsx +80 -75
- 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 +1 -1
- 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 +30 -21
- package/src/components/Table/Table.stories.mdx +38 -11
- package/src/components/Table/Table.test.tsx +15 -0
- package/src/components/Table/Table.tsx +7 -7
- package/src/components/Table/__snapshots__/Table.test.tsx.snap +408 -5
- package/src/components/Tabs/Tabs.stories.mdx +52 -3
- package/src/components/Tabs/Tabs.test.tsx +16 -0
- package/src/components/Tabs/Tabs.tsx +10 -6
- package/src/components/Tabs/__snapshots__/Tabs.test.tsx.snap +394 -5
- package/src/components/Template/Template.stories.mdx +47 -43
- package/src/components/Template/Template.test.tsx +33 -0
- package/src/components/Template/Template.tsx +65 -60
- package/src/components/Template/__snapshots__/Template.test.tsx.snap +191 -20
- package/src/components/Text/Text.stories.mdx +20 -1
- package/src/components/Text/Text.test.tsx +12 -0
- package/src/components/Text/Text.tsx +6 -4
- package/src/components/Text/__snapshots__/Text.test.tsx.snap +21 -4
- package/src/components/TextInput/TextInput.stories.mdx +65 -19
- package/src/components/TextInput/TextInput.test.tsx +42 -28
- package/src/components/TextInput/TextInput.tsx +121 -113
- package/src/components/TextInput/__snapshots__/TextInput.test.tsx.snap +96 -73
- package/src/components/Toggle/Toggle.stories.mdx +80 -22
- package/src/components/Toggle/Toggle.test.tsx +27 -9
- package/src/components/Toggle/Toggle.tsx +22 -18
- package/src/components/Toggle/__snapshots__/Toggle.test.tsx.snap +128 -5
- package/src/components/VideoPlayer/VideoPlayer.stories.mdx +52 -4
- package/src/components/VideoPlayer/VideoPlayer.test.tsx +23 -0
- package/src/components/VideoPlayer/VideoPlayer.tsx +133 -126
- 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 +160 -41
- package/src/hooks/useCarouselStyles.stories.mdx +22 -2
- package/src/hooks/useCarouselStyles.ts +3 -2
- package/src/hooks/useNYPLTheme.stories.mdx +101 -0
- package/src/hooks/useNYPLTheme.ts +30 -6
- package/src/hooks/useWindowSize.stories.mdx +23 -0
- package/src/index.ts +4 -1
- package/src/styles/base/_place-holder.scss +1 -1
- package/src/theme/components/button.ts +15 -7
- package/src/theme/components/card.ts +30 -19
- package/src/theme/components/checkbox.ts +10 -8
- package/src/theme/components/checkboxGroup.ts +1 -1
- 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 +25 -20
- package/src/theme/components/heading.ts +1 -1
- package/src/theme/components/helperErrorText.ts +1 -0
- package/src/theme/components/hero.ts +13 -15
- package/src/theme/components/label.ts +4 -3
- package/src/theme/components/list.ts +73 -66
- package/src/theme/components/notification.ts +2 -2
- package/src/theme/components/radio.ts +9 -9
- package/src/theme/components/radioGroup.ts +1 -1
- package/src/theme/components/select.ts +35 -22
- 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 +17 -10
- 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 +1 -2
- package/dist/components/SearchBar/SearchBar.Test.d.ts +0 -1
- package/dist/helpers/generateUUID.d.ts +0 -1
- 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,6 +356,7 @@ 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
|
/>
|
|
@@ -355,6 +373,7 @@ describe("DatePicker", () => {
|
|
|
355
373
|
const onChange = (_data) => {};
|
|
356
374
|
render(
|
|
357
375
|
<DatePicker
|
|
376
|
+
id="datePicker"
|
|
358
377
|
labelText="Select the date you want to visit NYPL"
|
|
359
378
|
ref={ref}
|
|
360
379
|
nameFrom="start-date"
|
|
@@ -425,11 +444,39 @@ describe("DatePicker", () => {
|
|
|
425
444
|
/>
|
|
426
445
|
)
|
|
427
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
|
+
|
|
428
473
|
expect(basic).toMatchSnapshot();
|
|
429
474
|
expect(withoutLabel).toMatchSnapshot();
|
|
430
475
|
expect(withCustomFormat).toMatchSnapshot();
|
|
431
476
|
expect(invalid).toMatchSnapshot();
|
|
432
477
|
expect(disabled).toMatchSnapshot();
|
|
478
|
+
expect(withChakraProps).toMatchSnapshot();
|
|
479
|
+
expect(withOtherProps).toMatchSnapshot();
|
|
433
480
|
});
|
|
434
481
|
});
|
|
435
482
|
|
|
@@ -437,6 +484,7 @@ describe("DatePicker", () => {
|
|
|
437
484
|
it("should render the date range with two input fields", () => {
|
|
438
485
|
render(
|
|
439
486
|
<DatePicker
|
|
487
|
+
id="datePicker"
|
|
440
488
|
labelText="Select the date range you want to visit NYPL"
|
|
441
489
|
isDateRange
|
|
442
490
|
/>
|
|
@@ -456,6 +504,7 @@ describe("DatePicker", () => {
|
|
|
456
504
|
it("should render the initial dates", () => {
|
|
457
505
|
render(
|
|
458
506
|
<DatePicker
|
|
507
|
+
id="datePicker"
|
|
459
508
|
labelText="Select the full date you want to visit NYPL"
|
|
460
509
|
isDateRange
|
|
461
510
|
initialDate="1/2/1988"
|
|
@@ -472,6 +521,7 @@ describe("DatePicker", () => {
|
|
|
472
521
|
it("should render two input labels and three separate helper text", () => {
|
|
473
522
|
render(
|
|
474
523
|
<DatePicker
|
|
524
|
+
id="datePicker"
|
|
475
525
|
labelText="Select the date range you want to visit NYPL"
|
|
476
526
|
helperText="Note that the Library may be closed on Sundays."
|
|
477
527
|
helperTextFrom="Note for the 'from' field."
|
|
@@ -498,6 +548,7 @@ describe("DatePicker", () => {
|
|
|
498
548
|
it("should render different states based on respective props", () => {
|
|
499
549
|
const { rerender } = render(
|
|
500
550
|
<DatePicker
|
|
551
|
+
id="datePicker"
|
|
501
552
|
labelText="Select the date range you want to visit NYPL"
|
|
502
553
|
helperText="Note that the Library may be closed on Sundays."
|
|
503
554
|
helperTextTo="Note for the 'to' field."
|
|
@@ -514,6 +565,7 @@ describe("DatePicker", () => {
|
|
|
514
565
|
|
|
515
566
|
rerender(
|
|
516
567
|
<DatePicker
|
|
568
|
+
id="datePicker"
|
|
517
569
|
labelText="Select the date range you want to visit NYPL"
|
|
518
570
|
helperText="Note that the Library may be closed on Sundays."
|
|
519
571
|
helperTextTo="Note for the 'to' field."
|
|
@@ -528,6 +580,7 @@ describe("DatePicker", () => {
|
|
|
528
580
|
|
|
529
581
|
rerender(
|
|
530
582
|
<DatePicker
|
|
583
|
+
id="datePicker"
|
|
531
584
|
labelText="Select the date range you want to visit NYPL"
|
|
532
585
|
helperText="Note that the Library may be closed on Sundays."
|
|
533
586
|
helperTextTo="Note for the 'to' field."
|
|
@@ -538,7 +591,7 @@ describe("DatePicker", () => {
|
|
|
538
591
|
);
|
|
539
592
|
// Both input fields are required.
|
|
540
593
|
// The "Required" text is only displayed once in the `legend`.
|
|
541
|
-
expect(screen.getAllByText(/
|
|
594
|
+
expect(screen.getAllByText(/Required/i)).toHaveLength(1);
|
|
542
595
|
expect(screen.getByLabelText(/From/i)).toHaveAttribute("required");
|
|
543
596
|
expect(screen.getByLabelText(/To/i)).toHaveAttribute("required");
|
|
544
597
|
});
|
|
@@ -620,6 +673,7 @@ describe("DatePicker", () => {
|
|
|
620
673
|
it("should select two new dates", () => {
|
|
621
674
|
render(
|
|
622
675
|
<DatePicker
|
|
676
|
+
id="datePicker"
|
|
623
677
|
initialDate="3/2/1988"
|
|
624
678
|
initialDateTo="3/28/1988"
|
|
625
679
|
isDateRange
|
|
@@ -662,7 +716,12 @@ describe("DatePicker", () => {
|
|
|
662
716
|
|
|
663
717
|
describe("Popup Calendar", () => {
|
|
664
718
|
it("should render a popup calendar for the full date", () => {
|
|
665
|
-
render(
|
|
719
|
+
render(
|
|
720
|
+
<DatePicker
|
|
721
|
+
id="datePicker"
|
|
722
|
+
labelText="Select the date you want to visit NYPL"
|
|
723
|
+
/>
|
|
724
|
+
);
|
|
666
725
|
const input = screen.getByLabelText(
|
|
667
726
|
/Select the date you want to visit NYPL/i
|
|
668
727
|
);
|
|
@@ -692,6 +751,7 @@ describe("DatePicker", () => {
|
|
|
692
751
|
it("should select a new date from the calendar", () => {
|
|
693
752
|
render(
|
|
694
753
|
<DatePicker
|
|
754
|
+
id="datePicker"
|
|
695
755
|
labelText="Select the date you want to visit NYPL"
|
|
696
756
|
initialDate="08/01/2021"
|
|
697
757
|
/>
|
|
@@ -736,6 +796,7 @@ describe("DatePicker", () => {
|
|
|
736
796
|
it("should render a popup calendar for the month date", () => {
|
|
737
797
|
render(
|
|
738
798
|
<DatePicker
|
|
799
|
+
id="datePicker"
|
|
739
800
|
dateType={DatePickerTypes.Month}
|
|
740
801
|
labelText="Select the month you want to visit NYPL"
|
|
741
802
|
/>
|
|
@@ -762,6 +823,7 @@ describe("DatePicker", () => {
|
|
|
762
823
|
it("should select a new month from the calendar", () => {
|
|
763
824
|
render(
|
|
764
825
|
<DatePicker
|
|
826
|
+
id="datePicker"
|
|
765
827
|
dateType={DatePickerTypes.Month}
|
|
766
828
|
initialDate="4/1/1988"
|
|
767
829
|
labelText="Select the month you want to visit NYPL"
|
|
@@ -801,6 +863,7 @@ describe("DatePicker", () => {
|
|
|
801
863
|
it("should render a popup calendar for the year date", () => {
|
|
802
864
|
render(
|
|
803
865
|
<DatePicker
|
|
866
|
+
id="datePicker"
|
|
804
867
|
dateType={DatePickerTypes.Year}
|
|
805
868
|
labelText="Select the year you want to visit NYPL"
|
|
806
869
|
/>
|
|
@@ -838,6 +901,7 @@ describe("DatePicker", () => {
|
|
|
838
901
|
it("should select a new year from the calendar", () => {
|
|
839
902
|
render(
|
|
840
903
|
<DatePicker
|
|
904
|
+
id="datePicker"
|
|
841
905
|
dateType={DatePickerTypes.Year}
|
|
842
906
|
labelText="Select the year you want to visit NYPL"
|
|
843
907
|
/>
|
|
@@ -858,5 +922,17 @@ describe("DatePicker", () => {
|
|
|
858
922
|
|
|
859
923
|
expect(screen.getByDisplayValue("2024")).toBeInTheDocument();
|
|
860
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
|
+
});
|
|
861
937
|
});
|
|
862
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,6 +325,12 @@ 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
336
|
"NYPL Reservoir DatePicker: A `ref` or `refTo` prop was passed but " +
|
|
@@ -408,7 +414,8 @@ const DatePicker = React.forwardRef<TextInputRefType, DatePickerProps>(
|
|
|
408
414
|
labelText={labelText}
|
|
409
415
|
className={className}
|
|
410
416
|
isRequired={isRequired}
|
|
411
|
-
|
|
417
|
+
showRequiredLabel={showRequiredLabel}
|
|
418
|
+
{...rest}
|
|
412
419
|
>
|
|
413
420
|
<DateRangeRow id={id} isDateRange={isDateRange}>
|
|
414
421
|
<FormField id={`${id}-start-form`}>
|
|
@@ -420,17 +427,16 @@ const DatePicker = React.forwardRef<TextInputRefType, DatePickerProps>(
|
|
|
420
427
|
)}
|
|
421
428
|
</DateRangeRow>
|
|
422
429
|
{helperText && isDateRange && showHelperInvalidText && (
|
|
423
|
-
<
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
/>
|
|
429
|
-
</Box>
|
|
430
|
+
<HelperErrorText
|
|
431
|
+
id={`${id}-helper-text`}
|
|
432
|
+
isInvalid={false}
|
|
433
|
+
text={helperText}
|
|
434
|
+
/>
|
|
430
435
|
)}
|
|
431
436
|
</DatePickerWrapper>
|
|
432
437
|
);
|
|
433
|
-
}
|
|
438
|
+
}),
|
|
439
|
+
{ shouldForwardProp: () => true }
|
|
434
440
|
);
|
|
435
441
|
|
|
436
442
|
export default DatePicker;
|