@nypl/design-system-react-components 1.0.0 → 1.0.3-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -5
- package/dist/components/Checkbox/Checkbox.d.ts +0 -1
- package/dist/components/ComponentWrapper/ComponentWrapper.d.ts +8 -0
- package/dist/components/Heading/Heading.d.ts +2 -0
- package/dist/components/Logo/Logo.d.ts +1 -1
- package/dist/components/Logo/LogoSvgs.d.ts +4 -0
- package/dist/components/Slider/Slider.d.ts +1 -2
- package/dist/components/TextInput/TextInput.d.ts +2 -1
- package/dist/design-system-react-components.cjs.development.js +1038 -674
- 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 +1039 -675
- package/dist/design-system-react-components.esm.js.map +1 -1
- package/dist/hooks/{tests → __tests__}/useCarouselStyles.test.d.ts +0 -0
- package/dist/theme/components/button.d.ts +1 -0
- package/dist/theme/components/card.d.ts +98 -13
- package/dist/theme/components/checkboxGroup.d.ts +1 -1
- package/dist/theme/components/global.d.ts +2 -2
- package/dist/theme/components/heading.d.ts +4 -16
- package/dist/theme/components/image.d.ts +6 -0
- package/dist/theme/components/radio.d.ts +8 -0
- package/dist/theme/components/radioGroup.d.ts +1 -1
- package/dist/theme/components/skipNavigation.d.ts +3 -0
- package/dist/theme/components/structuredContent.d.ts +0 -5
- package/dist/theme/components/template.d.ts +4 -1
- package/dist/utils/utils.d.ts +15 -0
- package/package.json +6 -7
- package/CHANGELOG.md +0 -1399
- package/src/__tests__/fileMock.ts +0 -6
- package/src/__tests__/setup.ts +0 -27
- package/src/__tests__/utils/utils.test.ts +0 -18
- package/src/components/AccessibilityGuide/SkipNavigation.stories.mdx +0 -42
- package/src/components/Accordion/Accordion.stories.mdx +0 -361
- package/src/components/Accordion/Accordion.test.tsx +0 -237
- package/src/components/Accordion/Accordion.tsx +0 -136
- package/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +0 -734
- package/src/components/Autosuggest/Autosuggest.stories.mdx +0 -75
- package/src/components/Autosuggest/Autosuggest.stories.tsx +0 -211
- package/src/components/Autosuggest/_Autosuggest.scss +0 -51
- package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +0 -231
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +0 -144
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +0 -98
- package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +0 -695
- package/src/components/Button/Button.stories.mdx +0 -320
- package/src/components/Button/Button.test.tsx +0 -184
- package/src/components/Button/Button.tsx +0 -95
- package/src/components/Button/__snapshots__/Button.test.tsx.snap +0 -106
- package/src/components/ButtonGroup/ButtonGroup.stories.mdx +0 -147
- package/src/components/ButtonGroup/ButtonGroup.test.tsx +0 -141
- package/src/components/ButtonGroup/ButtonGroup.tsx +0 -99
- package/src/components/ButtonGroup/__snapshots__/ButtonGroup.test.tsx.snap +0 -117
- package/src/components/Card/Card.stories.mdx +0 -1043
- package/src/components/Card/Card.test.tsx +0 -388
- package/src/components/Card/Card.tsx +0 -345
- package/src/components/Card/__snapshots__/Card.test.tsx.snap +0 -568
- package/src/components/Chakra/Box.stories.mdx +0 -52
- package/src/components/Chakra/Center.stories.mdx +0 -96
- package/src/components/Chakra/Flex.stories.mdx +0 -111
- package/src/components/Chakra/Grid.stories.mdx +0 -89
- package/src/components/Chakra/Stack.stories.mdx +0 -109
- package/src/components/Checkbox/Checkbox.stories.mdx +0 -243
- package/src/components/Checkbox/Checkbox.test.tsx +0 -319
- package/src/components/Checkbox/Checkbox.tsx +0 -166
- package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +0 -616
- package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +0 -462
- package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +0 -492
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +0 -173
- package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +0 -1722
- package/src/components/ComponentWrapper/ComponentWrapper.test.tsx +0 -163
- package/src/components/ComponentWrapper/ComponentWrapper.tsx +0 -67
- package/src/components/ComponentWrapper/__snapshots__/ComponentWrapper.test.tsx.snap +0 -98
- package/src/components/DatePicker/DatePicker.stories.mdx +0 -452
- package/src/components/DatePicker/DatePicker.test.tsx +0 -940
- package/src/components/DatePicker/DatePicker.tsx +0 -450
- package/src/components/DatePicker/_DatePicker.scss +0 -100
- package/src/components/DatePicker/__snapshots__/DatePicker.test.tsx.snap +0 -889
- package/src/components/Fieldset/Fieldset.stories.mdx +0 -96
- package/src/components/Fieldset/Fieldset.test.tsx +0 -155
- package/src/components/Fieldset/Fieldset.tsx +0 -55
- package/src/components/Fieldset/__snapshots__/Fieldset.test.tsx.snap +0 -89
- package/src/components/Form/Form.stories.mdx +0 -426
- package/src/components/Form/Form.test.tsx +0 -234
- package/src/components/Form/Form.tsx +0 -124
- package/src/components/Form/__snapshots__/Form.test.tsx.snap +0 -115
- package/src/components/Grid/SimpleGrid.stories.mdx +0 -338
- package/src/components/Grid/SimpleGrid.test.tsx +0 -79
- package/src/components/Grid/SimpleGrid.tsx +0 -49
- package/src/components/Grid/__snapshots__/SimpleGrid.test.tsx.snap +0 -23
- package/src/components/Heading/Heading.stories.mdx +0 -184
- package/src/components/Heading/Heading.test.tsx +0 -171
- package/src/components/Heading/Heading.tsx +0 -101
- package/src/components/Heading/__snapshots__/Heading.test.tsx.snap +0 -90
- package/src/components/HelperErrorText/HelperErrorText.stories.mdx +0 -172
- package/src/components/HelperErrorText/HelperErrorText.test.tsx +0 -114
- package/src/components/HelperErrorText/HelperErrorText.tsx +0 -62
- package/src/components/HelperErrorText/__snapshots__/HelperErrorText.test.tsx.snap +0 -93
- package/src/components/Hero/Hero.stories.mdx +0 -378
- package/src/components/Hero/Hero.test.tsx +0 -611
- package/src/components/Hero/Hero.tsx +0 -203
- package/src/components/Hero/__snapshots__/Hero.test.tsx.snap +0 -379
- package/src/components/HorizontalRule/HorizontalRule.stories.mdx +0 -73
- package/src/components/HorizontalRule/HorizontalRule.test.tsx +0 -54
- package/src/components/HorizontalRule/HorizontalRule.tsx +0 -27
- package/src/components/HorizontalRule/__snapshots__/HorizontalRule.test.tsx.snap +0 -44
- package/src/components/Icons/Icon.stories.mdx +0 -413
- package/src/components/Icons/Icon.test.tsx +0 -120
- package/src/components/Icons/Icon.tsx +0 -187
- package/src/components/Icons/IconSvgs.tsx +0 -64
- package/src/components/Icons/__snapshots__/Icon.test.tsx.snap +0 -129
- package/src/components/Image/Image.stories.mdx +0 -332
- package/src/components/Image/Image.test.tsx +0 -155
- package/src/components/Image/Image.tsx +0 -171
- package/src/components/Image/__snapshots__/Image.test.tsx.snap +0 -269
- package/src/components/Label/Label.stories.mdx +0 -100
- package/src/components/Label/Label.test.tsx +0 -116
- package/src/components/Label/Label.tsx +0 -55
- package/src/components/Label/__snapshots__/Label.test.tsx.snap +0 -45
- package/src/components/Link/Link.stories.mdx +0 -249
- package/src/components/Link/Link.test.tsx +0 -224
- package/src/components/Link/Link.tsx +0 -178
- package/src/components/Link/__snapshots__/Link.test.tsx.snap +0 -286
- package/src/components/List/List.stories.mdx +0 -393
- package/src/components/List/List.test.tsx +0 -265
- package/src/components/List/List.tsx +0 -156
- package/src/components/List/__snapshots__/List.test.tsx.snap +0 -213
- package/src/components/Logo/Logo.stories.mdx +0 -290
- package/src/components/Logo/Logo.test.tsx +0 -116
- package/src/components/Logo/Logo.tsx +0 -147
- package/src/components/Logo/LogoSvgs.tsx +0 -82
- package/src/components/Logo/__snapshots__/Logo.test.tsx.snap +0 -142
- package/src/components/Modal/Modal.stories.mdx +0 -301
- package/src/components/Modal/Modal.test.tsx +0 -157
- package/src/components/Modal/Modal.tsx +0 -154
- package/src/components/Modal/__snapshots__/Modal.test.tsx.snap +0 -25
- package/src/components/Notification/Notification.stories.mdx +0 -358
- package/src/components/Notification/Notification.test.tsx +0 -279
- package/src/components/Notification/Notification.tsx +0 -224
- package/src/components/Notification/__snapshots__/Notification.test.tsx.snap +0 -525
- package/src/components/Pagination/Pagination.stories.mdx +0 -184
- package/src/components/Pagination/Pagination.test.tsx +0 -419
- package/src/components/Pagination/Pagination.tsx +0 -269
- package/src/components/Pagination/__snapshots__/Pagination.test.tsx.snap +0 -544
- package/src/components/Placeholder/Placeholder.tsx +0 -19
- package/src/components/ProgressIndicator/ProgressIndicator.stories.mdx +0 -360
- package/src/components/ProgressIndicator/ProgressIndicator.test.tsx +0 -298
- package/src/components/ProgressIndicator/ProgressIndicator.tsx +0 -132
- package/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap +0 -434
- package/src/components/Radio/Radio.stories.mdx +0 -216
- package/src/components/Radio/Radio.test.tsx +0 -247
- package/src/components/Radio/Radio.tsx +0 -128
- package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +0 -411
- package/src/components/RadioGroup/RadioGroup.stories.mdx +0 -478
- package/src/components/RadioGroup/RadioGroup.test.tsx +0 -471
- package/src/components/RadioGroup/RadioGroup.tsx +0 -170
- package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +0 -1430
- package/src/components/SearchBar/SearchBar.stories.mdx +0 -518
- package/src/components/SearchBar/SearchBar.test.tsx +0 -435
- package/src/components/SearchBar/SearchBar.tsx +0 -210
- package/src/components/SearchBar/__snapshots__/SearchBar.test.tsx.snap +0 -1027
- package/src/components/Select/Select.stories.mdx +0 -439
- package/src/components/Select/Select.test.tsx +0 -358
- package/src/components/Select/Select.tsx +0 -181
- package/src/components/Select/__snapshots__/Select.test.tsx.snap +0 -885
- package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +0 -142
- package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +0 -116
- package/src/components/SkeletonLoader/SkeletonLoader.tsx +0 -123
- package/src/components/SkeletonLoader/__snapshots__/SkeletonLoader.test.tsx.snap +0 -898
- package/src/components/SkipNavigation/SkipNavigation.stories.mdx +0 -90
- package/src/components/SkipNavigation/SkipNavigation.test.tsx +0 -63
- package/src/components/SkipNavigation/SkipNavigation.tsx +0 -51
- package/src/components/SkipNavigation/__snapshots__/SkipNavigation.test.tsx.snap +0 -130
- package/src/components/Slider/Slider.stories.mdx +0 -628
- package/src/components/Slider/Slider.test.tsx +0 -736
- package/src/components/Slider/Slider.tsx +0 -322
- package/src/components/Slider/__snapshots__/Slider.test.tsx.snap +0 -2153
- package/src/components/StatusBadge/StatusBadge.stories.mdx +0 -109
- package/src/components/StatusBadge/StatusBadge.test.tsx +0 -70
- package/src/components/StatusBadge/StatusBadge.tsx +0 -35
- package/src/components/StatusBadge/__snapshots__/StatusBadge.test.tsx.snap +0 -47
- package/src/components/StructuredContent/StructuredContent.stories.mdx +0 -567
- package/src/components/StructuredContent/StructuredContent.test.tsx +0 -435
- package/src/components/StructuredContent/StructuredContent.tsx +0 -139
- package/src/components/StructuredContent/__snapshots__/StructuredContent.test.tsx.snap +0 -368
- package/src/components/StyleGuide/Bidirectionality.stories.mdx +0 -206
- package/src/components/StyleGuide/Breakpoints.stories.mdx +0 -55
- package/src/components/StyleGuide/Buttons.stories.mdx +0 -194
- package/src/components/StyleGuide/ColorCard.tsx +0 -43
- package/src/components/StyleGuide/Colors.stories.mdx +0 -201
- package/src/components/StyleGuide/DesignTokens.stories.mdx +0 -193
- package/src/components/StyleGuide/Forms.stories.mdx +0 -94
- package/src/components/StyleGuide/Iconography.stories.mdx +0 -142
- package/src/components/StyleGuide/Spacing.stories.mdx +0 -116
- package/src/components/StyleGuide/Typography.stories.mdx +0 -419
- package/src/components/Table/Table.stories.mdx +0 -276
- package/src/components/Table/Table.test.tsx +0 -208
- package/src/components/Table/Table.tsx +0 -131
- package/src/components/Table/__snapshots__/Table.test.tsx.snap +0 -1703
- package/src/components/Tabs/Tabs.stories.mdx +0 -338
- package/src/components/Tabs/Tabs.test.tsx +0 -298
- package/src/components/Tabs/Tabs.tsx +0 -264
- package/src/components/Tabs/__snapshots__/Tabs.test.tsx.snap +0 -584
- package/src/components/Template/Template.stories.mdx +0 -691
- package/src/components/Template/Template.test.tsx +0 -309
- package/src/components/Template/Template.tsx +0 -326
- package/src/components/Template/__snapshots__/Template.test.tsx.snap +0 -342
- package/src/components/Text/Text.stories.mdx +0 -103
- package/src/components/Text/Text.test.tsx +0 -63
- package/src/components/Text/Text.tsx +0 -50
- package/src/components/Text/__snapshots__/Text.test.tsx.snap +0 -50
- package/src/components/TextInput/TextInput.stories.mdx +0 -268
- package/src/components/TextInput/TextInput.test.tsx +0 -451
- package/src/components/TextInput/TextInput.tsx +0 -240
- package/src/components/TextInput/__snapshots__/TextInput.test.tsx.snap +0 -264
- package/src/components/Toggle/Toggle.stories.mdx +0 -237
- package/src/components/Toggle/Toggle.test.tsx +0 -170
- package/src/components/Toggle/Toggle.tsx +0 -126
- package/src/components/Toggle/__snapshots__/Toggle.test.tsx.snap +0 -442
- package/src/components/VideoPlayer/VideoPlayer.stories.mdx +0 -211
- package/src/components/VideoPlayer/VideoPlayer.test.tsx +0 -308
- package/src/components/VideoPlayer/VideoPlayer.tsx +0 -188
- package/src/components/VideoPlayer/__snapshots__/VideoPlayer.test.tsx.snap +0 -187
- package/src/docs/Chakra.stories.mdx +0 -563
- package/src/docs/Welcome.stories.mdx +0 -148
- package/src/helpers/types.ts +0 -1
- package/src/hooks/tests/useCarouselStyles.test.ts +0 -140
- package/src/hooks/tests/useNYPLTheme.test.tsx +0 -36
- package/src/hooks/useCarouselStyles.stories.mdx +0 -30
- package/src/hooks/useCarouselStyles.ts +0 -35
- package/src/hooks/useNYPLTheme.stories.mdx +0 -98
- package/src/hooks/useNYPLTheme.ts +0 -91
- package/src/hooks/useWindowSize.stories.mdx +0 -23
- package/src/hooks/useWindowSize.ts +0 -40
- package/src/index.ts +0 -136
- package/src/resources.scss +0 -6
- package/src/styles/base/_01-breakpoints.scss +0 -27
- package/src/styles/base/_02-mixins.scss +0 -103
- package/src/styles/base/_place-holder.scss +0 -33
- package/src/styles/space/_space-inline.scss +0 -79
- package/src/styles/space/_space-inset.scss +0 -57
- package/src/styles/space/_space-stack.scss +0 -116
- package/src/styles.scss +0 -23
- package/src/theme/components/accordion.ts +0 -25
- package/src/theme/components/breadcrumb.ts +0 -94
- package/src/theme/components/button.ts +0 -132
- package/src/theme/components/buttonGroup.ts +0 -10
- package/src/theme/components/card.ts +0 -231
- package/src/theme/components/checkbox.ts +0 -110
- package/src/theme/components/checkboxGroup.ts +0 -10
- package/src/theme/components/componentWrapper.ts +0 -14
- package/src/theme/components/customTable.ts +0 -77
- package/src/theme/components/datePicker.ts +0 -17
- package/src/theme/components/fieldset.ts +0 -23
- package/src/theme/components/global.ts +0 -91
- package/src/theme/components/globalMixins.ts +0 -24
- package/src/theme/components/heading.ts +0 -79
- package/src/theme/components/helperErrorText.ts +0 -14
- package/src/theme/components/hero.ts +0 -238
- package/src/theme/components/horizontalRule.ts +0 -17
- package/src/theme/components/icon.ts +0 -88
- package/src/theme/components/image.ts +0 -135
- package/src/theme/components/label.ts +0 -15
- package/src/theme/components/link.ts +0 -63
- package/src/theme/components/list.ts +0 -88
- package/src/theme/components/logo.ts +0 -58
- package/src/theme/components/notification.ts +0 -132
- package/src/theme/components/pagination.ts +0 -17
- package/src/theme/components/progressIndicator.ts +0 -67
- package/src/theme/components/radio.ts +0 -103
- package/src/theme/components/radioGroup.ts +0 -10
- package/src/theme/components/searchBar.ts +0 -19
- package/src/theme/components/select.ts +0 -72
- package/src/theme/components/skeletonLoader.ts +0 -113
- package/src/theme/components/skipNavigation.ts +0 -26
- package/src/theme/components/slider.ts +0 -95
- package/src/theme/components/statusBadge.ts +0 -26
- package/src/theme/components/structuredContent.ts +0 -149
- package/src/theme/components/tabs.ts +0 -109
- package/src/theme/components/template.ts +0 -114
- package/src/theme/components/text.ts +0 -38
- package/src/theme/components/textInput.ts +0 -65
- package/src/theme/components/toggle.ts +0 -109
- package/src/theme/components/videoPlayer.ts +0 -47
- package/src/theme/foundations/breakpoints.ts +0 -24
- package/src/theme/foundations/colors.ts +0 -212
- package/src/theme/foundations/global.ts +0 -43
- package/src/theme/foundations/radii.ts +0 -7
- package/src/theme/foundations/shadows.ts +0 -5
- package/src/theme/foundations/spacing.ts +0 -136
- package/src/theme/foundations/typography.ts +0 -107
- package/src/theme/index.ts +0 -131
- package/src/theme/provider.tsx +0 -9
- package/src/theme/types.ts +0 -1
- package/src/utils/componentCategories.ts +0 -152
- package/src/utils/interfaces.ts +0 -5
- package/src/utils/utils.ts +0 -44
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import { HStack, VStack, Grid, Box } from "@chakra-ui/react";
|
|
2
|
-
import {
|
|
3
|
-
Meta,
|
|
4
|
-
Story,
|
|
5
|
-
Canvas,
|
|
6
|
-
ArgsTable,
|
|
7
|
-
Description,
|
|
8
|
-
} from "@storybook/addon-docs";
|
|
9
|
-
import { withDesign } from "storybook-addon-designs";
|
|
10
|
-
|
|
11
|
-
import Heading from "../Heading/Heading";
|
|
12
|
-
import SimpleGrid from "../Grid/SimpleGrid";
|
|
13
|
-
import Toggle from "./Toggle";
|
|
14
|
-
import { getCategory } from "../../utils/componentCategories";
|
|
15
|
-
import DSProvider from "../../theme/provider";
|
|
16
|
-
|
|
17
|
-
<Meta
|
|
18
|
-
title={getCategory("Toggle")}
|
|
19
|
-
component={Toggle}
|
|
20
|
-
decorators={[withDesign]}
|
|
21
|
-
parameters={{
|
|
22
|
-
design: {
|
|
23
|
-
type: "figma",
|
|
24
|
-
url: "https://www.figma.com/file/qShodlfNCJHb8n03IFyApM/Main?node-id=31581%3A302",
|
|
25
|
-
},
|
|
26
|
-
jest: ["Toggle.test.tsx"],
|
|
27
|
-
}}
|
|
28
|
-
argTypes={{
|
|
29
|
-
defaultChecked: { control: false },
|
|
30
|
-
id: { control: false },
|
|
31
|
-
key: { table: { disable: true } },
|
|
32
|
-
name: { control: false },
|
|
33
|
-
onChange: { control: false },
|
|
34
|
-
ref: { table: { disable: true } },
|
|
35
|
-
size: {
|
|
36
|
-
control: {
|
|
37
|
-
table: { defaultValue: { summary: "default" } },
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
}}
|
|
41
|
-
/>
|
|
42
|
-
|
|
43
|
-
# Toggle
|
|
44
|
-
|
|
45
|
-
| Component Version | DS Version |
|
|
46
|
-
| ----------------- | ---------- |
|
|
47
|
-
| Added | `0.25.8` |
|
|
48
|
-
| Latest | `0.28.0` |
|
|
49
|
-
|
|
50
|
-
## Table of Contents
|
|
51
|
-
|
|
52
|
-
- [Overview](#overview)
|
|
53
|
-
- [Component Props](#component-props)
|
|
54
|
-
- [Accessibility](#accessibility)
|
|
55
|
-
- [Sizes](#sizes)
|
|
56
|
-
- [Controlled Toggle](#controlled-toggle)
|
|
57
|
-
- [Browser States](#browser-states)
|
|
58
|
-
- [Layouts](#layouts)
|
|
59
|
-
|
|
60
|
-
## Overview
|
|
61
|
-
|
|
62
|
-
<Description of={Toggle} />
|
|
63
|
-
|
|
64
|
-
The `Toggle` component is used as an alternative for the Checkbox component and
|
|
65
|
-
returns a boolean response. Like the Checkbox component, the `Toggle` component
|
|
66
|
-
can display a label to the right of the toggle and helper/error text below the toggle.
|
|
67
|
-
|
|
68
|
-
### Best Practices
|
|
69
|
-
|
|
70
|
-
`Toggle` components are commonly used for “on/off” switches to perform binary
|
|
71
|
-
actions that occur immediately after a user “flips the switch.”
|
|
72
|
-
|
|
73
|
-
The Toggle component label should clarify the action being performed. Labels
|
|
74
|
-
should be short and to the point, often three words or less.
|
|
75
|
-
|
|
76
|
-
## Component Props
|
|
77
|
-
|
|
78
|
-
<Canvas>
|
|
79
|
-
<Story
|
|
80
|
-
name="Toggle"
|
|
81
|
-
args={{
|
|
82
|
-
defaultChecked: false,
|
|
83
|
-
helperText: "This is the helper text!",
|
|
84
|
-
id: "toggle-1",
|
|
85
|
-
invalidText: "",
|
|
86
|
-
isChecked: undefined,
|
|
87
|
-
isDisabled: false,
|
|
88
|
-
isInvalid: false,
|
|
89
|
-
isRequired: false,
|
|
90
|
-
labelText: "Test Label",
|
|
91
|
-
name: "toggle-1",
|
|
92
|
-
onChange: undefined,
|
|
93
|
-
size: "ToogleSizes.Large",
|
|
94
|
-
}}
|
|
95
|
-
>
|
|
96
|
-
{(args) => <Toggle {...args} />}
|
|
97
|
-
</Story>
|
|
98
|
-
</Canvas>
|
|
99
|
-
|
|
100
|
-
<ArgsTable story="Toggle" />
|
|
101
|
-
|
|
102
|
-
## Accessibility
|
|
103
|
-
|
|
104
|
-
The `Toggle` component is implemented using Chakra's `Switch` component. While
|
|
105
|
-
some accessibility resources state that using a `<button>` element is better for
|
|
106
|
-
a toggle or switch component, Chakra UI internally uses a `checkbox` element.
|
|
107
|
-
Because Chakra's `Switch` component handles the internal state so well and its
|
|
108
|
-
styles, we chose this over implementing this component with a `<button>` element.
|
|
109
|
-
|
|
110
|
-
For comparison and reference, resources that build toggle components with the
|
|
111
|
-
`<button>` element are linked below.
|
|
112
|
-
|
|
113
|
-
Resources:
|
|
114
|
-
|
|
115
|
-
- [Chakra UI Switch](https://chakra-ui.com/docs/components/form/switch)
|
|
116
|
-
- [W3C Switch Example Using HTML Button](https://w3c.github.io/aria-practices/examples/switch/switch-button.html)
|
|
117
|
-
- [Inclusive Components Toggle Buttons](https://inclusive-components.design/toggle-button/)
|
|
118
|
-
- [Accessible HTML Toggle Button (Switch)](https://www.erikkroes.nl/blog/accessible-html-toggle-button-switch/)
|
|
119
|
-
|
|
120
|
-
## Sizes
|
|
121
|
-
|
|
122
|
-
<Canvas>
|
|
123
|
-
<DSProvider>
|
|
124
|
-
<SimpleGrid columns="2">
|
|
125
|
-
<VStack align="left" spacing="s">
|
|
126
|
-
<Heading level={3}>Default</Heading>
|
|
127
|
-
<Toggle defaultChecked={true} id="default-checked" labelText="On" />
|
|
128
|
-
<Toggle id="default" labelText="Off" />
|
|
129
|
-
</VStack>
|
|
130
|
-
<VStack align="left" spacing="s">
|
|
131
|
-
<Heading level={3}>Small</Heading>
|
|
132
|
-
<Toggle
|
|
133
|
-
defaultChecked={true}
|
|
134
|
-
id="small-checked"
|
|
135
|
-
size="small"
|
|
136
|
-
labelText="On"
|
|
137
|
-
/>
|
|
138
|
-
<Toggle id="default-small" size="small" labelText="Off" />
|
|
139
|
-
</VStack>
|
|
140
|
-
</SimpleGrid>
|
|
141
|
-
</DSProvider>
|
|
142
|
-
</Canvas>
|
|
143
|
-
|
|
144
|
-
## Controlled Toggle
|
|
145
|
-
|
|
146
|
-
Note that the `isChecked` property in this example is set to `true`. Clicking
|
|
147
|
-
on it won't change the toggle; The `isChecked` prop must now be controlled
|
|
148
|
-
and removed manually by the parent component that controls this state. The
|
|
149
|
-
`onChange` function will be called every time the `isChecked` prop changes.
|
|
150
|
-
|
|
151
|
-
```jsx
|
|
152
|
-
const isChecked = true;
|
|
153
|
-
const onChange = (e) => {
|
|
154
|
-
// This will return the value through the event object.
|
|
155
|
-
console.log(e.target.value);
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
<Toggle
|
|
159
|
-
id="toggle"
|
|
160
|
-
isChecked={true}
|
|
161
|
-
labelText="Controlled Toggle"
|
|
162
|
-
onChange={onChange}
|
|
163
|
-
/>;
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
<Canvas>
|
|
167
|
-
<DSProvider>
|
|
168
|
-
<Toggle
|
|
169
|
-
id="toggle"
|
|
170
|
-
isChecked={true}
|
|
171
|
-
labelText="Controlled Toggle"
|
|
172
|
-
onChange={(e) => {
|
|
173
|
-
console.log(e.target.value);
|
|
174
|
-
}}
|
|
175
|
-
/>
|
|
176
|
-
</DSProvider>
|
|
177
|
-
</Canvas>
|
|
178
|
-
|
|
179
|
-
## Browser States
|
|
180
|
-
|
|
181
|
-
<Canvas>
|
|
182
|
-
<DSProvider>
|
|
183
|
-
<SimpleGrid columns="3">
|
|
184
|
-
<VStack align="left" spacing="s">
|
|
185
|
-
<Heading level={3}>Default</Heading>
|
|
186
|
-
<Toggle defaultChecked={true} id="checked-default2" labelText="On" />
|
|
187
|
-
<Toggle id="default2" labelText="Off" />
|
|
188
|
-
</VStack>
|
|
189
|
-
<VStack align="left" spacing="s">
|
|
190
|
-
<Heading level={3}>Disabled</Heading>
|
|
191
|
-
<Toggle
|
|
192
|
-
defaultChecked={true}
|
|
193
|
-
id="disabled-checked"
|
|
194
|
-
isDisabled={true}
|
|
195
|
-
labelText="On"
|
|
196
|
-
/>
|
|
197
|
-
<Toggle id="disabled2" isDisabled={true} labelText="Off" />
|
|
198
|
-
</VStack>
|
|
199
|
-
<VStack align="left" spacing="s">
|
|
200
|
-
<Heading level={3}>Error</Heading>
|
|
201
|
-
<Toggle
|
|
202
|
-
defaultChecked={true}
|
|
203
|
-
id="error-default"
|
|
204
|
-
isInvalid={true}
|
|
205
|
-
labelText="On"
|
|
206
|
-
/>
|
|
207
|
-
<Toggle id="error2" isInvalid={true} labelText="Off" />
|
|
208
|
-
</VStack>
|
|
209
|
-
</SimpleGrid>
|
|
210
|
-
</DSProvider>
|
|
211
|
-
</Canvas>
|
|
212
|
-
|
|
213
|
-
## Layouts
|
|
214
|
-
|
|
215
|
-
<Canvas>
|
|
216
|
-
<DSProvider>
|
|
217
|
-
<SimpleGrid columns="2">
|
|
218
|
-
<VStack align="left" spacing="s">
|
|
219
|
-
<Heading level={3}>Grouped</Heading>
|
|
220
|
-
<Toggle defaultChecked={true} id="layout1" labelText="On" />
|
|
221
|
-
<Toggle defaultChecked={true} id="layout2" labelText="On" />
|
|
222
|
-
<Toggle defaultChecked={true} id="layout3" labelText="On" />
|
|
223
|
-
<Toggle defaultChecked={true} id="layout4" labelText="On" />
|
|
224
|
-
<Toggle defaultChecked={true} id="layout5" labelText="On" />
|
|
225
|
-
</VStack>
|
|
226
|
-
<VStack align="left" spacing="s">
|
|
227
|
-
<Heading level={3}>With Helper Text</Heading>
|
|
228
|
-
<Toggle
|
|
229
|
-
defaultChecked={true}
|
|
230
|
-
helperText="Component Helper Text"
|
|
231
|
-
id="helper-text"
|
|
232
|
-
labelText="On"
|
|
233
|
-
/>
|
|
234
|
-
</VStack>
|
|
235
|
-
</SimpleGrid>
|
|
236
|
-
</DSProvider>
|
|
237
|
-
</Canvas>
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { render, screen } from "@testing-library/react";
|
|
2
|
-
import userEvent from "@testing-library/user-event";
|
|
3
|
-
import { axe } from "jest-axe";
|
|
4
|
-
import * as React from "react";
|
|
5
|
-
import renderer from "react-test-renderer";
|
|
6
|
-
|
|
7
|
-
import Toggle from "./Toggle";
|
|
8
|
-
|
|
9
|
-
describe("Toggle Accessibility", () => {
|
|
10
|
-
it("Passes axe accessibility test", async () => {
|
|
11
|
-
const { container } = render(
|
|
12
|
-
<Toggle id="inputID" onChange={jest.fn()} labelText="Test Label" />
|
|
13
|
-
);
|
|
14
|
-
expect(await axe(container)).toHaveNoViolations();
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe("Toggle", () => {
|
|
19
|
-
let changeHandler: jest.MockedFunction<() => void>;
|
|
20
|
-
|
|
21
|
-
beforeEach(() => {
|
|
22
|
-
changeHandler = jest.fn();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("Renders with a Toggle input and label", () => {
|
|
26
|
-
render(<Toggle id="inputID" labelText="Test Label" />);
|
|
27
|
-
expect(screen.getByLabelText("Test Label")).toBeInTheDocument();
|
|
28
|
-
expect(screen.getByRole("checkbox")).toBeInTheDocument();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("Renders visible helper or error text", () => {
|
|
32
|
-
const { rerender } = render(
|
|
33
|
-
<Toggle
|
|
34
|
-
id="inputID"
|
|
35
|
-
labelText="Test Label"
|
|
36
|
-
helperText="This is the helper text."
|
|
37
|
-
invalidText="This is the error text :("
|
|
38
|
-
/>
|
|
39
|
-
);
|
|
40
|
-
expect(screen.getByText("This is the helper text.")).toBeVisible();
|
|
41
|
-
expect(
|
|
42
|
-
screen.queryByText("This is the error text :(")
|
|
43
|
-
).not.toBeInTheDocument();
|
|
44
|
-
|
|
45
|
-
rerender(
|
|
46
|
-
<Toggle
|
|
47
|
-
id="inputID"
|
|
48
|
-
labelText="Test Label"
|
|
49
|
-
isInvalid
|
|
50
|
-
helperText="This is the helper text."
|
|
51
|
-
invalidText="This is the error text :("
|
|
52
|
-
/>
|
|
53
|
-
);
|
|
54
|
-
expect(screen.getByText("This is the error text :(")).toBeVisible();
|
|
55
|
-
expect(
|
|
56
|
-
screen.queryByText("This is the helper text.")
|
|
57
|
-
).not.toBeInTheDocument();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("Sets the Toggle's ID", () => {
|
|
61
|
-
render(<Toggle id="inputID" labelText="Test Label" />);
|
|
62
|
-
expect(screen.getByRole("checkbox")).toHaveAttribute("id", "inputID");
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("Sets the 'checked' attribute", () => {
|
|
66
|
-
render(<Toggle id="inputID" labelText="Test Label" isChecked />);
|
|
67
|
-
expect(screen.getByRole("checkbox")).toHaveAttribute("checked");
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("Sets the 'disabled' attribute", () => {
|
|
71
|
-
render(<Toggle id="inputID" labelText="Test Label" isDisabled />);
|
|
72
|
-
expect(screen.getByRole("checkbox")).toHaveAttribute("disabled");
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("Sets the error state", () => {
|
|
76
|
-
render(
|
|
77
|
-
<Toggle
|
|
78
|
-
id="inputID-attributes"
|
|
79
|
-
labelText="onChange test"
|
|
80
|
-
invalidText="This is the error text!"
|
|
81
|
-
isInvalid
|
|
82
|
-
/>
|
|
83
|
-
);
|
|
84
|
-
expect(screen.getByRole("checkbox")).toHaveAttribute("aria-invalid");
|
|
85
|
-
expect(screen.getByText("This is the error text!")).toBeInTheDocument();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("does not render the error text when 'isInvalid' is true but 'invalidText' is not passed", () => {
|
|
89
|
-
render(
|
|
90
|
-
<Toggle id="inputID-attributes" labelText="onChange test" isInvalid />
|
|
91
|
-
);
|
|
92
|
-
expect(screen.getByRole("checkbox")).toHaveAttribute("aria-invalid");
|
|
93
|
-
expect(
|
|
94
|
-
screen.queryByText("This is the error text!")
|
|
95
|
-
).not.toBeInTheDocument();
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it("Changing the value calls the onChange handler", () => {
|
|
99
|
-
const utils = render(
|
|
100
|
-
<Toggle
|
|
101
|
-
id="onChangeTest"
|
|
102
|
-
onChange={changeHandler}
|
|
103
|
-
labelText="onChangeTest Lab"
|
|
104
|
-
isChecked
|
|
105
|
-
/>
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
expect(changeHandler).toHaveBeenCalledTimes(0);
|
|
109
|
-
userEvent.click(utils.getByText("onChangeTest Lab"));
|
|
110
|
-
expect(changeHandler).toHaveBeenCalledTimes(1);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("Logs a warning when there is no `id` passed", () => {
|
|
114
|
-
const warn = jest.spyOn(console, "warn");
|
|
115
|
-
render(
|
|
116
|
-
// @ts-ignore: Typescript complains when a required prop is not passed, but
|
|
117
|
-
// here we don't want to pass the required prop to make sure the warning appears.
|
|
118
|
-
<Toggle labelText="test" />
|
|
119
|
-
);
|
|
120
|
-
expect(warn).toHaveBeenCalledWith(
|
|
121
|
-
"NYPL Reservoir Toggle: This component's required `id` prop was not passed."
|
|
122
|
-
);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it("Renders the UI snapshot correctly", () => {
|
|
126
|
-
const primary = renderer
|
|
127
|
-
.create(<Toggle id="inputID" labelText="Test Label" />)
|
|
128
|
-
.toJSON();
|
|
129
|
-
const isChecked = renderer
|
|
130
|
-
.create(<Toggle id="Toggle-checked" labelText="Test Label" isChecked />)
|
|
131
|
-
.toJSON();
|
|
132
|
-
const isInvalid = renderer
|
|
133
|
-
.create(<Toggle id="Toggle-invalid" labelText="Test Label" isInvalid />)
|
|
134
|
-
.toJSON();
|
|
135
|
-
const isDisabled = renderer
|
|
136
|
-
.create(<Toggle id="Toggle-disabled" labelText="Test Label" isDisabled />)
|
|
137
|
-
.toJSON();
|
|
138
|
-
const small = renderer
|
|
139
|
-
.create(
|
|
140
|
-
<Toggle
|
|
141
|
-
id="Toggle-disabled"
|
|
142
|
-
labelText="Test Label"
|
|
143
|
-
isDisabled
|
|
144
|
-
size="small"
|
|
145
|
-
/>
|
|
146
|
-
)
|
|
147
|
-
.toJSON();
|
|
148
|
-
const withChakraProps = renderer
|
|
149
|
-
.create(
|
|
150
|
-
<Toggle
|
|
151
|
-
id="chakra"
|
|
152
|
-
labelText="Test Label"
|
|
153
|
-
p="20px"
|
|
154
|
-
color="ui.error.primray"
|
|
155
|
-
/>
|
|
156
|
-
)
|
|
157
|
-
.toJSON();
|
|
158
|
-
const withOtherProps = renderer
|
|
159
|
-
.create(<Toggle id="props" labelText="Test Label" data-testid="props" />)
|
|
160
|
-
.toJSON();
|
|
161
|
-
|
|
162
|
-
expect(primary).toMatchSnapshot();
|
|
163
|
-
expect(isChecked).toMatchSnapshot();
|
|
164
|
-
expect(isInvalid).toMatchSnapshot();
|
|
165
|
-
expect(isDisabled).toMatchSnapshot();
|
|
166
|
-
expect(small).toMatchSnapshot();
|
|
167
|
-
expect(withChakraProps).toMatchSnapshot();
|
|
168
|
-
expect(withOtherProps).toMatchSnapshot();
|
|
169
|
-
});
|
|
170
|
-
});
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Box,
|
|
3
|
-
chakra,
|
|
4
|
-
Switch,
|
|
5
|
-
useMultiStyleConfig,
|
|
6
|
-
useStyleConfig,
|
|
7
|
-
} from "@chakra-ui/react";
|
|
8
|
-
import * as React from "react";
|
|
9
|
-
|
|
10
|
-
import HelperErrorText, {
|
|
11
|
-
HelperErrorTextType,
|
|
12
|
-
} from "../HelperErrorText/HelperErrorText";
|
|
13
|
-
import { AriaAttributes } from "../../utils/interfaces";
|
|
14
|
-
|
|
15
|
-
export type ToggleSizes = "default" | "small";
|
|
16
|
-
export interface ToggleProps {
|
|
17
|
-
/** Used for uncontrolled scenarios. Sets the state of the Toggle when the page first loads.
|
|
18
|
-
* If true, the toggle will be initially set to the "on" position. */
|
|
19
|
-
defaultChecked?: boolean;
|
|
20
|
-
/** Optional string to populate the HelperErrorText for standard state */
|
|
21
|
-
helperText?: HelperErrorTextType;
|
|
22
|
-
/** ID that other components can cross reference for accessibility purposes */
|
|
23
|
-
id: string;
|
|
24
|
-
/** Optional string to populate the HelperErrorText for the error state
|
|
25
|
-
* when `isInvalid` is true. */
|
|
26
|
-
invalidText?: HelperErrorTextType;
|
|
27
|
-
/** When using the Toggle as a "controlled" form element, you can specify
|
|
28
|
-
* the Toggle's checked state using this prop.
|
|
29
|
-
* Learn more about controlled and uncontrolled form fields:
|
|
30
|
-
* https://goshakkk.name/controlled-vs-uncontrolled-inputs-react/ */
|
|
31
|
-
isChecked?: boolean;
|
|
32
|
-
/** Adds the 'disabled' and `aria-disabled` attributes to the input when true.
|
|
33
|
-
* This also makes the text italic and color scheme gray. */
|
|
34
|
-
isDisabled?: boolean;
|
|
35
|
-
/** Adds the 'aria-invalid' attribute to the input when true. */
|
|
36
|
-
isInvalid?: boolean;
|
|
37
|
-
/** Adds the 'required' attribute to the input when true. */
|
|
38
|
-
isRequired?: boolean;
|
|
39
|
-
/** The toggle's label. This will serve as the text content for the `<label>` element */
|
|
40
|
-
labelText: string;
|
|
41
|
-
/** The name prop indicates the `Toggle`'s form element name. If none is
|
|
42
|
-
* specified, 'default' will be used. */
|
|
43
|
-
name?: string;
|
|
44
|
-
/** The action to perform on the `<input>`'s onChange function */
|
|
45
|
-
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
46
|
-
/** The size of the Toggle. Defaults to "large". */
|
|
47
|
-
size?: ToggleSizes;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export const onChangeDefault = () => {
|
|
51
|
-
return;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Component that renders Chakra's `Switch` component along with NYPL defaults.
|
|
56
|
-
*/
|
|
57
|
-
export const Toggle = chakra(
|
|
58
|
-
React.forwardRef<HTMLInputElement, ToggleProps>((props, ref?) => {
|
|
59
|
-
const {
|
|
60
|
-
defaultChecked = false,
|
|
61
|
-
helperText,
|
|
62
|
-
id,
|
|
63
|
-
invalidText,
|
|
64
|
-
isChecked,
|
|
65
|
-
isDisabled = false,
|
|
66
|
-
isInvalid = false,
|
|
67
|
-
isRequired = false,
|
|
68
|
-
labelText,
|
|
69
|
-
name,
|
|
70
|
-
onChange = onChangeDefault,
|
|
71
|
-
size = "default",
|
|
72
|
-
...rest
|
|
73
|
-
} = props;
|
|
74
|
-
const footnote = isInvalid ? invalidText : helperText;
|
|
75
|
-
const ariaAttributes: AriaAttributes = {};
|
|
76
|
-
const styles = useMultiStyleConfig("Toggle", { isDisabled, size });
|
|
77
|
-
const switchStyles = useStyleConfig("Switch", { size });
|
|
78
|
-
ariaAttributes["aria-label"] =
|
|
79
|
-
labelText && footnote ? `${labelText} - ${footnote}` : labelText;
|
|
80
|
-
|
|
81
|
-
if (!id) {
|
|
82
|
-
console.warn(
|
|
83
|
-
"NYPL Reservoir Toggle: This component's required `id` prop was not passed."
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
<>
|
|
89
|
-
<Box __css={styles} {...rest}>
|
|
90
|
-
<Switch
|
|
91
|
-
id={id}
|
|
92
|
-
name={name || "default"}
|
|
93
|
-
isDisabled={isDisabled}
|
|
94
|
-
isInvalid={isInvalid}
|
|
95
|
-
isRequired={isRequired}
|
|
96
|
-
ref={ref}
|
|
97
|
-
size={size === "default" ? "lg" : "sm"}
|
|
98
|
-
lineHeight="1.5"
|
|
99
|
-
{...(isChecked !== undefined
|
|
100
|
-
? {
|
|
101
|
-
isChecked,
|
|
102
|
-
onChange,
|
|
103
|
-
}
|
|
104
|
-
: {
|
|
105
|
-
defaultChecked,
|
|
106
|
-
})}
|
|
107
|
-
{...ariaAttributes}
|
|
108
|
-
__css={switchStyles}
|
|
109
|
-
>
|
|
110
|
-
{labelText}
|
|
111
|
-
</Switch>
|
|
112
|
-
</Box>
|
|
113
|
-
{footnote && (
|
|
114
|
-
<HelperErrorText
|
|
115
|
-
id={`${id}-helperText`}
|
|
116
|
-
isInvalid={isInvalid}
|
|
117
|
-
text={footnote}
|
|
118
|
-
__css={styles.helperErrorText}
|
|
119
|
-
/>
|
|
120
|
-
)}
|
|
121
|
-
</>
|
|
122
|
-
);
|
|
123
|
-
})
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
export default Toggle;
|