@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,145 @@
|
|
|
1
|
+
import React, { FC, ChangeEvent, FocusEvent, ReactNode } from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { Box } from '../Box/Box';
|
|
4
|
+
import { InputValidationMessage } from '../InputValidationMessage/InputValidationMessage';
|
|
5
|
+
import { RadioInput, RadioInputProps } from './RadioInput/RadioInput'; // eslint-disable-line import/no-cycle
|
|
6
|
+
import styles from './RadioGroup.module.scss';
|
|
7
|
+
|
|
8
|
+
export interface RadioGroupProps {
|
|
9
|
+
/**
|
|
10
|
+
* Radio group name.
|
|
11
|
+
*/
|
|
12
|
+
name: string;
|
|
13
|
+
/**
|
|
14
|
+
* Callback function to call on change event.
|
|
15
|
+
*/
|
|
16
|
+
onChange: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Options for radio group.
|
|
19
|
+
*/
|
|
20
|
+
options: {
|
|
21
|
+
id: string;
|
|
22
|
+
value: string;
|
|
23
|
+
label: ReactNode;
|
|
24
|
+
disabled?: boolean | null;
|
|
25
|
+
}[];
|
|
26
|
+
/**
|
|
27
|
+
* Additional classes to add.
|
|
28
|
+
*/
|
|
29
|
+
className?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Description to be displayed below the title, and above the RadioGroup.
|
|
32
|
+
*/
|
|
33
|
+
description?: ReactNode;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the radios should be aligned in a row or in a column
|
|
36
|
+
*/
|
|
37
|
+
direction?: 'row' | 'column';
|
|
38
|
+
/**
|
|
39
|
+
* Mark the radio group as invalid and display a validation message.
|
|
40
|
+
* Pass a string or node to render a validation message below the input.
|
|
41
|
+
*/
|
|
42
|
+
error?: ReactNode;
|
|
43
|
+
/**
|
|
44
|
+
* If the radio group should be disabled and not focusable.
|
|
45
|
+
*/
|
|
46
|
+
isDisabled?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* If the radio group is required or not
|
|
49
|
+
*/
|
|
50
|
+
isRequired?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Callback function to call on blur event.
|
|
53
|
+
*/
|
|
54
|
+
onBlur?: (event: FocusEvent<HTMLInputElement>) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Callback function to call on focus event.
|
|
57
|
+
*/
|
|
58
|
+
onFocus?: (event: FocusEvent<HTMLInputElement>) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Visual indicator that the field is required, that gets appended to the label
|
|
61
|
+
*/
|
|
62
|
+
requiredIndicator?: React.ReactNode;
|
|
63
|
+
/**
|
|
64
|
+
* Size of the radio icons in the group.
|
|
65
|
+
*/
|
|
66
|
+
size?: RadioInputProps['size'];
|
|
67
|
+
/**
|
|
68
|
+
* Title to be displayed above the RadioGroup.
|
|
69
|
+
*/
|
|
70
|
+
title?: ReactNode;
|
|
71
|
+
/**
|
|
72
|
+
* The value of selected radio input.
|
|
73
|
+
*/
|
|
74
|
+
value?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Additional props to be spread to rendered element
|
|
77
|
+
*/
|
|
78
|
+
[x: string]: any; // eslint-disable-line
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const RadioGroup: FC<RadioGroupProps> = ({
|
|
82
|
+
name,
|
|
83
|
+
onChange,
|
|
84
|
+
options,
|
|
85
|
+
className = '',
|
|
86
|
+
description = undefined,
|
|
87
|
+
direction = 'column',
|
|
88
|
+
error = false,
|
|
89
|
+
isDisabled = false,
|
|
90
|
+
isRequired = false,
|
|
91
|
+
onBlur = undefined,
|
|
92
|
+
onFocus = undefined,
|
|
93
|
+
requiredIndicator = ' *',
|
|
94
|
+
size = 'md',
|
|
95
|
+
title = undefined,
|
|
96
|
+
value = undefined,
|
|
97
|
+
...restProps
|
|
98
|
+
}) => {
|
|
99
|
+
const groupClasses = classNames(
|
|
100
|
+
'hyphen-components__variables__form-control',
|
|
101
|
+
className,
|
|
102
|
+
{
|
|
103
|
+
[styles.loading]: error,
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<div
|
|
109
|
+
className={classNames(styles['radio-group'], groupClasses)}
|
|
110
|
+
{...restProps}
|
|
111
|
+
>
|
|
112
|
+
<fieldset className={styles.fieldset}>
|
|
113
|
+
{(title || description) && (
|
|
114
|
+
<legend className={styles.legend}>
|
|
115
|
+
{title}
|
|
116
|
+
{isRequired && <span>{requiredIndicator}</span>}
|
|
117
|
+
{description && (
|
|
118
|
+
<div className={styles.description}>{description}</div>
|
|
119
|
+
)}
|
|
120
|
+
</legend>
|
|
121
|
+
)}
|
|
122
|
+
<Box direction={direction} gap="sm" className={styles.options}>
|
|
123
|
+
{options &&
|
|
124
|
+
options.map((option) => (
|
|
125
|
+
<RadioInput
|
|
126
|
+
key={option.id}
|
|
127
|
+
name={name}
|
|
128
|
+
onChange={onChange}
|
|
129
|
+
option={option}
|
|
130
|
+
isDisabled={isDisabled || option.disabled || false}
|
|
131
|
+
isRequired={isRequired}
|
|
132
|
+
isSelected={value === option.value}
|
|
133
|
+
onBlur={onBlur}
|
|
134
|
+
onFocus={onFocus}
|
|
135
|
+
size={size}
|
|
136
|
+
/>
|
|
137
|
+
))}
|
|
138
|
+
</Box>
|
|
139
|
+
</fieldset>
|
|
140
|
+
{error && typeof error !== 'boolean' && (
|
|
141
|
+
<InputValidationMessage>{error}</InputValidationMessage>
|
|
142
|
+
)}
|
|
143
|
+
</div>
|
|
144
|
+
);
|
|
145
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
@import '../../../styles/mixins';
|
|
2
|
+
@import '@hyphen/hyphen-design-tokens/build/scss/variables';
|
|
3
|
+
|
|
4
|
+
$sm-dimension: 16px;
|
|
5
|
+
$md-dimension: 20px;
|
|
6
|
+
$lg-dimension: 24px;
|
|
7
|
+
|
|
8
|
+
@mixin size-sm {
|
|
9
|
+
> :not(label) {
|
|
10
|
+
width: $sm-dimension;
|
|
11
|
+
height: $sm-dimension;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
%size-sm {
|
|
16
|
+
@include size-sm;
|
|
17
|
+
}
|
|
18
|
+
.size-sm {
|
|
19
|
+
@extend %size-sm;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@mixin size-md {
|
|
23
|
+
> :not(label) {
|
|
24
|
+
width: $md-dimension;
|
|
25
|
+
height: $md-dimension;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
%size-md {
|
|
30
|
+
@include size-md;
|
|
31
|
+
}
|
|
32
|
+
.size-md {
|
|
33
|
+
@extend %size-md;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@mixin size-lg {
|
|
37
|
+
> :not(label) {
|
|
38
|
+
width: $lg-dimension;
|
|
39
|
+
height: $lg-dimension;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
%size-lg {
|
|
44
|
+
@include size-lg;
|
|
45
|
+
}
|
|
46
|
+
.size-lg {
|
|
47
|
+
@extend %size-lg;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.radio-container {
|
|
51
|
+
input:focus + div {
|
|
52
|
+
outline: 0;
|
|
53
|
+
box-shadow: var(
|
|
54
|
+
--form-control-box-shadow-focus,
|
|
55
|
+
var(--INTERNAL_form-control-box-shadow-focus)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//Show focus styles on keyboard focus.
|
|
60
|
+
input:focus-visible + div {
|
|
61
|
+
outline: 0;
|
|
62
|
+
box-shadow: var(
|
|
63
|
+
--form-control-box-shadow-focus,
|
|
64
|
+
var(--INTERNAL_form-control-box-shadow-focus)
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Hide focus styles if they are not needed, for example,
|
|
69
|
+
// when an element receives focus via the mouse.
|
|
70
|
+
input:focus:not(:focus-visible) + div {
|
|
71
|
+
outline: 0;
|
|
72
|
+
box-shadow: none;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
&.hidden {
|
|
76
|
+
@include accessible-hidden-element;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@media (min-width: $size-breakpoint-tablet) {
|
|
81
|
+
.size-sm-tablet {
|
|
82
|
+
@include size-sm;
|
|
83
|
+
}
|
|
84
|
+
.size-md-tablet {
|
|
85
|
+
@include size-md;
|
|
86
|
+
}
|
|
87
|
+
.size-lg-tablet {
|
|
88
|
+
@include size-lg;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@media (min-width: $size-breakpoint-desktop) {
|
|
93
|
+
.size-sm-desktop {
|
|
94
|
+
@include size-sm;
|
|
95
|
+
}
|
|
96
|
+
.size-md-desktop {
|
|
97
|
+
@include size-md;
|
|
98
|
+
}
|
|
99
|
+
.size-lg-desktop {
|
|
100
|
+
@include size-lg;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@media (min-width: $size-breakpoint-hd) {
|
|
105
|
+
.size-sm-hd {
|
|
106
|
+
@include size-sm;
|
|
107
|
+
}
|
|
108
|
+
.size-md-hd {
|
|
109
|
+
@include size-md;
|
|
110
|
+
}
|
|
111
|
+
.size-lg-hd {
|
|
112
|
+
@include size-lg;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, fireEvent, screen } from '@testing-library/react';
|
|
3
|
+
import { RadioInput } from './RadioInput';
|
|
4
|
+
|
|
5
|
+
const mockOption = {
|
|
6
|
+
id: 'chocolate',
|
|
7
|
+
value: 'chocolate',
|
|
8
|
+
label: 'Chocolate',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const mockedHandleChange = jest.fn();
|
|
12
|
+
|
|
13
|
+
describe('RadioInput', () => {
|
|
14
|
+
describe('Callback Handling', () => {
|
|
15
|
+
describe('onChange', () => {
|
|
16
|
+
test('onChange event fires callback function', () => {
|
|
17
|
+
render(
|
|
18
|
+
<RadioInput
|
|
19
|
+
size="sm"
|
|
20
|
+
name="mockName"
|
|
21
|
+
onChange={mockedHandleChange}
|
|
22
|
+
option={mockOption}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const radioInput = screen.getByLabelText('Chocolate');
|
|
27
|
+
fireEvent.click(radioInput);
|
|
28
|
+
expect(mockedHandleChange).toHaveBeenCalledTimes(1);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('calls onChange and passes checked value in event', () => {
|
|
32
|
+
let value = null;
|
|
33
|
+
const mockedHandleChangeWithValue = jest.fn((event) => {
|
|
34
|
+
value = event.target.value;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
render(
|
|
38
|
+
<RadioInput
|
|
39
|
+
size="sm"
|
|
40
|
+
name="mockName"
|
|
41
|
+
onChange={mockedHandleChangeWithValue}
|
|
42
|
+
option={mockOption}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
const radioInput = screen.getByLabelText('Chocolate');
|
|
46
|
+
fireEvent.click(radioInput);
|
|
47
|
+
expect(mockedHandleChange).toBeCalledTimes(1);
|
|
48
|
+
expect(value).toBe('chocolate');
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('onFocus', () => {
|
|
53
|
+
test('onFocus event fires callback function', () => {
|
|
54
|
+
const mockedHandleFocus = jest.fn();
|
|
55
|
+
|
|
56
|
+
render(
|
|
57
|
+
<RadioInput
|
|
58
|
+
size="sm"
|
|
59
|
+
name="mockName"
|
|
60
|
+
onChange={mockedHandleChange}
|
|
61
|
+
option={mockOption}
|
|
62
|
+
onFocus={mockedHandleFocus}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
const radioInput = screen.getByLabelText('Chocolate');
|
|
66
|
+
fireEvent.focus(radioInput);
|
|
67
|
+
expect(mockedHandleFocus).toBeCalledTimes(1);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('onBlur', () => {
|
|
72
|
+
test('onBlur event fires callback function', () => {
|
|
73
|
+
const mockedHandleBlur = jest.fn();
|
|
74
|
+
|
|
75
|
+
render(
|
|
76
|
+
<RadioInput
|
|
77
|
+
size="sm"
|
|
78
|
+
name="mockName"
|
|
79
|
+
onChange={mockedHandleChange}
|
|
80
|
+
option={mockOption}
|
|
81
|
+
onBlur={mockedHandleBlur}
|
|
82
|
+
/>
|
|
83
|
+
);
|
|
84
|
+
const radioInput = screen.getByLabelText('Chocolate');
|
|
85
|
+
fireEvent.blur(radioInput);
|
|
86
|
+
expect(mockedHandleBlur).toBeCalledTimes(1);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('States', () => {
|
|
92
|
+
describe('Default', () => {
|
|
93
|
+
test('it renders a radio input', () => {
|
|
94
|
+
render(
|
|
95
|
+
<RadioInput
|
|
96
|
+
size="sm"
|
|
97
|
+
name="mockName"
|
|
98
|
+
onChange={mockedHandleChange}
|
|
99
|
+
option={mockOption}
|
|
100
|
+
/>
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const radioInputElement = screen.getByRole('radio');
|
|
104
|
+
expect(radioInputElement).toBeInTheDocument();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('it renders a label', () => {
|
|
108
|
+
render(
|
|
109
|
+
<RadioInput
|
|
110
|
+
size="sm"
|
|
111
|
+
name="mockName"
|
|
112
|
+
onChange={mockedHandleChange}
|
|
113
|
+
option={mockOption}
|
|
114
|
+
/>
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const radioInputLabel = screen.getByLabelText('Chocolate');
|
|
118
|
+
expect(radioInputLabel).toBeInTheDocument();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe('Disabled', () => {
|
|
123
|
+
test('the radio input is disabled', () => {
|
|
124
|
+
render(
|
|
125
|
+
<RadioInput
|
|
126
|
+
size="sm"
|
|
127
|
+
name="mockName"
|
|
128
|
+
onChange={mockedHandleChange}
|
|
129
|
+
option={mockOption}
|
|
130
|
+
isDisabled
|
|
131
|
+
/>
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
const radioInputElement = screen.getByRole('radio');
|
|
135
|
+
expect(radioInputElement).toBeDisabled();
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe('Hidden', () => {
|
|
140
|
+
test('the radio input is hidden', () => {
|
|
141
|
+
render(
|
|
142
|
+
<RadioInput
|
|
143
|
+
size="sm"
|
|
144
|
+
name="mockName"
|
|
145
|
+
onChange={mockedHandleChange}
|
|
146
|
+
option={mockOption}
|
|
147
|
+
isHidden
|
|
148
|
+
/>
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const radioInputContainer = screen.getByRole('radio').closest('div');
|
|
152
|
+
expect(radioInputContainer).toHaveClass('hidden');
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import React, { ChangeEvent, FocusEvent, ReactNode } from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { ResponsiveProp } from '../../../types';
|
|
4
|
+
import { generateResponsiveClasses } from '../../../lib/generateResponsiveClasses';
|
|
5
|
+
import { Box, BoxProps } from '../../Box/Box';
|
|
6
|
+
import { FormLabel } from '../../FormLabel/FormLabel';
|
|
7
|
+
import { RadioInputIcon } from './RadioInputIcon'; // eslint-disable-line import/no-cycle
|
|
8
|
+
import styles from './RadioInput.module.scss';
|
|
9
|
+
|
|
10
|
+
type BaseSize = 'sm' | 'md' | 'lg';
|
|
11
|
+
export type RadioSize = BaseSize | ResponsiveProp<BaseSize>;
|
|
12
|
+
|
|
13
|
+
export interface RadioInputProps {
|
|
14
|
+
/**
|
|
15
|
+
* Radio input name.
|
|
16
|
+
*/
|
|
17
|
+
name: string;
|
|
18
|
+
/**
|
|
19
|
+
* Callback function to call on change event.
|
|
20
|
+
*/
|
|
21
|
+
onChange: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Options for radio group.
|
|
24
|
+
*/
|
|
25
|
+
option: {
|
|
26
|
+
id: string;
|
|
27
|
+
value: string;
|
|
28
|
+
label: ReactNode;
|
|
29
|
+
disabled?: boolean | null;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Additional classes to add.
|
|
33
|
+
*/
|
|
34
|
+
className?: string;
|
|
35
|
+
/**
|
|
36
|
+
* If the radio group should be disabled and not focusable.
|
|
37
|
+
*/
|
|
38
|
+
isDisabled?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* If the radio input should be hidden to make way for a custom radio.
|
|
41
|
+
*/
|
|
42
|
+
isHidden?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* The required and aria-required attributes
|
|
45
|
+
*/
|
|
46
|
+
isRequired?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* If the radio group should be disabled and not focusable.
|
|
49
|
+
*/
|
|
50
|
+
isSelected?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Callback function to call on blur event.
|
|
53
|
+
*/
|
|
54
|
+
onBlur?: (event: FocusEvent<HTMLInputElement>) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Callback function to call on focus event.
|
|
57
|
+
*/
|
|
58
|
+
onFocus?: (event: FocusEvent<HTMLInputElement>) => void;
|
|
59
|
+
/**
|
|
60
|
+
* The size of the radio icon.
|
|
61
|
+
*/
|
|
62
|
+
size: RadioSize;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const RadioInput = React.forwardRef<HTMLDivElement, RadioInputProps>(
|
|
66
|
+
(
|
|
67
|
+
{
|
|
68
|
+
name,
|
|
69
|
+
onChange,
|
|
70
|
+
option,
|
|
71
|
+
className = '',
|
|
72
|
+
isDisabled = false,
|
|
73
|
+
isHidden = false,
|
|
74
|
+
isRequired = false,
|
|
75
|
+
isSelected = false,
|
|
76
|
+
onBlur = undefined,
|
|
77
|
+
onFocus = undefined,
|
|
78
|
+
size = 'md',
|
|
79
|
+
},
|
|
80
|
+
ref
|
|
81
|
+
) => {
|
|
82
|
+
const responsiveClasses = classNames(
|
|
83
|
+
...generateResponsiveClasses('size', size).map((c) => styles[c])
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const labelProps = {
|
|
87
|
+
inputId: option.id,
|
|
88
|
+
isDisabled,
|
|
89
|
+
display: 'flex' as BoxProps['display'],
|
|
90
|
+
isRadioInputLabel: true,
|
|
91
|
+
justifyContent: 'center' as BoxProps['justifyContent'],
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const containerClasses = classNames(
|
|
95
|
+
'hyphen-components__variables__form-control',
|
|
96
|
+
className,
|
|
97
|
+
styles['radio-container'],
|
|
98
|
+
responsiveClasses,
|
|
99
|
+
{ [styles.hidden]: isHidden }
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<>
|
|
104
|
+
{option && (
|
|
105
|
+
<Box
|
|
106
|
+
className={containerClasses}
|
|
107
|
+
key={option.id}
|
|
108
|
+
direction="row"
|
|
109
|
+
alignItems="center"
|
|
110
|
+
ref={ref}
|
|
111
|
+
position="relative"
|
|
112
|
+
>
|
|
113
|
+
<Box
|
|
114
|
+
aria-required={isRequired}
|
|
115
|
+
as="input"
|
|
116
|
+
id={option.id}
|
|
117
|
+
type="radio"
|
|
118
|
+
name={name}
|
|
119
|
+
value={option.value}
|
|
120
|
+
checked={isSelected}
|
|
121
|
+
onChange={onChange}
|
|
122
|
+
onFocus={onFocus}
|
|
123
|
+
onBlur={onBlur}
|
|
124
|
+
disabled={isDisabled}
|
|
125
|
+
position="absolute"
|
|
126
|
+
required={isRequired}
|
|
127
|
+
style={{ opacity: '0' }}
|
|
128
|
+
margin={isHidden ? '0' : '0 xs 0 2xs'}
|
|
129
|
+
/>
|
|
130
|
+
{!isHidden && (
|
|
131
|
+
<RadioInputIcon
|
|
132
|
+
isSelected={isSelected}
|
|
133
|
+
isDisabled={isDisabled}
|
|
134
|
+
margin={isHidden ? '0' : '0 xs 0 2xs'}
|
|
135
|
+
className={responsiveClasses}
|
|
136
|
+
background={isDisabled && !isSelected ? 'secondary' : 'primary'}
|
|
137
|
+
radius="circle"
|
|
138
|
+
/>
|
|
139
|
+
)}
|
|
140
|
+
{option.label && (
|
|
141
|
+
<FormLabel {...labelProps}>{option.label}</FormLabel>
|
|
142
|
+
)}
|
|
143
|
+
</Box>
|
|
144
|
+
)}
|
|
145
|
+
</>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, BoxProps } from '../../Box/Box';
|
|
3
|
+
import { Icon } from '../../Icon/Icon';
|
|
4
|
+
import { FontColor } from '../../../types';
|
|
5
|
+
import { RadioInputProps } from './RadioInput'; // eslint-disable-line import/no-cycle
|
|
6
|
+
import { RadioGroupProps } from '../RadioGroup'; // eslint-disable-line import/no-cycle
|
|
7
|
+
|
|
8
|
+
export interface RadioIconProps extends BoxProps {
|
|
9
|
+
/**
|
|
10
|
+
* Custom className to be applied to root node of component.
|
|
11
|
+
*/
|
|
12
|
+
className?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Whether the input is in an error state. The icon will visually change accordingly.
|
|
15
|
+
*/
|
|
16
|
+
error?: RadioGroupProps['error'];
|
|
17
|
+
/**
|
|
18
|
+
* Whether the radio is selected.
|
|
19
|
+
*/
|
|
20
|
+
isSelected?: RadioInputProps['isSelected'];
|
|
21
|
+
/**
|
|
22
|
+
* If the input should be disabled and not focusable.
|
|
23
|
+
*/
|
|
24
|
+
isDisabled?: RadioInputProps['isDisabled'];
|
|
25
|
+
/**
|
|
26
|
+
* Additional props to be spread to rendered element
|
|
27
|
+
*/
|
|
28
|
+
[x: string]: any; // eslint-disable-line
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const RadioInputIcon: React.FC<RadioIconProps> = ({
|
|
32
|
+
className = undefined,
|
|
33
|
+
isSelected = false,
|
|
34
|
+
isDisabled = false,
|
|
35
|
+
error = null,
|
|
36
|
+
...restProps
|
|
37
|
+
}) => {
|
|
38
|
+
let color: FontColor = 'secondary';
|
|
39
|
+
let name: 'radio-btn-unchecked' | 'radio-btn-checked' = 'radio-btn-unchecked';
|
|
40
|
+
|
|
41
|
+
if (isSelected && isDisabled) {
|
|
42
|
+
color = 'disabled';
|
|
43
|
+
name = 'radio-btn-checked';
|
|
44
|
+
} else if (isSelected && !isDisabled) {
|
|
45
|
+
color = 'base';
|
|
46
|
+
name = 'radio-btn-checked';
|
|
47
|
+
} else if (isDisabled) {
|
|
48
|
+
color = 'disabled';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (error) color = 'danger';
|
|
52
|
+
if (isDisabled && error) color = 'danger-disabled';
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<Box className={className} {...restProps}>
|
|
56
|
+
<Icon color={color} name={name} />
|
|
57
|
+
</Box>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Canvas, Meta, ArgTypes } from '@storybook/blocks';
|
|
2
|
+
import { ResponsiveProvider } from './ResponsiveProvider';
|
|
3
|
+
import * as Stories from './ResponsiveProvider.stories';
|
|
4
|
+
|
|
5
|
+
<Meta of={Stories} />
|
|
6
|
+
|
|
7
|
+
# ResponsiveProvider
|
|
8
|
+
|
|
9
|
+
Use a `ResponsiveProvider` to provide window size context to all children components. This circumvents the need
|
|
10
|
+
to set up individual resize listeners per component when detailed responsive behavior is required.
|
|
11
|
+
|
|
12
|
+
This component is meant to be used in conjunction with the `useWindowSize` and `useBreakpoint` hooks provided in order to write responsive
|
|
13
|
+
markup without diving into CSS.
|
|
14
|
+
|
|
15
|
+
## Props
|
|
16
|
+
|
|
17
|
+
<ArgTypes of={ResponsiveProvider} />
|
|
18
|
+
|
|
19
|
+
## Basic Usage
|
|
20
|
+
|
|
21
|
+
The `ResponsiveProvider` component can wrap any JSX component but in order to leverage the performance gains of a single context,
|
|
22
|
+
it is best to use it once in an application, and placed as high as possible in the component tree (likely wrapping the App itself).
|
|
23
|
+
|
|
24
|
+
The example below shows basic usage.
|
|
25
|
+
|
|
26
|
+
**NOTE:** we've included hooks that work in conjuction with this component in order to get
|
|
27
|
+
window size data from the provider. the example below uses `useWindowSize`.
|
|
28
|
+
|
|
29
|
+
<Canvas isExpanded of={Stories.BasicUsage} />
|
|
30
|
+
|
|
31
|
+
## Breakpoints
|
|
32
|
+
|
|
33
|
+
Our library includes opinionated [breakpoints](?path=/story/design-tokens-design-tokens--page#breakpoints). The `useBreakpoint` hook exposes
|
|
34
|
+
these to any component nested under a `ResponsiveProvider`
|
|
35
|
+
|
|
36
|
+
<Canvas isExpanded of={Stories.Breakpoints} />
|