@nypl/design-system-react-components 0.25.0 → 0.25.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/dist/components/Accordion/Accordion.d.ts +14 -14
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +11 -14
- package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +6 -0
- package/dist/components/Button/ButtonTypes.d.ts +2 -1
- package/dist/components/Card/Card.d.ts +1 -1
- package/dist/components/Card/CardTypes.d.ts +2 -2
- package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +43 -0
- package/dist/components/CheckboxGroup/CheckboxGroupLayoutTypes.d.ts +4 -0
- package/dist/components/DatePicker/DatePicker.d.ts +3 -3
- package/dist/components/Form/Form.d.ts +13 -8
- package/dist/components/Form/FormTypes.d.ts +2 -8
- package/dist/components/Grid/GridTypes.d.ts +9 -0
- package/dist/components/Grid/SimpleGrid.d.ts +14 -0
- package/dist/components/Heading/Heading.d.ts +4 -4
- package/dist/components/Hero/Hero.d.ts +19 -14
- package/dist/components/Hero/HeroTypes.d.ts +10 -5
- package/dist/components/Icons/Icon.d.ts +13 -16
- package/dist/components/Icons/IconTypes.d.ts +78 -64
- package/dist/components/Label/Label.d.ts +5 -17
- package/dist/components/Link/Link.d.ts +8 -12
- package/dist/components/SearchBar/SearchBar.d.ts +45 -27
- package/dist/components/Select/Select.d.ts +32 -35
- package/dist/components/Select/SelectTypes.d.ts +4 -0
- package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +1 -1
- package/dist/components/SkeletonLoader/SkeletonLoaderTypes.d.ts +2 -2
- package/dist/components/StatusBadge/StatusBadge.d.ts +8 -6
- package/dist/components/StatusBadge/StatusBadgeTypes.d.ts +5 -0
- package/dist/components/Template/Template.d.ts +91 -0
- package/dist/components/Text/Text.d.ts +16 -0
- package/dist/components/Text/TextTypes.d.ts +6 -0
- package/dist/components/TextInput/TextInput.d.ts +32 -31
- package/dist/components/TextInput/TextInputTypes.d.ts +5 -0
- package/dist/design-system-react-components.cjs.development.js +2597 -1170
- 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 +2580 -1173
- package/dist/design-system-react-components.esm.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/styles.css +1 -1
- package/dist/theme/components/accordion.d.ts +25 -0
- package/dist/theme/components/breadcrumb.d.ts +90 -0
- package/dist/theme/components/button.d.ts +17 -7
- package/dist/theme/components/checkbox.d.ts +7 -7
- package/dist/theme/components/customCheckboxGroup.d.ts +18 -0
- package/dist/theme/components/customRadioGroup.d.ts +4 -3
- package/dist/theme/components/global.d.ts +55 -0
- package/dist/theme/components/globalMixins.d.ts +15 -0
- package/dist/theme/components/heading.d.ts +50 -20
- package/dist/theme/components/hero.d.ts +492 -0
- package/dist/theme/components/icon.d.ts +13 -0
- package/dist/theme/components/label.d.ts +16 -0
- package/dist/theme/components/link.d.ts +45 -0
- package/dist/theme/components/radio.d.ts +8 -7
- package/dist/theme/components/searchBar.d.ts +20 -0
- package/dist/theme/components/select.d.ts +58 -0
- package/dist/theme/components/statusBadge.d.ts +25 -0
- package/dist/theme/components/tabs.d.ts +9 -9
- package/dist/theme/components/template.d.ts +105 -0
- package/dist/theme/components/text.d.ts +20 -0
- package/dist/theme/components/textInput.d.ts +105 -0
- package/dist/theme/foundations/global.d.ts +3 -0
- package/dist/theme/foundations/shadows.d.ts +4 -0
- package/dist/utils/utils.d.ts +6 -0
- package/package.json +3 -2
- package/src/components/Accordion/Accordion.stories.mdx +227 -33
- package/src/components/Accordion/Accordion.test.tsx +135 -19
- package/src/components/Accordion/Accordion.tsx +81 -56
- package/src/components/Autosuggest/Autosuggest.stories.mdx +1 -1
- package/src/components/Autosuggest/Autosuggest.stories.tsx +1 -1
- package/src/components/Autosuggest/_Autosuggest.scss +2 -2
- package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +46 -52
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +31 -25
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +71 -73
- package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +6 -0
- package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +100 -0
- package/src/components/Button/Button.stories.mdx +31 -27
- package/src/components/Button/Button.test.tsx +17 -5
- package/src/components/Button/ButtonTypes.tsx +1 -0
- package/src/components/Button/_Button.scss +3 -27
- package/src/components/Button/__snapshots__/Button.test.tsx.snap +11 -0
- package/src/components/Card/Card.stories.mdx +24 -20
- package/src/components/Card/Card.test.tsx +13 -19
- package/src/components/Card/Card.tsx +1 -1
- package/src/components/Card/CardTypes.tsx +2 -2
- package/src/components/Card/_Card.scss +1 -1
- package/src/components/CardEdition/CardEdition.stories.tsx +11 -6
- package/src/components/CardEdition/CardEdition.test.tsx +23 -31
- package/src/components/CardEdition/_CardEdition.scss +2 -2
- package/src/components/Chakra/Center.stories.mdx +31 -14
- package/src/components/Chakra/Grid.stories.mdx +79 -0
- package/src/components/Chakra/Stack.stories.mdx +4 -4
- package/src/components/Checkbox/Checkbox.tsx +9 -12
- package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +2 -5
- package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +249 -0
- package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +345 -0
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +148 -0
- package/src/components/CheckboxGroup/CheckboxGroupLayoutTypes.tsx +4 -0
- package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +1360 -0
- package/src/components/DatePicker/DatePicker.test.tsx +4 -4
- package/src/components/DatePicker/DatePicker.tsx +13 -13
- package/src/components/DatePicker/_DatePicker.scss +1 -0
- package/src/components/Form/Form.stories.mdx +46 -21
- package/src/components/Form/Form.test.tsx +58 -45
- package/src/components/Form/Form.tsx +49 -21
- package/src/components/Form/FormTypes.tsx +3 -8
- package/src/components/Form/__snapshots__/Form.test.tsx.snap +24 -14
- package/src/components/Grid/GridTypes.tsx +9 -0
- package/src/components/Grid/SimpleGrid.stories.mdx +275 -0
- package/src/components/Grid/SimpleGrid.test.tsx +66 -0
- package/src/components/Grid/SimpleGrid.tsx +37 -0
- package/src/components/Grid/__snapshots__/SimpleGrid.test.tsx.snap +8 -0
- package/src/components/Heading/Heading.stories.mdx +1 -0
- package/src/components/Heading/Heading.tsx +12 -6
- package/src/components/HelperErrorText/_HelperErrorText.scss +1 -1
- package/src/components/Hero/Hero.stories.mdx +188 -121
- package/src/components/Hero/Hero.test.tsx +537 -107
- package/src/components/Hero/Hero.tsx +79 -92
- package/src/components/Hero/HeroTypes.tsx +17 -5
- package/src/components/Hero/__snapshots__/Hero.test.tsx.snap +307 -0
- package/src/components/HorizontalRule/_HorizontalRule.scss +1 -1
- package/src/components/Icons/Icon.stories.mdx +83 -74
- package/src/components/Icons/Icon.test.tsx +30 -22
- package/src/components/Icons/Icon.tsx +63 -61
- package/src/components/Icons/IconTypes.tsx +80 -64
- package/src/components/Input/_Input.scss +2 -2
- package/src/components/Label/Label.stories.mdx +28 -7
- package/src/components/Label/Label.test.tsx +43 -12
- package/src/components/Label/Label.tsx +21 -34
- package/src/components/Label/__snapshots__/Label.test.tsx.snap +41 -0
- package/src/components/Link/Link.stories.mdx +41 -41
- package/src/components/Link/Link.test.tsx +33 -44
- package/src/components/Link/Link.tsx +114 -100
- package/src/components/List/List.stories.mdx +0 -2
- package/src/components/List/List.stories.tsx +5 -5
- package/src/components/List/_List.scss +3 -3
- package/src/components/Modal/_Modal.scss +1 -1
- package/src/components/Notification/Notification.stories.mdx +12 -1
- package/src/components/Notification/Notification.test.tsx +3 -16
- package/src/components/Notification/Notification.tsx +9 -10
- package/src/components/Notification/_Notification.scss +4 -4
- package/src/components/Pagination/Pagination.test.tsx +16 -10
- package/src/components/RadioGroup/RadioGroup.stories.mdx +1 -1
- package/src/components/RadioGroup/RadioGroup.tsx +2 -10
- package/src/components/SearchBar/SearchBar.Test.tsx +151 -16
- package/src/components/SearchBar/SearchBar.stories.mdx +189 -219
- package/src/components/SearchBar/SearchBar.tsx +151 -46
- package/src/components/Select/Select.stories.mdx +188 -170
- package/src/components/Select/Select.test.tsx +125 -380
- package/src/components/Select/Select.tsx +118 -165
- package/src/components/Select/SelectTypes.tsx +4 -0
- package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +13 -25
- package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +7 -7
- package/src/components/SkeletonLoader/SkeletonLoader.tsx +4 -2
- package/src/components/SkeletonLoader/SkeletonLoaderTypes.tsx +2 -2
- package/src/components/SkeletonLoader/_SkeletonLoader.scss +3 -3
- package/src/components/StatusBadge/StatusBadge.stories.mdx +91 -0
- package/src/components/StatusBadge/StatusBadge.test.tsx +35 -7
- package/src/components/StatusBadge/StatusBadge.tsx +24 -25
- package/src/components/StatusBadge/StatusBadgeTypes.tsx +5 -0
- package/src/components/StatusBadge/__snapshots__/StatusBadge.test.tsx.snap +28 -0
- package/src/components/StyleGuide/Bidirectionality.stories.mdx +16 -16
- package/src/components/StyleGuide/Buttons.stories.mdx +15 -15
- package/src/components/StyleGuide/Colors.stories.mdx +336 -0
- package/src/components/StyleGuide/Iconography.stories.mdx +88 -90
- package/src/components/StyleGuide/UIDocCard.tsx +1 -1
- package/src/components/Tabs/Tabs.tsx +7 -9
- package/src/components/Template/Template.stories.mdx +574 -0
- package/src/components/Template/Template.test.tsx +124 -0
- package/src/components/Template/Template.tsx +226 -0
- package/src/components/Text/Text.stories.mdx +70 -0
- package/src/components/Text/Text.test.tsx +63 -0
- package/src/components/Text/Text.tsx +55 -0
- package/src/components/Text/TextTypes.tsx +6 -0
- package/src/components/Text/__snapshots__/Text.test.tsx.snap +33 -0
- package/src/components/TextInput/TextInput.stories.mdx +89 -90
- package/src/components/TextInput/TextInput.test.tsx +65 -86
- package/src/components/TextInput/TextInput.tsx +101 -95
- package/src/components/TextInput/TextInputTypes.tsx +6 -0
- package/src/components/VideoPlayer/_VideoPlayer.scss +1 -1
- package/src/docs/Chakra.stories.mdx +4 -4
- package/src/docs/Intro.stories.mdx +15 -13
- package/src/index.ts +20 -0
- package/src/styles/01-colors/_colors-brand.scss +6 -0
- package/src/styles/01-colors/_colors-utility.scss +14 -12
- package/src/styles/base/_04-base.scss +2 -1
- package/src/styles/base/_place-holder.scss +1 -1
- package/src/styles.scss +10 -12
- package/src/theme/components/accordion.ts +30 -0
- package/src/theme/components/breadcrumb.ts +77 -0
- package/src/theme/components/button.ts +77 -63
- package/src/theme/components/checkbox.ts +15 -27
- package/src/theme/components/customCheckboxGroup.ts +12 -0
- package/src/theme/components/customRadioGroup.ts +4 -10
- package/src/theme/components/global.ts +71 -0
- package/src/theme/components/globalMixins.ts +16 -0
- package/src/theme/components/heading.ts +15 -8
- package/src/theme/components/hero.ts +239 -0
- package/src/theme/components/icon.ts +79 -0
- package/src/theme/components/label.ts +17 -0
- package/src/theme/components/link.ts +47 -0
- package/src/theme/components/radio.ts +20 -31
- package/src/theme/components/searchBar.ts +21 -0
- package/src/theme/components/select.ts +50 -0
- package/src/theme/components/statusBadge.ts +27 -0
- package/src/theme/components/tabs.ts +72 -69
- package/src/theme/components/template.ts +114 -0
- package/src/theme/components/text.ts +31 -0
- package/src/theme/components/textInput.ts +61 -0
- package/src/theme/foundations/colors.ts +29 -13
- package/src/theme/foundations/global.ts +3 -0
- package/src/theme/foundations/shadows.ts +5 -0
- package/src/theme/index.ts +37 -7
- package/src/utils/componentCategories.ts +8 -2
- package/src/utils/utils.ts +13 -0
- package/dist/components/Accordion/Accordion.stories.d.ts +0 -6
- package/dist/components/StatusBadge/StatusBadge.stories.d.ts +0 -8
- package/dist/components/StyleGuide/Colors.stories.d.ts +0 -25
- package/dist/components/Template/Template.stories.d.ts +0 -30
- package/src/components/Accordion/Accordion.stories.tsx +0 -66
- package/src/components/Accordion/_Accordion.scss +0 -81
- package/src/components/Breadcrumbs/_Breadcrumbs.scss +0 -97
- package/src/components/Form/_Form.scss +0 -67
- package/src/components/Hero/_Hero.scss +0 -256
- package/src/components/Icons/_Icons.scss +0 -116
- package/src/components/Label/_Label.scss +0 -22
- package/src/components/Link/_Link.scss +0 -73
- package/src/components/SearchBar/_SearchBar.scss +0 -16
- package/src/components/Select/_Select.scss +0 -82
- package/src/components/StatusBadge/StatusBadge.stories.tsx +0 -34
- package/src/components/StatusBadge/_StatusBadge.scss +0 -23
- package/src/components/StyleGuide/Colors.stories.tsx +0 -289
- package/src/components/Template/Template.stories.tsx +0 -86
- package/src/components/Template/_Template.scss +0 -63
- package/src/components/TextInput/_TextInput.scss +0 -59
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Meta, Story, Canvas } from "@storybook/addon-docs/blocks";
|
|
2
|
-
import { Box, Center, Square, Circle } from "@chakra-ui/react";
|
|
2
|
+
import { Box, Center, Square, Circle, HStack } from "@chakra-ui/react";
|
|
3
3
|
|
|
4
4
|
import { getCategory } from "../../utils/componentCategories";
|
|
5
5
|
import Image from "../Image/Image";
|
|
6
6
|
import Icon from "../Icons/Icon";
|
|
7
|
-
import { IconNames, IconColors } from "../Icons/IconTypes";
|
|
7
|
+
import { IconNames, IconColors, IconSizes } from "../Icons/IconTypes";
|
|
8
|
+
import DSProvider from "../../theme/provider";
|
|
8
9
|
|
|
9
10
|
<Meta title={getCategory("Center, Circle, Square")} component={Center} />
|
|
10
11
|
|
|
@@ -60,12 +61,20 @@ guide on the Chakra UI site.
|
|
|
60
61
|
Similar to `Center` but is always a circle!
|
|
61
62
|
|
|
62
63
|
<Canvas>
|
|
63
|
-
<
|
|
64
|
-
<
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
<DSProvider>
|
|
65
|
+
<HStack spacing="s">
|
|
66
|
+
<Circle size="50px" bg="var(--ui-test)">
|
|
67
|
+
<Icon name={IconNames.Download} size={IconSizes.Large} />
|
|
68
|
+
</Circle>
|
|
69
|
+
<Circle size="50px" bg="var(--ui-link-primary)">
|
|
70
|
+
<Icon
|
|
71
|
+
name={IconNames.Check}
|
|
72
|
+
color={IconColors.UiWhite}
|
|
73
|
+
size={IconSizes.Large}
|
|
74
|
+
/>
|
|
75
|
+
</Circle>
|
|
76
|
+
</HStack>
|
|
77
|
+
</DSProvider>
|
|
69
78
|
</Canvas>
|
|
70
79
|
|
|
71
80
|
## Square
|
|
@@ -73,10 +82,18 @@ Similar to `Center` but is always a circle!
|
|
|
73
82
|
Similar to `Center` but always has equal height and width.
|
|
74
83
|
|
|
75
84
|
<Canvas>
|
|
76
|
-
<
|
|
77
|
-
<
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
<DSProvider>
|
|
86
|
+
<HStack spacing="s">
|
|
87
|
+
<Square size="50px" bg="var(--ui-test)">
|
|
88
|
+
<Icon name={IconNames.Download} size={IconSizes.Large} />
|
|
89
|
+
</Square>
|
|
90
|
+
<Square size="50px" bg="var(--ui-link-primary)">
|
|
91
|
+
<Icon
|
|
92
|
+
name={IconNames.Check}
|
|
93
|
+
color={IconColors.UiWhite}
|
|
94
|
+
size={IconSizes.Large}
|
|
95
|
+
/>
|
|
96
|
+
</Square>
|
|
97
|
+
</HStack>
|
|
98
|
+
</DSProvider>
|
|
82
99
|
</Canvas>
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Meta, Story, Canvas } from "@storybook/addon-docs/blocks";
|
|
2
|
+
import { Box } from "@chakra-ui/react";
|
|
3
|
+
import { Grid, GridItem } from "@chakra-ui/react";
|
|
4
|
+
import { getCategory } from "../../utils/componentCategories";
|
|
5
|
+
|
|
6
|
+
<Meta title={getCategory("Grid")} component={Grid} />
|
|
7
|
+
|
|
8
|
+
# Grid
|
|
9
|
+
|
|
10
|
+
| Component Version | DS Version |
|
|
11
|
+
| ----------------- | ---------- |
|
|
12
|
+
| Added | `0.25.1` |
|
|
13
|
+
|
|
14
|
+
Note: This needs the use of the `DSProvider` component. See the [README](https://github.com/NYPL/nypl-design-system#using-the-design-system-in-your-product)
|
|
15
|
+
for more information.
|
|
16
|
+
|
|
17
|
+
This component is directly exported from Chakra UI. The `Grid` component is useful for grid layouts and offers more complexity and formatting options than the DS `SimpleGrid` component. `Grid` is `Box` with `display: grid` and it comes with helpful style shorthand. It renders a `div` element.
|
|
18
|
+
|
|
19
|
+
Details about available props and related child components can be found on the [Grid component](https://chakra-ui.com/docs/layout/grid)
|
|
20
|
+
page on the Chakra UI site.
|
|
21
|
+
|
|
22
|
+
<Canvas>
|
|
23
|
+
<Story
|
|
24
|
+
name="Grid"
|
|
25
|
+
args={{
|
|
26
|
+
templateColumns: "repeat(5, 1fr)",
|
|
27
|
+
gap: "l",
|
|
28
|
+
}}
|
|
29
|
+
>
|
|
30
|
+
{(args) => (
|
|
31
|
+
<Grid {...args}>
|
|
32
|
+
<Box w="100%" h="20" bg="brand.primary" />
|
|
33
|
+
<Box w="100%" h="20" bg="brand.secondary" />
|
|
34
|
+
<Box w="100%" h="20" bg="brand.primary" />
|
|
35
|
+
<Box w="100%" h="20" bg="brand.secondary" />
|
|
36
|
+
<Box w="100%" h="20" bg="brand.primary" />
|
|
37
|
+
<Box w="100%" h="20" bg="brand.secondary" />
|
|
38
|
+
<Box w="100%" h="20" bg="brand.primary" />
|
|
39
|
+
<Box w="100%" h="20" bg="brand.secondary" />
|
|
40
|
+
<Box w="100%" h="20" bg="brand.primary" />
|
|
41
|
+
<Box w="100%" h="20" bg="brand.secondary" />
|
|
42
|
+
</Grid>
|
|
43
|
+
)}
|
|
44
|
+
</Story>
|
|
45
|
+
</Canvas>
|
|
46
|
+
|
|
47
|
+
## Complex Layouts with Grid Child Components
|
|
48
|
+
|
|
49
|
+
In some layouts, you may need certain grid items to span a specific amount of columns or rows instead of an even distribution. To achieve this, you need to pass the `colSpan` prop to the `GridItem` component to span across columns and also pass the `rowSpan` component to span across rows. You also need to specify the `templateColumns` and `templateRows`.
|
|
50
|
+
|
|
51
|
+
<Canvas>
|
|
52
|
+
<DSProvider>
|
|
53
|
+
<Grid
|
|
54
|
+
h="200px"
|
|
55
|
+
templateRows="repeat(2, 1fr)"
|
|
56
|
+
templateColumns="repeat(5, 1fr)"
|
|
57
|
+
gap="32"
|
|
58
|
+
>
|
|
59
|
+
<GridItem rowSpan={2} colSpan={1} bg="var(--ui-link-primary)" />
|
|
60
|
+
<GridItem colSpan={2} bg="var(--ui-success-primary)" />
|
|
61
|
+
<GridItem colSpan={2} bg="var(--ui-success-secondary)" />
|
|
62
|
+
<GridItem colSpan={4} bg="var(--ui-link-secondary)" />
|
|
63
|
+
</Grid>
|
|
64
|
+
</DSProvider>
|
|
65
|
+
</Canvas>
|
|
66
|
+
|
|
67
|
+
```jsx
|
|
68
|
+
<Grid
|
|
69
|
+
h="200px"
|
|
70
|
+
templateRows="repeat(2, 1fr)"
|
|
71
|
+
templateColumns="repeat(5, 1fr)"
|
|
72
|
+
gap="32"
|
|
73
|
+
>
|
|
74
|
+
<GridItem rowSpan={2} colSpan={1} bg="var(--ui-link-primary)" />
|
|
75
|
+
<GridItem colSpan={2} bg="var(--ui-success-primary)" />
|
|
76
|
+
<GridItem colSpan={2} bg="var(--ui-success-secondary)" />
|
|
77
|
+
<GridItem colSpan={4} bg="var(--ui-link-secondary)" />
|
|
78
|
+
</Grid>
|
|
79
|
+
```
|
|
@@ -4,7 +4,7 @@ import { Box, Stack, HStack, VStack, Circle } from "@chakra-ui/react";
|
|
|
4
4
|
import { getCategory } from "../../utils/componentCategories";
|
|
5
5
|
import DSProvider from "../../theme/provider";
|
|
6
6
|
import Icon from "../Icons/Icon";
|
|
7
|
-
import { IconNames, IconRotationTypes,
|
|
7
|
+
import { IconNames, IconRotationTypes, IconSizes } from "../Icons/IconTypes";
|
|
8
8
|
import Radio from "../Radio/Radio";
|
|
9
9
|
|
|
10
10
|
<Meta title={getCategory("Stack, HStack, VStack")} component={Stack} />
|
|
@@ -49,13 +49,13 @@ both horizontally and vertically through the `direction` prop.
|
|
|
49
49
|
{(args) => (
|
|
50
50
|
<Stack {...args}>
|
|
51
51
|
<Circle size="50px" borderColor="ui.black" borderWidth="1px">
|
|
52
|
-
<Icon name={IconNames.
|
|
52
|
+
<Icon name={IconNames.ErrorFilled} size={IconSizes.Large} />
|
|
53
53
|
</Circle>
|
|
54
54
|
<Circle size="50px" borderColor="ui.black" borderWidth="1px">
|
|
55
|
-
<Icon name={IconNames.
|
|
55
|
+
<Icon name={IconNames.ErrorOutline} size={IconSizes.Large} />
|
|
56
56
|
</Circle>
|
|
57
57
|
<Circle size="50px" borderColor="ui.black" borderWidth="1px">
|
|
58
|
-
<Icon name={IconNames.
|
|
58
|
+
<Icon name={IconNames.Check} size={IconSizes.Large} />
|
|
59
59
|
</Circle>
|
|
60
60
|
</Stack>
|
|
61
61
|
)}
|
|
@@ -51,7 +51,9 @@ export const onChangeDefault = () => {
|
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
function CheckboxIcon(props) {
|
|
54
|
-
|
|
54
|
+
// Don't need the `isChecked` prop but it causes
|
|
55
|
+
// rendering issues on the SVG element.
|
|
56
|
+
const { isIndeterminate, isChecked, ...rest } = props;
|
|
55
57
|
|
|
56
58
|
const d = isIndeterminate
|
|
57
59
|
? "M12,0A12,12,0,1,0,24,12,12.013,12.013,0,0,0,12,0Zm0,19a1.5,1.5,0,1,1,1.5-1.5A1.5,1.5,0,0,1,12,19Zm1.6-6.08a1,1,0,0,0-.6.917,1,1,0,1,1-2,0,3,3,0,0,1,1.8-2.75A2,2,0,1,0,10,9.255a1,1,0,1,1-2,0,4,4,0,1,1,5.6,3.666Z"
|
|
@@ -70,7 +72,7 @@ const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
|
|
|
70
72
|
className,
|
|
71
73
|
errorText,
|
|
72
74
|
helperText,
|
|
73
|
-
id,
|
|
75
|
+
id = generateUUID(),
|
|
74
76
|
isChecked,
|
|
75
77
|
isDisabled = false,
|
|
76
78
|
isInvalid = false,
|
|
@@ -84,20 +86,19 @@ const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
|
|
|
84
86
|
const styles = useMultiStyleConfig("Checkbox", {});
|
|
85
87
|
const footnote = isInvalid ? errorText : helperText;
|
|
86
88
|
const attributes = {};
|
|
87
|
-
const checkboxID = id || generateUUID();
|
|
88
89
|
const onChange = props.onChange || onChangeDefault;
|
|
89
90
|
|
|
90
91
|
if (!showLabel) {
|
|
91
92
|
attributes["aria-label"] =
|
|
92
93
|
labelText && footnote ? `${labelText} - ${footnote}` : labelText;
|
|
93
94
|
} else {
|
|
94
|
-
if (footnote) attributes["aria-describedby"] = `${
|
|
95
|
+
if (footnote) attributes["aria-describedby"] = `${id}-helperText`;
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
return (
|
|
98
99
|
<>
|
|
99
100
|
<ChakraCheckbox
|
|
100
|
-
id={
|
|
101
|
+
id={id}
|
|
101
102
|
className={className}
|
|
102
103
|
name={name || "default"}
|
|
103
104
|
isDisabled={isDisabled}
|
|
@@ -107,14 +108,13 @@ const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
|
|
|
107
108
|
value={value}
|
|
108
109
|
{...(isChecked !== undefined
|
|
109
110
|
? {
|
|
110
|
-
isChecked
|
|
111
|
-
onChange
|
|
111
|
+
isChecked,
|
|
112
|
+
onChange,
|
|
112
113
|
}
|
|
113
114
|
: {
|
|
114
115
|
defaultIsChecked: false,
|
|
115
116
|
})}
|
|
116
117
|
icon={<CheckboxIcon />}
|
|
117
|
-
//iconColor="ui.focus"
|
|
118
118
|
__css={styles}
|
|
119
119
|
{...attributes}
|
|
120
120
|
>
|
|
@@ -122,10 +122,7 @@ const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
|
|
|
122
122
|
</ChakraCheckbox>
|
|
123
123
|
{footnote && showLabel && (
|
|
124
124
|
<Box __css={styles.helper} aria-disabled={isDisabled}>
|
|
125
|
-
<HelperErrorText
|
|
126
|
-
isError={isInvalid}
|
|
127
|
-
id={`${checkboxID}-helperText`}
|
|
128
|
-
>
|
|
125
|
+
<HelperErrorText isError={isInvalid} id={`${id}-helperText`}>
|
|
129
126
|
{footnote}
|
|
130
127
|
</HelperErrorText>
|
|
131
128
|
</Box>
|
|
@@ -45,7 +45,6 @@ exports[`Checkbox Renders the UI snapshot correctly 1`] = `
|
|
|
45
45
|
<svg
|
|
46
46
|
className="chakra-icon css-1vfv7ic"
|
|
47
47
|
focusable={false}
|
|
48
|
-
isChecked={false}
|
|
49
48
|
viewBox="0 0 24 24"
|
|
50
49
|
>
|
|
51
50
|
<path
|
|
@@ -67,6 +66,7 @@ exports[`Checkbox Renders the UI snapshot correctly 1`] = `
|
|
|
67
66
|
exports[`Checkbox Renders the UI snapshot correctly 2`] = `
|
|
68
67
|
<label
|
|
69
68
|
className="chakra-checkbox css-1uiwwan"
|
|
69
|
+
data-checked=""
|
|
70
70
|
onClick={[Function]}
|
|
71
71
|
>
|
|
72
72
|
<input
|
|
@@ -110,7 +110,6 @@ exports[`Checkbox Renders the UI snapshot correctly 2`] = `
|
|
|
110
110
|
<svg
|
|
111
111
|
className="chakra-icon css-oi1lnb"
|
|
112
112
|
focusable={false}
|
|
113
|
-
isChecked={true}
|
|
114
113
|
viewBox="0 0 24 24"
|
|
115
114
|
>
|
|
116
115
|
<path
|
|
@@ -175,7 +174,6 @@ exports[`Checkbox Renders the UI snapshot correctly 3`] = `
|
|
|
175
174
|
<svg
|
|
176
175
|
className="chakra-icon css-1vfv7ic"
|
|
177
176
|
focusable={false}
|
|
178
|
-
isChecked={false}
|
|
179
177
|
viewBox="0 0 24 24"
|
|
180
178
|
>
|
|
181
179
|
<path
|
|
@@ -197,6 +195,7 @@ exports[`Checkbox Renders the UI snapshot correctly 3`] = `
|
|
|
197
195
|
exports[`Checkbox Renders the UI snapshot correctly 4`] = `
|
|
198
196
|
<label
|
|
199
197
|
className="chakra-checkbox css-1uiwwan"
|
|
198
|
+
data-invalid=""
|
|
200
199
|
onClick={[Function]}
|
|
201
200
|
>
|
|
202
201
|
<input
|
|
@@ -240,7 +239,6 @@ exports[`Checkbox Renders the UI snapshot correctly 4`] = `
|
|
|
240
239
|
<svg
|
|
241
240
|
className="chakra-icon css-1vfv7ic"
|
|
242
241
|
focusable={false}
|
|
243
|
-
isChecked={false}
|
|
244
242
|
viewBox="0 0 24 24"
|
|
245
243
|
>
|
|
246
244
|
<path
|
|
@@ -307,7 +305,6 @@ exports[`Checkbox Renders the UI snapshot correctly 5`] = `
|
|
|
307
305
|
<svg
|
|
308
306
|
className="chakra-icon css-1vfv7ic"
|
|
309
307
|
focusable={false}
|
|
310
|
-
isChecked={false}
|
|
311
308
|
viewBox="0 0 24 24"
|
|
312
309
|
>
|
|
313
310
|
<path
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Meta,
|
|
3
|
+
Story,
|
|
4
|
+
Canvas,
|
|
5
|
+
ArgsTable,
|
|
6
|
+
Description,
|
|
7
|
+
} from "@storybook/addon-docs/blocks";
|
|
8
|
+
import { withDesign } from "storybook-addon-designs";
|
|
9
|
+
|
|
10
|
+
import { getCategory } from "../../utils/componentCategories";
|
|
11
|
+
import DSProvider from "../../theme/provider";
|
|
12
|
+
import CheckboxGroup from "./CheckboxGroup";
|
|
13
|
+
import { CheckboxGroupLayoutTypes } from "./CheckboxGroupLayoutTypes";
|
|
14
|
+
import Checkbox from "../Checkbox/Checkbox";
|
|
15
|
+
|
|
16
|
+
<Meta
|
|
17
|
+
title={getCategory("CheckboxGroup")}
|
|
18
|
+
component={CheckboxGroup}
|
|
19
|
+
decorators={[withDesign]}
|
|
20
|
+
parameters={{
|
|
21
|
+
design: {
|
|
22
|
+
type: "figma",
|
|
23
|
+
url:
|
|
24
|
+
"https://www.figma.com/file/qShodlfNCJHb8n03IFyApM/Main?node-id=11895%3A658",
|
|
25
|
+
},
|
|
26
|
+
jest: ["CheckboxGroup.test.tsx"],
|
|
27
|
+
}}
|
|
28
|
+
argTypes={{
|
|
29
|
+
children: { table: { disable: true } },
|
|
30
|
+
defaultValue: { table: { disable: true } },
|
|
31
|
+
id: { table: { disable: true } },
|
|
32
|
+
name: { table: { disable: true } },
|
|
33
|
+
onChange: { table: { disable: true } },
|
|
34
|
+
}}
|
|
35
|
+
/>
|
|
36
|
+
|
|
37
|
+
# CheckboxGroup
|
|
38
|
+
|
|
39
|
+
| Component Version | DS Version |
|
|
40
|
+
| ----------------- | ---------- |
|
|
41
|
+
| Added | `0.25.1` |
|
|
42
|
+
| Latest | `0.25.1` |
|
|
43
|
+
|
|
44
|
+
<Description of={CheckboxGroup} />
|
|
45
|
+
|
|
46
|
+
<Canvas withToolbar>
|
|
47
|
+
<Story
|
|
48
|
+
name="CheckboxGroup"
|
|
49
|
+
args={{
|
|
50
|
+
defaultValue: ["4"],
|
|
51
|
+
invalidText: "This is the error text :(",
|
|
52
|
+
helperText: "This is the helper text for the full group.",
|
|
53
|
+
isDisabled: false,
|
|
54
|
+
isInvalid: false,
|
|
55
|
+
isRequired: false,
|
|
56
|
+
labelText: "Standard Checkbox Group",
|
|
57
|
+
layout: CheckboxGroupLayoutTypes.Column,
|
|
58
|
+
name: "checkbox-story",
|
|
59
|
+
optReqFlag: true,
|
|
60
|
+
showLabel: true,
|
|
61
|
+
}}
|
|
62
|
+
>
|
|
63
|
+
{(args) => (
|
|
64
|
+
<CheckboxGroup {...args}>
|
|
65
|
+
<Checkbox value="2" labelText="Checkbox 2" />
|
|
66
|
+
<Checkbox value="3" labelText="Checkbox 3" />
|
|
67
|
+
<Checkbox value="4" labelText="Checkbox 4" />
|
|
68
|
+
<Checkbox value="5" labelText="Checkbox 5" />
|
|
69
|
+
</CheckboxGroup>
|
|
70
|
+
)}
|
|
71
|
+
</Story>
|
|
72
|
+
</Canvas>
|
|
73
|
+
|
|
74
|
+
<ArgsTable story="CheckboxGroup" />
|
|
75
|
+
|
|
76
|
+
## Layout Patterns
|
|
77
|
+
|
|
78
|
+
Use the `layout` prop to set the `Checkbox` buttons to display in a column or in
|
|
79
|
+
a row.
|
|
80
|
+
|
|
81
|
+
<Canvas>
|
|
82
|
+
<DSProvider>
|
|
83
|
+
<CheckboxGroup
|
|
84
|
+
labelText="Column (default)"
|
|
85
|
+
name="column-example"
|
|
86
|
+
optReqFlag={false}
|
|
87
|
+
>
|
|
88
|
+
<Checkbox value="2" labelText="Checkbox 2" />
|
|
89
|
+
<Checkbox value="3" labelText="Checkbox 3" />
|
|
90
|
+
<Checkbox value="4" labelText="Checkbox 4" />
|
|
91
|
+
<Checkbox value="5" labelText="Checkbox 5" />
|
|
92
|
+
</CheckboxGroup>
|
|
93
|
+
<br />
|
|
94
|
+
<CheckboxGroup
|
|
95
|
+
labelText="Row"
|
|
96
|
+
name="row-example"
|
|
97
|
+
layout={CheckboxGroupLayoutTypes.Row}
|
|
98
|
+
optReqFlag={false}
|
|
99
|
+
>
|
|
100
|
+
<Checkbox value="2" labelText="Checkbox 2" />
|
|
101
|
+
<Checkbox value="3" labelText="Checkbox 3" />
|
|
102
|
+
<Checkbox value="4" labelText="Checkbox 4" />
|
|
103
|
+
<Checkbox value="5" labelText="Checkbox 5" />
|
|
104
|
+
</CheckboxGroup>
|
|
105
|
+
</DSProvider>
|
|
106
|
+
</Canvas>
|
|
107
|
+
|
|
108
|
+
## Errored
|
|
109
|
+
|
|
110
|
+
<Canvas>
|
|
111
|
+
<DSProvider>
|
|
112
|
+
<CheckboxGroup
|
|
113
|
+
labelText="Errored Checkbox Group"
|
|
114
|
+
name="errored-example"
|
|
115
|
+
optReqFlag={false}
|
|
116
|
+
invalidText="Error message for the full group."
|
|
117
|
+
isInvalid
|
|
118
|
+
>
|
|
119
|
+
<Checkbox value="2" labelText="Checkbox 2" />
|
|
120
|
+
<Checkbox value="3" labelText="Checkbox 3" />
|
|
121
|
+
<Checkbox value="4" labelText="Checkbox 4" />
|
|
122
|
+
<Checkbox value="5" labelText="Checkbox 5" />
|
|
123
|
+
</CheckboxGroup>
|
|
124
|
+
</DSProvider>
|
|
125
|
+
</Canvas>
|
|
126
|
+
|
|
127
|
+
## Disabled
|
|
128
|
+
|
|
129
|
+
<Canvas>
|
|
130
|
+
<DSProvider>
|
|
131
|
+
<CheckboxGroup
|
|
132
|
+
labelText="Disabled Checkbox Group"
|
|
133
|
+
name="disabled-example"
|
|
134
|
+
optReqFlag={false}
|
|
135
|
+
helperText="The reason for being disabled."
|
|
136
|
+
isDisabled
|
|
137
|
+
>
|
|
138
|
+
<Checkbox value="2" labelText="Checkbox 2" />
|
|
139
|
+
<Checkbox value="3" labelText="Checkbox 3" />
|
|
140
|
+
<Checkbox value="4" labelText="Checkbox 4" />
|
|
141
|
+
<Checkbox value="5" labelText="Checkbox 5" />
|
|
142
|
+
</CheckboxGroup>
|
|
143
|
+
</DSProvider>
|
|
144
|
+
</Canvas>
|
|
145
|
+
|
|
146
|
+
## Getting Checkbox Data Values
|
|
147
|
+
|
|
148
|
+
### Controlled Component using `name`, `defaultValue`, and `onChange` props
|
|
149
|
+
|
|
150
|
+
If your application uses controlled React components and the DS CheckboxGroup
|
|
151
|
+
must be controlled, you can extract the data through the `name`, `defaultValue`,
|
|
152
|
+
and `onChange` props. The `onChange` function will be called every time a new
|
|
153
|
+
`Checkbox` value is checked or unchecked.
|
|
154
|
+
|
|
155
|
+
```jsx
|
|
156
|
+
const onChange = (data: string[]) => {
|
|
157
|
+
// This will return the values selected as an array of strings.
|
|
158
|
+
// Ex: ["2", "4"]
|
|
159
|
+
console.log(data);
|
|
160
|
+
};
|
|
161
|
+
// ...
|
|
162
|
+
|
|
163
|
+
// Example of the DS CheckboxGroup instance with the function above:
|
|
164
|
+
<CheckboxGroup
|
|
165
|
+
id="controlled-example"
|
|
166
|
+
labelText="Checkbox Group"
|
|
167
|
+
name="CheckboxExample"
|
|
168
|
+
defaultValue={["2"]}
|
|
169
|
+
onChange={onChange}
|
|
170
|
+
>
|
|
171
|
+
<Checkbox value="2" labelText="Checkbox 2" />
|
|
172
|
+
<Checkbox value="3" labelText="Checkbox 3" />
|
|
173
|
+
<Checkbox value="4" labelText="Checkbox 4" />
|
|
174
|
+
</CheckboxGroup>;
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Uncontrolled Component using `ref`s
|
|
178
|
+
|
|
179
|
+
If your application uses uncontrolled components, you can pass React `ref` props
|
|
180
|
+
to the DS CheckboxGroup component to get the selected value from the DOM.
|
|
181
|
+
|
|
182
|
+
The following example is using the `register` React `ref` from the
|
|
183
|
+
`react-hook-form` package.
|
|
184
|
+
|
|
185
|
+
```jsx
|
|
186
|
+
import { useFormContext, Controller } from "react-hook-form";
|
|
187
|
+
// ...
|
|
188
|
+
const { register, handleSubmit, control } = useFormContext();
|
|
189
|
+
// ...
|
|
190
|
+
const submitForm = (formData) => {
|
|
191
|
+
// This will return an object with all the DOM element values that were
|
|
192
|
+
// registered with a `name` attribute.
|
|
193
|
+
// {
|
|
194
|
+
// checkboxExample: ["3"]
|
|
195
|
+
// }
|
|
196
|
+
console.log(formData);
|
|
197
|
+
// ...
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
<form
|
|
201
|
+
onSubmit={handleSubmit(submitForm)}
|
|
202
|
+
method="post"
|
|
203
|
+
action="/some/api/endpoint"
|
|
204
|
+
>
|
|
205
|
+
<Controller
|
|
206
|
+
as={
|
|
207
|
+
<CheckboxGroup
|
|
208
|
+
id="uncontrolled-example"
|
|
209
|
+
labelText="Checkbox Group"
|
|
210
|
+
name="checkboxExample"
|
|
211
|
+
defaultValue={["3"]}
|
|
212
|
+
ref={register()}
|
|
213
|
+
>
|
|
214
|
+
<Checkbox value="2" labelText="Checkbox 2" />
|
|
215
|
+
<Checkbox value="3" labelText="Checkbox 3" />
|
|
216
|
+
<Checkbox value="4" labelText="Checkbox 4" />
|
|
217
|
+
</CheckboxGroup>
|
|
218
|
+
}
|
|
219
|
+
name="checkboxExample"
|
|
220
|
+
control={control}
|
|
221
|
+
/>
|
|
222
|
+
</form>;
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
The above is specific to `react-hook-form` but a similar pattern can be used
|
|
226
|
+
with normal React `ref` values.
|
|
227
|
+
|
|
228
|
+
```jsx
|
|
229
|
+
const CheckboxGroupRef = React.createRef<HTMLInputElement>();
|
|
230
|
+
// ...
|
|
231
|
+
<CheckboxGroup
|
|
232
|
+
id="uncontrolled-example"
|
|
233
|
+
labelText="Checkbox Group"
|
|
234
|
+
name="checkboxExample"
|
|
235
|
+
defaultValue={["3"]}
|
|
236
|
+
ref={CheckboxGroupRef}
|
|
237
|
+
>
|
|
238
|
+
<Checkbox value="2" labelText="Checkbox 2" />
|
|
239
|
+
<Checkbox value="3" labelText="Checkbox 3" />
|
|
240
|
+
<Checkbox value="4" labelText="Checkbox 4" />
|
|
241
|
+
</CheckboxGroup>
|
|
242
|
+
|
|
243
|
+
// ...
|
|
244
|
+
// Get the value through:
|
|
245
|
+
const onSubmit = () => {
|
|
246
|
+
// ...
|
|
247
|
+
const CheckboxGroupValue = CheckboxGroupRef.current.value;
|
|
248
|
+
};
|
|
249
|
+
```
|