@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
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Meta,
|
|
3
|
+
Story,
|
|
4
|
+
Canvas,
|
|
5
|
+
ArgsTable,
|
|
6
|
+
Preview,
|
|
7
|
+
Description,
|
|
8
|
+
} from "@storybook/addon-docs/blocks";
|
|
9
|
+
import { withDesign } from "storybook-addon-designs";
|
|
10
|
+
import { getCategory } from "../../utils/componentCategories";
|
|
11
|
+
|
|
12
|
+
import DatePicker from "./DatePicker";
|
|
13
|
+
import { DatePickerTypes } from "./DatePickerTypes";
|
|
14
|
+
|
|
15
|
+
<Meta
|
|
16
|
+
title={getCategory("DatePicker")}
|
|
17
|
+
component={DatePicker}
|
|
18
|
+
decorators={[withDesign]}
|
|
19
|
+
parameters={{
|
|
20
|
+
design: {
|
|
21
|
+
type: "figma",
|
|
22
|
+
url:
|
|
23
|
+
"https://www.figma.com/file/qShodlfNCJHb8n03IFyApM/Main?node-id=11689%3A0",
|
|
24
|
+
},
|
|
25
|
+
jest: ["DatePicker.test.tsx"],
|
|
26
|
+
}}
|
|
27
|
+
argTypes={{
|
|
28
|
+
blockName: { table: { disable: true } },
|
|
29
|
+
className: { table: { disable: true } },
|
|
30
|
+
modifiers: { table: { disable: true } },
|
|
31
|
+
id: { table: { disable: true } },
|
|
32
|
+
nameTo: { table: { disable: true } },
|
|
33
|
+
nameFrom: { table: { disable: true } },
|
|
34
|
+
value: { table: { disable: true } },
|
|
35
|
+
refTo: { table: { disable: true } },
|
|
36
|
+
}}
|
|
37
|
+
/>
|
|
38
|
+
|
|
39
|
+
# DatePicker
|
|
40
|
+
|
|
41
|
+
| Component Version | DS Version |
|
|
42
|
+
| ----------------- | ---------- |
|
|
43
|
+
| Added | `0.24.0` |
|
|
44
|
+
| Latest | `0.24.0` |
|
|
45
|
+
|
|
46
|
+
<Description of={DatePicker} />
|
|
47
|
+
|
|
48
|
+
<Canvas withToolbar>
|
|
49
|
+
<Story
|
|
50
|
+
name="DatePicker"
|
|
51
|
+
args={{
|
|
52
|
+
dateType: DatePickerTypes.Full,
|
|
53
|
+
dateFormat: "yyyy-MM-dd",
|
|
54
|
+
dateRange: false,
|
|
55
|
+
initialDate: "1/1/2021",
|
|
56
|
+
minDate: "1/1/2021",
|
|
57
|
+
maxDate: "1/1/2022",
|
|
58
|
+
nameFrom: "visit-dates",
|
|
59
|
+
labelText: "Select the date you want to visit NYPL",
|
|
60
|
+
helperText: "Note that the Library may be closed on Sundays.",
|
|
61
|
+
helperTextFrom: "Select start date.",
|
|
62
|
+
helperTextTo: "Select end date.",
|
|
63
|
+
invalidText: "Please select a valid date.",
|
|
64
|
+
showLabel: true,
|
|
65
|
+
errored: false,
|
|
66
|
+
disabled: false,
|
|
67
|
+
required: false,
|
|
68
|
+
showOptReqLabel: true,
|
|
69
|
+
}}
|
|
70
|
+
>
|
|
71
|
+
{(args) => <DatePicker id="visit-dates" {...args} />}
|
|
72
|
+
</Story>
|
|
73
|
+
</Canvas>
|
|
74
|
+
|
|
75
|
+
<ArgsTable story="DatePicker" />
|
|
76
|
+
|
|
77
|
+
## Date Range
|
|
78
|
+
|
|
79
|
+
A date range can be rendered by setting the `dateRange` prop to `true`. This
|
|
80
|
+
will render two input fields with labels "From" and "To". If the component has
|
|
81
|
+
an error, or if this is a required field, or if it is disabled, then both input
|
|
82
|
+
elements will share the props and styling. Note that for date range types, a
|
|
83
|
+
`fieldset` is used as the parent wrapper and the `labelText` is used for the
|
|
84
|
+
`legend` element text.
|
|
85
|
+
|
|
86
|
+
Note: In the following example, the minimum date is "1/1/2021" and the max date
|
|
87
|
+
is "1/1/22". This means only values within this range are selectable from the
|
|
88
|
+
popup calendar.
|
|
89
|
+
|
|
90
|
+
<Canvas withToolbar>
|
|
91
|
+
<Story name="Date Range">
|
|
92
|
+
<DatePicker
|
|
93
|
+
id="date-range"
|
|
94
|
+
dateType={DatePickerTypes.Full}
|
|
95
|
+
dateFormat="yyyy-MM-dd"
|
|
96
|
+
dateRange={true}
|
|
97
|
+
minDate="1/1/2021"
|
|
98
|
+
maxDate="1/1/2022"
|
|
99
|
+
labelText="Select the date range you want to visit NYPL"
|
|
100
|
+
nameFrom="visit-dates"
|
|
101
|
+
helperTextFrom="From this date."
|
|
102
|
+
helperTextTo="To this date."
|
|
103
|
+
helperText="Select a valid date range."
|
|
104
|
+
invalidText="Please select a valid date range."
|
|
105
|
+
showOptReqLabel={false}
|
|
106
|
+
/>
|
|
107
|
+
</Story>
|
|
108
|
+
</Canvas>
|
|
109
|
+
|
|
110
|
+
## Month Date Input
|
|
111
|
+
|
|
112
|
+
It's possible to select dates by skipping the day value and only selecting
|
|
113
|
+
the month and the year when `dateType` is set to `DatePickerTypes.Month`. Note
|
|
114
|
+
that all 12 months will appear in the popup calendar with their abbreviated names.
|
|
115
|
+
|
|
116
|
+
<Canvas withToolbar>
|
|
117
|
+
<Story name="Month Date Input">
|
|
118
|
+
<DatePicker
|
|
119
|
+
id="month-date"
|
|
120
|
+
dateType={DatePickerTypes.Month}
|
|
121
|
+
dateRange={false}
|
|
122
|
+
labelText="Select the month you want to visit NYPL"
|
|
123
|
+
helperText="Note that the Library may be closed on Sundays."
|
|
124
|
+
invalidText="Please select a valid month."
|
|
125
|
+
/>
|
|
126
|
+
</Story>
|
|
127
|
+
</Canvas>
|
|
128
|
+
|
|
129
|
+
## Year Date Input
|
|
130
|
+
|
|
131
|
+
It's possible to select dates by only the year when `dateType` is set to
|
|
132
|
+
`DatePickerTypes.Year`. Note that only 12 values will appear in the popup
|
|
133
|
+
calendar; the four previous years, the current year, and the next seven years.
|
|
134
|
+
|
|
135
|
+
<Canvas withToolbar>
|
|
136
|
+
<Story name="Year Date Input">
|
|
137
|
+
<DatePicker
|
|
138
|
+
id="month-date"
|
|
139
|
+
dateType={DatePickerTypes.Year}
|
|
140
|
+
dateRange={false}
|
|
141
|
+
labelText="Select the year you want to visit NYPL"
|
|
142
|
+
helperText="Note that the Library may be closed on Sundays."
|
|
143
|
+
showOptReqLabel={false}
|
|
144
|
+
/>
|
|
145
|
+
</Story>
|
|
146
|
+
</Canvas>
|
|
147
|
+
|
|
148
|
+
## Other States
|
|
149
|
+
|
|
150
|
+
### Errored State
|
|
151
|
+
|
|
152
|
+
<DatePicker
|
|
153
|
+
id="month-date"
|
|
154
|
+
dateType={DatePickerTypes.Full}
|
|
155
|
+
dateRange={true}
|
|
156
|
+
labelText="Select the year you want to visit NYPL"
|
|
157
|
+
helperText="Note that the Library may be closed on Sundays."
|
|
158
|
+
invalidText="Please select a valid year."
|
|
159
|
+
errored={true}
|
|
160
|
+
showOptReqLabel={false}
|
|
161
|
+
/>
|
|
162
|
+
<br />
|
|
163
|
+
|
|
164
|
+
### Disabled State
|
|
165
|
+
|
|
166
|
+
<DatePicker
|
|
167
|
+
id="month-date"
|
|
168
|
+
dateType={DatePickerTypes.Full}
|
|
169
|
+
dateRange={true}
|
|
170
|
+
labelText="Select the year you want to visit NYPL"
|
|
171
|
+
disabled={true}
|
|
172
|
+
showOptReqLabel={false}
|
|
173
|
+
/>
|
|
174
|
+
|
|
175
|
+
## Getting Date Data Values
|
|
176
|
+
|
|
177
|
+
### Controlled Component Using `onChange` prop
|
|
178
|
+
|
|
179
|
+
If your application uses controlled React components and the DS DatePicker must
|
|
180
|
+
be controlled, you can extract the data through the `onChange` prop function.
|
|
181
|
+
This will be called every time the date is updated in either the start date input
|
|
182
|
+
field or the end date input field. The returned data is an object with `startDate`
|
|
183
|
+
and `endDate` keys and `Date` object values.
|
|
184
|
+
|
|
185
|
+
```jsx
|
|
186
|
+
const onChange = (data) => {
|
|
187
|
+
// This will return an object such as:
|
|
188
|
+
// {
|
|
189
|
+
// startDate: dateValue,
|
|
190
|
+
// endDate: dateValue
|
|
191
|
+
// }
|
|
192
|
+
// Note that `dateValue` is a `Date` object so you need to get the date value
|
|
193
|
+
// yourself. The `endDate` attribute will only appear if the DS DatePicker
|
|
194
|
+
// component is a date range.
|
|
195
|
+
console.log(data);
|
|
196
|
+
};
|
|
197
|
+
// ...
|
|
198
|
+
|
|
199
|
+
// Example of the DS DatePicker instance with the function above:
|
|
200
|
+
<DatePicker
|
|
201
|
+
id="date-range"
|
|
202
|
+
dateType={DatePickerTypes.Full}
|
|
203
|
+
dateRange={true}
|
|
204
|
+
labelText="Select the date range you want to visit NYPL"
|
|
205
|
+
invalidText="Please select a valid date range."
|
|
206
|
+
onChange={onChange}
|
|
207
|
+
/>;
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Uncontrolled Component Using `ref`s
|
|
211
|
+
|
|
212
|
+
If your application uses uncontrolled components, you can pass React `ref` props
|
|
213
|
+
to the DS DatePicker component to get values from the DOM. In this scenario, you
|
|
214
|
+
need to also pass in a `nameFrom` prop so that the `ref` values knows what DOM
|
|
215
|
+
element to get the value from. If you are using a date range, you need to pass
|
|
216
|
+
additional `nameTo` and `refTo` props or else only the start date value will be
|
|
217
|
+
obtained.
|
|
218
|
+
|
|
219
|
+
The following example is using the `register` React `ref` from the
|
|
220
|
+
`react-hook-form` package.
|
|
221
|
+
|
|
222
|
+
```jsx
|
|
223
|
+
import { useFormContext } from "react-hook-form";
|
|
224
|
+
// ...
|
|
225
|
+
const { register, handleSubmit } = useFormContext();
|
|
226
|
+
// ...
|
|
227
|
+
const submitForm = (formData) => {
|
|
228
|
+
// This will return an object with all the DOM element values that were
|
|
229
|
+
// registered with a `name` attribute.
|
|
230
|
+
// Note that the returned values are strings and NOT Date objects.
|
|
231
|
+
// {
|
|
232
|
+
// visitDateFrom: "2020-01-01"
|
|
233
|
+
// visitDateTo: "2021-01-01"
|
|
234
|
+
// }
|
|
235
|
+
console.log(formData);
|
|
236
|
+
// ...
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
<form
|
|
240
|
+
onSubmit={handleSubmit(submitForm)}
|
|
241
|
+
method="post"
|
|
242
|
+
action="/some/api/endpoint"
|
|
243
|
+
>
|
|
244
|
+
<DatePicker
|
|
245
|
+
id="date-range"
|
|
246
|
+
dateType={DatePickerTypes.Full}
|
|
247
|
+
dateRange={true}
|
|
248
|
+
labelText="Select the date range you want to visit NYPL"
|
|
249
|
+
nameFrom="visitDateFrom"
|
|
250
|
+
nameTo="visitDateTo"
|
|
251
|
+
invalidText="Please select a valid date range."
|
|
252
|
+
ref={register()}
|
|
253
|
+
refTo={register()}
|
|
254
|
+
/>
|
|
255
|
+
</form>;
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
The above is specific to `react-hook-form` but a similar pattern can be used
|
|
259
|
+
with normal React `ref` values.
|
|
260
|
+
|
|
261
|
+
```jsx
|
|
262
|
+
const refStart = React.createRef<TextInputRefType>();
|
|
263
|
+
const refEnd = React.createRef<TextInputRefType>();
|
|
264
|
+
// ...
|
|
265
|
+
<DatePicker
|
|
266
|
+
id="date-range"
|
|
267
|
+
dateType={DatePickerTypes.Full}
|
|
268
|
+
dateRange={true}
|
|
269
|
+
labelText="Select the date range you want to visit NYPL"
|
|
270
|
+
nameFrom="visitDateFrom"
|
|
271
|
+
nameTo="visitDateTo"
|
|
272
|
+
invalidText="Please select a valid date range."
|
|
273
|
+
ref={refStart}
|
|
274
|
+
refTo={refEnd}
|
|
275
|
+
/>
|
|
276
|
+
|
|
277
|
+
// ...
|
|
278
|
+
// Get the value through:
|
|
279
|
+
const onSubmit = () => {
|
|
280
|
+
// ...
|
|
281
|
+
const startDate = refStart.current.value;
|
|
282
|
+
const endDate = refEnd.current.value;
|
|
283
|
+
};
|
|
284
|
+
```
|