@hyphen/hyphen-components 2.9.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/LICENSE +21 -0
- package/README.md +70 -0
- package/package.json +138 -0
- package/src/components/Alert/Alert.constants.ts +19 -0
- package/src/components/Alert/Alert.mdx +29 -0
- package/src/components/Alert/Alert.module.scss +74 -0
- package/src/components/Alert/Alert.stories.tsx +102 -0
- package/src/components/Alert/Alert.test.tsx +187 -0
- package/src/components/Alert/Alert.tsx +157 -0
- package/src/components/Alert/Alert.types.ts +14 -0
- package/src/components/Badge/Badge.mdx +28 -0
- package/src/components/Badge/Badge.module.scss +155 -0
- package/src/components/Badge/Badge.stories.tsx +52 -0
- package/src/components/Badge/Badge.test.tsx +74 -0
- package/src/components/Badge/Badge.tsx +70 -0
- package/src/components/Box/Box.mdx +259 -0
- package/src/components/Box/Box.module.scss +16 -0
- package/src/components/Box/Box.stories.tsx +1679 -0
- package/src/components/Box/Box.test.tsx +478 -0
- package/src/components/Box/Box.tsx +636 -0
- package/src/components/Button/Button.constants.ts +10 -0
- package/src/components/Button/Button.mdx +71 -0
- package/src/components/Button/Button.module.scss +312 -0
- package/src/components/Button/Button.stories.tsx +117 -0
- package/src/components/Button/Button.test.tsx +460 -0
- package/src/components/Button/Button.tsx +241 -0
- package/src/components/Card/Card.mdx +46 -0
- package/src/components/Card/Card.module.scss +6 -0
- package/src/components/Card/Card.stories.tsx +101 -0
- package/src/components/Card/Card.test.tsx +11 -0
- package/src/components/Card/Card.tsx +61 -0
- package/src/components/Card/components/CardFooter/CardFooter.test.tsx +11 -0
- package/src/components/Card/components/CardFooter/CardFooter.tsx +35 -0
- package/src/components/Card/components/CardHeader/CardHeader.test.tsx +23 -0
- package/src/components/Card/components/CardHeader/CardHeader.tsx +54 -0
- package/src/components/Card/components/CardSection/CardSection.test.tsx +28 -0
- package/src/components/Card/components/CardSection/CardSection.tsx +102 -0
- package/src/components/Card/components/index.ts +3 -0
- package/src/components/CheckboxInput/CheckboxInput.mdx +98 -0
- package/src/components/CheckboxInput/CheckboxInput.stories.tsx +254 -0
- package/src/components/CheckboxInput/CheckboxInput.test.tsx +436 -0
- package/src/components/CheckboxInput/CheckboxInput.tsx +171 -0
- package/src/components/CheckboxInput/components/Checkbox.module.scss +174 -0
- package/src/components/CheckboxInput/components/Checkbox.test.tsx +201 -0
- package/src/components/CheckboxInput/components/Checkbox.tsx +176 -0
- package/src/components/CheckboxInput/components/CheckboxIcon.tsx +71 -0
- package/src/components/DateInput/DateInput.mdx +61 -0
- package/src/components/DateInput/DateInput.stories.tsx +168 -0
- package/src/components/DateInput/DateInput.test.tsx +258 -0
- package/src/components/DateInput/DateInput.tsx +189 -0
- package/src/components/DatePicker/DatePicker.mdx +52 -0
- package/src/components/DatePicker/DatePicker.module.scss +603 -0
- package/src/components/DatePicker/DatePicker.stories.tsx +199 -0
- package/src/components/DatePicker/DatePicker.test.tsx +26 -0
- package/src/components/DatePicker/DatePicker.tsx +138 -0
- package/src/components/Details/Details.mdx +30 -0
- package/src/components/Details/Details.module.scss +32 -0
- package/src/components/Details/Details.stories.tsx +38 -0
- package/src/components/Details/Details.test.tsx +189 -0
- package/src/components/Details/Details.tsx +51 -0
- package/src/components/Details/DetailsSummary.tsx +65 -0
- package/src/components/Drawer/Drawer.mdx +117 -0
- package/src/components/Drawer/Drawer.module.scss +96 -0
- package/src/components/Drawer/Drawer.stories.tsx +380 -0
- package/src/components/Drawer/Drawer.test.tsx +90 -0
- package/src/components/Drawer/Drawer.tsx +249 -0
- package/src/components/FormControl/FormControl.tsx +78 -0
- package/src/components/FormLabel/FormLabel.mdx +24 -0
- package/src/components/FormLabel/FormLabel.module.scss +19 -0
- package/src/components/FormLabel/FormLabel.stories.tsx +20 -0
- package/src/components/FormLabel/FormLabel.test.tsx +35 -0
- package/src/components/FormLabel/FormLabel.tsx +96 -0
- package/src/components/Formik/Formik.mdx +10 -0
- package/src/components/Formik/Formik.stories.tsx +307 -0
- package/src/components/Formik/FormikCheckboxInput/FormikCheckboxInput.test.tsx +172 -0
- package/src/components/Formik/FormikCheckboxInput/FormikCheckboxInput.tsx +41 -0
- package/src/components/Formik/FormikRadioGroup/FormikRadioGroup.test.tsx +205 -0
- package/src/components/Formik/FormikRadioGroup/FormikRadioGroup.tsx +37 -0
- package/src/components/Formik/FormikSelectInput/FormikSelectInput.test.tsx +210 -0
- package/src/components/Formik/FormikSelectInput/FormikSelectInput.tsx +41 -0
- package/src/components/Formik/FormikSelectInputInset/FormikSelectInputInset.test.tsx +153 -0
- package/src/components/Formik/FormikSelectInputInset/FormikSelectInputInset.tsx +44 -0
- package/src/components/Formik/FormikSelectInputNative/FormikSelectInputNative.test.tsx +161 -0
- package/src/components/Formik/FormikSelectInputNative/FormikSelectInputNative.tsx +46 -0
- package/src/components/Formik/FormikTextInput/FormikTextInput.test.tsx +176 -0
- package/src/components/Formik/FormikTextInput/FormikTextInput.tsx +38 -0
- package/src/components/Formik/FormikTextInputInset/FormikTextInputInset.test.tsx +170 -0
- package/src/components/Formik/FormikTextInputInset/FormikTextInputInset.tsx +42 -0
- package/src/components/Formik/FormikTextareaInput/FormikTextareaInput.test.tsx +186 -0
- package/src/components/Formik/FormikTextareaInput/FormikTextareaInput.tsx +42 -0
- package/src/components/Formik/FormikTextareaInputInset/FormikTextareaInputInset.test.tsx +179 -0
- package/src/components/Formik/FormikTextareaInputInset/FormikTextareaInputInset.tsx +42 -0
- package/src/components/Formik/FormikTimePicker/FormikTimePicker.test.tsx +224 -0
- package/src/components/Formik/FormikTimePicker/FormikTimePicker.tsx +37 -0
- package/src/components/Formik/FormikTimePickerNative/FormikTimePickerNative.test.tsx +175 -0
- package/src/components/Formik/FormikTimePickerNative/FormikTimePickerNative.tsx +38 -0
- package/src/components/Formik/FormikToggle/FormikToggle.test.tsx +172 -0
- package/src/components/Formik/FormikToggle/FormikToggle.tsx +38 -0
- package/src/components/Heading/Heading.constants.ts +19 -0
- package/src/components/Heading/Heading.mdx +35 -0
- package/src/components/Heading/Heading.module.scss +5 -0
- package/src/components/Heading/Heading.stories.tsx +90 -0
- package/src/components/Heading/Heading.test.tsx +67 -0
- package/src/components/Heading/Heading.tsx +67 -0
- package/src/components/HelpText/HelpText.module.scss +14 -0
- package/src/components/HelpText/HelpText.tsx +33 -0
- package/src/components/Icon/Icon.mdx +40 -0
- package/src/components/Icon/Icon.stories.tsx +72 -0
- package/src/components/Icon/Icon.test.tsx +30 -0
- package/src/components/Icon/Icon.tsx +61 -0
- package/src/components/InputValidationMessage/InputValidationMessage.module.scss +3 -0
- package/src/components/InputValidationMessage/InputValidationMessage.tsx +27 -0
- package/src/components/Modal/Modal.mdx +60 -0
- package/src/components/Modal/Modal.module.scss +135 -0
- package/src/components/Modal/Modal.stories.tsx +194 -0
- package/src/components/Modal/Modal.test.tsx +81 -0
- package/src/components/Modal/Modal.tsx +174 -0
- package/src/components/Modal/components/ModalBody/ModalBody.test.tsx +20 -0
- package/src/components/Modal/components/ModalBody/ModalBody.tsx +24 -0
- package/src/components/Modal/components/ModalFooter/ModalFooter.test.tsx +32 -0
- package/src/components/Modal/components/ModalFooter/ModalFooter.tsx +37 -0
- package/src/components/Modal/components/ModalHeader/ModalHeader.test.tsx +29 -0
- package/src/components/Modal/components/ModalHeader/ModalHeader.tsx +58 -0
- package/src/components/Modal/components/index.ts +5 -0
- package/src/components/Pagination/Pagination.mdx +26 -0
- package/src/components/Pagination/Pagination.stories.tsx +55 -0
- package/src/components/Pagination/Pagination.test.tsx +225 -0
- package/src/components/Pagination/Pagination.tsx +162 -0
- package/src/components/Pagination/Pagination.utilities.test.ts +133 -0
- package/src/components/Pagination/Pagination.utilities.ts +101 -0
- package/src/components/Popover/Popover.mdx +104 -0
- package/src/components/Popover/Popover.module.scss +74 -0
- package/src/components/Popover/Popover.stories.tsx +471 -0
- package/src/components/Popover/Popover.test.tsx +128 -0
- package/src/components/Popover/Popover.tsx +277 -0
- package/src/components/RadioGroup/RadioGroup.mdx +81 -0
- package/src/components/RadioGroup/RadioGroup.module.scss +23 -0
- package/src/components/RadioGroup/RadioGroup.stories.tsx +375 -0
- package/src/components/RadioGroup/RadioGroup.test.tsx +282 -0
- package/src/components/RadioGroup/RadioGroup.tsx +145 -0
- package/src/components/RadioGroup/RadioInput/RadioInput.module.scss +114 -0
- package/src/components/RadioGroup/RadioInput/RadioInput.test.tsx +156 -0
- package/src/components/RadioGroup/RadioInput/RadioInput.tsx +148 -0
- package/src/components/RadioGroup/RadioInput/RadioInputIcon.tsx +59 -0
- package/src/components/ResponsiveProvider/ResponsiveProvider.mdx +36 -0
- package/src/components/ResponsiveProvider/ResponsiveProvider.stories.tsx +54 -0
- package/src/components/ResponsiveProvider/ResponsiveProvider.test.tsx +70 -0
- package/src/components/ResponsiveProvider/ResponsiveProvider.tsx +73 -0
- package/src/components/SelectInput/SelectInput.mdx +115 -0
- package/src/components/SelectInput/SelectInput.module.scss +357 -0
- package/src/components/SelectInput/SelectInput.stories.tsx +373 -0
- package/src/components/SelectInput/SelectInput.test.tsx +403 -0
- package/src/components/SelectInput/SelectInput.tsx +245 -0
- package/src/components/SelectInputInset/SelectInputInset.mdx +56 -0
- package/src/components/SelectInputInset/SelectInputInset.module.scss +397 -0
- package/src/components/SelectInputInset/SelectInputInset.stories.tsx +189 -0
- package/src/components/SelectInputInset/SelectInputInset.test.tsx +305 -0
- package/src/components/SelectInputInset/SelectInputInset.tsx +235 -0
- package/src/components/SelectInputNative/SelectInputNative.mdx +87 -0
- package/src/components/SelectInputNative/SelectInputNative.module.scss +356 -0
- package/src/components/SelectInputNative/SelectInputNative.stories.tsx +282 -0
- package/src/components/SelectInputNative/SelectInputNative.test.tsx +341 -0
- package/src/components/SelectInputNative/SelectInputNative.tsx +121 -0
- package/src/components/Spinner/Spinner.mdx +29 -0
- package/src/components/Spinner/Spinner.module.scss +16 -0
- package/src/components/Spinner/Spinner.stories.tsx +48 -0
- package/src/components/Spinner/Spinner.test.tsx +47 -0
- package/src/components/Spinner/Spinner.tsx +116 -0
- package/src/components/Table/Table.mdx +216 -0
- package/src/components/Table/Table.module.scss +61 -0
- package/src/components/Table/Table.stories.tsx +884 -0
- package/src/components/Table/Table.test.tsx +437 -0
- package/src/components/Table/Table.tsx +171 -0
- package/src/components/Table/TableBody/TableBody.module.scss +19 -0
- package/src/components/Table/TableBody/TableBody.test.tsx +38 -0
- package/src/components/Table/TableBody/TableBody.tsx +96 -0
- package/src/components/Table/TableBody/TableBodyCell/TableBodyCell.module.scss +47 -0
- package/src/components/Table/TableBody/TableBodyCell/TableBodyCell.test.tsx +81 -0
- package/src/components/Table/TableBody/TableBodyCell/TableBodyCell.tsx +94 -0
- package/src/components/Table/TableHead/TableHead.test.tsx +20 -0
- package/src/components/Table/TableHead/TableHead.tsx +78 -0
- package/src/components/Table/TableHead/TableHeaderCell/TableHeaderCell.module.scss +72 -0
- package/src/components/Table/TableHead/TableHeaderCell/TableHeaderCell.test.tsx +187 -0
- package/src/components/Table/TableHead/TableHeaderCell/TableHeaderCell.tsx +192 -0
- package/src/components/Table/common/TableRow/TableRow.module.scss +5 -0
- package/src/components/Table/common/TableRow/TableRow.test.tsx +52 -0
- package/src/components/Table/common/TableRow/TableRow.tsx +155 -0
- package/src/components/TextInput/TextInput.mdx +96 -0
- package/src/components/TextInput/TextInput.module.scss +405 -0
- package/src/components/TextInput/TextInput.stories.tsx +268 -0
- package/src/components/TextInput/TextInput.test.tsx +231 -0
- package/src/components/TextInput/TextInput.tsx +263 -0
- package/src/components/TextInputInset/TextInputInset.mdx +62 -0
- package/src/components/TextInputInset/TextInputInset.module.scss +418 -0
- package/src/components/TextInputInset/TextInputInset.stories.tsx +213 -0
- package/src/components/TextInputInset/TextInputInset.test.tsx +222 -0
- package/src/components/TextInputInset/TextInputInset.tsx +261 -0
- package/src/components/TextareaInput/TextareaInput.mdx +117 -0
- package/src/components/TextareaInput/TextareaInput.module.scss +275 -0
- package/src/components/TextareaInput/TextareaInput.stories.tsx +293 -0
- package/src/components/TextareaInput/TextareaInput.test.tsx +195 -0
- package/src/components/TextareaInput/TextareaInput.tsx +182 -0
- package/src/components/TextareaInputInset/TextareaInputInset.mdx +55 -0
- package/src/components/TextareaInputInset/TextareaInputInset.module.scss +337 -0
- package/src/components/TextareaInputInset/TextareaInputInset.stories.tsx +160 -0
- package/src/components/TextareaInputInset/TextareaInputInset.test.tsx +199 -0
- package/src/components/TextareaInputInset/TextareaInputInset.tsx +213 -0
- package/src/components/ThemeProvider/ThemeProvider.mdx +11 -0
- package/src/components/ThemeProvider/ThemeProvider.stories.tsx +56 -0
- package/src/components/ThemeProvider/ThemeProvider.tsx +75 -0
- package/src/components/TimePicker/TimePicker.mdx +75 -0
- package/src/components/TimePicker/TimePicker.stories.tsx +149 -0
- package/src/components/TimePicker/TimePicker.test.tsx +97 -0
- package/src/components/TimePicker/TimePicker.tsx +83 -0
- package/src/components/TimePickerNative/TimePickerNative.mdx +67 -0
- package/src/components/TimePickerNative/TimePickerNative.stories.tsx +151 -0
- package/src/components/TimePickerNative/TimePickerNative.test.tsx +117 -0
- package/src/components/TimePickerNative/TimePickerNative.tsx +93 -0
- package/src/components/Toast/Toast.mdx +134 -0
- package/src/components/Toast/Toast.store.ts +280 -0
- package/src/components/Toast/Toast.stories.tsx +283 -0
- package/src/components/Toast/Toast.test.tsx +784 -0
- package/src/components/Toast/Toast.types.ts +98 -0
- package/src/components/Toast/ToastContainer.tsx +170 -0
- package/src/components/Toast/ToastNotification.module.scss +63 -0
- package/src/components/Toast/ToastNotification.tsx +176 -0
- package/src/components/Toast/index.ts +4 -0
- package/src/components/Toast/toast.ts +102 -0
- package/src/components/Toast/useToasts.ts +102 -0
- package/src/components/Toggle/Toggle.mdx +51 -0
- package/src/components/Toggle/Toggle.module.scss +294 -0
- package/src/components/Toggle/Toggle.stories.tsx +128 -0
- package/src/components/Toggle/Toggle.test.tsx +308 -0
- package/src/components/Toggle/Toggle.tsx +184 -0
- package/src/constants/keyCodes.ts +2 -0
- package/src/docs/Brands.mdx +153 -0
- package/src/docs/Colors.mdx +158 -0
- package/src/docs/DesignTokens.mdx +415 -0
- package/src/docs/GetStarted.mdx +47 -0
- package/src/docs/intro.mdx +12 -0
- package/src/fonts/AvenirBold.otf +0 -0
- package/src/fonts/AvenirBold.woff +0 -0
- package/src/fonts/AvenirBold.woff2 +0 -0
- package/src/fonts/AvenirLight.otf +0 -0
- package/src/fonts/AvenirLight.woff +0 -0
- package/src/fonts/AvenirLight.woff2 +0 -0
- package/src/fonts/AvenirRegular.otf +0 -0
- package/src/fonts/AvenirRegular.woff +0 -0
- package/src/fonts/AvenirRegular.woff2 +0 -0
- package/src/fonts/Geist-Bold.otf +0 -0
- package/src/fonts/Geist-Bold.woff +0 -0
- package/src/fonts/Geist-Bold.woff2 +0 -0
- package/src/fonts/Geist-Medium.otf +0 -0
- package/src/fonts/Geist-Medium.woff +0 -0
- package/src/fonts/Geist-Medium.woff2 +0 -0
- package/src/fonts/Geist-Regular.otf +0 -0
- package/src/fonts/Geist-Regular.woff +0 -0
- package/src/fonts/Geist-Regular.woff2 +0 -0
- package/src/fonts/Geist-SemiBold.otf +0 -0
- package/src/fonts/Geist-SemiBold.woff +0 -0
- package/src/fonts/Geist-SemiBold.woff2 +0 -0
- package/src/fonts/GeistMono-Regular.otf +0 -0
- package/src/fonts/GeistMono-Regular.woff +0 -0
- package/src/fonts/GeistMono-Regular.woff2 +0 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useBreakpoint/useBreakpoint.mdx +26 -0
- package/src/hooks/useBreakpoint/useBreakpoint.stories.tsx +30 -0
- package/src/hooks/useBreakpoint/useBreakpoint.test.tsx +19 -0
- package/src/hooks/useBreakpoint/useBreakpoint.ts +50 -0
- package/src/hooks/useIsomorphicLayoutEffect/useIsomorphicLayouEffect.ts +5 -0
- package/src/hooks/useOpenClose/useOpenClose.mdx +15 -0
- package/src/hooks/useOpenClose/useOpenClose.stories.tsx +41 -0
- package/src/hooks/useOpenClose/useOpenClose.test.tsx +119 -0
- package/src/hooks/useOpenClose/useOpenClose.tsx +95 -0
- package/src/hooks/useWindowSize/useWindowSize.mdx +25 -0
- package/src/hooks/useWindowSize/useWindowSize.stories.tsx +35 -0
- package/src/hooks/useWindowSize/useWindowSize.ts +24 -0
- package/src/index.ts +48 -0
- package/src/lib/cssShorthandToClasses.test.ts +149 -0
- package/src/lib/cssShorthandToClasses.ts +133 -0
- package/src/lib/doesStringIncludeCssUnit.ts +6 -0
- package/src/lib/generateResponsiveClasses.test.ts +24 -0
- package/src/lib/generateResponsiveClasses.ts +30 -0
- package/src/lib/getAutoCompleteValue.test.ts +27 -0
- package/src/lib/getAutoCompleteValue.ts +12 -0
- package/src/lib/getColumnKeys.ts +27 -0
- package/src/lib/getDimensionCss.test.ts +148 -0
- package/src/lib/getDimensionCss.ts +73 -0
- package/src/lib/getElementType.test.tsx +42 -0
- package/src/lib/getElementType.ts +42 -0
- package/src/lib/getFlexCss.test.ts +122 -0
- package/src/lib/getFlexCss.ts +67 -0
- package/src/lib/index.ts +15 -0
- package/src/lib/isFunction.ts +6 -0
- package/src/lib/mergeRefs.ts +15 -0
- package/src/lib/prefersReducedMotion.ts +12 -0
- package/src/lib/react-children-utilities/filter.ts +12 -0
- package/src/lib/react-children-utilities/index.ts +1 -0
- package/src/lib/reactRouterClickHandler.ts +37 -0
- package/src/lib/resolveValue.ts +7 -0
- package/src/lib/tokens.ts +139 -0
- package/src/modes.ts +8 -0
- package/src/styles/animation.scss +152 -0
- package/src/styles/cursor.scss +43 -0
- package/src/styles/display.scss +119 -0
- package/src/styles/flex.scss +453 -0
- package/src/styles/fonts.scss +44 -0
- package/src/styles/globals/utilities.scss +4 -0
- package/src/styles/mixins.scss +14 -0
- package/src/styles/overflow.scss +41 -0
- package/src/styles/position.scss +45 -0
- package/src/styles/reset.scss +108 -0
- package/src/styles/text-align.scss +21 -0
- package/src/styles/utilities.scss +9 -0
- package/src/styles/variables/forms.scss +71 -0
- package/src/styles/variables/index.scss +3 -0
- package/src/styles/white-space.scss +21 -0
- package/src/types/index.ts +201 -0
- package/src/types/lib.types.ts +3 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Canvas, Meta, ArgTypes } from '@storybook/blocks';
|
|
2
|
+
import { Toggle } from './Toggle';
|
|
3
|
+
import * as Stories from './Toggle.stories';
|
|
4
|
+
|
|
5
|
+
<Meta of={Stories} />
|
|
6
|
+
|
|
7
|
+
# Toggle
|
|
8
|
+
|
|
9
|
+
A `Toggle` switch is like a digital on/off switch. They prompt users to choose between two mutually exclusive options and always have a default value.
|
|
10
|
+
Toggles should provide immediate results and should not require the user to Save or Submit to apply the new state.
|
|
11
|
+
|
|
12
|
+
<Canvas of={Stories.Overview} />
|
|
13
|
+
|
|
14
|
+
## Props
|
|
15
|
+
|
|
16
|
+
<ArgTypes of={Toggle} />
|
|
17
|
+
|
|
18
|
+
### Basic Example
|
|
19
|
+
|
|
20
|
+
<Canvas of={Stories.Basic} />
|
|
21
|
+
|
|
22
|
+
### Help Text
|
|
23
|
+
|
|
24
|
+
Use the `helpText` prop to add clarifying text beneath the toggle label.
|
|
25
|
+
|
|
26
|
+
<Canvas of={Stories.HelpText} />
|
|
27
|
+
|
|
28
|
+
### Hidden Label
|
|
29
|
+
|
|
30
|
+
Use the `hideLabel` prop to not render the label, however a `label` is still required for accessability purposes.
|
|
31
|
+
|
|
32
|
+
<Canvas of={Stories.HiddenLabel} />
|
|
33
|
+
|
|
34
|
+
### Sizes
|
|
35
|
+
|
|
36
|
+
Set the size of the `toggle` to `sm`, `md` or `lg`. `md` is the default size.
|
|
37
|
+
The `size` prop is also a `ResponsiveProp`, so it can be sized differently at each [breakpoint](?path=/docs/design-tokens-design-tokens--page#breakpoints) by passing an object.
|
|
38
|
+
|
|
39
|
+
<Canvas of={Stories.Sizes} />
|
|
40
|
+
|
|
41
|
+
### Disabled
|
|
42
|
+
|
|
43
|
+
Disable the toggle by setting the `isDisabled` prop.
|
|
44
|
+
|
|
45
|
+
<Canvas of={Stories.Disabled} />
|
|
46
|
+
|
|
47
|
+
## Error
|
|
48
|
+
|
|
49
|
+
Use the `error` prop to mark the input as invalid. `error` accepts a `boolean`, `string`, or `node`. If either a `string` or `node` is passed, a validation message is displayed below it.
|
|
50
|
+
|
|
51
|
+
<Canvas of={Stories.Error} />
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
@import '@hyphen/hyphen-design-tokens/build/scss/variables';
|
|
2
|
+
|
|
3
|
+
@mixin thumb-size-sm {
|
|
4
|
+
width: calc(var(--size-spacing-2xl) - 4px);
|
|
5
|
+
height: calc(var(--size-spacing-2xl) - 4px);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
%thumb-size-sm {
|
|
9
|
+
@include thumb-size-sm;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.thumb-size-sm {
|
|
13
|
+
@extend %thumb-size-sm;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@mixin thumb-size-md {
|
|
17
|
+
width: calc(var(--size-spacing-3xl) - 4px);
|
|
18
|
+
height: calc(var(--size-spacing-3xl) - 4px);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
%thumb-size-md {
|
|
22
|
+
@include thumb-size-md;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.thumb-size-md {
|
|
26
|
+
@extend %thumb-size-md;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@mixin thumb-size-lg {
|
|
30
|
+
width: calc(var(--size-spacing-4xl) - 4px);
|
|
31
|
+
height: calc(var(--size-spacing-4xl) - 4px);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
%thumb-size-lg {
|
|
35
|
+
@include thumb-size-lg;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.thumb-size-lg {
|
|
39
|
+
@extend %thumb-size-lg;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@mixin track-size-sm {
|
|
43
|
+
min-width: 2rem;
|
|
44
|
+
width: 2rem;
|
|
45
|
+
height: var(--size-spacing-2xl);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
%track-size-sm {
|
|
49
|
+
@include track-size-sm;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.track-size-sm {
|
|
53
|
+
@extend %track-size-sm;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@mixin track-size-md {
|
|
57
|
+
min-width: 2.5rem;
|
|
58
|
+
width: 2.5rem;
|
|
59
|
+
height: var(--size-spacing-3xl);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
%track-size-md {
|
|
63
|
+
@include track-size-md;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.track-size-md {
|
|
67
|
+
@extend %track-size-md;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@mixin track-size-lg {
|
|
71
|
+
min-width: 3.5rem;
|
|
72
|
+
width: 3.5rem;
|
|
73
|
+
height: var(--size-spacing-4xl);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
%track-size-lg {
|
|
77
|
+
@include track-size-lg;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.track-size-lg {
|
|
81
|
+
@extend %track-size-lg;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@media (min-width: $size-breakpoint-tablet) {
|
|
85
|
+
.thumb-size-sm-tablet {
|
|
86
|
+
@include thumb-size-sm;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.thumb-size-md-tablet {
|
|
90
|
+
@include thumb-size-md;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.thumb-size-lg-tablet {
|
|
94
|
+
@include thumb-size-lg;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.track-size-sm-tablet {
|
|
98
|
+
@include track-size-sm;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.track-size-md-tablet {
|
|
102
|
+
@include track-size-md;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.track-size-lg-tablet {
|
|
106
|
+
@include track-size-lg;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@media (min-width: $size-breakpoint-desktop) {
|
|
111
|
+
.thumb-size-sm-desktop {
|
|
112
|
+
@include thumb-size-sm;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.thumb-size-md-desktop {
|
|
116
|
+
@include thumb-size-md;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.thumb-size-lg-desktop {
|
|
120
|
+
@include thumb-size-lg;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.track-size-sm-desktop {
|
|
124
|
+
@include track-size-sm;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.track-size-md-desktop {
|
|
128
|
+
@include track-size-md;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.track-size-lg-desktop {
|
|
132
|
+
@include track-size-lg;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@media (min-width: $size-breakpoint-hd) {
|
|
137
|
+
.thumb-size-sm-hd {
|
|
138
|
+
@include thumb-size-sm;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.thumb-size-md-hd {
|
|
142
|
+
@include thumb-size-md;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.thumb-size-lg-hd {
|
|
146
|
+
@include thumb-size-lg;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.track-size-sm-hd {
|
|
150
|
+
@include track-size-sm;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.track-size-md-hd {
|
|
154
|
+
@include track-size-md;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.track-size-lg-hd {
|
|
158
|
+
@include track-size-lg;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.disabled {
|
|
163
|
+
opacity: 0.4;
|
|
164
|
+
cursor: not-allowed;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.toggle-thumb {
|
|
168
|
+
display: block;
|
|
169
|
+
transition: transform 0.25s ease;
|
|
170
|
+
border-radius: 50%;
|
|
171
|
+
box-shadow: 0 0 2px rgb(0 0 0 / 45%);
|
|
172
|
+
background-color: var(--color-base-white);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.toggle-track {
|
|
176
|
+
display: block;
|
|
177
|
+
transition: background-color 0.25s ease;
|
|
178
|
+
border-radius: 9999em;
|
|
179
|
+
background-color: var(--toggle-background-color, var(--color-base-grey-200));
|
|
180
|
+
cursor: pointer;
|
|
181
|
+
padding: 2px;
|
|
182
|
+
|
|
183
|
+
&.error {
|
|
184
|
+
background-color: var(
|
|
185
|
+
--toggle-background-color-error,
|
|
186
|
+
var(--color-base-red-500)
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
//Hide the checkbox input (only needed for `:checked` property)
|
|
192
|
+
.toggle-input {
|
|
193
|
+
position: absolute;
|
|
194
|
+
clip: rect(0, 0, 0, 0);
|
|
195
|
+
margin: -1px;
|
|
196
|
+
border: 0;
|
|
197
|
+
padding: 0;
|
|
198
|
+
width: 1px;
|
|
199
|
+
height: 1px;
|
|
200
|
+
overflow: hidden;
|
|
201
|
+
white-space: nowrap;
|
|
202
|
+
|
|
203
|
+
&:checked + .toggle-track {
|
|
204
|
+
background-color: var(
|
|
205
|
+
--toggle-background-color-checked,
|
|
206
|
+
var(--color-base-green-500)
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
&:checked + .toggle-track.error {
|
|
211
|
+
background-color: var(
|
|
212
|
+
--toggle-background-color-error,
|
|
213
|
+
var(--color-base-red-500)
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
&:checked + .toggle-track .toggle-thumb.thumb-size-sm {
|
|
218
|
+
transform: translateX(0.75rem);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
&:checked + .toggle-track .toggle-thumb.thumb-size-md {
|
|
222
|
+
transform: translateX(1rem);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
&:checked + .toggle-track .toggle-thumb.thumb-size-lg {
|
|
226
|
+
transform: translateX(1.5rem);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
@media (min-width: $size-breakpoint-tablet) {
|
|
230
|
+
&:checked + .toggle-track .toggle-thumb.thumb-size-sm-tablet {
|
|
231
|
+
transform: translateX(0.5rem);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
&:checked + .toggle-track .toggle-thumb.thumb-size-md-tablet {
|
|
235
|
+
transform: translateX(1rem);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
&:checked + .toggle-track .toggle-thumb.thumb-size-lg-tablet {
|
|
239
|
+
transform: translateX(1.5rem);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
@media (min-width: $size-breakpoint-desktop) {
|
|
244
|
+
&:checked + .toggle-track .toggle-thumb.thumb-size-sm-desktop {
|
|
245
|
+
transform: translateX(0.5rem);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
&:checked + .toggle-track .toggle-thumb.thumb-size-md-desktop {
|
|
249
|
+
transform: translateX(1rem);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
&:checked + .toggle-track .toggle-thumb.thumb-size-lg-desktop {
|
|
253
|
+
transform: translateX(1.5rem);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
@media (min-width: $size-breakpoint-hd) {
|
|
258
|
+
&:checked + .toggle-track .toggle-thumb.thumb-size-sm-hd {
|
|
259
|
+
transform: translateX(0.5rem);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
&:checked + .toggle-track .toggle-thumb.thumb-size-md-hd {
|
|
263
|
+
transform: translateX(1rem);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
&:checked + .toggle-track .toggle-thumb.thumb-size-lg-hd {
|
|
267
|
+
transform: translateX(1.5rem);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
&:focus + .toggle-track {
|
|
272
|
+
outline: 0;
|
|
273
|
+
box-shadow: var(
|
|
274
|
+
--form-control-box-shadow-focus,
|
|
275
|
+
var(--INTERNAL_form-control-box-shadow-focus)
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Show focus styles on keyboard focus.
|
|
280
|
+
&:focus-visible + .toggle-track {
|
|
281
|
+
outline: 0;
|
|
282
|
+
box-shadow: var(
|
|
283
|
+
--form-control-box-shadow-focus,
|
|
284
|
+
var(--INTERNAL_form-control-box-shadow-focus)
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Hide focus styles if they are not needed, for example,
|
|
289
|
+
// when an element receives focus via the mouse.
|
|
290
|
+
&:focus:not(:focus-visible) + .toggle-track {
|
|
291
|
+
outline: 0;
|
|
292
|
+
box-shadow: none;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Box } from '../Box/Box';
|
|
4
|
+
import type { Meta } from '@storybook/react';
|
|
5
|
+
import { Toggle } from './Toggle';
|
|
6
|
+
|
|
7
|
+
const meta: Meta<typeof Toggle> = {
|
|
8
|
+
title: 'Components/Toggle',
|
|
9
|
+
component: Toggle,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default meta;
|
|
13
|
+
|
|
14
|
+
export const Overview = () => (
|
|
15
|
+
<Toggle id="example" label="toggle label" isChecked onChange={() => {}} />
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export const Basic = () => {
|
|
19
|
+
const [value, setValue] = useState(false);
|
|
20
|
+
return (
|
|
21
|
+
<Toggle
|
|
22
|
+
id="defaultStateIsUnchecked"
|
|
23
|
+
label="toggle label"
|
|
24
|
+
onChange={(event) => setValue(event.target.checked)}
|
|
25
|
+
isChecked={value}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const HelpText = () => {
|
|
31
|
+
const [value, setValue] = useState(false);
|
|
32
|
+
return (
|
|
33
|
+
<Toggle
|
|
34
|
+
id="helpText"
|
|
35
|
+
label="toggle label"
|
|
36
|
+
helpText="descriptive help text"
|
|
37
|
+
onChange={(event) => setValue(event.target.checked)}
|
|
38
|
+
isChecked={value}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const HiddenLabel = () => {
|
|
44
|
+
const [value, setValue] = useState(false);
|
|
45
|
+
return (
|
|
46
|
+
<Toggle
|
|
47
|
+
id="hiddenLabelToggle"
|
|
48
|
+
label="Hidden Label"
|
|
49
|
+
helpText="hidden help text too"
|
|
50
|
+
hideLabel
|
|
51
|
+
onChange={(event) => setValue(event.target.checked)}
|
|
52
|
+
isChecked={value}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const Sizes = () => {
|
|
58
|
+
const [value, setValue] = useState(true);
|
|
59
|
+
return (
|
|
60
|
+
<Box gap="md">
|
|
61
|
+
<Toggle
|
|
62
|
+
id="smToggle"
|
|
63
|
+
label="small toggle"
|
|
64
|
+
onChange={(event) => setValue(event.target.checked)}
|
|
65
|
+
isChecked={value}
|
|
66
|
+
size="sm"
|
|
67
|
+
/>
|
|
68
|
+
<Toggle
|
|
69
|
+
id="mediumToggle"
|
|
70
|
+
label="medium toggle"
|
|
71
|
+
onChange={(event) => setValue(event.target.checked)}
|
|
72
|
+
isChecked={value}
|
|
73
|
+
size="md"
|
|
74
|
+
/>
|
|
75
|
+
<Toggle
|
|
76
|
+
id="largeToggle"
|
|
77
|
+
label="large toggle"
|
|
78
|
+
onChange={(event) => setValue(event.target.checked)}
|
|
79
|
+
isChecked={value}
|
|
80
|
+
size="lg"
|
|
81
|
+
/>
|
|
82
|
+
<Toggle
|
|
83
|
+
id="responsiveToggle"
|
|
84
|
+
label="responsive toggle"
|
|
85
|
+
onChange={(event) => setValue(event.target.checked)}
|
|
86
|
+
isChecked={value}
|
|
87
|
+
size={{ base: 'sm', tablet: 'md', desktop: 'lg', hd: 'sm' }}
|
|
88
|
+
/>
|
|
89
|
+
</Box>
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const Disabled = () => {
|
|
94
|
+
const [value, setValue] = useState(false);
|
|
95
|
+
return (
|
|
96
|
+
<Toggle
|
|
97
|
+
id="disabledToggle"
|
|
98
|
+
label="Label"
|
|
99
|
+
onChange={(event) => setValue(event.target.checked)}
|
|
100
|
+
isChecked={value}
|
|
101
|
+
isDisabled
|
|
102
|
+
/>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const Error = () => {
|
|
107
|
+
const [value, setValue] = useState(false);
|
|
108
|
+
const [value2, setValue2] = useState(true);
|
|
109
|
+
return (
|
|
110
|
+
<Box gap="md">
|
|
111
|
+
<Toggle
|
|
112
|
+
id="invalidToggle"
|
|
113
|
+
label="Agree to Terms and Conditions"
|
|
114
|
+
isChecked={value}
|
|
115
|
+
onChange={(event) => setValue(event.target.checked)}
|
|
116
|
+
isRequired
|
|
117
|
+
error="You must accept the Terms and Conditions"
|
|
118
|
+
/>
|
|
119
|
+
<Toggle
|
|
120
|
+
id="invalidToggle2"
|
|
121
|
+
label="Roof Replacement"
|
|
122
|
+
isChecked={value2}
|
|
123
|
+
onChange={(event) => setValue2(event.target.checked)}
|
|
124
|
+
error="Site Improvements can not be present with PPA"
|
|
125
|
+
/>
|
|
126
|
+
</Box>
|
|
127
|
+
);
|
|
128
|
+
};
|