@nypl/design-system-react-components 0.26.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -0
- package/README.md +7 -7
- package/dist/components/Accordion/Accordion.d.ts +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +1 -5
- package/dist/components/Button/Button.d.ts +2 -10
- package/dist/components/ButtonGroup/ButtonGroup.d.ts +22 -0
- package/dist/components/Card/Card.d.ts +2 -2
- package/dist/components/Checkbox/Checkbox.d.ts +10 -8
- package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +1 -1
- package/dist/components/DatePicker/DatePicker.d.ts +1 -1
- package/dist/components/Form/Form.d.ts +2 -2
- package/dist/components/Grid/SimpleGrid.d.ts +6 -3
- package/dist/components/Heading/Heading.d.ts +2 -5
- package/dist/components/HelperErrorText/HelperErrorText.d.ts +1 -5
- package/dist/components/Hero/Hero.d.ts +13 -9
- package/dist/components/Icons/Icon.d.ts +6 -5
- package/dist/components/Icons/IconSvgs.d.ts +21 -21
- package/dist/components/Image/Image.d.ts +8 -5
- package/dist/components/Link/Link.d.ts +1 -9
- package/dist/components/List/List.d.ts +7 -11
- package/dist/components/Logo/Logo.d.ts +2 -5
- package/dist/components/Logo/LogoSvgs.d.ts +39 -39
- package/dist/components/Modal/Modal.d.ts +28 -8
- package/dist/components/Notification/Notification.d.ts +1 -1
- package/dist/components/ProgressIndicator/ProgressIndicator.d.ts +2 -1
- package/dist/components/RadioGroup/RadioGroup.d.ts +1 -1
- package/dist/components/SearchBar/SearchBar.d.ts +3 -2
- package/dist/components/Select/Select.d.ts +2 -5
- package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +4 -4
- package/dist/components/SkipNavigation/SkipNavigation.d.ts +17 -0
- package/dist/components/StatusBadge/StatusBadge.d.ts +2 -3
- package/dist/components/StructuredContent/StructuredContent.d.ts +2 -2
- package/dist/components/Table/Table.d.ts +1 -1
- package/dist/components/Template/Template.d.ts +2 -0
- package/dist/components/Text/Text.d.ts +1 -1
- package/dist/components/TextInput/TextInput.d.ts +21 -9
- package/dist/components/Toggle/Toggle.d.ts +1 -5
- package/dist/components/VideoPlayer/VideoPlayer.d.ts +2 -1
- package/dist/design-system-react-components.cjs.development.js +983 -1222
- 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 +982 -1285
- package/dist/design-system-react-components.esm.js.map +1 -1
- package/dist/helpers/types.d.ts +1 -0
- package/dist/index.d.ts +27 -48
- package/dist/styles.css +1 -1
- package/dist/theme/components/buttonGroup.d.ts +11 -0
- package/dist/theme/components/card.d.ts +104 -8
- package/dist/theme/components/componentWrapper.d.ts +4 -3
- package/dist/theme/components/customTable.d.ts +11 -14
- package/dist/theme/components/fieldset.d.ts +4 -3
- package/dist/theme/components/helperErrorText.d.ts +4 -3
- package/dist/theme/components/hero.d.ts +1 -1
- package/dist/theme/components/horizontalRule.d.ts +4 -3
- package/dist/theme/components/icon.d.ts +47743 -1
- package/dist/theme/components/image.d.ts +563 -10
- package/dist/theme/components/label.d.ts +4 -3
- package/dist/theme/components/list.d.ts +6 -7
- package/dist/theme/components/logo.d.ts +474 -1
- package/dist/theme/components/notification.d.ts +20 -16
- package/dist/theme/components/progressIndicator.d.ts +6 -4
- package/dist/theme/components/select.d.ts +4 -10
- package/dist/theme/components/skeletonLoader.d.ts +14 -10
- package/dist/theme/components/skipNavigation.d.ts +22 -0
- package/dist/theme/components/slider.d.ts +7 -6
- package/dist/theme/components/structuredContent.d.ts +10 -9
- package/dist/theme/components/text.d.ts +7 -1
- package/dist/theme/components/toggle.d.ts +6 -4
- package/dist/theme/provider.d.ts +2 -4
- package/dist/utils/componentCategories.d.ts +1 -1
- package/dist/utils/interfaces.d.ts +5 -0
- package/dist/utils/utils.d.ts +2 -18
- package/package.json +15 -16
- package/src/__tests__/setup.ts +3 -3
- package/src/__tests__/utils/utils.test.ts +1 -23
- package/src/components/AccessibilityGuide/SkipNavigation.stories.mdx +22 -14
- package/src/components/Accordion/Accordion.stories.mdx +43 -44
- package/src/components/Accordion/Accordion.test.tsx +5 -13
- package/src/components/Accordion/Accordion.tsx +14 -18
- package/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +6 -6
- package/src/components/Autosuggest/Autosuggest.stories.mdx +1 -1
- package/src/components/Autosuggest/Autosuggest.stories.tsx +23 -25
- package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +21 -37
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +4 -17
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +18 -21
- package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +1 -100
- package/src/components/Button/Button.stories.mdx +89 -126
- package/src/components/Button/Button.test.tsx +16 -30
- package/src/components/Button/Button.tsx +14 -20
- package/src/components/ButtonGroup/ButtonGroup.stories.mdx +147 -0
- package/src/components/ButtonGroup/ButtonGroup.test.tsx +141 -0
- package/src/components/ButtonGroup/ButtonGroup.tsx +99 -0
- package/src/components/ButtonGroup/__snapshots__/ButtonGroup.test.tsx.snap +117 -0
- package/src/components/Card/Card.stories.mdx +144 -178
- package/src/components/Card/Card.test.tsx +36 -97
- package/src/components/Card/Card.tsx +78 -74
- package/src/components/Chakra/Box.stories.mdx +3 -7
- package/src/components/Chakra/Center.stories.mdx +6 -24
- package/src/components/Chakra/Flex.stories.mdx +5 -7
- package/src/components/Chakra/Grid.stories.mdx +1 -1
- package/src/components/Chakra/Stack.stories.mdx +10 -11
- package/src/components/Checkbox/Checkbox.stories.mdx +1 -1
- package/src/components/Checkbox/Checkbox.test.tsx +2 -2
- package/src/components/Checkbox/Checkbox.tsx +20 -13
- package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +6 -17
- package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +1 -7
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +33 -29
- package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +0 -11
- package/src/components/ComponentWrapper/ComponentWrapper.tsx +3 -10
- package/src/components/DatePicker/DatePicker.stories.mdx +23 -37
- package/src/components/DatePicker/DatePicker.test.tsx +21 -19
- package/src/components/DatePicker/DatePicker.tsx +57 -49
- package/src/components/Form/Form.stories.mdx +46 -31
- package/src/components/Form/Form.test.tsx +1 -18
- package/src/components/Form/Form.tsx +7 -7
- package/src/components/Grid/SimpleGrid.stories.mdx +73 -49
- package/src/components/Grid/SimpleGrid.test.tsx +7 -9
- package/src/components/Grid/SimpleGrid.tsx +14 -11
- package/src/components/Heading/Heading.stories.mdx +27 -72
- package/src/components/Heading/Heading.test.tsx +18 -44
- package/src/components/Heading/Heading.tsx +7 -10
- package/src/components/HelperErrorText/HelperErrorText.stories.mdx +1 -3
- package/src/components/HelperErrorText/HelperErrorText.tsx +1 -5
- package/src/components/Hero/Hero.stories.mdx +219 -216
- package/src/components/Hero/Hero.test.tsx +107 -223
- package/src/components/Hero/Hero.tsx +63 -61
- package/src/components/Icons/Icon.stories.mdx +172 -118
- package/src/components/Icons/Icon.test.tsx +8 -16
- package/src/components/Icons/Icon.tsx +75 -29
- package/src/components/Icons/IconSvgs.tsx +42 -42
- package/src/components/Image/Image.stories.mdx +45 -132
- package/src/components/Image/Image.test.tsx +16 -31
- package/src/components/Image/Image.tsx +28 -12
- package/src/components/Link/Link.stories.mdx +30 -94
- package/src/components/Link/Link.test.tsx +25 -75
- package/src/components/Link/Link.tsx +43 -56
- package/src/components/Link/__snapshots__/Link.test.tsx.snap +1 -2
- package/src/components/List/List.stories.mdx +20 -31
- package/src/components/List/List.test.tsx +24 -43
- package/src/components/List/List.tsx +25 -36
- package/src/components/Logo/Logo.stories.mdx +94 -50
- package/src/components/Logo/Logo.test.tsx +10 -19
- package/src/components/Logo/Logo.tsx +50 -17
- package/src/components/Logo/LogoSvgs.tsx +78 -78
- package/src/components/Logo/__snapshots__/Logo.test.tsx.snap +4 -4
- package/src/components/Modal/Modal.stories.mdx +245 -139
- package/src/components/Modal/Modal.test.tsx +147 -10
- package/src/components/Modal/Modal.tsx +140 -20
- package/src/components/Modal/__snapshots__/Modal.test.tsx.snap +25 -0
- package/src/components/Notification/Notification.stories.mdx +10 -28
- package/src/components/Notification/Notification.test.tsx +9 -12
- package/src/components/Notification/Notification.tsx +34 -37
- package/src/components/Pagination/Pagination.stories.mdx +3 -4
- package/src/components/Pagination/Pagination.tsx +15 -10
- package/src/components/ProgressIndicator/ProgressIndicator.stories.mdx +27 -53
- package/src/components/ProgressIndicator/ProgressIndicator.test.tsx +9 -10
- package/src/components/ProgressIndicator/ProgressIndicator.tsx +17 -21
- package/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap +0 -10
- package/src/components/Radio/Radio.stories.mdx +1 -1
- package/src/components/Radio/Radio.tsx +9 -6
- package/src/components/RadioGroup/RadioGroup.stories.mdx +15 -16
- package/src/components/RadioGroup/RadioGroup.test.tsx +2 -8
- package/src/components/RadioGroup/RadioGroup.tsx +28 -24
- package/src/components/SearchBar/SearchBar.stories.mdx +4 -4
- package/src/components/SearchBar/SearchBar.test.tsx +1 -1
- package/src/components/SearchBar/SearchBar.tsx +14 -22
- package/src/components/SearchBar/__snapshots__/SearchBar.test.tsx.snap +1 -13
- package/src/components/Select/Select.stories.mdx +10 -25
- package/src/components/Select/Select.test.tsx +6 -7
- package/src/components/Select/Select.tsx +28 -35
- package/src/components/Select/__snapshots__/Select.test.tsx.snap +24 -24
- package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +17 -56
- package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +7 -21
- package/src/components/SkeletonLoader/SkeletonLoader.tsx +9 -8
- package/src/components/SkeletonLoader/__snapshots__/SkeletonLoader.test.tsx.snap +33 -33
- package/src/components/SkipNavigation/SkipNavigation.stories.mdx +90 -0
- package/src/components/SkipNavigation/SkipNavigation.test.tsx +63 -0
- package/src/components/SkipNavigation/SkipNavigation.tsx +51 -0
- package/src/components/SkipNavigation/__snapshots__/SkipNavigation.test.tsx.snap +130 -0
- package/src/components/Slider/Slider.stories.mdx +19 -53
- package/src/components/Slider/Slider.test.tsx +2 -2
- package/src/components/Slider/Slider.tsx +10 -12
- package/src/components/Slider/__snapshots__/Slider.test.tsx.snap +2 -9
- package/src/components/StatusBadge/StatusBadge.stories.mdx +6 -21
- package/src/components/StatusBadge/StatusBadge.test.tsx +2 -3
- package/src/components/StatusBadge/StatusBadge.tsx +3 -10
- package/src/components/StructuredContent/StructuredContent.stories.mdx +30 -58
- package/src/components/StructuredContent/StructuredContent.test.tsx +42 -44
- package/src/components/StructuredContent/StructuredContent.tsx +9 -18
- package/src/components/StyleGuide/Bidirectionality.stories.mdx +9 -23
- package/src/components/StyleGuide/Buttons.stories.mdx +63 -63
- package/src/components/StyleGuide/ColorCard.tsx +2 -4
- package/src/components/StyleGuide/Colors.stories.mdx +9 -10
- package/src/components/StyleGuide/DesignTokens.stories.mdx +5 -7
- package/src/components/StyleGuide/Forms.stories.mdx +2 -2
- package/src/components/StyleGuide/Iconography.stories.mdx +60 -78
- package/src/components/StyleGuide/Spacing.stories.mdx +1 -2
- package/src/components/StyleGuide/Typography.stories.mdx +16 -19
- package/src/components/Table/Table.stories.mdx +85 -1
- package/src/components/Table/Table.test.tsx +57 -1
- package/src/components/Table/Table.tsx +7 -4
- package/src/components/Table/__snapshots__/Table.test.tsx.snap +121 -0
- package/src/components/Tabs/Tabs.stories.mdx +1 -1
- package/src/components/Tabs/Tabs.test.tsx +2 -2
- package/src/components/Tabs/Tabs.tsx +26 -27
- package/src/components/Template/Template.stories.mdx +49 -54
- package/src/components/Template/Template.tsx +9 -3
- package/src/components/Text/Text.stories.mdx +5 -11
- package/src/components/Text/Text.test.tsx +3 -6
- package/src/components/Text/Text.tsx +3 -5
- package/src/components/TextInput/TextInput.stories.mdx +10 -22
- package/src/components/TextInput/TextInput.test.tsx +32 -62
- package/src/components/TextInput/TextInput.tsx +61 -30
- package/src/components/TextInput/__snapshots__/TextInput.test.tsx.snap +1 -0
- package/src/components/Toggle/Toggle.stories.mdx +5 -16
- package/src/components/Toggle/Toggle.test.tsx +2 -3
- package/src/components/Toggle/Toggle.tsx +9 -10
- package/src/components/VideoPlayer/VideoPlayer.stories.mdx +13 -29
- package/src/components/VideoPlayer/VideoPlayer.test.tsx +18 -23
- package/src/components/VideoPlayer/VideoPlayer.tsx +13 -10
- package/src/docs/Chakra.stories.mdx +14 -11
- package/src/docs/Welcome.stories.mdx +23 -43
- package/src/helpers/types.ts +1 -0
- package/src/hooks/tests/useNYPLTheme.test.tsx +1 -1
- package/src/hooks/useNYPLTheme.stories.mdx +3 -6
- package/src/index.ts +52 -46
- package/src/styles.scss +0 -1
- package/src/theme/components/buttonGroup.ts +10 -0
- package/src/theme/components/card.ts +50 -15
- package/src/theme/components/componentWrapper.ts +5 -1
- package/src/theme/components/customTable.ts +8 -2
- package/src/theme/components/fieldset.ts +5 -1
- package/src/theme/components/helperErrorText.ts +5 -1
- package/src/theme/components/hero.ts +2 -2
- package/src/theme/components/horizontalRule.ts +5 -1
- package/src/theme/components/icon.ts +7 -1
- package/src/theme/components/image.ts +14 -3
- package/src/theme/components/label.ts +5 -1
- package/src/theme/components/list.ts +8 -2
- package/src/theme/components/logo.ts +5 -1
- package/src/theme/components/notification.ts +38 -14
- package/src/theme/components/progressIndicator.ts +10 -5
- package/src/theme/components/select.ts +5 -6
- package/src/theme/components/skeletonLoader.ts +8 -2
- package/src/theme/components/skipNavigation.ts +26 -0
- package/src/theme/components/slider.ts +13 -1
- package/src/theme/components/structuredContent.ts +11 -1
- package/src/theme/components/text.ts +12 -5
- package/src/theme/components/toggle.ts +9 -3
- package/src/theme/foundations/colors.ts +6 -9
- package/src/theme/index.ts +4 -0
- package/src/theme/provider.tsx +1 -1
- package/src/utils/componentCategories.ts +13 -5
- package/src/utils/interfaces.ts +5 -0
- package/src/utils/utils.ts +2 -32
- package/dist/components/Accordion/AccordionTypes.d.ts +0 -5
- package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +0 -8
- package/dist/components/Button/ButtonTypes.d.ts +0 -8
- package/dist/components/DatePicker/DatePickerTypes.d.ts +0 -5
- package/dist/components/Form/FormTypes.d.ts +0 -2
- package/dist/components/Grid/GridTypes.d.ts +0 -9
- package/dist/components/Heading/HeadingTypes.d.ts +0 -14
- package/dist/components/Hero/HeroTypes.d.ts +0 -12
- package/dist/components/Icons/IconTypes.d.ts +0 -77
- package/dist/components/Image/ImageTypes.d.ts +0 -22
- package/dist/components/Link/LinkTypes.d.ts +0 -8
- package/dist/components/List/ListTypes.d.ts +0 -5
- package/dist/components/Logo/LogoTypes.d.ts +0 -54
- package/dist/components/Notification/NotificationTypes.d.ts +0 -5
- package/dist/components/ProgressIndicator/ProgressIndicatorTypes.d.ts +0 -8
- package/dist/components/Select/SelectTypes.d.ts +0 -8
- package/dist/components/SkeletonLoader/SkeletonLoaderTypes.d.ts +0 -5
- package/dist/components/StatusBadge/StatusBadgeTypes.d.ts +0 -5
- package/dist/components/StructuredContent/StructuredContentTypes.d.ts +0 -5
- package/dist/components/Text/TextTypes.d.ts +0 -6
- package/dist/components/TextInput/TextInputTypes.d.ts +0 -25
- package/dist/components/Toggle/ToggleTypes.d.ts +0 -4
- package/dist/components/VideoPlayer/VideoPlayerTypes.d.ts +0 -9
- package/dist/helpers/enums.d.ts +0 -4
- package/dist/utils/siteSections.d.ts +0 -2
- package/src/components/Accordion/AccordionTypes.tsx +0 -5
- package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +0 -8
- package/src/components/Button/ButtonTypes.tsx +0 -8
- package/src/components/DatePicker/DatePickerTypes.tsx +0 -5
- package/src/components/Form/FormTypes.tsx +0 -3
- package/src/components/Grid/GridTypes.tsx +0 -9
- package/src/components/Heading/HeadingTypes.tsx +0 -15
- package/src/components/Hero/HeroTypes.tsx +0 -20
- package/src/components/Icons/IconTypes.tsx +0 -83
- package/src/components/Image/ImageTypes.ts +0 -24
- package/src/components/Link/LinkTypes.tsx +0 -8
- package/src/components/List/ListTypes.tsx +0 -5
- package/src/components/Logo/LogoTypes.tsx +0 -56
- package/src/components/Modal/_Modal.scss +0 -18
- package/src/components/Notification/NotificationTypes.tsx +0 -5
- package/src/components/ProgressIndicator/ProgressIndicatorTypes.ts +0 -8
- package/src/components/Select/SelectTypes.tsx +0 -10
- package/src/components/SkeletonLoader/SkeletonLoaderTypes.tsx +0 -5
- package/src/components/StatusBadge/StatusBadgeTypes.tsx +0 -5
- package/src/components/StructuredContent/StructuredContentTypes.tsx +0 -5
- package/src/components/Text/TextTypes.tsx +0 -6
- package/src/components/TextInput/TextInputTypes.tsx +0 -48
- package/src/components/Toggle/ToggleTypes.tsx +0 -4
- package/src/components/VideoPlayer/VideoPlayerTypes.tsx +0 -10
- package/src/helpers/enums.ts +0 -4
- package/src/utils/siteSections.ts +0 -10
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ArgsTable,
|
|
3
|
+
Canvas,
|
|
4
|
+
Description,
|
|
5
|
+
Meta,
|
|
6
|
+
Story,
|
|
7
|
+
} from "@storybook/addon-docs";
|
|
8
|
+
import { withDesign } from "storybook-addon-designs";
|
|
9
|
+
|
|
10
|
+
import Button from "../Button/Button";
|
|
11
|
+
import ButtonGroup from "./ButtonGroup";
|
|
12
|
+
import Heading from "../Heading/Heading";
|
|
13
|
+
import SimpleGrid from "../Grid/SimpleGrid";
|
|
14
|
+
import { getCategory } from "../../utils/componentCategories";
|
|
15
|
+
import DSProvider from "../../theme/provider";
|
|
16
|
+
|
|
17
|
+
<Meta
|
|
18
|
+
title={getCategory("ButtonGroup")}
|
|
19
|
+
component={ButtonGroup}
|
|
20
|
+
decorators={[withDesign]}
|
|
21
|
+
parameters={{
|
|
22
|
+
jest: ["ButtonGroup.test.tsx"],
|
|
23
|
+
}}
|
|
24
|
+
argTypes={{
|
|
25
|
+
buttonWidth: { table: { defaultValue: { summary: "default" } } },
|
|
26
|
+
className: { control: false },
|
|
27
|
+
id: { control: false },
|
|
28
|
+
isDisabled: { table: { defaultValue: { summary: false } } },
|
|
29
|
+
layout: { table: { defaultValue: { summary: "row" } } },
|
|
30
|
+
}}
|
|
31
|
+
/>
|
|
32
|
+
|
|
33
|
+
# ButtonGroup
|
|
34
|
+
|
|
35
|
+
| Component Version | DS Version |
|
|
36
|
+
| ----------------- | ---------- |
|
|
37
|
+
| Added | `0.28.0` |
|
|
38
|
+
| Latest | `0.28.0` |
|
|
39
|
+
|
|
40
|
+
## Table of Contents
|
|
41
|
+
|
|
42
|
+
- [Overview](#overview)
|
|
43
|
+
- [Component Props](#component-props)
|
|
44
|
+
- [Accessibility](#accessibility)
|
|
45
|
+
- [Button Width](#button-width)
|
|
46
|
+
- [Layout](#layout)
|
|
47
|
+
|
|
48
|
+
## Overview
|
|
49
|
+
|
|
50
|
+
<Description of={ButtonGroup} />
|
|
51
|
+
|
|
52
|
+
Note: The `ButtonGroup` component does not come from Chakra because we want to
|
|
53
|
+
display the `Button`s in a column layout as an option, as well as control the
|
|
54
|
+
width.
|
|
55
|
+
|
|
56
|
+
## Component Props
|
|
57
|
+
|
|
58
|
+
<Canvas withToolbar>
|
|
59
|
+
<Story
|
|
60
|
+
name="ButtonGroup with Controls"
|
|
61
|
+
args={{
|
|
62
|
+
buttonWidth: "default",
|
|
63
|
+
className: undefined,
|
|
64
|
+
id: "button-id",
|
|
65
|
+
isDisabled: false,
|
|
66
|
+
layout: "row",
|
|
67
|
+
}}
|
|
68
|
+
>
|
|
69
|
+
{(args) => (
|
|
70
|
+
<ButtonGroup {...args}>
|
|
71
|
+
<Button buttonType="secondary" id="group-1">
|
|
72
|
+
Button
|
|
73
|
+
</Button>
|
|
74
|
+
<Button id="group-2">Submit</Button>
|
|
75
|
+
</ButtonGroup>
|
|
76
|
+
)}
|
|
77
|
+
</Story>
|
|
78
|
+
</Canvas>
|
|
79
|
+
|
|
80
|
+
<ArgsTable story="ButtonGroup with Controls" />
|
|
81
|
+
|
|
82
|
+
## Accessibility
|
|
83
|
+
|
|
84
|
+
This component is a wrapper around the `Button` component. For accessibility
|
|
85
|
+
information on the `Button` component, see the
|
|
86
|
+
[Button Accessibility](https://nypl.github.io/nypl-design-system/reservoir/v1/?path=/docs/components-form-elements-button--button-with-controls#accessibility)
|
|
87
|
+
documentation.
|
|
88
|
+
|
|
89
|
+
## Button Width
|
|
90
|
+
|
|
91
|
+
The `buttonWidth` prop can be used to set the width of the internal `Button`
|
|
92
|
+
components. The default value is `default` and it sets the width to `"fit-content"`
|
|
93
|
+
so the buttons will expand to its content. The `"full"` value will set the width
|
|
94
|
+
to the parent's width.
|
|
95
|
+
|
|
96
|
+
<Canvas>
|
|
97
|
+
<DSProvider>
|
|
98
|
+
<SimpleGrid columns={1}>
|
|
99
|
+
<Heading level="three">default fit-content</Heading>
|
|
100
|
+
<ButtonGroup>
|
|
101
|
+
<Button buttonType="secondary" id="width-fit-1">
|
|
102
|
+
Button
|
|
103
|
+
</Button>
|
|
104
|
+
<Button id="width-fit-2">Submit</Button>
|
|
105
|
+
</ButtonGroup>
|
|
106
|
+
<Heading level="three">full width</Heading>
|
|
107
|
+
<ButtonGroup buttonWidth="full">
|
|
108
|
+
<Button buttonType="secondary" id="width-full-1">
|
|
109
|
+
Button
|
|
110
|
+
</Button>
|
|
111
|
+
<Button id="width-full-2">Submit</Button>
|
|
112
|
+
</ButtonGroup>
|
|
113
|
+
</SimpleGrid>
|
|
114
|
+
</DSProvider>
|
|
115
|
+
</Canvas>
|
|
116
|
+
|
|
117
|
+
## Layout
|
|
118
|
+
|
|
119
|
+
The `layout` prop can be used to set the layout to either `row` or `column`.
|
|
120
|
+
|
|
121
|
+
<Canvas>
|
|
122
|
+
<DSProvider>
|
|
123
|
+
<SimpleGrid columns={1}>
|
|
124
|
+
<Heading level="three">default row</Heading>
|
|
125
|
+
<ButtonGroup>
|
|
126
|
+
<Button buttonType="secondary" id="row-1">
|
|
127
|
+
Button
|
|
128
|
+
</Button>
|
|
129
|
+
<Button id="row-2">Submit</Button>
|
|
130
|
+
</ButtonGroup>
|
|
131
|
+
<Heading level="three">column</Heading>
|
|
132
|
+
<ButtonGroup layout="column">
|
|
133
|
+
<Button buttonType="secondary" id="column-1">
|
|
134
|
+
Button
|
|
135
|
+
</Button>
|
|
136
|
+
<Button id="column-2">Submit</Button>
|
|
137
|
+
</ButtonGroup>
|
|
138
|
+
<Heading level="three">column layout with full-width</Heading>
|
|
139
|
+
<ButtonGroup buttonWidth="full" layout="column">
|
|
140
|
+
<Button buttonType="secondary" id="column-full-1">
|
|
141
|
+
Button
|
|
142
|
+
</Button>
|
|
143
|
+
<Button id="column-full-2">Submit</Button>
|
|
144
|
+
</ButtonGroup>
|
|
145
|
+
</SimpleGrid>
|
|
146
|
+
</DSProvider>
|
|
147
|
+
</Canvas>
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import { axe } from "jest-axe";
|
|
4
|
+
import renderer from "react-test-renderer";
|
|
5
|
+
|
|
6
|
+
import Button from "../Button/Button";
|
|
7
|
+
import ButtonGroup from "../ButtonGroup/ButtonGroup";
|
|
8
|
+
|
|
9
|
+
describe("ButtonGroup Accessibility", () => {
|
|
10
|
+
it("passes axe accessibility test", async () => {
|
|
11
|
+
const { container } = render(
|
|
12
|
+
<ButtonGroup>
|
|
13
|
+
<Button buttonType="secondary" id="btn-1">
|
|
14
|
+
Button
|
|
15
|
+
</Button>
|
|
16
|
+
<Button id="btn-2">Submit</Button>
|
|
17
|
+
</ButtonGroup>
|
|
18
|
+
);
|
|
19
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("ButtonGroup", () => {
|
|
24
|
+
it("renders only Button components", () => {
|
|
25
|
+
render(
|
|
26
|
+
<ButtonGroup>
|
|
27
|
+
<Button buttonType="secondary" id="btn-1">
|
|
28
|
+
Button
|
|
29
|
+
</Button>
|
|
30
|
+
<Button id="btn-2">Submit</Button>
|
|
31
|
+
<p data-test="paragraph">This is not a button</p>
|
|
32
|
+
</ButtonGroup>
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
expect(screen.getAllByRole("button")).toHaveLength(2);
|
|
36
|
+
expect(screen.queryByTestId("paragraph")).not.toBeInTheDocument();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("sets all `Button` children as disabled if isDisabled is true", () => {
|
|
40
|
+
const { rerender } = render(
|
|
41
|
+
<ButtonGroup>
|
|
42
|
+
<Button buttonType="secondary" id="btn-1">
|
|
43
|
+
Button
|
|
44
|
+
</Button>
|
|
45
|
+
<Button id="btn-2">Submit</Button>
|
|
46
|
+
</ButtonGroup>
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
expect(screen.getAllByRole("button")[0]).not.toBeDisabled();
|
|
50
|
+
expect(screen.getAllByRole("button")[1]).not.toBeDisabled();
|
|
51
|
+
|
|
52
|
+
rerender(
|
|
53
|
+
<ButtonGroup isDisabled>
|
|
54
|
+
<Button buttonType="secondary" id="btn-1">
|
|
55
|
+
Button
|
|
56
|
+
</Button>
|
|
57
|
+
<Button id="btn-2">Submit</Button>
|
|
58
|
+
</ButtonGroup>
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
expect(screen.getAllByRole("button")[0]).toBeDisabled();
|
|
62
|
+
expect(screen.getAllByRole("button")[1]).toBeDisabled();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("logs a warning when any element that is not a Button is passed ", () => {
|
|
66
|
+
const warn = jest.spyOn(console, "warn");
|
|
67
|
+
render(
|
|
68
|
+
<ButtonGroup>
|
|
69
|
+
<Button buttonType="secondary" id="btn-1">
|
|
70
|
+
Button
|
|
71
|
+
</Button>
|
|
72
|
+
<Button id="btn-2">Submit</Button>
|
|
73
|
+
<p data-test="paragraph">This is not a button</p>
|
|
74
|
+
</ButtonGroup>
|
|
75
|
+
);
|
|
76
|
+
expect(warn).toHaveBeenCalledWith(
|
|
77
|
+
"NYPL Reservoir ButtonGroup: Only Button components can be children of ButtonGroup."
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe("ButtonGroup Snapshot", () => {
|
|
83
|
+
it("renders the UI snapshot correctly", () => {
|
|
84
|
+
const basic = renderer
|
|
85
|
+
.create(
|
|
86
|
+
<ButtonGroup>
|
|
87
|
+
<Button buttonType="secondary" id="btn-1">
|
|
88
|
+
Button
|
|
89
|
+
</Button>
|
|
90
|
+
<Button id="btn-2">Submit</Button>
|
|
91
|
+
</ButtonGroup>
|
|
92
|
+
)
|
|
93
|
+
.toJSON();
|
|
94
|
+
const fullWidth = renderer
|
|
95
|
+
.create(
|
|
96
|
+
<ButtonGroup buttonWidth="full">
|
|
97
|
+
<Button buttonType="secondary" id="btn-1">
|
|
98
|
+
Button
|
|
99
|
+
</Button>
|
|
100
|
+
<Button id="btn-2">Submit</Button>
|
|
101
|
+
</ButtonGroup>
|
|
102
|
+
)
|
|
103
|
+
.toJSON();
|
|
104
|
+
const column = renderer
|
|
105
|
+
.create(
|
|
106
|
+
<ButtonGroup layout="column">
|
|
107
|
+
<Button buttonType="secondary" id="btn-1">
|
|
108
|
+
Button
|
|
109
|
+
</Button>
|
|
110
|
+
<Button id="btn-2">Submit</Button>
|
|
111
|
+
</ButtonGroup>
|
|
112
|
+
)
|
|
113
|
+
.toJSON();
|
|
114
|
+
const withChakraProps = renderer
|
|
115
|
+
.create(
|
|
116
|
+
<ButtonGroup p="s" color="ui.error.primary">
|
|
117
|
+
<Button buttonType="secondary" id="btn-1">
|
|
118
|
+
Button
|
|
119
|
+
</Button>
|
|
120
|
+
<Button id="btn-2">Submit</Button>
|
|
121
|
+
</ButtonGroup>
|
|
122
|
+
)
|
|
123
|
+
.toJSON();
|
|
124
|
+
const withOtherProps = renderer
|
|
125
|
+
.create(
|
|
126
|
+
<ButtonGroup data-testid="testid">
|
|
127
|
+
<Button buttonType="secondary" id="btn-1">
|
|
128
|
+
Button
|
|
129
|
+
</Button>
|
|
130
|
+
<Button id="btn-2">Submit</Button>
|
|
131
|
+
</ButtonGroup>
|
|
132
|
+
)
|
|
133
|
+
.toJSON();
|
|
134
|
+
|
|
135
|
+
expect(basic).toMatchSnapshot();
|
|
136
|
+
expect(fullWidth).toMatchSnapshot();
|
|
137
|
+
expect(column).toMatchSnapshot();
|
|
138
|
+
expect(withChakraProps).toMatchSnapshot();
|
|
139
|
+
expect(withOtherProps).toMatchSnapshot();
|
|
140
|
+
});
|
|
141
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { chakra, Stack, useStyleConfig } from "@chakra-ui/react";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
|
|
4
|
+
import Button from "../Button/Button";
|
|
5
|
+
import { LayoutTypes } from "../../helpers/types";
|
|
6
|
+
import useWindowSize from "../../hooks/useWindowSize";
|
|
7
|
+
|
|
8
|
+
export type ButtonGroupWidths = "default" | "full";
|
|
9
|
+
|
|
10
|
+
interface ButtonGroupProps {
|
|
11
|
+
/** Sets the width to "default" (for "fit-content") or "full". */
|
|
12
|
+
buttonWidth?: ButtonGroupWidths;
|
|
13
|
+
/** Additional className to use. */
|
|
14
|
+
className?: string;
|
|
15
|
+
/** ID that other components can cross reference for accessibility purposes. */
|
|
16
|
+
id?: string;
|
|
17
|
+
/** Set's the disabled state to all the internal `Button` components. */
|
|
18
|
+
isDisabled?: boolean;
|
|
19
|
+
/** Renders the layout of `Button` components in a row or column. */
|
|
20
|
+
layout?: LayoutTypes;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const noop = () => {};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A simple wrapper to group `Button` components together. The layout can be set
|
|
27
|
+
* to row or column and the width of internal `Button` components can be set to
|
|
28
|
+
* the parent's full width or the `Button`'s content width
|
|
29
|
+
*/
|
|
30
|
+
export const ButtonGroup = chakra(
|
|
31
|
+
(props: React.PropsWithChildren<ButtonGroupProps>) => {
|
|
32
|
+
const {
|
|
33
|
+
buttonWidth = "default",
|
|
34
|
+
children,
|
|
35
|
+
className = "",
|
|
36
|
+
id,
|
|
37
|
+
isDisabled = false,
|
|
38
|
+
layout = "row",
|
|
39
|
+
...rest
|
|
40
|
+
} = props;
|
|
41
|
+
const newChildren: JSX.Element[] = [];
|
|
42
|
+
// Based on --nypl-breakpoint-medium
|
|
43
|
+
const breakpointMedium = 600;
|
|
44
|
+
const [finalLayout, setFinalLayout] = React.useState<LayoutTypes>(layout);
|
|
45
|
+
const [finalButtonWidth, setFinalButtonWidth] =
|
|
46
|
+
React.useState<ButtonGroupWidths>(buttonWidth);
|
|
47
|
+
const windowDimensions = useWindowSize();
|
|
48
|
+
React.useEffect(() => {
|
|
49
|
+
// When on a mobile device or narrow window, always set the layout to
|
|
50
|
+
// column and the button width to "full".
|
|
51
|
+
if (windowDimensions.width <= breakpointMedium) {
|
|
52
|
+
setFinalButtonWidth("full");
|
|
53
|
+
setFinalLayout("column");
|
|
54
|
+
} else {
|
|
55
|
+
// Otherwise, set the layout and button width to the values
|
|
56
|
+
// passed in via the `buttonWidth` and `layout` props.
|
|
57
|
+
setFinalButtonWidth(buttonWidth);
|
|
58
|
+
setFinalLayout(layout);
|
|
59
|
+
}
|
|
60
|
+
}, [buttonWidth, layout, windowDimensions.width]);
|
|
61
|
+
const styles = useStyleConfig("ButtonGroup", {
|
|
62
|
+
buttonWidth: finalButtonWidth,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
React.Children.map(
|
|
66
|
+
children as JSX.Element,
|
|
67
|
+
(child: React.ReactElement, key: number) => {
|
|
68
|
+
if (child.type !== Button) {
|
|
69
|
+
// Special case for Storybook MDX documentation.
|
|
70
|
+
if (child.props.mdxType && child.props.mdxType === "Button") {
|
|
71
|
+
noop();
|
|
72
|
+
} else {
|
|
73
|
+
console.warn(
|
|
74
|
+
"NYPL Reservoir ButtonGroup: Only Button components can be children of ButtonGroup."
|
|
75
|
+
);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
newChildren.push(React.cloneElement(child, { key, isDisabled }));
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<Stack
|
|
85
|
+
id={id}
|
|
86
|
+
className={className}
|
|
87
|
+
direction={finalLayout}
|
|
88
|
+
// Always set the spacing to "8px".
|
|
89
|
+
spacing="xs"
|
|
90
|
+
sx={styles}
|
|
91
|
+
{...rest}
|
|
92
|
+
>
|
|
93
|
+
{newChildren}
|
|
94
|
+
</Stack>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
export default ButtonGroup;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`ButtonGroup Snapshot renders the UI snapshot correctly 1`] = `
|
|
4
|
+
<div
|
|
5
|
+
className="chakra-stack css-ytb711"
|
|
6
|
+
>
|
|
7
|
+
<button
|
|
8
|
+
className="chakra-button css-1xdhyk6"
|
|
9
|
+
data-testid="button"
|
|
10
|
+
id="btn-1"
|
|
11
|
+
type="button"
|
|
12
|
+
>
|
|
13
|
+
Button
|
|
14
|
+
</button>
|
|
15
|
+
<button
|
|
16
|
+
className="chakra-button css-1xdhyk6"
|
|
17
|
+
data-testid="button"
|
|
18
|
+
id="btn-2"
|
|
19
|
+
type="button"
|
|
20
|
+
>
|
|
21
|
+
Submit
|
|
22
|
+
</button>
|
|
23
|
+
</div>
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
exports[`ButtonGroup Snapshot renders the UI snapshot correctly 2`] = `
|
|
27
|
+
<div
|
|
28
|
+
className="chakra-stack css-ytb711"
|
|
29
|
+
>
|
|
30
|
+
<button
|
|
31
|
+
className="chakra-button css-1xdhyk6"
|
|
32
|
+
data-testid="button"
|
|
33
|
+
id="btn-1"
|
|
34
|
+
type="button"
|
|
35
|
+
>
|
|
36
|
+
Button
|
|
37
|
+
</button>
|
|
38
|
+
<button
|
|
39
|
+
className="chakra-button css-1xdhyk6"
|
|
40
|
+
data-testid="button"
|
|
41
|
+
id="btn-2"
|
|
42
|
+
type="button"
|
|
43
|
+
>
|
|
44
|
+
Submit
|
|
45
|
+
</button>
|
|
46
|
+
</div>
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
exports[`ButtonGroup Snapshot renders the UI snapshot correctly 3`] = `
|
|
50
|
+
<div
|
|
51
|
+
className="chakra-stack css-6dfzd0"
|
|
52
|
+
>
|
|
53
|
+
<button
|
|
54
|
+
className="chakra-button css-1xdhyk6"
|
|
55
|
+
data-testid="button"
|
|
56
|
+
id="btn-1"
|
|
57
|
+
type="button"
|
|
58
|
+
>
|
|
59
|
+
Button
|
|
60
|
+
</button>
|
|
61
|
+
<button
|
|
62
|
+
className="chakra-button css-1xdhyk6"
|
|
63
|
+
data-testid="button"
|
|
64
|
+
id="btn-2"
|
|
65
|
+
type="button"
|
|
66
|
+
>
|
|
67
|
+
Submit
|
|
68
|
+
</button>
|
|
69
|
+
</div>
|
|
70
|
+
`;
|
|
71
|
+
|
|
72
|
+
exports[`ButtonGroup Snapshot renders the UI snapshot correctly 4`] = `
|
|
73
|
+
<div
|
|
74
|
+
className="chakra-stack css-1pxah8o"
|
|
75
|
+
>
|
|
76
|
+
<button
|
|
77
|
+
className="chakra-button css-1xdhyk6"
|
|
78
|
+
data-testid="button"
|
|
79
|
+
id="btn-1"
|
|
80
|
+
type="button"
|
|
81
|
+
>
|
|
82
|
+
Button
|
|
83
|
+
</button>
|
|
84
|
+
<button
|
|
85
|
+
className="chakra-button css-1xdhyk6"
|
|
86
|
+
data-testid="button"
|
|
87
|
+
id="btn-2"
|
|
88
|
+
type="button"
|
|
89
|
+
>
|
|
90
|
+
Submit
|
|
91
|
+
</button>
|
|
92
|
+
</div>
|
|
93
|
+
`;
|
|
94
|
+
|
|
95
|
+
exports[`ButtonGroup Snapshot renders the UI snapshot correctly 5`] = `
|
|
96
|
+
<div
|
|
97
|
+
className="chakra-stack css-ytb711"
|
|
98
|
+
data-testid="testid"
|
|
99
|
+
>
|
|
100
|
+
<button
|
|
101
|
+
className="chakra-button css-1xdhyk6"
|
|
102
|
+
data-testid="button"
|
|
103
|
+
id="btn-1"
|
|
104
|
+
type="button"
|
|
105
|
+
>
|
|
106
|
+
Button
|
|
107
|
+
</button>
|
|
108
|
+
<button
|
|
109
|
+
className="chakra-button css-1xdhyk6"
|
|
110
|
+
data-testid="button"
|
|
111
|
+
id="btn-2"
|
|
112
|
+
type="button"
|
|
113
|
+
>
|
|
114
|
+
Submit
|
|
115
|
+
</button>
|
|
116
|
+
</div>
|
|
117
|
+
`;
|