@nypl/design-system-react-components 2.0.0 → 2.1.0-rc
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/README.md +466 -17
- package/dist/design-system-react-components.cjs +528 -0
- package/dist/design-system-react-components.js +37957 -0
- package/dist/src/components/Accordion/Accordion.d.ts +29 -0
- package/dist/src/components/AlphabetFilter/AlphabetFilter.d.ts +23 -0
- package/dist/src/components/AudioPlayer/AudioPlayer.d.ts +43 -0
- package/dist/src/components/Breadcrumbs/Breadcrumbs.d.ts +24 -0
- package/dist/src/components/Button/Button.d.ts +35 -0
- package/dist/src/components/ButtonGroup/ButtonGroup.d.ts +25 -0
- package/dist/src/components/Card/Card.d.ts +55 -0
- package/dist/src/components/Checkbox/Checkbox.d.ts +47 -0
- package/dist/src/components/CheckboxGroup/CheckboxGroup.d.ts +51 -0
- package/dist/src/components/ComponentWrapper/ComponentWrapper.d.ts +31 -0
- package/dist/src/components/DatePicker/DatePicker.d.ts +82 -0
- package/dist/src/components/FeaturedContent/FeaturedContent.d.ts +29 -0
- package/dist/src/components/FeedbackBox/FeedbackBox.d.ts +64 -0
- package/dist/src/components/FeedbackBox/useFeedbackBoxReducer.d.ts +19 -0
- package/dist/src/components/Fieldset/Fieldset.d.ts +24 -0
- package/dist/src/components/Form/Form.d.ts +31 -0
- package/dist/src/components/Grid/SimpleGrid.d.ts +20 -0
- package/dist/src/components/Heading/Heading.d.ts +42 -0
- package/dist/src/components/HelperErrorText/HelperErrorText.d.ts +34 -0
- package/dist/src/components/Hero/Hero.d.ts +49 -0
- package/dist/src/components/HorizontalRule/HorizontalRule.d.ts +11 -0
- package/dist/src/components/Icons/Icon.d.ts +41 -0
- package/dist/src/components/Icons/IconSvgs.d.ts +196 -0
- package/dist/src/components/Icons/iconVariables.d.ts +6 -0
- package/dist/src/components/Image/Image.d.ts +68 -0
- package/dist/src/components/Label/Label.d.ts +25 -0
- package/dist/src/components/Link/Link.d.ts +32 -0
- package/dist/src/components/List/List.d.ts +43 -0
- package/dist/src/components/Logo/Logo.d.ts +29 -0
- package/dist/src/components/Logo/LogoSvgs.d.ts +166 -0
- package/dist/src/components/Logo/logoVariables.d.ts +2 -0
- package/dist/src/components/Modal/Modal.d.ts +35 -0
- package/dist/src/components/NewsletterSignup/NewsletterSignup.d.ts +46 -0
- package/dist/src/components/Notification/Notification.d.ts +52 -0
- package/dist/src/components/Pagination/Pagination.d.ts +27 -0
- package/dist/src/components/ProgressIndicator/ProgressIndicator.d.ts +32 -0
- package/dist/src/components/Radio/Radio.d.ts +43 -0
- package/dist/src/components/RadioGroup/RadioGroup.d.ts +51 -0
- package/dist/src/components/SearchBar/SearchBar.d.ts +58 -0
- package/dist/src/components/Select/Select.d.ts +59 -0
- package/dist/src/components/SkeletonLoader/SkeletonLoader.d.ts +42 -0
- package/dist/src/components/SkipNavigation/SkipNavigation.d.ts +19 -0
- package/dist/src/components/Slider/Slider.d.ts +65 -0
- package/dist/src/components/SocialMediaLinks/SocialMediaLinks.d.ts +42 -0
- package/dist/src/components/SocialMediaLinks/SocialMediaLinksUtils.d.ts +7 -0
- package/dist/src/components/StatusBadge/StatusBadge.d.ts +19 -0
- package/dist/src/components/StructuredContent/StructuredContent.d.ts +30 -0
- package/dist/src/components/StyleGuide/ColorCard.d.ts +348 -0
- package/dist/src/components/StyledList/StyledList.d.ts +26 -0
- package/dist/src/components/Table/Table.d.ts +32 -0
- package/dist/src/components/Tabs/Tabs.d.ts +28 -0
- package/dist/src/components/TagSet/TagSet.d.ts +24 -0
- package/dist/src/components/TagSet/TagSetExplore.d.ts +28 -0
- package/dist/src/components/TagSet/TagSetFilter.d.ts +25 -0
- package/dist/src/components/TagSet/TooltipWrapper.d.ts +9 -0
- package/dist/src/components/Template/Template.d.ts +140 -0
- package/dist/src/components/Text/Text.d.ts +27 -0
- package/dist/src/components/TextInput/TextInput.d.ts +92 -0
- package/dist/src/components/Toggle/Toggle.d.ts +43 -0
- package/dist/src/components/Tooltip/Tooltip.d.ts +17 -0
- package/dist/src/components/VideoPlayer/VideoPlayer.d.ts +42 -0
- package/dist/src/helpers/getSectionColors.d.ts +8 -0
- package/dist/src/helpers/types.d.ts +50 -0
- package/dist/src/hooks/useCarouselStyles.d.ts +17 -0
- package/dist/src/hooks/useCloseDropDown.d.ts +7 -0
- package/dist/src/hooks/useNYPLBreakpoints.d.ts +13 -0
- package/dist/src/hooks/useNYPLTheme.d.ts +75 -0
- package/dist/src/hooks/useStateWithDependencies.d.ts +8 -0
- package/dist/src/hooks/useWindowSize.d.ts +10 -0
- package/dist/src/index.d.ts +87 -0
- package/dist/src/theme/components/accordion.d.ts +34 -0
- package/dist/src/theme/components/alphabetFilter.d.ts +40 -0
- package/dist/src/theme/components/audioPlayer.d.ts +16 -0
- package/dist/src/theme/components/breadcrumb.d.ts +158 -0
- package/dist/src/theme/components/button.d.ts +152 -0
- package/dist/src/theme/components/buttonGroup.d.ts +11 -0
- package/dist/src/theme/components/card.d.ts +485 -0
- package/dist/src/theme/components/checkbox.d.ts +178 -0
- package/dist/src/theme/components/checkboxGroup.d.ts +14 -0
- package/dist/src/theme/components/componentWrapper.d.ts +12 -0
- package/dist/src/theme/components/customTable.d.ts +739 -0
- package/dist/src/theme/components/datePicker.d.ts +17 -0
- package/dist/src/theme/components/featuredContent.d.ts +70 -0
- package/dist/src/theme/components/feedbackBox.d.ts +100 -0
- package/dist/src/theme/components/fieldset.d.ts +24 -0
- package/dist/src/theme/components/filterBar.d.ts +46 -0
- package/dist/src/theme/components/global.d.ts +141 -0
- package/dist/src/theme/components/globalMixins.d.ts +40 -0
- package/dist/src/theme/components/heading.d.ts +372 -0
- package/dist/src/theme/components/helperErrorText.d.ts +18 -0
- package/dist/src/theme/components/hero.d.ts +639 -0
- package/dist/src/theme/components/horizontalRule.d.ts +18 -0
- package/dist/src/theme/components/icon.d.ts +62251 -0
- package/dist/src/theme/components/image.d.ts +754 -0
- package/dist/src/theme/components/label.d.ts +22 -0
- package/dist/src/theme/components/link.d.ts +152 -0
- package/dist/src/theme/components/list.d.ts +230 -0
- package/dist/src/theme/components/logo.d.ts +477 -0
- package/dist/src/theme/components/modal.d.ts +27 -0
- package/dist/src/theme/components/multiSelect.d.ts +29 -0
- package/dist/src/theme/components/multiSelectMenuButton.d.ts +99 -0
- package/dist/src/theme/components/newsletterSignup.d.ts +93 -0
- package/dist/src/theme/components/notification.d.ts +137 -0
- package/dist/src/theme/components/pagination.d.ts +19 -0
- package/dist/src/theme/components/progressIndicator.d.ts +69 -0
- package/dist/src/theme/components/radio.d.ts +202 -0
- package/dist/src/theme/components/radioGroup.d.ts +14 -0
- package/dist/src/theme/components/searchBar.d.ts +34 -0
- package/dist/src/theme/components/select.d.ts +126 -0
- package/dist/src/theme/components/skeletonLoader.d.ts +105 -0
- package/dist/src/theme/components/skipNavigation.d.ts +28 -0
- package/dist/src/theme/components/slider.d.ts +78 -0
- package/dist/src/theme/components/socialmedialinks.d.ts +192 -0
- package/dist/src/theme/components/statusBadge.d.ts +37 -0
- package/dist/src/theme/components/structuredContent.d.ts +454 -0
- package/dist/src/theme/components/styledList.d.ts +51 -0
- package/dist/src/theme/components/tabs.d.ts +172 -0
- package/dist/src/theme/components/tagSet.d.ts +154 -0
- package/dist/src/theme/components/template.d.ts +98 -0
- package/dist/src/theme/components/text.d.ts +59 -0
- package/dist/src/theme/components/textInput.d.ts +360 -0
- package/dist/src/theme/components/toggle.d.ts +129 -0
- package/dist/src/theme/components/tooltip.d.ts +21 -0
- package/dist/src/theme/components/videoPlayer.d.ts +47 -0
- package/dist/src/theme/foundations/breakpoints.d.ts +23 -0
- package/dist/src/theme/foundations/colors.d.ts +3 -0
- package/dist/src/theme/foundations/global.d.ts +68 -0
- package/dist/src/theme/foundations/radii.d.ts +11 -0
- package/dist/src/theme/foundations/shadows.d.ts +4 -0
- package/dist/src/theme/foundations/spacing.d.ts +96 -0
- package/dist/src/theme/foundations/typography.d.ts +8 -0
- package/dist/src/theme/index.d.ts +20 -0
- package/dist/src/theme/internalChakraProvider.d.ts +67 -0
- package/dist/src/theme/provider.d.ts +4 -0
- package/dist/src/theme/types.d.ts +1 -0
- package/dist/src/utils/colorUtils.d.ts +5 -0
- package/dist/src/utils/interfaces.d.ts +5 -0
- package/dist/src/utils/utils.d.ts +42 -0
- package/dist/styles.css +1 -0
- package/package.json +132 -24
- package/CHANGELOG.md +0 -139
- package/dist/design-system-react-components.min.js +0 -23
- package/dist/design-system-react-components.min.js.map +0 -1
- package/lib/components/00-base/Container/Container.d.ts +0 -6
- package/lib/components/00-base/Container/Container.js +0 -19
- package/lib/components/00-base/Container/Modal.d.ts +0 -12
- package/lib/components/00-base/Container/Modal.js +0 -29
- package/lib/components/00-base/Container/Modal.stories.d.ts +0 -7
- package/lib/components/00-base/Container/Modal.stories.js +0 -20
- package/lib/components/00-base/Placeholder.d.ts +0 -10
- package/lib/components/00-base/Placeholder.js +0 -23
- package/lib/components/00-base/SectionName.d.ts +0 -4
- package/lib/components/00-base/SectionName.js +0 -16
- package/lib/components/01-atoms/Button/Button.d.ts +0 -52
- package/lib/components/01-atoms/Button/Button.js +0 -76
- package/lib/components/01-atoms/Button/Button.stories.d.ts +0 -14
- package/lib/components/01-atoms/Button/Button.stories.js +0 -33
- package/lib/components/01-atoms/Button/ButtonTypes.d.ts +0 -10
- package/lib/components/01-atoms/Button/ButtonTypes.js +0 -14
- package/lib/components/01-atoms/Forms/Checkbox.d.ts +0 -21
- package/lib/components/01-atoms/Forms/Checkbox.js +0 -27
- package/lib/components/01-atoms/Forms/Checkbox.stories.d.ts +0 -7
- package/lib/components/01-atoms/Forms/Checkbox.stories.js +0 -23
- package/lib/components/01-atoms/Forms/DateRangeForm.d.ts +0 -31
- package/lib/components/01-atoms/Forms/DateRangeForm.js +0 -27
- package/lib/components/01-atoms/Forms/DateRangeForm.stories.d.ts +0 -9
- package/lib/components/01-atoms/Forms/DateRangeForm.stories.js +0 -23
- package/lib/components/01-atoms/Forms/FormDropdown.d.ts +0 -22
- package/lib/components/01-atoms/Forms/FormDropdown.js +0 -64
- package/lib/components/01-atoms/Forms/FormDropdown.stories.d.ts +0 -8
- package/lib/components/01-atoms/Forms/FormDropdown.stories.js +0 -22
- package/lib/components/01-atoms/Forms/HelperErrorText.d.ts +0 -26
- package/lib/components/01-atoms/Forms/HelperErrorText.js +0 -29
- package/lib/components/01-atoms/Forms/HelperErrorText.stories.d.ts +0 -9
- package/lib/components/01-atoms/Forms/HelperErrorText.stories.js +0 -23
- package/lib/components/01-atoms/Forms/Input.d.ts +0 -47
- package/lib/components/01-atoms/Forms/Input.js +0 -39
- package/lib/components/01-atoms/Forms/Input.stories.d.ts +0 -10
- package/lib/components/01-atoms/Forms/Input.stories.js +0 -22
- package/lib/components/01-atoms/Forms/Label.d.ts +0 -19
- package/lib/components/01-atoms/Forms/Label.js +0 -22
- package/lib/components/01-atoms/Forms/Label.stories.d.ts +0 -7
- package/lib/components/01-atoms/Forms/Label.stories.js +0 -20
- package/lib/components/01-atoms/Forms/TextField.d.ts +0 -26
- package/lib/components/01-atoms/Forms/TextField.js +0 -36
- package/lib/components/01-atoms/Forms/TextField.stories.d.ts +0 -7
- package/lib/components/01-atoms/Forms/TextField.stories.js +0 -20
- package/lib/components/01-atoms/Images/Icons/Icon.d.ts +0 -14
- package/lib/components/01-atoms/Images/Icons/Icon.js +0 -38
- package/lib/components/01-atoms/Images/Image/Image.d.ts +0 -8
- package/lib/components/01-atoms/Images/Image/Image.js +0 -32
- package/lib/components/01-atoms/Images/Image/Image.stories.d.ts +0 -8
- package/lib/components/01-atoms/Images/Image/Image.stories.js +0 -24
- package/lib/components/01-atoms/Links/BasicLink.d.ts +0 -15
- package/lib/components/01-atoms/Links/BasicLink.js +0 -50
- package/lib/components/01-atoms/Links/BasicLink.stories.d.ts +0 -8
- package/lib/components/01-atoms/Links/BasicLink.stories.js +0 -21
- package/lib/components/01-atoms/Links/IconLink.d.ts +0 -13
- package/lib/components/01-atoms/Links/IconLink.js +0 -44
- package/lib/components/01-atoms/Links/IconLink.stories.d.ts +0 -10
- package/lib/components/01-atoms/Links/IconLink.stories.js +0 -24
- package/lib/components/01-atoms/Links/Link.d.ts +0 -13
- package/lib/components/01-atoms/Links/Link.js +0 -51
- package/lib/components/01-atoms/Links/UnderlineLink.d.ts +0 -11
- package/lib/components/01-atoms/Links/UnderlineLink.js +0 -29
- package/lib/components/01-atoms/Links/UnderlineLink.stories.d.ts +0 -8
- package/lib/components/01-atoms/Links/UnderlineLink.stories.js +0 -21
- package/lib/components/01-atoms/Text/Headings/Heading.d.ts +0 -16
- package/lib/components/01-atoms/Text/Headings/Heading.js +0 -40
- package/lib/components/01-atoms/Text/Headings/Heading.stories.d.ts +0 -12
- package/lib/components/01-atoms/Text/Headings/Heading.stories.js +0 -35
- package/lib/components/01-atoms/Text/Headings/RNSectionTitle.d.ts +0 -2
- package/lib/components/01-atoms/Text/Headings/RNSectionTitle.js +0 -18
- package/lib/components/01-atoms/Text/Headings/RNSectionTitle.stories.d.ts +0 -7
- package/lib/components/01-atoms/Text/Headings/RNSectionTitle.stories.js +0 -24
- package/lib/components/01-atoms/Text/Text/BodyText.d.ts +0 -12
- package/lib/components/01-atoms/Text/Text/BodyText.js +0 -73
- package/lib/components/01-atoms/Text/Text/BodyText.stories.d.ts +0 -14
- package/lib/components/01-atoms/Text/Text/BodyText.stories.js +0 -54
- package/lib/components/02-molecules/Cards/EditionCard.d.ts +0 -31
- package/lib/components/02-molecules/Cards/EditionCard.js +0 -51
- package/lib/components/02-molecules/Cards/EditionCard.stories.d.ts +0 -13
- package/lib/components/02-molecules/Cards/EditionCard.stories.js +0 -26
- package/lib/components/02-molecules/Cards/SearchResultItem.d.ts +0 -17
- package/lib/components/02-molecules/Cards/SearchResultItem.js +0 -40
- package/lib/components/02-molecules/Cards/SearchResultItem.stories.d.ts +0 -8
- package/lib/components/02-molecules/Cards/SearchResultItem.stories.js +0 -31
- package/lib/components/02-molecules/Dropdown/Dropdown.d.ts +0 -21
- package/lib/components/02-molecules/Dropdown/Dropdown.js +0 -55
- package/lib/components/02-molecules/Dropdown/Dropdown.stories.d.ts +0 -14
- package/lib/components/02-molecules/Dropdown/Dropdown.stories.js +0 -33
- package/lib/components/02-molecules/Headings/SectionTitle.d.ts +0 -17
- package/lib/components/02-molecules/Headings/SectionTitle.js +0 -42
- package/lib/components/02-molecules/Headings/SectionTitle.stories.d.ts +0 -8
- package/lib/components/02-molecules/Headings/SectionTitle.stories.js +0 -20
- package/lib/components/02-molecules/Menus/Breadcrumbs/Breadcrumbs.d.ts +0 -14
- package/lib/components/02-molecules/Menus/Breadcrumbs/Breadcrumbs.js +0 -51
- package/lib/components/02-molecules/Menus/Breadcrumbs/Breadcrumbs.stories.d.ts +0 -8
- package/lib/components/02-molecules/Menus/Breadcrumbs/Breadcrumbs.stories.js +0 -30
- package/lib/components/02-molecules/Menus/Pagination/Pagination.d.ts +0 -11
- package/lib/components/02-molecules/Menus/Pagination/Pagination.js +0 -57
- package/lib/components/02-molecules/Menus/Pagination/Pagination.stories.d.ts +0 -7
- package/lib/components/02-molecules/Menus/Pagination/Pagination.stories.js +0 -20
- package/lib/components/02-molecules/SearchBar/SearchBar.d.ts +0 -26
- package/lib/components/02-molecules/SearchBar/SearchBar.js +0 -69
- package/lib/components/02-molecules/SearchBar/SearchBar.stories.d.ts +0 -11
- package/lib/components/02-molecules/SearchBar/SearchBar.stories.js +0 -24
- package/lib/components/03-organisms/Accordion/Accordion.d.ts +0 -19
- package/lib/components/03-organisms/Accordion/Accordion.js +0 -41
- package/lib/components/03-organisms/Accordion/Accordion.stories.d.ts +0 -7
- package/lib/components/03-organisms/Accordion/Accordion.stories.js +0 -30
- package/lib/components/03-organisms/Headers/HeaderImgRight.d.ts +0 -12
- package/lib/components/03-organisms/Headers/HeaderImgRight.js +0 -32
- package/lib/components/03-organisms/Headers/HeaderImgRight.stories.d.ts +0 -7
- package/lib/components/03-organisms/Headers/HeaderImgRight.stories.js +0 -19
- package/lib/components/03-organisms/Headers/RNHeaderWithSearch.d.ts +0 -19
- package/lib/components/03-organisms/Headers/RNHeaderWithSearch.js +0 -27
- package/lib/components/03-organisms/Headers/RNHeaderWithSearch.stories.d.ts +0 -7
- package/lib/components/03-organisms/Headers/RNHeaderWithSearch.stories.js +0 -26
- package/lib/components/03-organisms/Hero/Hero.d.ts +0 -31
- package/lib/components/03-organisms/Hero/Hero.js +0 -62
- package/lib/components/03-organisms/Hero/Hero.stories.d.ts +0 -11
- package/lib/components/03-organisms/Hero/Hero.stories.js +0 -35
- package/lib/components/03-organisms/Hero/HeroTypes.d.ts +0 -6
- package/lib/components/03-organisms/Hero/HeroTypes.js +0 -9
- package/lib/components/03-organisms/List/UnorderedList.d.ts +0 -18
- package/lib/components/03-organisms/List/UnorderedList.js +0 -28
- package/lib/components/03-organisms/List/UnorderedList.stories.d.ts +0 -11
- package/lib/components/03-organisms/List/UnorderedList.stories.js +0 -73
- package/lib/components/03-organisms/SearchPromo/SearchPromo.d.ts +0 -22
- package/lib/components/03-organisms/SearchPromo/SearchPromo.js +0 -30
- package/lib/components/03-organisms/SearchPromo/SearchPromo.stories.d.ts +0 -8
- package/lib/components/03-organisms/SearchPromo/SearchPromo.stories.js +0 -28
- package/lib/helpers/hoc/WithOneChild.d.ts +0 -8
- package/lib/helpers/hoc/WithOneChild.js +0 -63
- package/lib/index.d.ts +0 -24
- package/lib/index.js +0 -51
- package/lib/utils/bem.d.ts +0 -1
- package/lib/utils/bem.js +0 -35
- package/tsd.d.ts +0 -4
- package/webpack.prod.js +0 -38
package/README.md
CHANGED
|
@@ -1,32 +1,481 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Reservoir Design System
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
This is intended to be used with [NYPL Design System Styles](https://github.com/NYPL/nypl-design-system/blob/development/src/styles/README.md)
|
|
5
|
+
[](https://badge.fury.io/js/%40nypl%2Fdesign-system-react-components)
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
The Reservoir Design System (DS) is NYPL’s open-source extensible React library for products and experiences with the accessibility as its foundation. It ships functional, stateless components with consistent NYPL styling. You can learn more about the project and its goals [on the project's wiki](https://github.com/NYPL/nypl-design-system/wiki).
|
|
9
8
|
|
|
9
|
+
Storybook documentation
|
|
10
|
+
|
|
11
|
+
- [V2 Production - deployed to Github Pages](https://nypl.github.io/nypl-design-system/reservoir/v2/?path=/docs/welcome--docs)
|
|
12
|
+
- [Development/QA - deployed to Vercel](https://nypl-design-system.vercel.app/?path=/docs/welcome--docs)
|
|
13
|
+
- [V1 Production - deployed to Vercel](https://nypl-design-system-git-reservoir-v173-nypl.vercel.app/)
|
|
14
|
+
|
|
15
|
+
| Table of Contents | |
|
|
16
|
+
| ----------------- | ----------------------------------------------------------------------------------- |
|
|
17
|
+
| 1. | [Using the Design System in Your Product](#using-the-design-system-in-your-product) |
|
|
18
|
+
| 2. | [Using Chakra UI Components](#using-chakra-ui-components) |
|
|
19
|
+
| 3. | [Storybook](#storybook) |
|
|
20
|
+
| 4. | [Accessibility](#accessibility) |
|
|
21
|
+
| 5. | [Contributing Quickstart](#contributing-quickstart) |
|
|
22
|
+
| 6. | [Local App Development](#local-app-development) |
|
|
23
|
+
| 7. | [Typescript Usage](#typescript-usage) |
|
|
24
|
+
| 8. | [Unit Testing](#unit-testing) |
|
|
25
|
+
| 9. | [CDN](#cdn) |
|
|
26
|
+
|
|
27
|
+
## Using the Design System in Your Product
|
|
28
|
+
|
|
29
|
+
The Reservoir Design System package is distributed on npm.
|
|
30
|
+
|
|
31
|
+
1. Install the package in your app's directory:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
$ npm install @nypl/design-system-react-components
|
|
10
35
|
```
|
|
11
|
-
|
|
36
|
+
|
|
37
|
+
2. Import the `DSProvider` component
|
|
38
|
+
|
|
39
|
+
In order to use DS components in a consuming application, there is a necessary step that must be done for component styles to properly render. Consuming applications need to wrap all the DS components with a simple provider component. Fortunately, this only needs to be done once at the top level of the consuming application.
|
|
40
|
+
|
|
41
|
+
Once the following is completed, DS components that internally use Chakra UI will render styles properly.
|
|
42
|
+
|
|
43
|
+
```jsx
|
|
44
|
+
// your main application file
|
|
45
|
+
import { DSProvider } from "@nypl/design-system-react-components";
|
|
46
|
+
|
|
47
|
+
// ...
|
|
48
|
+
const ApplicationContainer = (props) => {
|
|
49
|
+
// ...
|
|
50
|
+
return (
|
|
51
|
+
<DSProvider>
|
|
52
|
+
<div className="my-app">
|
|
53
|
+
// ...
|
|
54
|
+
{children}
|
|
55
|
+
</div>
|
|
56
|
+
</DSProvider>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
12
59
|
```
|
|
13
60
|
|
|
14
|
-
|
|
61
|
+
3. Import the minified styles `@nypl/design-system-react-components/dist/styles.css` file in your app.
|
|
62
|
+
|
|
63
|
+
This file contains normalized reset CSS rules, system fonts, the `react-datepicker`'s styles, breakpoint CSS variables, and overriding styles for a few components.
|
|
15
64
|
|
|
16
|
-
|
|
65
|
+
Importing this file varies on the stack of the application. For Nextjs apps, the file can be imported in the `_app.tsx` file:
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
// _app.tsx
|
|
69
|
+
@import "@nypl/design-system-react-components/dist/styles.css";
|
|
70
|
+
|
|
71
|
+
import {
|
|
72
|
+
DSProvider,
|
|
73
|
+
TemplateAppContainer,
|
|
74
|
+
} from "@nypl/design-system-react-components";
|
|
75
|
+
...
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Otherwise, it can be imported in the app's main SCSS file:
|
|
79
|
+
|
|
80
|
+
```scss
|
|
81
|
+
// main.scss (for example)
|
|
82
|
+
@import "@nypl/design-system-react-components/dist/styles.css";
|
|
83
|
+
|
|
84
|
+
body {
|
|
85
|
+
....
|
|
86
|
+
}
|
|
17
87
|
```
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
88
|
+
|
|
89
|
+
Note: Using tilde to import scss/css is no longer a best practice for apps using _recent_ versions of webpack or parcel.
|
|
90
|
+
|
|
91
|
+
```scss
|
|
92
|
+
// No longer a best practice:
|
|
93
|
+
@import "~@nypl/design-system-react-components/dist/styles.css";
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
For apps using parcel, prepend the string import with `npm:` such as :
|
|
97
|
+
|
|
98
|
+
```scss
|
|
99
|
+
@import "npm:@nypl/design-system-react-components/dist/styles.css";
|
|
22
100
|
```
|
|
23
101
|
|
|
24
|
-
|
|
102
|
+
4. Use DS components!
|
|
103
|
+
|
|
104
|
+
Consult Storybook for the list of available components and props that they require.
|
|
105
|
+
|
|
106
|
+
Here's an example with the `Link` component:
|
|
107
|
+
|
|
108
|
+
```jsx
|
|
109
|
+
import { Link } from "@nypl/design-system-react-components";
|
|
110
|
+
|
|
111
|
+
function NewComponent(props) {
|
|
112
|
+
return <Link href="https://www.hathitrust.org/">HathiTrust</Link>;
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Sometimes you may have conflicts, perhaps with `React-Router`. In that case, you can alias your imports:
|
|
117
|
+
|
|
118
|
+
```jsx
|
|
119
|
+
import * as DS from "@nypl/design-system-react-components";
|
|
120
|
+
import { Link } from "react-router";
|
|
121
|
+
|
|
122
|
+
function NewComponent(props) {
|
|
123
|
+
return (
|
|
124
|
+
<DS.Link>
|
|
125
|
+
<Link to="/license">public domain</Link>
|
|
126
|
+
</DS.Link>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Using Chakra UI Components
|
|
132
|
+
|
|
133
|
+
The Chakra UI component library has been integrated into the Reservoir Design System. We are still progressing towards using Chakra components and patterns to build DS components, and therefore documentation and features are expected to change. While the implementation details of DS components will use Chakra, the DS package itself will export _some_ Chakra components.
|
|
134
|
+
|
|
135
|
+
The list of re-exported Chakra components can be found in the main [index.ts](/src/index.ts) file. They include:
|
|
136
|
+
|
|
137
|
+
- `Box`, `Center`, `Circle`, `Grid`, `GridItem`, `HStack`, `Square`, `Stack`, `VStack`
|
|
138
|
+
|
|
139
|
+
Find more information about the Design System's internal use of Chakra to create and refactor components in the Storybook documentation page. The following two links have the same information but in different formats for your reading preference:
|
|
140
|
+
|
|
141
|
+
- [MDX format](/src/docs/Chakra.stories.mdx)
|
|
142
|
+
- [Storybook page](https://nypl.github.io/nypl-design-system/reservoir/v2/?path=/docs/chakra-ui--docs)
|
|
143
|
+
|
|
144
|
+
Chakra was integrated into the Design System in version `0.25.0`. For those looking to update to a version greater than or equal `0.25.0`, check out our [Chakra Migration Guide](/CHAKRA_MIGRATION_GUIDE.md).
|
|
145
|
+
|
|
146
|
+
## Storybook
|
|
147
|
+
|
|
148
|
+
The Reservoir Design System leverages Storybook to document all the React components and style guidelines. The Storybook documentation for version 2.x can be found [on Github Pages](https://nypl.github.io/nypl-design-system/reservoir/v2/?path=/docs/welcome--docs). For your convenience, the Reservoir Design System components have been organized into logical categories based on both form and function. Please refer to the COMPONENTS section in the Storybook sidebar.
|
|
149
|
+
|
|
150
|
+
### Documentation Instances
|
|
151
|
+
|
|
152
|
+
There are currently three main instances of the Reservoir Design System Storybook documentation. There are also "preview" sites that are used to quickly and easily view pull request changes.
|
|
153
|
+
|
|
154
|
+
**Production**
|
|
155
|
+
|
|
156
|
+
The production Storybook documentation for DS version 2.x is deployed to [Github Pages](https://nypl.github.io/nypl-design-system/reservoir/v2/?path=/docs/welcome--docs). This is the main instance we use to share the latest stable release of the Reservoir Design System. This documentation site is deployed through [Github Actions](/.github/workflows/gh-pages.yml) only on merges to the `release` and `gh-pages` branches.
|
|
157
|
+
|
|
158
|
+
As of July, 2021, the Github Pages production site gets deployed every two weeks on the same schedule as npm releases.
|
|
159
|
+
|
|
160
|
+
**Development**
|
|
161
|
+
|
|
162
|
+
The development Storybook documentation is deployed to [Vercel](https://nypl-design-system.vercel.app/?path=/docs/welcome--docs). This development site has all the working updates that get merged to the `development` branch. This means that this site is constantly being updated as pull requests are being merged in. This site is used to see the lastest changes during a working sprint before a production release is made.
|
|
163
|
+
|
|
164
|
+
**Version 1.x**
|
|
165
|
+
|
|
166
|
+
The Storybook documentation for DS version 1.x is deployed to [Vercel](https://nypl-design-system-git-reservoir-v173-nypl.vercel.app/). If you are using a DS version less than 2.0, this is the Storybook documentation you should be referencing. While the DS team will continue to support version 1.x, we will not be adding new features or components to this version. We highly recommend updating to version 2.x for design update and bug fixes.
|
|
167
|
+
|
|
168
|
+
**Preview Sites**
|
|
169
|
+
|
|
170
|
+
Preview Storybook documentation sites are deployed to Vercel on every commit push to every branch in this repository. They follow a pattern such as `nypl-design-system-[hash]-nypl.vercel.app` where `[hash]` is a random hash created by Vercel. This means that the URL varies and that those instances are eventually shut off. They are not meant to be used as long-term sites but rather for reviewing working changes within the team.
|
|
171
|
+
|
|
172
|
+
### React Component Documentation
|
|
173
|
+
|
|
174
|
+
When actively developing components or fixing bugs, make sure that the related stories are created or updated. This means updating the respective `[component-name].stories.mdx` file. For information on how to write stories, check out the [Anatomy of a Story](https://github.com/NYPL/nypl-design-system/wiki/Anatomy-of-a-Story) wiki page.
|
|
175
|
+
|
|
176
|
+
For stand-alone document pages in Storybook, you need to:
|
|
177
|
+
|
|
178
|
+
1. create the `[page-name].stories.mdx` file in `src/docs/`
|
|
179
|
+
2. add the file reference to the `.storybook/main.cjs` file in the `stories` array
|
|
180
|
+
|
|
181
|
+
### React Component Versions
|
|
182
|
+
|
|
183
|
+
To help consuming application developers understand which version of the DS is required for a specific component, each component story page includes the following:
|
|
184
|
+
|
|
185
|
+
- when a component was added to the DS
|
|
186
|
+
- minimum version of the DS required for the latest version of a component
|
|
187
|
+
|
|
188
|
+
**Example Component Version Table**
|
|
189
|
+
|
|
190
|
+
| Component Version | DS Version |
|
|
191
|
+
| ----------------- | ---------- |
|
|
192
|
+
| Added | `0.20.1` |
|
|
193
|
+
| Latest | `0.23.2` |
|
|
194
|
+
|
|
195
|
+
### Static Build
|
|
196
|
+
|
|
197
|
+
_Make sure not to commit the directory created from the following process_.
|
|
198
|
+
|
|
199
|
+
There should be no need to run the static Storybook instance while actively developing -- it's used exclusively for building out the `gh-pages` environment and deploying it to [Github Pages](https://nypl.github.io/nypl-design-system/reservoir/v2/?path=/docs/welcome--docs). In the event that you do run the static Storybook npm script, run:
|
|
200
|
+
|
|
201
|
+
```sh
|
|
202
|
+
$ npm run build-storybook:v2
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
You can then view `/reservoir/v2/index.html` in your browser. _Make sure not to commit this directory_.
|
|
206
|
+
|
|
207
|
+
## Accessibility
|
|
208
|
+
|
|
209
|
+
### Development and Storybook
|
|
210
|
+
|
|
211
|
+
The Reservoir Design System is built with accessibility in mind. By using Chakra UI as our foundational base, the custom DS components built with Chakra have accessibility concerns already implemented. On top of built-in accessible elements, DS components internally work to link labels with input elements, to add correct `aria-*` attributes, to visually hide text but still associate it with the correct element for titles and descriptions, and much more.
|
|
212
|
+
|
|
213
|
+
We make use of:
|
|
214
|
+
|
|
215
|
+
- `eslint-plugin-jsx-a11y` for finding accessibility errors through linting and through IDE environments.
|
|
216
|
+
- `jest-axe` for running [`axe-core`](https://github.com/dequelabs/axe-core) on _every_ component's unit test file. This is part of the automated tests that run in Github Actions through the `npm test` command.
|
|
217
|
+
- `@storybook/addon-a11y` for real-time accessibility testing in the browser through Storybook. _Every_ component has a tab that displays violations, passes, and incomplete checks performed by `axe-core`.
|
|
218
|
+
|
|
219
|
+
If applicable, DS components have section(s) on accessibility in their Storybook documentation. For example, in the `Slider`'s [Storybook file](/src/components/Slider/Slider.stories.mdx), there are two "Accessibility" sections for each of the two `Slider` types, "single" and "range". This gives an explanation on additional changes we made to make the combination of elements in the `Slider` component accessible.
|
|
220
|
+
|
|
221
|
+
### Product Requirements
|
|
222
|
+
|
|
223
|
+
The Reservoir Design System provides accessible stories, but real data can necessitate additional accessibility requirements beyond what we're committed to in our generic, extensible components. To ensure your products' final result is accessible, please adhere to the accessibility requirements put together by NYPL's accessibility coordinator on [Metronome](http://themetronome.co/).
|
|
224
|
+
|
|
225
|
+
NYPL's Metronome instance is currently password protected. For access to Metronome, please contact NYPL's UX team or Design System team.
|
|
226
|
+
|
|
227
|
+
## Contributing Quickstart
|
|
228
|
+
|
|
229
|
+
Follow these steps to setup a local installation of the project:
|
|
230
|
+
|
|
231
|
+
1. Clone the repo
|
|
232
|
+
|
|
233
|
+
```sh
|
|
234
|
+
$ git clone https://github.com/NYPL/nypl-design-system.git
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
2. Install all the dependencies
|
|
238
|
+
|
|
239
|
+
```sh
|
|
240
|
+
$ npm install
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
3. Run the Storybook instance and view it at `http://localhost:6006`
|
|
244
|
+
|
|
245
|
+
```sh
|
|
246
|
+
$ npm run storybook
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
You can now edit styles or templates in the `src` directory, and they will automatically re-build and update in the Storybook instance. Adding new stories or changing story names will require a page refresh.
|
|
250
|
+
|
|
251
|
+
Information about active maintainers, how we run reviews, and more can be found in our wiki page for [Contributing to the Design System](https://github.com/NYPL/nypl-design-system/wiki/Contributing-to-the-React-Library).
|
|
25
252
|
|
|
253
|
+
Follow the [contribution document](/.github/CONTRIBUTING.md) to follow git branching convetions, component creation and update guidelines, testing methodoly, and documentation guidelines.
|
|
26
254
|
|
|
27
|
-
|
|
28
|
-
Working simultaneously on an npm package and a repo can be tedious and publishing a new version to test changes isn't appropriate. To fix this, run `npm run dist` and `npm link` on this repo and `npm link @nypl/design-system-react-components` in the app repo to link both repos together. Any changes in the webpack build bundle will be picked up in the app.
|
|
255
|
+
### Node Version
|
|
29
256
|
|
|
30
|
-
|
|
257
|
+
We recommend using Node version 16.x. The Github Actions for linting, automated testing, deploying to Github Pages, and releasing to npm are all running on Node 16.x.
|
|
258
|
+
|
|
259
|
+
If you are using `nvm`, the local `.nvmrc` file (using `16.x`) can be use to set your local Node version with the `nvm use` command. Make sure your machine has Node version 16.x installed through `nvm` already.
|
|
260
|
+
|
|
261
|
+
### Git Branch Workflow
|
|
262
|
+
|
|
263
|
+
There are currently two main branches for the DS:
|
|
264
|
+
|
|
265
|
+
- `development` is the main and default branch for the DS. All new feature and bug fix pull requests should be made against this branch.
|
|
266
|
+
- `release` is the branch used to deploy the static Storybook instance to Github Pages, the DS' production Storybook instance.
|
|
267
|
+
|
|
268
|
+
When a new version of the DS is ready for release, the `development` branch is merged into the `release` branch through a pull request. Once merged, Github Actions will run to deploy the static Storybook as well as publish the new version to npm. Here is a [pull request](https://github.com/NYPL/nypl-design-system/pull/1249) that follows the convention outlined in [How to Run a Release](https://github.com/NYPL/nypl-design-system/wiki/How-to-Run-a-Release).
|
|
269
|
+
|
|
270
|
+
When working on a new feature or a bug fix:
|
|
271
|
+
|
|
272
|
+
1. Create a new branch off of `development` with the following naming convention: `[ticket-number]/your-feature-or-bug-name`. For example, if the JIRA ticket is DSD-1234 and the feature is "Add more Animal Crossing examples", then potential branch names can be `DSD-1234/add-more-animal-crossing-examples`, `DSD-1234/more-ac-examples`, or `DSD-1234/animal-crossing-examples`. The ticket number in the branch name is usually more helpful than the text that follows.
|
|
273
|
+
2. Create a pull request that points to the `development` branch.
|
|
274
|
+
3. If your pull request is approved and _should_ be merged, merge it. This is indicated with the "SHIP IT" Github label. Sometimes, some features must wait and the "DO NOT MERGE" label is added to the pull request.
|
|
275
|
+
|
|
276
|
+
### Release Candidates
|
|
277
|
+
|
|
278
|
+
For new big feature updates, we typically want to QA it in the Turbine test app before the real stable release is made. In this case, we create "release candidate" npm packages. This can be based off the feature branch or the `developement` branch once the feature is merged in.
|
|
279
|
+
|
|
280
|
+
At the moment, this is a manual process. For this example, we will use version `1.5.0` as the new version that will be released.
|
|
281
|
+
|
|
282
|
+
1. Whether on the feature branch or the `development` branch, the version in the `package.json` file must be updated to include the `-rc` suffix. For example, `1.5.0` becomes `1.5.0-rc`. This is to indicate that this is a release candidate version.
|
|
283
|
+
2. Delete the `package-lock.json` file and the `node_modules` directory.
|
|
284
|
+
3. Run `npm install` to install all the dependencies and create a new `package-lock.json` file with the updated version.
|
|
285
|
+
4. Run `npm publish` to publish the new release candidate version to npm. Make sure you have an npm account, are logged in to npm on your machine, and have the correct permissions to publish to the `@nypl/design-system-react-components` package.
|
|
286
|
+
|
|
287
|
+
What happens if QA finds a bug in the release candidate version in the Turbine test app?
|
|
288
|
+
|
|
289
|
+
1. Update or fix the bug in a new branch.
|
|
290
|
+
2. Once approved, merge the pull request into the feature branch or the `development` branch.
|
|
291
|
+
3. Follow the same steps above to create a new release candidate version but this time the `-rc` suffix should be incremented. For example, `1.5.0-rc` becomes `1.5.0-rc1`.
|
|
292
|
+
4. QA the new release candidate version in the Turbine test app.
|
|
293
|
+
|
|
294
|
+
The release candidate version passed QA and is ready for production! What do we do now?
|
|
295
|
+
|
|
296
|
+
1. Celebrate.
|
|
297
|
+
2. Make sure all the new changes are merged into the `development` branch.
|
|
298
|
+
3. Remove the `-rc` suffix from the version in the `package.json` file.
|
|
299
|
+
4. Delete the `package-lock.json` file and the `node_modules` directory.
|
|
300
|
+
5. Run `npm install` to install all the dependencies and create a new `package-lock.json` file with the updated version.
|
|
301
|
+
6. Push the changes to Github and create a new pull request from `development` that points to the `release` branch.
|
|
302
|
+
7. Once approved and merged, a Github Action will run that will automatically deploy the static Storybook to Github Pages and publish the new version to npm. |
|
|
303
|
+
|
|
304
|
+
## Local App Development
|
|
305
|
+
|
|
306
|
+
Sometimes, you may want to test out a new feature or bug fix in a local app rather than publishing a release candidate version to npm. While this is possible, it is not always straightforward.
|
|
307
|
+
|
|
308
|
+
_Please note that the following instructions depend on the node version for both the Design System and the local app. If the node versions are different, the instructions may not work. This is a limitation of npm._
|
|
309
|
+
|
|
310
|
+
### Developing with npm install
|
|
311
|
+
|
|
312
|
+
To develop with a local version of the Design System:
|
|
313
|
+
|
|
314
|
+
1. In the root of the consuming application directory, run:
|
|
315
|
+
|
|
316
|
+
```sh
|
|
317
|
+
$ npm install --no-save [../path/to/design-system]
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Developing with npm link
|
|
321
|
+
|
|
322
|
+
To develop with a local version of the Design System:
|
|
323
|
+
|
|
324
|
+
1. In the Design System directory, run:
|
|
325
|
+
|
|
326
|
+
```sh
|
|
327
|
+
$ npm link
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
2. Go to the consuming application directory and run:
|
|
331
|
+
|
|
332
|
+
```sh
|
|
333
|
+
$ npm link @nypl/design-system-react-components
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
3. Go back to the Design System directory and run the following command. It allows the local Design System to be rebuilt and exported automatically:
|
|
337
|
+
|
|
338
|
+
```sh
|
|
339
|
+
$ npm start
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
#### Error Troubleshooting
|
|
343
|
+
|
|
344
|
+
It's possible when running `npm link` that you'll get an `Invalid Hook` issue. If this occurs, it's most likely caused by having two versions of React when trying to run the application while the NYPL DS package is linked. This [Duplicate React](https://reactjs.org/warnings/invalid-hook-call-warning.html#duplicate-react) issue is covered by the React team.
|
|
345
|
+
|
|
346
|
+
To be more specific, you should run the following in your local DS directory, where `[../path/to/application]` is the local directory of the consuming application.
|
|
347
|
+
|
|
348
|
+
```sh
|
|
349
|
+
$ npm link [../path/to/application]/node_modules/react
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
Now you should be able to run `npm start` in the DS directory and `npm run dev` (or whatever your application uses) in the application directory and not get an `Invalid Hook` error.
|
|
353
|
+
|
|
354
|
+
#### npm Unlink
|
|
355
|
+
|
|
356
|
+
To unlink the DS codebase:
|
|
357
|
+
|
|
358
|
+
1. Run `npm unlink` in the Design System directory.
|
|
359
|
+
2. Run `npm unlink --no-save @nypl/design-system-react-components` in the consuming application.
|
|
360
|
+
|
|
361
|
+
## Typescript Usage
|
|
362
|
+
|
|
363
|
+
The Reservoir Design System is built with Typescript. Check out the Design System's [Typescript documentation](/TYPESCRIPT.md) for more information on why we chose to build React components in Typescript and the benefits and the gotchas we encountered.
|
|
364
|
+
|
|
365
|
+
## Unit Testing
|
|
366
|
+
|
|
367
|
+
The Reservoir Design System runs unit tests with Jest and React Testing Library.
|
|
368
|
+
|
|
369
|
+
To run all tests once:
|
|
370
|
+
|
|
371
|
+
```sh
|
|
372
|
+
$ npm test
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
If you're actively writing or updating tests, you can run the tests in watch mode. This will wait for any changes and run when a file is saved:
|
|
376
|
+
|
|
377
|
+
```sh
|
|
378
|
+
$ npm run test:watch
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
If you want to run tests on only one specific file, run:
|
|
382
|
+
|
|
383
|
+
```sh
|
|
384
|
+
$ npm test -- src/[path/to/file]
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
For example, to test the `Link` component, run:
|
|
388
|
+
|
|
389
|
+
```sh
|
|
390
|
+
$ npm test -- src/components/Link/Link.test.tsx
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
### Snapshot Testing
|
|
394
|
+
|
|
395
|
+
The NYPL DS implements snapshot testing with `react-test-renderer` and `jest`. Using React Testing Library to test our components works well to make sure that what the user sees is what the component should be rendering. There are also some behavioral tests that test user interactions. If, however, a component's DOM or SCSS styling was unintentionally updated, we can catch those bugs through snapshot testing.
|
|
396
|
+
|
|
397
|
+
The `react-test-renderer` package, will create a directory and a file to hold `.snap` files after a unit test is created. Using the `Notification` component as an example, this is the basic layout for a snapshot test:
|
|
398
|
+
|
|
399
|
+
```tsx
|
|
400
|
+
import renderer from "react-test-renderer";
|
|
401
|
+
|
|
402
|
+
// ...
|
|
403
|
+
|
|
404
|
+
it("Renders the UI snapshot correctly", () => {
|
|
405
|
+
const tree = renderer
|
|
406
|
+
.create(
|
|
407
|
+
<Notification
|
|
408
|
+
id="notificationID"
|
|
409
|
+
notificationHeading="Notification Heading"
|
|
410
|
+
notificationContent={<>Notification content.</>}
|
|
411
|
+
/>
|
|
412
|
+
)
|
|
413
|
+
.toJSON();
|
|
414
|
+
expect(tree).toMatchSnapshot();
|
|
415
|
+
});
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
If this is a new test and we run `npm test`, a [`/__snapshots__/Notification.test.tsx.snap`](/src/components/Notification/__snapshots__/Notification.test.tsx.snap) file is created. This holds the DOM structure as well as any inline CSS that was added.
|
|
419
|
+
|
|
420
|
+
```tsx
|
|
421
|
+
exports[`Notification Snapshot Renders the UI snapshot correctly 1`] = `
|
|
422
|
+
<aside
|
|
423
|
+
className="notification notification--standard "
|
|
424
|
+
id="notificationID"
|
|
425
|
+
>
|
|
426
|
+
// Removed for brevity...
|
|
427
|
+
</aside>
|
|
428
|
+
`;
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
Now, if we unintentionally update the `Notification.tsx` component to render a `div` instead of an `aside` element, this test will fail.
|
|
432
|
+
|
|
433
|
+
If you want to update any existing snapshots, re-run the test script as:
|
|
434
|
+
|
|
435
|
+
```sh
|
|
436
|
+
$ npm test -- --updateSnapshot
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
Each snapshot file also includes a link to its [Jest Snapshot documentation](https://jestjs.io/docs/snapshot-testing) which is recommended to read!
|
|
440
|
+
|
|
441
|
+
### Storybook Jest Addon
|
|
442
|
+
|
|
443
|
+
Through the [`@storybook/addon-jest`](https://www.npmjs.com/package/@storybook/addon-jest) plugin, we can see a component's suite of unit tests right Storybook. In the "Addons" panel, a "Test" tab will display all the tests for the current component and whether they pass or fail.
|
|
444
|
+
|
|
445
|
+
After writing new tests, run `npm run test:generate-output` to create a new JSON file that is used by Storybook. This JSON file contains all the test suites for all the components and Storybook picks this up and automatically combines a component with its relevant unit tests. Make sure to commit this file although new builds on Github Pages will recreate this file for the production Storybook instance.
|
|
446
|
+
|
|
447
|
+
## CDN
|
|
448
|
+
|
|
449
|
+
You can also use the Design System styles in your project through the `unpkg` CDN, but not that this is not recommended for production use.
|
|
450
|
+
|
|
451
|
+
```html
|
|
452
|
+
<link
|
|
453
|
+
href="https://unpkg.com/@nypl/design-system-react-components/dist/styles.css"
|
|
454
|
+
/>
|
|
455
|
+
<script src="https://unpkg.com/@nypl/design-system-react-components/dist/design-system-react-components.umd.cjs" />
|
|
456
|
+
<script src="https://unpkg.com/@nypl/design-system-react-components/dist/design-system-react-components.js" />
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
If you need to reference a particular version you can do do by including the version number in the URL.
|
|
460
|
+
|
|
461
|
+
For version < 1.6.0:
|
|
462
|
+
|
|
463
|
+
```html
|
|
464
|
+
<link
|
|
465
|
+
href="https://unpkg.com/@nypl/design-system-react-components@1.5.1/dist/styles.css"
|
|
466
|
+
/>
|
|
467
|
+
<script src="https://unpkg.com/@nypl/design-system-react-components@1.5.1/dist/design-system-react-components.cjs.production.min.js" />
|
|
468
|
+
<script src="https://unpkg.com/@nypl/design-system-react-components@1.5.1/dist/design-system-react-components.esm.js" />
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
For version >= 1.6.0:
|
|
472
|
+
|
|
473
|
+
```html
|
|
474
|
+
<link
|
|
475
|
+
href="https://unpkg.com/@nypl/design-system-react-components@1.6.0/dist/styles.css"
|
|
476
|
+
/>
|
|
477
|
+
<script src="https://unpkg.com/@nypl/design-system-react-components@1.6.0/dist/design-system-react-components.umd.cjs" />
|
|
478
|
+
<script src="https://unpkg.com/@nypl/design-system-react-components@1.6.0/dist/design-system-react-components.js" />
|
|
479
|
+
```
|
|
31
480
|
|
|
32
|
-
|
|
481
|
+
You can check out a working Codepen with unpkg [here](https://codepen.io/edwinguzman/pen/ExmXGKx).
|