@nypl/design-system-react-components 0.25.1 → 0.25.5
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 +118 -1
- package/README.md +98 -50
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +4 -0
- package/dist/components/Button/Button.d.ts +13 -8
- package/dist/components/Button/ButtonTypes.d.ts +2 -1
- package/dist/components/Card/Card.d.ts +36 -52
- package/dist/components/Card/CardTypes.d.ts +0 -15
- package/dist/components/Checkbox/Checkbox.d.ts +17 -13
- package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +4 -2
- package/dist/components/ComponentWrapper/ComponentWrapper.d.ts +15 -0
- package/dist/components/DatePicker/DatePicker.d.ts +36 -34
- package/dist/components/Fieldset/Fieldset.d.ts +25 -0
- package/dist/components/Heading/Heading.d.ts +4 -4
- package/dist/components/HelperErrorText/HelperErrorText.d.ts +17 -14
- package/dist/components/HorizontalRule/HorizontalRule.d.ts +10 -9
- package/dist/components/Icons/Icon.d.ts +8 -0
- package/dist/components/Icons/IconSvgs.d.ts +11 -0
- package/dist/components/Icons/IconTypes.d.ts +11 -0
- package/dist/components/Image/Image.d.ts +19 -9
- package/dist/components/Image/ImageTypes.d.ts +20 -0
- package/dist/components/Link/Link.d.ts +4 -0
- package/dist/components/List/List.d.ts +19 -14
- package/dist/components/Notification/Notification.d.ts +37 -16
- package/dist/components/Pagination/Pagination.d.ts +16 -13
- package/dist/components/Pagination/Pagination.stories.d.ts +2 -0
- package/dist/components/ProgressIndicator/ProgressIndicator.d.ts +29 -0
- package/dist/components/ProgressIndicator/ProgressIndicatorTypes.d.ts +8 -0
- package/dist/components/Radio/Radio.d.ts +2 -0
- package/dist/components/RadioGroup/RadioGroup.d.ts +4 -2
- package/dist/components/SearchBar/SearchBar.d.ts +3 -3
- package/dist/components/Select/Select.d.ts +2 -0
- package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +18 -14
- package/dist/components/Slider/Slider.d.ts +57 -0
- package/dist/components/StyleGuide/ColorCard.d.ts +12 -0
- package/dist/components/Tabs/Tabs.d.ts +1 -1
- package/dist/components/TextInput/TextInput.d.ts +12 -0
- package/dist/components/VideoPlayer/VideoPlayer.d.ts +6 -8
- package/dist/components/VideoPlayer/VideoPlayerTypes.d.ts +2 -2
- package/dist/design-system-react-components.cjs.development.js +6131 -3715
- 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 +6124 -3699
- package/dist/design-system-react-components.esm.js.map +1 -1
- package/dist/hooks/tests/useCarouselStyles.test.d.ts +1 -0
- package/dist/hooks/useCarouselStyles.d.ts +16 -0
- package/dist/hooks/useNYPLTheme.d.ts +54 -0
- package/dist/hooks/useWindowSize.d.ts +10 -0
- package/dist/index.d.ts +13 -8
- package/dist/resources.scss +180 -170
- package/dist/styles.css +1 -1
- package/dist/theme/components/button.d.ts +22 -8
- package/dist/theme/components/card.d.ts +168 -0
- package/dist/theme/components/checkbox.d.ts +5 -1
- package/dist/theme/components/checkboxGroup.d.ts +12 -0
- package/dist/theme/components/componentWrapper.d.ts +11 -0
- package/dist/theme/components/datePicker.d.ts +16 -0
- package/dist/theme/components/fieldset.d.ts +27 -0
- package/dist/theme/components/global.d.ts +23 -13
- package/dist/theme/components/globalMixins.d.ts +9 -1
- package/dist/theme/components/heading.d.ts +5 -0
- package/dist/theme/components/helperErrorText.d.ts +10 -0
- package/dist/theme/components/hero.d.ts +1 -0
- package/dist/theme/components/horizontalRule.d.ts +14 -0
- package/dist/theme/components/image.d.ts +31 -0
- package/dist/theme/components/label.d.ts +5 -3
- package/dist/theme/components/link.d.ts +4 -0
- package/dist/theme/components/list.d.ts +89 -0
- package/dist/theme/components/notification.d.ts +75 -0
- package/dist/theme/components/pagination.d.ts +19 -0
- package/dist/theme/components/progressIndicator.d.ts +50 -0
- package/dist/theme/components/radioGroup.d.ts +12 -0
- package/dist/theme/components/select.d.ts +11 -2
- package/dist/theme/components/skeletonLoader.d.ts +98 -0
- package/dist/theme/components/slider.d.ts +51 -0
- package/dist/theme/components/tabs.d.ts +54 -3
- package/dist/theme/components/textInput.d.ts +8 -1
- package/dist/theme/components/videoPlayer.d.ts +40 -0
- package/dist/theme/foundations/breakpoints.d.ts +8 -8
- package/dist/theme/foundations/global.d.ts +6 -1
- package/dist/theme/foundations/radii.d.ts +5 -0
- package/dist/theme/foundations/spacing.d.ts +16 -16
- package/package.json +72 -83
- package/src/__tests__/setup.ts +2 -2
- package/src/components/Accordion/Accordion.stories.mdx +39 -44
- package/src/components/Autosuggest/Autosuggest.stories.mdx +3 -3
- package/src/components/Autosuggest/Autosuggest.stories.tsx +2 -1
- package/src/components/Autosuggest/_Autosuggest.scss +5 -5
- package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +14 -10
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +23 -0
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +5 -1
- package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +199 -1
- package/src/components/Button/Button.stories.mdx +15 -10
- package/src/components/Button/Button.test.tsx +21 -7
- package/src/components/Button/Button.tsx +22 -34
- package/src/components/Button/ButtonTypes.tsx +1 -0
- package/src/components/Button/__snapshots__/Button.test.tsx.snap +41 -10
- package/src/components/Card/Card.stories.mdx +296 -259
- package/src/components/Card/Card.test.tsx +156 -84
- package/src/components/Card/Card.tsx +195 -145
- package/src/components/Card/CardTypes.tsx +0 -17
- package/src/components/Card/__snapshots__/Card.test.tsx.snap +410 -0
- package/src/components/CardEdition/CardEdition.stories.tsx +15 -47
- package/src/components/CardEdition/_CardEdition.scss +22 -23
- package/src/components/Chakra/Box.stories.mdx +15 -16
- package/src/components/Chakra/Center.stories.mdx +31 -16
- package/src/components/Chakra/Grid.stories.mdx +28 -15
- package/src/components/Chakra/Stack.stories.mdx +35 -18
- package/src/components/Checkbox/Checkbox.stories.mdx +33 -11
- package/src/components/Checkbox/Checkbox.test.tsx +47 -2
- package/src/components/Checkbox/Checkbox.tsx +39 -33
- package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +90 -2
- package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +82 -2
- package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +29 -2
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +22 -18
- package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +47 -81
- package/src/components/ComponentWrapper/ComponentWrapper.tsx +63 -0
- package/src/components/DatePicker/DatePicker.stories.mdx +163 -62
- package/src/components/DatePicker/DatePicker.test.tsx +264 -64
- package/src/components/DatePicker/DatePicker.tsx +159 -128
- package/src/components/DatePicker/_DatePicker.scss +33 -67
- package/src/components/DatePicker/__snapshots__/DatePicker.test.tsx.snap +818 -0
- package/src/components/Fieldset/Fieldset.stories.mdx +55 -0
- package/src/components/Fieldset/Fieldset.test.tsx +125 -0
- package/src/components/Fieldset/Fieldset.tsx +52 -0
- package/src/components/Fieldset/__snapshots__/Fieldset.test.tsx.snap +68 -0
- package/src/components/Form/Form.stories.mdx +24 -6
- package/src/components/Form/Form.test.tsx +1 -1
- package/src/components/Form/Form.tsx +1 -0
- package/src/components/Grid/SimpleGrid.stories.mdx +32 -39
- package/src/components/Grid/SimpleGrid.test.tsx +4 -4
- package/src/components/Heading/Heading.stories.mdx +3 -4
- package/src/components/Heading/Heading.tsx +5 -5
- package/src/components/HelperErrorText/HelperErrorText.stories.mdx +124 -0
- package/src/components/HelperErrorText/HelperErrorText.test.tsx +39 -44
- package/src/components/HelperErrorText/HelperErrorText.tsx +37 -39
- package/src/components/HelperErrorText/__snapshots__/HelperErrorText.test.tsx.snap +25 -0
- package/src/components/Hero/Hero.stories.mdx +12 -2
- package/src/components/Hero/Hero.tsx +1 -1
- package/src/components/Hero/HeroTypes.tsx +1 -0
- package/src/components/Hero/__snapshots__/Hero.test.tsx.snap +7 -7
- package/src/components/HorizontalRule/HorizontalRule.stories.mdx +8 -6
- package/src/components/HorizontalRule/HorizontalRule.test.tsx +33 -28
- package/src/components/HorizontalRule/HorizontalRule.tsx +27 -29
- package/src/components/HorizontalRule/__snapshots__/HorizontalRule.test.tsx.snap +27 -9
- package/src/components/Icons/Icon.stories.mdx +12 -4
- package/src/components/Icons/Icon.test.tsx +18 -0
- package/src/components/Icons/Icon.tsx +16 -1
- package/src/components/Icons/IconSvgs.tsx +22 -0
- package/src/components/Icons/IconTypes.tsx +11 -0
- package/src/components/Image/Image.stories.mdx +220 -0
- package/src/components/Image/Image.test.tsx +131 -29
- package/src/components/Image/Image.tsx +84 -56
- package/src/components/Image/ImageTypes.ts +22 -0
- package/src/components/Image/__snapshots__/Image.test.tsx.snap +190 -0
- package/src/components/Input/Input.stories.tsx +23 -67
- package/src/components/Input/Input.test.tsx +4 -4
- package/src/components/Input/_Input.scss +23 -14
- package/src/components/Link/Link.tsx +4 -1
- package/src/components/List/List.stories.mdx +124 -49
- package/src/components/List/List.test.tsx +142 -63
- package/src/components/List/List.tsx +89 -93
- package/src/components/List/__snapshots__/List.test.tsx.snap +109 -0
- package/src/components/Modal/Modal.stories.mdx +3 -3
- package/src/components/Modal/_Modal.scss +2 -2
- package/src/components/Notification/Notification.stories.mdx +109 -112
- package/src/components/Notification/Notification.test.tsx +99 -110
- package/src/components/Notification/Notification.tsx +156 -159
- package/src/components/Notification/__snapshots__/Notification.test.tsx.snap +159 -8
- package/src/components/Pagination/Pagination.stories.mdx +26 -27
- package/src/components/Pagination/Pagination.stories.tsx +11 -16
- package/src/components/Pagination/Pagination.test.tsx +276 -146
- package/src/components/Pagination/Pagination.tsx +174 -154
- package/src/components/Pagination/__snapshots__/Pagination.test.tsx.snap +285 -0
- package/src/components/ProgressIndicator/ProgressIndicator.stories.mdx +292 -0
- package/src/components/ProgressIndicator/ProgressIndicator.test.tsx +225 -0
- package/src/components/ProgressIndicator/ProgressIndicator.tsx +126 -0
- package/src/components/ProgressIndicator/ProgressIndicatorTypes.ts +8 -0
- package/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap +357 -0
- package/src/components/Radio/Radio.test.tsx +20 -4
- package/src/components/Radio/Radio.tsx +6 -3
- package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +3 -0
- package/src/components/RadioGroup/RadioGroup.stories.mdx +3 -4
- package/src/components/RadioGroup/RadioGroup.test.tsx +24 -1
- package/src/components/RadioGroup/RadioGroup.tsx +19 -19
- package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +42 -72
- package/src/components/SearchBar/SearchBar.Test.tsx +20 -1
- package/src/components/SearchBar/SearchBar.stories.mdx +113 -8
- package/src/components/SearchBar/SearchBar.tsx +20 -10
- package/src/components/Select/Select.test.tsx +12 -0
- package/src/components/Select/Select.tsx +5 -2
- package/src/components/Select/SelectTypes.tsx +1 -0
- package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +28 -59
- package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +97 -177
- package/src/components/SkeletonLoader/SkeletonLoader.tsx +74 -71
- package/src/components/SkeletonLoader/__snapshots__/SkeletonLoader.test.tsx.snap +739 -0
- package/src/components/Slider/Slider.stories.mdx +529 -0
- package/src/components/Slider/Slider.test.tsx +653 -0
- package/src/components/Slider/Slider.tsx +303 -0
- package/src/components/Slider/__snapshots__/Slider.test.tsx.snap +1946 -0
- package/src/components/StyleGuide/Bidirectionality.stories.mdx +1 -1
- package/src/components/StyleGuide/Breakpoints.stories.mdx +34 -10
- package/src/components/StyleGuide/Buttons.stories.mdx +89 -73
- package/src/components/StyleGuide/ColorCard.tsx +46 -0
- package/src/components/StyleGuide/Colors.stories.mdx +171 -311
- package/src/components/StyleGuide/DesignTokens.stories.mdx +170 -0
- package/src/components/StyleGuide/Forms.stories.mdx +9 -7
- package/src/components/StyleGuide/Iconography.stories.mdx +85 -91
- package/src/components/StyleGuide/Spacing.stories.mdx +31 -23
- package/src/components/StyleGuide/Typography.stories.mdx +202 -189
- package/src/components/StyleGuide/UIDocCard.tsx +1 -1
- package/src/components/Tabs/Tabs.stories.mdx +73 -11
- package/src/components/Tabs/Tabs.tsx +87 -64
- package/src/components/Template/Template.stories.mdx +25 -27
- package/src/components/TextInput/TextInput.stories.mdx +1 -1
- package/src/components/TextInput/TextInput.test.tsx +22 -2
- package/src/components/TextInput/TextInput.tsx +28 -8
- package/src/components/TextInput/TextInputTypes.tsx +2 -0
- package/src/components/VideoPlayer/VideoPlayer.stories.mdx +17 -4
- package/src/components/VideoPlayer/VideoPlayer.test.tsx +54 -53
- package/src/components/VideoPlayer/VideoPlayer.tsx +50 -51
- package/src/components/VideoPlayer/VideoPlayerTypes.tsx +2 -2
- package/src/components/VideoPlayer/__snapshots__/VideoPlayer.test.tsx.snap +91 -0
- package/src/docs/Chakra.stories.mdx +244 -63
- package/src/docs/Intro.stories.mdx +5 -2
- package/src/hooks/tests/useCarouselStyles.test.ts +140 -0
- package/src/hooks/tests/useNYPLTheme.test.tsx +36 -0
- package/src/hooks/useCarouselStyles.ts +34 -0
- package/src/hooks/useNYPLTheme.ts +67 -0
- package/src/hooks/useWindowSize.ts +40 -0
- package/src/index.ts +22 -19
- package/src/resources.scss +5 -5
- package/src/styles/base/{_02-breakpoints.scss → _01-breakpoints.scss} +9 -10
- package/src/styles/base/{_03-mixins.scss → _02-mixins.scss} +16 -5
- package/src/styles/base/{_04-base.scss → _03-base.scss} +7 -2
- package/src/styles/base/{_05-focus.scss → _04-focus.scss} +0 -15
- package/src/styles/base/_place-holder.scss +14 -3
- package/src/styles/{03-space → space}/_space-inline.scss +14 -14
- package/src/styles/{03-space → space}/_space-inset.scss +10 -10
- package/src/styles/space/_space-stack.scss +116 -0
- package/src/styles.scss +13 -60
- package/src/theme/components/button.ts +21 -15
- package/src/theme/components/card.ts +174 -0
- package/src/theme/components/checkbox.ts +8 -3
- package/src/theme/components/checkboxGroup.ts +8 -0
- package/src/theme/components/componentWrapper.ts +10 -0
- package/src/theme/components/datePicker.ts +17 -0
- package/src/theme/components/fieldset.ts +18 -0
- package/src/theme/components/global.ts +26 -15
- package/src/theme/components/globalMixins.ts +9 -1
- package/src/theme/components/heading.ts +10 -5
- package/src/theme/components/helperErrorText.ts +9 -0
- package/src/theme/components/hero.ts +4 -3
- package/src/theme/components/horizontalRule.ts +13 -0
- package/src/theme/components/icon.ts +9 -9
- package/src/theme/components/image.ts +116 -0
- package/src/theme/components/label.ts +3 -10
- package/src/theme/components/link.ts +5 -1
- package/src/theme/components/list.ts +73 -0
- package/src/theme/components/notification.ts +93 -0
- package/src/theme/components/pagination.ts +20 -0
- package/src/theme/components/progressIndicator.ts +62 -0
- package/src/theme/components/radio.ts +2 -2
- package/src/theme/components/radioGroup.ts +8 -0
- package/src/theme/components/select.ts +6 -3
- package/src/theme/components/skeletonLoader.ts +107 -0
- package/src/theme/components/slider.ts +79 -0
- package/src/theme/components/statusBadge.ts +1 -2
- package/src/theme/components/tabs.ts +49 -19
- package/src/theme/components/template.ts +8 -8
- package/src/theme/components/textInput.ts +5 -4
- package/src/theme/components/videoPlayer.ts +49 -0
- package/src/theme/foundations/breakpoints.ts +8 -8
- package/src/theme/foundations/global.ts +6 -1
- package/src/theme/foundations/radii.ts +6 -0
- package/src/theme/foundations/spacing.ts +24 -24
- package/src/theme/index.ts +41 -10
- package/src/utils/componentCategories.ts +4 -3
- package/dist/components/HelperErrorText/HelperErrorText.stories.d.ts +0 -16
- package/dist/components/Image/Image.stories.d.ts +0 -18
- package/dist/components/List/List.stories.d.ts +0 -7
- package/dist/theme/components/customCheckboxGroup.d.ts +0 -18
- package/dist/theme/components/customRadioGroup.d.ts +0 -18
- package/src/components/Button/_Button.scss +0 -32
- package/src/components/Card/_Card.scss +0 -308
- package/src/components/HelperErrorText/HelperErrorText.stories.tsx +0 -48
- package/src/components/HelperErrorText/_HelperErrorText.scss +0 -9
- package/src/components/HorizontalRule/_HorizontalRule.scss +0 -15
- package/src/components/Image/Image.stories.tsx +0 -54
- package/src/components/Image/_Image.scss +0 -38
- package/src/components/List/List.stories.tsx +0 -139
- package/src/components/List/_List.scss +0 -76
- package/src/components/Notification/_Notification.scss +0 -110
- package/src/components/Pagination/_Pagination.scss +0 -40
- package/src/components/SkeletonLoader/_SkeletonLoader.scss +0 -142
- package/src/components/VideoPlayer/_VideoPlayer.scss +0 -38
- package/src/styles/01-colors/_colors-brand.scss +0 -62
- package/src/styles/01-colors/_colors-utility.scss +0 -67
- package/src/styles/02-typography/_type-scale.css +0 -11
- package/src/styles/02-typography/_type-weight.css +0 -7
- package/src/styles/02-typography/_typefaces.css +0 -4
- package/src/styles/03-space/_space-stack.scss +0 -116
- package/src/styles/03-space/_space.css +0 -30
- package/src/styles/base/_card-grid.scss +0 -78
- package/src/styles/base/_typography.scss +0 -11
- package/src/theme/components/customCheckboxGroup.ts +0 -12
- package/src/theme/components/customRadioGroup.ts +0 -12
|
@@ -10,6 +10,7 @@ import { Meta } from "@storybook/addon-docs/blocks";
|
|
|
10
10
|
| 2. [DSProvider](#dsprovider) |
|
|
11
11
|
| 3. [Components](#components) |
|
|
12
12
|
| 4. [Styling](#styling) |
|
|
13
|
+
| 5. [Hooks](#hooks) |
|
|
13
14
|
| 5. [Testing](#testing) |
|
|
14
15
|
|
|
15
16
|
## Why Chakra UI?
|
|
@@ -37,19 +38,23 @@ We recommend to read Chakra's own [documentation](https://chakra-ui.com/docs/get
|
|
|
37
38
|
to get up to speed on it. This file will provide information on how it is used
|
|
38
39
|
in the DS but we rely on Chakra's documentation.
|
|
39
40
|
|
|
41
|
+
If you need help updating to a newer version of the NYPL Design System, check out
|
|
42
|
+
our [Chakra Migration Guide](https://github.com/NYPL/nypl-design-system/blob/development/CHAKRA_MIGRATION_GUIDE.md).
|
|
43
|
+
|
|
40
44
|
## DSProvider
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
In order to use DS components in a consuming application, there is a necessary
|
|
47
|
+
step that must be done for component styles to properly render. Consuming
|
|
48
|
+
applications need to wrap all the DS components with a simple provider
|
|
49
|
+
component. Fortunately, this only needs to be done once at the top level of the
|
|
50
|
+
consuming application.
|
|
47
51
|
|
|
48
52
|
Once the following is completed, DS components that internally use Chakra UI
|
|
49
53
|
will render styles properly. Internally, the `DSProvider` is built on top of
|
|
50
|
-
Chakra's `ChakraProvider` with NYPL's custom theme.
|
|
54
|
+
Chakra's `ChakraProvider` component with NYPL's custom theme as input. This sets
|
|
55
|
+
up the style context to propogate through all the children nodes in the DOM tree.
|
|
51
56
|
|
|
52
|
-
```
|
|
57
|
+
```tsx
|
|
53
58
|
// your main application file
|
|
54
59
|
import { DSProvider } from "@nypl/design-system-react-components";
|
|
55
60
|
|
|
@@ -76,14 +81,14 @@ appropriately. Unfortunately, this only works within the `Story` component.
|
|
|
76
81
|
When rendering components in documentation examples within a `Canvas` component,
|
|
77
82
|
wrap the elements in the `DSProvider` component.
|
|
78
83
|
|
|
79
|
-
```
|
|
84
|
+
```tsx
|
|
80
85
|
// These buttons are not a part of a "story" but still appear only
|
|
81
86
|
// in the documentation.
|
|
82
87
|
<Canvas>
|
|
83
88
|
<DSProvider>
|
|
84
89
|
<ButtonGroup>
|
|
85
|
-
<Button
|
|
86
|
-
<Button
|
|
90
|
+
<Button isDisabled={false}>Enabled</Button>
|
|
91
|
+
<Button isDisabled>Disabled</Button>
|
|
87
92
|
</ButtonGroup>
|
|
88
93
|
</DSProvider>
|
|
89
94
|
</Canvas>
|
|
@@ -91,12 +96,12 @@ wrap the elements in the `DSProvider` component.
|
|
|
91
96
|
|
|
92
97
|
## Components
|
|
93
98
|
|
|
94
|
-
|
|
95
|
-
components
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
Although Chakra is integrated into the DS repo, we are still working to compose
|
|
100
|
+
DS components with Chakra components or patterns. For example, both the DS and
|
|
101
|
+
Chakra have a `Button` component so we will use Chakra's `Button` component to
|
|
102
|
+
compose the DS `Button` component. However, the DS has a `Hero` component that
|
|
103
|
+
is not already built by Chakra. In this case, the DS `Hero` component will
|
|
104
|
+
internally use `Chakra` components such as `Box`.
|
|
100
105
|
|
|
101
106
|
### Components Composed with Chakra
|
|
102
107
|
|
|
@@ -111,14 +116,14 @@ components that internally are composed with Chakra components.
|
|
|
111
116
|
|
|
112
117
|
Components built from Chakra rename the component with the `Chakra` name prefix.
|
|
113
118
|
|
|
114
|
-
```
|
|
119
|
+
```tsx
|
|
115
120
|
import { Tabs as ChakraTabs, useStyleConfig } from "@chakra-ui/react";
|
|
116
121
|
```
|
|
117
122
|
|
|
118
123
|
In this example, the `ChakraTabs` component is returned with NYPL specific
|
|
119
124
|
functionality, styles, and other requirements.
|
|
120
125
|
|
|
121
|
-
```
|
|
126
|
+
```tsx
|
|
122
127
|
function Tabs(props) {
|
|
123
128
|
// ...
|
|
124
129
|
const styles = useStyleConfig("Tabs", { variant: props.tabsType });
|
|
@@ -136,12 +141,13 @@ function Tabs(props) {
|
|
|
136
141
|
|
|
137
142
|
#### Patterns
|
|
138
143
|
|
|
139
|
-
The NYPL DS uses the [CSS BEM](http://getbem.com/introduction/) pattern to
|
|
140
|
-
and write CSS
|
|
141
|
-
|
|
142
|
-
for a component with a class name,
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
The NYPL DS uses the [CSS BEM](http://getbem.com/introduction/) pattern to
|
|
145
|
+
structure and write CSS, but it is slowly being phased out. We are moving away
|
|
146
|
+
from this and re-writing SCSS classes into Javascript objects that work with
|
|
147
|
+
Chakra's theme. Instead of creating a variant for a component with a class name,
|
|
148
|
+
now different props or internal logic are used to get the appropriate variant.
|
|
149
|
+
Internally, the right variant will be mapped to a Chakra theme variant that will
|
|
150
|
+
provide all the necessary styles.
|
|
145
151
|
|
|
146
152
|
For the `Button` component, for example, we would convert a SCSS class rule such
|
|
147
153
|
as `.button-outline` to a Javascript object (more on this in the [Anatomy of a
|
|
@@ -152,25 +158,32 @@ Component Styling Object](#anatomy-of-a-component-styling-object) section).
|
|
|
152
158
|
Some components are directly exported from Chakra. These components can be found
|
|
153
159
|
in the `/src/index.ts` file. Note that not _all_ Chakra components are re-exported
|
|
154
160
|
because we want to limit what developers should use in consuming applications.
|
|
161
|
+
They include:
|
|
162
|
+
|
|
163
|
+
- `Box`, `Center`, `Circle`, `Grid`, `GridItem`, `HStack`, `Square`, `Stack`, `VStack`
|
|
155
164
|
|
|
156
165
|
Note: These components are harder to have snapshot tests for because, internally,
|
|
157
166
|
these components autogenerate ids and class names on every new render. We can't
|
|
158
167
|
override them so snapshot tests will fail.
|
|
159
168
|
|
|
169
|
+
Update: Newer Chakra UI versions have mostly fixed this issue. Still, since
|
|
170
|
+
Chakra components have already been tested, we don't necessarily want or need
|
|
171
|
+
to test them ourselves.
|
|
172
|
+
|
|
160
173
|
## Styling
|
|
161
174
|
|
|
162
175
|
As mentioned in the [Components composed with Chakra](#components-composed-with-chakra)
|
|
163
|
-
section, we are moving away from using the BEM structure to using Javascript
|
|
164
|
-
to extend Chakra's theme.
|
|
176
|
+
section, we are moving away from using the BEM structure to using Javascript
|
|
177
|
+
objects to extend Chakra's theme.
|
|
165
178
|
|
|
166
179
|
The NYPL DS' theme file can be found at `src/theme/index.ts`. This creates a new
|
|
167
180
|
theme that extends Chakra's theme and is set in the `DSProvider` component. Note
|
|
168
181
|
that the example below is the general structure of the `theme` object but the DS
|
|
169
182
|
`theme` object has values already set so it may look different. You would generally
|
|
170
|
-
only work and add new object values in the `components`
|
|
183
|
+
only work and add new object values in the `components` obejct key for new
|
|
171
184
|
components and their theme or variants.
|
|
172
185
|
|
|
173
|
-
```
|
|
186
|
+
```ts
|
|
174
187
|
const theme = extendTheme({
|
|
175
188
|
styles: { ... },
|
|
176
189
|
breakpoints: { ... },
|
|
@@ -191,7 +204,7 @@ For in-depth information, read Chakra's [Component Style documentation](https://
|
|
|
191
204
|
Component theme files can be found in the `src/theme/components/` directory.
|
|
192
205
|
Here is an example using the `Button` component.
|
|
193
206
|
|
|
194
|
-
```
|
|
207
|
+
```ts
|
|
195
208
|
// The basic structure for all component style objects.
|
|
196
209
|
const Button = {
|
|
197
210
|
baseStyle: {},
|
|
@@ -204,24 +217,26 @@ const Button = {
|
|
|
204
217
|
A current variant class rule can be converted to a Javascript object and go in
|
|
205
218
|
the `variants` object as in the following example.
|
|
206
219
|
|
|
207
|
-
```
|
|
220
|
+
```scss
|
|
208
221
|
// Button.scss
|
|
209
222
|
// This is the "Secondary" variant.
|
|
210
223
|
.button--outline {
|
|
211
224
|
@include button-base;
|
|
212
225
|
|
|
213
|
-
background-color: var(--ui-white);
|
|
214
|
-
border: 1px solid var(--ui-gray-light-cool);
|
|
226
|
+
background-color: var(--nypl-colors-ui-white);
|
|
227
|
+
border: 1px solid var(--nypl-colors-ui-gray-light-cool);
|
|
215
228
|
color: inherit;
|
|
216
229
|
|
|
217
230
|
&:hover {
|
|
218
|
-
background-color: var(--ui-gray-xx-light-cool);
|
|
231
|
+
background-color: var(--nypl-colors-ui-gray-xx-light-cool);
|
|
219
232
|
}
|
|
220
233
|
}
|
|
234
|
+
```
|
|
221
235
|
|
|
222
|
-
|
|
236
|
+
```ts
|
|
237
|
+
// button.ts
|
|
223
238
|
const Button = {
|
|
224
|
-
|
|
239
|
+
baseStyle: { ... },
|
|
225
240
|
sizes: { ... },
|
|
226
241
|
variants: {
|
|
227
242
|
secondary: {
|
|
@@ -241,13 +256,82 @@ const Button = {
|
|
|
241
256
|
|
|
242
257
|
Now this variant can be rendered:
|
|
243
258
|
|
|
244
|
-
```
|
|
259
|
+
```tsx
|
|
245
260
|
<Button buttonType={ButtonTypes.Secondary}>Press me</Button>
|
|
246
261
|
```
|
|
247
262
|
|
|
248
263
|
### Breakpoints
|
|
249
264
|
|
|
250
|
-
|
|
265
|
+
There are currently five (5) breakpoint values used in the DS:
|
|
266
|
+
|
|
267
|
+
| Key Name | EM/PX value |
|
|
268
|
+
| -------- | ----------- |
|
|
269
|
+
| sm | 20em/320px |
|
|
270
|
+
| md | 38em/600px |
|
|
271
|
+
| lg | 60em/960px |
|
|
272
|
+
| xl | 80em/1280px |
|
|
273
|
+
| 2xl | 96em/1536px |
|
|
274
|
+
|
|
275
|
+
There are two ways to set breakpoint values for a style rule: the array method
|
|
276
|
+
and the object method. We prefer the object method and recommend to use the
|
|
277
|
+
object method since it is easier to read and readily know what values take
|
|
278
|
+
effect at defined breakpoint values. Note that the Chakra `"base"` key value is
|
|
279
|
+
the same as `"sm"`.
|
|
280
|
+
|
|
281
|
+
#### Object Method
|
|
282
|
+
|
|
283
|
+
We recommend and follow this pattern in the DS. As an example, let's say we want
|
|
284
|
+
to increase the width of the `Button` component as the device width increases.
|
|
285
|
+
We start at value "100px" and increase by "50px" at every breakpoint. In the
|
|
286
|
+
`button.ts` style file, we can define it as in the example below:
|
|
287
|
+
|
|
288
|
+
```ts
|
|
289
|
+
// button.ts
|
|
290
|
+
const Button = {
|
|
291
|
+
baseStyle: {
|
|
292
|
+
width: {
|
|
293
|
+
base: "100px",
|
|
294
|
+
md: "150px",
|
|
295
|
+
lg: "200px",
|
|
296
|
+
xl: "250px",
|
|
297
|
+
"2xl": "300px",
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
// ...
|
|
301
|
+
};
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
You do not have to define every breakpoint. If you only want to change the width
|
|
305
|
+
of the `Button` at the `lg` breakpoint, it can be defined as:
|
|
306
|
+
|
|
307
|
+
```ts
|
|
308
|
+
// button.ts
|
|
309
|
+
const Button = {
|
|
310
|
+
baseStyle: {
|
|
311
|
+
width: {
|
|
312
|
+
base: "100px",
|
|
313
|
+
lg: "200px",
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
// ...
|
|
317
|
+
};
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
#### Array Method
|
|
321
|
+
|
|
322
|
+
We do not recommend this pattern because it is harder to read and implicit on
|
|
323
|
+
breakpoint values. Following the same example as the one above, the width of the
|
|
324
|
+
`Button` component can be updated wiht all five values in an array:
|
|
325
|
+
|
|
326
|
+
```ts
|
|
327
|
+
// button.ts
|
|
328
|
+
const Button = {
|
|
329
|
+
baseStyle: {
|
|
330
|
+
width: ["100px", "150px", "200px", "250px", "300px"],
|
|
331
|
+
},
|
|
332
|
+
// ...
|
|
333
|
+
};
|
|
334
|
+
```
|
|
251
335
|
|
|
252
336
|
### Colors
|
|
253
337
|
|
|
@@ -255,7 +339,7 @@ All available colors can be found in `src/theme/foundations/colors.ts`. Chakra
|
|
|
255
339
|
autogenerates the `colors` object into CSS variables. We will rely on these
|
|
256
340
|
variables rather than creating our own.
|
|
257
341
|
|
|
258
|
-
```
|
|
342
|
+
```tsx
|
|
259
343
|
const colors: Colors = {
|
|
260
344
|
// ui fills
|
|
261
345
|
ui: {
|
|
@@ -280,17 +364,13 @@ const colors: Colors = {
|
|
|
280
364
|
|
|
281
365
|
In the shorten object example above, the following will be generated by Chakra:
|
|
282
366
|
|
|
283
|
-
| Theme object value | CSS variable
|
|
284
|
-
| -------------------------------------- |
|
|
285
|
-
| `colors.ui.focus` | `--
|
|
286
|
-
| `colors.ui.link.primary` | `--
|
|
287
|
-
| `colors.ui.link.secondary` | `--
|
|
288
|
-
| `colors.section["whats-on"].primary` | `--
|
|
289
|
-
| `colors.section["whats-on"].secondary` | `--
|
|
290
|
-
|
|
291
|
-
The current prefix is `--chakra` but we expect to update that soon. DS specified
|
|
292
|
-
CSS variables are still exported but we will remove those in favor of the CSS
|
|
293
|
-
variables provided by Chakra for ease of use.
|
|
367
|
+
| Theme object value | CSS variable |
|
|
368
|
+
| -------------------------------------- | ------------------------------------------ |
|
|
369
|
+
| `colors.ui.focus` | `--nypl-colors-ui-focus` |
|
|
370
|
+
| `colors.ui.link.primary` | `--nypl-colors-ui-link-primary` |
|
|
371
|
+
| `colors.ui.link.secondary` | `--nypl-colors-ui-link-secondary` |
|
|
372
|
+
| `colors.section["whats-on"].primary` | `--nypl-colors-section-whats-on-primary` |
|
|
373
|
+
| `colors.section["whats-on"].secondary` | `--nypl-colors-section-whats-on-secondary` |
|
|
294
374
|
|
|
295
375
|
Note: while each Chakra color has number range values from 50 to 900 (such as
|
|
296
376
|
`red.400`, `blue.600`, etc) and each one is based on the color coming from
|
|
@@ -301,16 +381,16 @@ DS' Figma documentation, we recommend NOT to use them.
|
|
|
301
381
|
All the spacing values can be found in the `src/theme/foundations/spacing.ts`
|
|
302
382
|
file. While Chakra provides many values, only use the eight DS defined values.
|
|
303
383
|
|
|
304
|
-
| Chakra Value | DS Variable
|
|
305
|
-
| ------------ |
|
|
306
|
-
| 1 | --space-xxs
|
|
307
|
-
| 2 | --space-xs
|
|
308
|
-
| 4 | --space-s
|
|
309
|
-
| 6 | --space-m
|
|
310
|
-
| 8 | --space-l
|
|
311
|
-
| 12 | --space-xl
|
|
312
|
-
| 16 | --space-xxl
|
|
313
|
-
| 24 | --space-
|
|
384
|
+
| NYPL name Value | Chakra Value | DS Variable |
|
|
385
|
+
| --------------- | ------------ | ----------------- |
|
|
386
|
+
| xxs | 1 | --nypl-space-xxs |
|
|
387
|
+
| xs | 2 | --nypl-space-xs |
|
|
388
|
+
| s | 4 | --nypl-space-s |
|
|
389
|
+
| m | 6 | --nypl-space-m |
|
|
390
|
+
| l | 8 | --nypl-space-l |
|
|
391
|
+
| xl | 12 | --nypl-space-xl |
|
|
392
|
+
| xxl | 16 | --nypl-space-xxl |
|
|
393
|
+
| xxxl | 24 | --nypl-space-xxxl |
|
|
314
394
|
|
|
315
395
|
For example, to make all `button`s have a `padding: 8px 16px` value:
|
|
316
396
|
|
|
@@ -318,8 +398,8 @@ For example, to make all `button`s have a `padding: 8px 16px` value:
|
|
|
318
398
|
// src/theme/components/button.ts
|
|
319
399
|
const Button = {
|
|
320
400
|
baseStyle: {
|
|
321
|
-
py:
|
|
322
|
-
px:
|
|
401
|
+
py: "xs", // var(--nypl-space-xs) which results in a value of 8px or 0.5rem.
|
|
402
|
+
px: "s", // var(--nypl-space-s) which results in a value of 16px or 1rem.
|
|
323
403
|
// ... other styles
|
|
324
404
|
},
|
|
325
405
|
sizes: { ... },
|
|
@@ -334,8 +414,109 @@ All typography values can be found in the `src/theme/foundations/typography.ts`
|
|
|
334
414
|
file. These values declare the font family, font sizes, and font weights to use
|
|
335
415
|
for all text.
|
|
336
416
|
|
|
417
|
+
## Hooks
|
|
418
|
+
|
|
419
|
+
The following hooks are available to use and can be imported from
|
|
420
|
+
`@nypl/design-system-react-components`.
|
|
421
|
+
|
|
422
|
+
### useNYPLTheme
|
|
423
|
+
|
|
424
|
+
If your application does not use CSS or SCSS files and you want to write
|
|
425
|
+
CSS-in-JS styles in your React components, the `useNYPLTheme` hook will provide
|
|
426
|
+
you with NYPL-specific style values. This hook depends on the `DSProvider`
|
|
427
|
+
component and if the function is used outside of this wrapper component, then
|
|
428
|
+
the theme object will be empty.
|
|
429
|
+
|
|
430
|
+
After importing and rendering the `DSProvider` wrapper component, as explained
|
|
431
|
+
in the [DSProvider](#dsprovider) section, your children components can use this
|
|
432
|
+
hook function.
|
|
433
|
+
|
|
434
|
+
```tsx
|
|
435
|
+
import { useNYPLTheme } from "@nypl/design-system-react-components";
|
|
436
|
+
// ...
|
|
437
|
+
|
|
438
|
+
const theme = useNYPLTheme();
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
The `theme` variable will be a JS object with style values discussed in the
|
|
442
|
+
sections above. This will allow you to use NYPL-specific styles in your
|
|
443
|
+
components through CSS-in-JS.
|
|
444
|
+
|
|
445
|
+
```ts
|
|
446
|
+
// theme:
|
|
447
|
+
{
|
|
448
|
+
breakpoints: { ... },
|
|
449
|
+
colors: {
|
|
450
|
+
brand: { ... },
|
|
451
|
+
section: { ... },
|
|
452
|
+
transparent: { ... },
|
|
453
|
+
ui: { ... },
|
|
454
|
+
},
|
|
455
|
+
fontSizes: { ... },
|
|
456
|
+
fontWeights: { ... },
|
|
457
|
+
fonts: { ... },
|
|
458
|
+
radii: { ... },
|
|
459
|
+
space: { ... },
|
|
460
|
+
}
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
#### Usage
|
|
464
|
+
|
|
465
|
+
_Note: more patterns will be added._
|
|
466
|
+
|
|
467
|
+
1. NYPL DS Components
|
|
468
|
+
|
|
469
|
+
All DS components _should_ be used with their current styles. If a DS component
|
|
470
|
+
needs an updated style, first contact the Design System and UX teams about this
|
|
471
|
+
update. If you really _need_ to update a style and there is no available
|
|
472
|
+
variant, then you can add styles directly to the `additionalStyles` prop. At the
|
|
473
|
+
moment, not all DS components have this prop or feature.
|
|
474
|
+
|
|
475
|
+
For example, if the `Heading` component should render the text in NYPL's green
|
|
476
|
+
color used for "success primary" and add a bold font weight, then you can do
|
|
477
|
+
the following:
|
|
478
|
+
|
|
479
|
+
```tsx
|
|
480
|
+
const theme = useNYPLTheme();
|
|
481
|
+
|
|
482
|
+
// ...
|
|
483
|
+
return (
|
|
484
|
+
<div>
|
|
485
|
+
<Heading
|
|
486
|
+
level={2}
|
|
487
|
+
additionalStyles={{
|
|
488
|
+
color: theme.colors.ui.sucess.primary,
|
|
489
|
+
fontWeight: theme.fontWeights.bold,
|
|
490
|
+
}}
|
|
491
|
+
>
|
|
492
|
+
Get a Digital Library Card Today in a Few Easy Steps
|
|
493
|
+
</Heading>
|
|
494
|
+
|
|
495
|
+
{/* Other components */}
|
|
496
|
+
</div>
|
|
497
|
+
);
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
Of course, you can destructure the `theme` object to only get the object keys
|
|
501
|
+
you need for your component (this is a general example). Log the object to the
|
|
502
|
+
console to see all the available styles.
|
|
503
|
+
|
|
504
|
+
2. HTML Components
|
|
505
|
+
|
|
506
|
+
Use the `style` attribute in HTML components to add inline styles.
|
|
507
|
+
|
|
508
|
+
```tsx
|
|
509
|
+
<p style={{ color: theme.colors.ui.success.primary }}>
|
|
510
|
+
If you are 13 or older and live, work, attend school, or pay property taxes in
|
|
511
|
+
New York State, you can get a free digital library card right now using this
|
|
512
|
+
online form. Visitors to New York State can also use this form to apply for a
|
|
513
|
+
temporary card.
|
|
514
|
+
</p>
|
|
515
|
+
```
|
|
516
|
+
|
|
337
517
|
## Testing
|
|
338
518
|
|
|
339
519
|
Do not re-test Chakra components that are re-exported since they are already
|
|
340
|
-
tested in the `@chakra-ui/react` package. We do expect all new components
|
|
341
|
-
from Chakra to have tests for functionality and styling
|
|
520
|
+
tested in the `@chakra-ui/react` package. We do expect all new components
|
|
521
|
+
composed from Chakra to have tests for functionality and styling
|
|
522
|
+
(such as snapshots).
|
|
@@ -10,6 +10,9 @@ import DSProvider from "../theme/provider";
|
|
|
10
10
|
|
|
11
11
|
# NYPL Design System
|
|
12
12
|
|
|
13
|
+
export const heroBackgroundColor = `var(--nypl-colors-section-books-and-more-primary)`;
|
|
14
|
+
export const heroForegroundColor = `var(--nypl-colors-ui-white)`;
|
|
15
|
+
|
|
13
16
|
<DSProvider>
|
|
14
17
|
<Hero
|
|
15
18
|
heroType={HeroTypes.FiftyFifty}
|
|
@@ -20,8 +23,8 @@ import DSProvider from "../theme/provider";
|
|
|
20
23
|
alt=""
|
|
21
24
|
/>
|
|
22
25
|
}
|
|
23
|
-
backgroundColor={
|
|
24
|
-
foregroundColor={
|
|
26
|
+
backgroundColor={heroBackgroundColor}
|
|
27
|
+
foregroundColor={heroForegroundColor}
|
|
25
28
|
/>
|
|
26
29
|
</DSProvider>
|
|
27
30
|
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { renderHook, act } from "@testing-library/react-hooks";
|
|
2
|
+
import useCarouselStyles from "../useCarouselStyles";
|
|
3
|
+
|
|
4
|
+
describe("useCarouselStyles hook", () => {
|
|
5
|
+
it("returns two functions and a CSS style object", () => {
|
|
6
|
+
const { result } = renderHook(() => useCarouselStyles());
|
|
7
|
+
|
|
8
|
+
expect(typeof result.current.nextSlide).toEqual("function");
|
|
9
|
+
expect(typeof result.current.prevSlide).toEqual("function");
|
|
10
|
+
expect(result.current.carouselStyle).toEqual({
|
|
11
|
+
marginLeft: "-0%",
|
|
12
|
+
transition: "all .5s",
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("updates the style object when the nextSlide function is clicked", () => {
|
|
17
|
+
// Mocking we have an array of five slides.
|
|
18
|
+
const slides = [1, 2, 3, 4, 5];
|
|
19
|
+
const { result } = renderHook(() => useCarouselStyles(slides.length));
|
|
20
|
+
const nextSlide = result.current.nextSlide;
|
|
21
|
+
|
|
22
|
+
// Start at the first slide.
|
|
23
|
+
expect(result.current.carouselStyle).toEqual({
|
|
24
|
+
marginLeft: "-0%",
|
|
25
|
+
transition: "all .5s",
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
act(() => nextSlide());
|
|
29
|
+
// Each slide takes up a width of 100% by default.
|
|
30
|
+
// So now we move by 100% to the left for the next slide.
|
|
31
|
+
expect(result.current.carouselStyle).toEqual({
|
|
32
|
+
marginLeft: "-100%",
|
|
33
|
+
transition: "all .5s",
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
act(() => nextSlide());
|
|
37
|
+
// Move on to the next slide.
|
|
38
|
+
expect(result.current.carouselStyle).toEqual({
|
|
39
|
+
marginLeft: "-200%",
|
|
40
|
+
transition: "all .5s",
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// We now click through all five slides and we expect to wrap around
|
|
44
|
+
// back to the first slide which starts at "-0%" (the negative value
|
|
45
|
+
// is set for direction but -0 is still 0).
|
|
46
|
+
act(() => nextSlide());
|
|
47
|
+
act(() => nextSlide());
|
|
48
|
+
act(() => nextSlide());
|
|
49
|
+
expect(result.current.carouselStyle).toEqual({
|
|
50
|
+
marginLeft: "-0%",
|
|
51
|
+
transition: "all .5s",
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("updates the style object when the prevSlide function is clicked", () => {
|
|
56
|
+
// Mocking we have an array of five slides.
|
|
57
|
+
const slides = [1, 2, 3, 4, 5];
|
|
58
|
+
const { result } = renderHook(() => useCarouselStyles(slides.length));
|
|
59
|
+
const prevSlide = result.current.prevSlide;
|
|
60
|
+
|
|
61
|
+
// Start at the first slide.
|
|
62
|
+
expect(result.current.carouselStyle).toEqual({
|
|
63
|
+
marginLeft: "-0%",
|
|
64
|
+
transition: "all .5s",
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
act(() => prevSlide());
|
|
68
|
+
// We started on the first slide and nwo we expect to wrap around
|
|
69
|
+
// to the last element.
|
|
70
|
+
expect(result.current.carouselStyle).toEqual({
|
|
71
|
+
marginLeft: "-400%",
|
|
72
|
+
transition: "all .5s",
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
act(() => prevSlide());
|
|
76
|
+
// Move on to the previous slide.
|
|
77
|
+
expect(result.current.carouselStyle).toEqual({
|
|
78
|
+
marginLeft: "-300%",
|
|
79
|
+
transition: "all .5s",
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// We now clicked through all five slides and we expect to
|
|
83
|
+
// be at the first slide.
|
|
84
|
+
act(() => prevSlide());
|
|
85
|
+
act(() => prevSlide());
|
|
86
|
+
act(() => prevSlide());
|
|
87
|
+
expect(result.current.carouselStyle).toEqual({
|
|
88
|
+
marginLeft: "-0%",
|
|
89
|
+
transition: "all .5s",
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("resets the slide back to the first slide", () => {
|
|
94
|
+
// Mocking we have an array of five slides.
|
|
95
|
+
const slides = [1, 2, 3, 4, 5];
|
|
96
|
+
const { result } = renderHook(() => useCarouselStyles(slides.length));
|
|
97
|
+
const { nextSlide, goToStart } = result.current;
|
|
98
|
+
|
|
99
|
+
// Start at the first slide.
|
|
100
|
+
expect(result.current.carouselStyle).toEqual({
|
|
101
|
+
marginLeft: "-0%",
|
|
102
|
+
transition: "all .5s",
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Move on to the third slide.
|
|
106
|
+
act(() => nextSlide());
|
|
107
|
+
act(() => nextSlide());
|
|
108
|
+
act(() => nextSlide());
|
|
109
|
+
expect(result.current.carouselStyle).toEqual({
|
|
110
|
+
marginLeft: "-300%",
|
|
111
|
+
transition: "all .5s",
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
act(() => goToStart());
|
|
115
|
+
expect(result.current.carouselStyle).toEqual({
|
|
116
|
+
marginLeft: "-0%",
|
|
117
|
+
transition: "all .5s",
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("can set a custom slide count and slide width", () => {
|
|
122
|
+
const slides = [1, 2, 3];
|
|
123
|
+
const slideWidth = 50;
|
|
124
|
+
const { result } = renderHook(() =>
|
|
125
|
+
useCarouselStyles(slides.length, slideWidth)
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
expect(result.current.carouselStyle).toEqual({
|
|
129
|
+
marginLeft: "-0%",
|
|
130
|
+
transition: "all .5s",
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
act(() => result.current.nextSlide());
|
|
134
|
+
// Since each slide is of length 50, we expect to move by a 50%.
|
|
135
|
+
expect(result.current.carouselStyle).toEqual({
|
|
136
|
+
marginLeft: "-50%",
|
|
137
|
+
transition: "all .5s",
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
3
|
+
|
|
4
|
+
import useNYPLTheme from "../useNYPLTheme";
|
|
5
|
+
import DSProvider from "../../theme/provider";
|
|
6
|
+
|
|
7
|
+
describe("useNYPLTheme", () => {
|
|
8
|
+
it("returns an empty object when not used inside a DSProvider component", () => {
|
|
9
|
+
const warn = jest.spyOn(console, "warn");
|
|
10
|
+
const { result } = renderHook(() => useNYPLTheme());
|
|
11
|
+
|
|
12
|
+
expect(warn).toHaveBeenCalledWith(
|
|
13
|
+
"The `useNYPLTheme` hook must be used inside of `<DSProvider />`."
|
|
14
|
+
);
|
|
15
|
+
expect(result.current).toEqual({});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("returns an object with NYPL styles", () => {
|
|
19
|
+
const { result } = renderHook(() => useNYPLTheme(), {
|
|
20
|
+
wrapper: ({ children }) => <DSProvider>{children}</DSProvider>,
|
|
21
|
+
});
|
|
22
|
+
const allKeys = Object.keys(result.current);
|
|
23
|
+
const colorsKeys = Object.keys(result.current.colors);
|
|
24
|
+
|
|
25
|
+
expect(allKeys).toEqual([
|
|
26
|
+
"breakpoints",
|
|
27
|
+
"colors",
|
|
28
|
+
"fontSizes",
|
|
29
|
+
"fontWeights",
|
|
30
|
+
"fonts",
|
|
31
|
+
"radii",
|
|
32
|
+
"space",
|
|
33
|
+
]);
|
|
34
|
+
expect(colorsKeys).toEqual(["brand", "section", "transparent", "ui"]);
|
|
35
|
+
});
|
|
36
|
+
});
|