@nypl/design-system-react-components 0.26.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -0
- package/README.md +7 -7
- package/dist/components/Accordion/Accordion.d.ts +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +1 -5
- package/dist/components/Button/Button.d.ts +2 -10
- package/dist/components/ButtonGroup/ButtonGroup.d.ts +22 -0
- package/dist/components/Card/Card.d.ts +2 -2
- package/dist/components/Checkbox/Checkbox.d.ts +10 -8
- package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +1 -1
- package/dist/components/DatePicker/DatePicker.d.ts +1 -1
- package/dist/components/Form/Form.d.ts +2 -2
- package/dist/components/Grid/SimpleGrid.d.ts +6 -3
- package/dist/components/Heading/Heading.d.ts +2 -5
- package/dist/components/HelperErrorText/HelperErrorText.d.ts +1 -5
- package/dist/components/Hero/Hero.d.ts +13 -9
- package/dist/components/Icons/Icon.d.ts +6 -5
- package/dist/components/Icons/IconSvgs.d.ts +21 -21
- package/dist/components/Image/Image.d.ts +8 -5
- package/dist/components/Link/Link.d.ts +1 -9
- package/dist/components/List/List.d.ts +7 -11
- package/dist/components/Logo/Logo.d.ts +2 -5
- package/dist/components/Logo/LogoSvgs.d.ts +39 -39
- package/dist/components/Modal/Modal.d.ts +28 -8
- package/dist/components/Notification/Notification.d.ts +1 -1
- package/dist/components/ProgressIndicator/ProgressIndicator.d.ts +2 -1
- package/dist/components/RadioGroup/RadioGroup.d.ts +1 -1
- package/dist/components/SearchBar/SearchBar.d.ts +3 -2
- package/dist/components/Select/Select.d.ts +2 -5
- package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +4 -4
- package/dist/components/SkipNavigation/SkipNavigation.d.ts +17 -0
- package/dist/components/StatusBadge/StatusBadge.d.ts +2 -3
- package/dist/components/StructuredContent/StructuredContent.d.ts +2 -2
- package/dist/components/Table/Table.d.ts +1 -1
- package/dist/components/Template/Template.d.ts +2 -0
- package/dist/components/Text/Text.d.ts +1 -1
- package/dist/components/TextInput/TextInput.d.ts +21 -9
- package/dist/components/Toggle/Toggle.d.ts +1 -5
- package/dist/components/VideoPlayer/VideoPlayer.d.ts +2 -1
- package/dist/design-system-react-components.cjs.development.js +983 -1222
- package/dist/design-system-react-components.cjs.development.js.map +1 -1
- package/dist/design-system-react-components.cjs.production.min.js +1 -1
- package/dist/design-system-react-components.cjs.production.min.js.map +1 -1
- package/dist/design-system-react-components.esm.js +982 -1285
- package/dist/design-system-react-components.esm.js.map +1 -1
- package/dist/helpers/types.d.ts +1 -0
- package/dist/index.d.ts +27 -48
- package/dist/styles.css +1 -1
- package/dist/theme/components/buttonGroup.d.ts +11 -0
- package/dist/theme/components/card.d.ts +104 -8
- package/dist/theme/components/componentWrapper.d.ts +4 -3
- package/dist/theme/components/customTable.d.ts +11 -14
- package/dist/theme/components/fieldset.d.ts +4 -3
- package/dist/theme/components/helperErrorText.d.ts +4 -3
- package/dist/theme/components/hero.d.ts +1 -1
- package/dist/theme/components/horizontalRule.d.ts +4 -3
- package/dist/theme/components/icon.d.ts +47743 -1
- package/dist/theme/components/image.d.ts +563 -10
- package/dist/theme/components/label.d.ts +4 -3
- package/dist/theme/components/list.d.ts +6 -7
- package/dist/theme/components/logo.d.ts +474 -1
- package/dist/theme/components/notification.d.ts +20 -16
- package/dist/theme/components/progressIndicator.d.ts +6 -4
- package/dist/theme/components/select.d.ts +4 -10
- package/dist/theme/components/skeletonLoader.d.ts +14 -10
- package/dist/theme/components/skipNavigation.d.ts +22 -0
- package/dist/theme/components/slider.d.ts +7 -6
- package/dist/theme/components/structuredContent.d.ts +10 -9
- package/dist/theme/components/text.d.ts +7 -1
- package/dist/theme/components/toggle.d.ts +6 -4
- package/dist/theme/provider.d.ts +2 -4
- package/dist/utils/componentCategories.d.ts +1 -1
- package/dist/utils/interfaces.d.ts +5 -0
- package/dist/utils/utils.d.ts +2 -18
- package/package.json +15 -16
- package/src/__tests__/setup.ts +3 -3
- package/src/__tests__/utils/utils.test.ts +1 -23
- package/src/components/AccessibilityGuide/SkipNavigation.stories.mdx +22 -14
- package/src/components/Accordion/Accordion.stories.mdx +43 -44
- package/src/components/Accordion/Accordion.test.tsx +5 -13
- package/src/components/Accordion/Accordion.tsx +14 -18
- package/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +6 -6
- package/src/components/Autosuggest/Autosuggest.stories.mdx +1 -1
- package/src/components/Autosuggest/Autosuggest.stories.tsx +23 -25
- package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +21 -37
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +4 -17
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +18 -21
- package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +1 -100
- package/src/components/Button/Button.stories.mdx +89 -126
- package/src/components/Button/Button.test.tsx +16 -30
- package/src/components/Button/Button.tsx +14 -20
- package/src/components/ButtonGroup/ButtonGroup.stories.mdx +147 -0
- package/src/components/ButtonGroup/ButtonGroup.test.tsx +141 -0
- package/src/components/ButtonGroup/ButtonGroup.tsx +99 -0
- package/src/components/ButtonGroup/__snapshots__/ButtonGroup.test.tsx.snap +117 -0
- package/src/components/Card/Card.stories.mdx +144 -178
- package/src/components/Card/Card.test.tsx +36 -97
- package/src/components/Card/Card.tsx +78 -74
- package/src/components/Chakra/Box.stories.mdx +3 -7
- package/src/components/Chakra/Center.stories.mdx +6 -24
- package/src/components/Chakra/Flex.stories.mdx +5 -7
- package/src/components/Chakra/Grid.stories.mdx +1 -1
- package/src/components/Chakra/Stack.stories.mdx +10 -11
- package/src/components/Checkbox/Checkbox.stories.mdx +1 -1
- package/src/components/Checkbox/Checkbox.test.tsx +2 -2
- package/src/components/Checkbox/Checkbox.tsx +20 -13
- package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +6 -17
- package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +1 -7
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +33 -29
- package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +0 -11
- package/src/components/ComponentWrapper/ComponentWrapper.tsx +3 -10
- package/src/components/DatePicker/DatePicker.stories.mdx +23 -37
- package/src/components/DatePicker/DatePicker.test.tsx +21 -19
- package/src/components/DatePicker/DatePicker.tsx +57 -49
- package/src/components/Form/Form.stories.mdx +46 -31
- package/src/components/Form/Form.test.tsx +1 -18
- package/src/components/Form/Form.tsx +7 -7
- package/src/components/Grid/SimpleGrid.stories.mdx +73 -49
- package/src/components/Grid/SimpleGrid.test.tsx +7 -9
- package/src/components/Grid/SimpleGrid.tsx +14 -11
- package/src/components/Heading/Heading.stories.mdx +27 -72
- package/src/components/Heading/Heading.test.tsx +18 -44
- package/src/components/Heading/Heading.tsx +7 -10
- package/src/components/HelperErrorText/HelperErrorText.stories.mdx +1 -3
- package/src/components/HelperErrorText/HelperErrorText.tsx +1 -5
- package/src/components/Hero/Hero.stories.mdx +219 -216
- package/src/components/Hero/Hero.test.tsx +107 -223
- package/src/components/Hero/Hero.tsx +63 -61
- package/src/components/Icons/Icon.stories.mdx +172 -118
- package/src/components/Icons/Icon.test.tsx +8 -16
- package/src/components/Icons/Icon.tsx +75 -29
- package/src/components/Icons/IconSvgs.tsx +42 -42
- package/src/components/Image/Image.stories.mdx +45 -132
- package/src/components/Image/Image.test.tsx +16 -31
- package/src/components/Image/Image.tsx +28 -12
- package/src/components/Link/Link.stories.mdx +30 -94
- package/src/components/Link/Link.test.tsx +25 -75
- package/src/components/Link/Link.tsx +43 -56
- package/src/components/Link/__snapshots__/Link.test.tsx.snap +1 -2
- package/src/components/List/List.stories.mdx +20 -31
- package/src/components/List/List.test.tsx +24 -43
- package/src/components/List/List.tsx +25 -36
- package/src/components/Logo/Logo.stories.mdx +94 -50
- package/src/components/Logo/Logo.test.tsx +10 -19
- package/src/components/Logo/Logo.tsx +50 -17
- package/src/components/Logo/LogoSvgs.tsx +78 -78
- package/src/components/Logo/__snapshots__/Logo.test.tsx.snap +4 -4
- package/src/components/Modal/Modal.stories.mdx +245 -139
- package/src/components/Modal/Modal.test.tsx +147 -10
- package/src/components/Modal/Modal.tsx +140 -20
- package/src/components/Modal/__snapshots__/Modal.test.tsx.snap +25 -0
- package/src/components/Notification/Notification.stories.mdx +10 -28
- package/src/components/Notification/Notification.test.tsx +9 -12
- package/src/components/Notification/Notification.tsx +34 -37
- package/src/components/Pagination/Pagination.stories.mdx +3 -4
- package/src/components/Pagination/Pagination.tsx +15 -10
- package/src/components/ProgressIndicator/ProgressIndicator.stories.mdx +27 -53
- package/src/components/ProgressIndicator/ProgressIndicator.test.tsx +9 -10
- package/src/components/ProgressIndicator/ProgressIndicator.tsx +17 -21
- package/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap +0 -10
- package/src/components/Radio/Radio.stories.mdx +1 -1
- package/src/components/Radio/Radio.tsx +9 -6
- package/src/components/RadioGroup/RadioGroup.stories.mdx +15 -16
- package/src/components/RadioGroup/RadioGroup.test.tsx +2 -8
- package/src/components/RadioGroup/RadioGroup.tsx +28 -24
- package/src/components/SearchBar/SearchBar.stories.mdx +4 -4
- package/src/components/SearchBar/SearchBar.test.tsx +1 -1
- package/src/components/SearchBar/SearchBar.tsx +14 -22
- package/src/components/SearchBar/__snapshots__/SearchBar.test.tsx.snap +1 -13
- package/src/components/Select/Select.stories.mdx +10 -25
- package/src/components/Select/Select.test.tsx +6 -7
- package/src/components/Select/Select.tsx +28 -35
- package/src/components/Select/__snapshots__/Select.test.tsx.snap +24 -24
- package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +17 -56
- package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +7 -21
- package/src/components/SkeletonLoader/SkeletonLoader.tsx +9 -8
- package/src/components/SkeletonLoader/__snapshots__/SkeletonLoader.test.tsx.snap +33 -33
- package/src/components/SkipNavigation/SkipNavigation.stories.mdx +90 -0
- package/src/components/SkipNavigation/SkipNavigation.test.tsx +63 -0
- package/src/components/SkipNavigation/SkipNavigation.tsx +51 -0
- package/src/components/SkipNavigation/__snapshots__/SkipNavigation.test.tsx.snap +130 -0
- package/src/components/Slider/Slider.stories.mdx +19 -53
- package/src/components/Slider/Slider.test.tsx +2 -2
- package/src/components/Slider/Slider.tsx +10 -12
- package/src/components/Slider/__snapshots__/Slider.test.tsx.snap +2 -9
- package/src/components/StatusBadge/StatusBadge.stories.mdx +6 -21
- package/src/components/StatusBadge/StatusBadge.test.tsx +2 -3
- package/src/components/StatusBadge/StatusBadge.tsx +3 -10
- package/src/components/StructuredContent/StructuredContent.stories.mdx +30 -58
- package/src/components/StructuredContent/StructuredContent.test.tsx +42 -44
- package/src/components/StructuredContent/StructuredContent.tsx +9 -18
- package/src/components/StyleGuide/Bidirectionality.stories.mdx +9 -23
- package/src/components/StyleGuide/Buttons.stories.mdx +63 -63
- package/src/components/StyleGuide/ColorCard.tsx +2 -4
- package/src/components/StyleGuide/Colors.stories.mdx +9 -10
- package/src/components/StyleGuide/DesignTokens.stories.mdx +5 -7
- package/src/components/StyleGuide/Forms.stories.mdx +2 -2
- package/src/components/StyleGuide/Iconography.stories.mdx +60 -78
- package/src/components/StyleGuide/Spacing.stories.mdx +1 -2
- package/src/components/StyleGuide/Typography.stories.mdx +16 -19
- package/src/components/Table/Table.stories.mdx +85 -1
- package/src/components/Table/Table.test.tsx +57 -1
- package/src/components/Table/Table.tsx +7 -4
- package/src/components/Table/__snapshots__/Table.test.tsx.snap +121 -0
- package/src/components/Tabs/Tabs.stories.mdx +1 -1
- package/src/components/Tabs/Tabs.test.tsx +2 -2
- package/src/components/Tabs/Tabs.tsx +26 -27
- package/src/components/Template/Template.stories.mdx +49 -54
- package/src/components/Template/Template.tsx +9 -3
- package/src/components/Text/Text.stories.mdx +5 -11
- package/src/components/Text/Text.test.tsx +3 -6
- package/src/components/Text/Text.tsx +3 -5
- package/src/components/TextInput/TextInput.stories.mdx +10 -22
- package/src/components/TextInput/TextInput.test.tsx +32 -62
- package/src/components/TextInput/TextInput.tsx +61 -30
- package/src/components/TextInput/__snapshots__/TextInput.test.tsx.snap +1 -0
- package/src/components/Toggle/Toggle.stories.mdx +5 -16
- package/src/components/Toggle/Toggle.test.tsx +2 -3
- package/src/components/Toggle/Toggle.tsx +9 -10
- package/src/components/VideoPlayer/VideoPlayer.stories.mdx +13 -29
- package/src/components/VideoPlayer/VideoPlayer.test.tsx +18 -23
- package/src/components/VideoPlayer/VideoPlayer.tsx +13 -10
- package/src/docs/Chakra.stories.mdx +14 -11
- package/src/docs/Welcome.stories.mdx +23 -43
- package/src/helpers/types.ts +1 -0
- package/src/hooks/tests/useNYPLTheme.test.tsx +1 -1
- package/src/hooks/useNYPLTheme.stories.mdx +3 -6
- package/src/index.ts +52 -46
- package/src/styles.scss +0 -1
- package/src/theme/components/buttonGroup.ts +10 -0
- package/src/theme/components/card.ts +50 -15
- package/src/theme/components/componentWrapper.ts +5 -1
- package/src/theme/components/customTable.ts +8 -2
- package/src/theme/components/fieldset.ts +5 -1
- package/src/theme/components/helperErrorText.ts +5 -1
- package/src/theme/components/hero.ts +2 -2
- package/src/theme/components/horizontalRule.ts +5 -1
- package/src/theme/components/icon.ts +7 -1
- package/src/theme/components/image.ts +14 -3
- package/src/theme/components/label.ts +5 -1
- package/src/theme/components/list.ts +8 -2
- package/src/theme/components/logo.ts +5 -1
- package/src/theme/components/notification.ts +38 -14
- package/src/theme/components/progressIndicator.ts +10 -5
- package/src/theme/components/select.ts +5 -6
- package/src/theme/components/skeletonLoader.ts +8 -2
- package/src/theme/components/skipNavigation.ts +26 -0
- package/src/theme/components/slider.ts +13 -1
- package/src/theme/components/structuredContent.ts +11 -1
- package/src/theme/components/text.ts +12 -5
- package/src/theme/components/toggle.ts +9 -3
- package/src/theme/foundations/colors.ts +6 -9
- package/src/theme/index.ts +4 -0
- package/src/theme/provider.tsx +1 -1
- package/src/utils/componentCategories.ts +13 -5
- package/src/utils/interfaces.ts +5 -0
- package/src/utils/utils.ts +2 -32
- package/dist/components/Accordion/AccordionTypes.d.ts +0 -5
- package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +0 -8
- package/dist/components/Button/ButtonTypes.d.ts +0 -8
- package/dist/components/DatePicker/DatePickerTypes.d.ts +0 -5
- package/dist/components/Form/FormTypes.d.ts +0 -2
- package/dist/components/Grid/GridTypes.d.ts +0 -9
- package/dist/components/Heading/HeadingTypes.d.ts +0 -14
- package/dist/components/Hero/HeroTypes.d.ts +0 -12
- package/dist/components/Icons/IconTypes.d.ts +0 -77
- package/dist/components/Image/ImageTypes.d.ts +0 -22
- package/dist/components/Link/LinkTypes.d.ts +0 -8
- package/dist/components/List/ListTypes.d.ts +0 -5
- package/dist/components/Logo/LogoTypes.d.ts +0 -54
- package/dist/components/Notification/NotificationTypes.d.ts +0 -5
- package/dist/components/ProgressIndicator/ProgressIndicatorTypes.d.ts +0 -8
- package/dist/components/Select/SelectTypes.d.ts +0 -8
- package/dist/components/SkeletonLoader/SkeletonLoaderTypes.d.ts +0 -5
- package/dist/components/StatusBadge/StatusBadgeTypes.d.ts +0 -5
- package/dist/components/StructuredContent/StructuredContentTypes.d.ts +0 -5
- package/dist/components/Text/TextTypes.d.ts +0 -6
- package/dist/components/TextInput/TextInputTypes.d.ts +0 -25
- package/dist/components/Toggle/ToggleTypes.d.ts +0 -4
- package/dist/components/VideoPlayer/VideoPlayerTypes.d.ts +0 -9
- package/dist/helpers/enums.d.ts +0 -4
- package/dist/utils/siteSections.d.ts +0 -2
- package/src/components/Accordion/AccordionTypes.tsx +0 -5
- package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +0 -8
- package/src/components/Button/ButtonTypes.tsx +0 -8
- package/src/components/DatePicker/DatePickerTypes.tsx +0 -5
- package/src/components/Form/FormTypes.tsx +0 -3
- package/src/components/Grid/GridTypes.tsx +0 -9
- package/src/components/Heading/HeadingTypes.tsx +0 -15
- package/src/components/Hero/HeroTypes.tsx +0 -20
- package/src/components/Icons/IconTypes.tsx +0 -83
- package/src/components/Image/ImageTypes.ts +0 -24
- package/src/components/Link/LinkTypes.tsx +0 -8
- package/src/components/List/ListTypes.tsx +0 -5
- package/src/components/Logo/LogoTypes.tsx +0 -56
- package/src/components/Modal/_Modal.scss +0 -18
- package/src/components/Notification/NotificationTypes.tsx +0 -5
- package/src/components/ProgressIndicator/ProgressIndicatorTypes.ts +0 -8
- package/src/components/Select/SelectTypes.tsx +0 -10
- package/src/components/SkeletonLoader/SkeletonLoaderTypes.tsx +0 -5
- package/src/components/StatusBadge/StatusBadgeTypes.tsx +0 -5
- package/src/components/StructuredContent/StructuredContentTypes.tsx +0 -5
- package/src/components/Text/TextTypes.tsx +0 -6
- package/src/components/TextInput/TextInputTypes.tsx +0 -48
- package/src/components/Toggle/ToggleTypes.tsx +0 -4
- package/src/components/VideoPlayer/VideoPlayerTypes.tsx +0 -10
- package/src/helpers/enums.ts +0 -4
- package/src/utils/siteSections.ts +0 -10
|
@@ -11,19 +11,8 @@ import { withDesign } from "storybook-addon-designs";
|
|
|
11
11
|
import Button from "../Button/Button";
|
|
12
12
|
import Form, { FormField } from "../Form/Form";
|
|
13
13
|
import Select from "./Select";
|
|
14
|
-
import { SelectTypes, LabelPositions } from "./SelectTypes";
|
|
15
14
|
import { getCategory } from "../../utils/componentCategories";
|
|
16
15
|
import DSProvider from "../../theme/provider";
|
|
17
|
-
import { getStorybookEnumValues } from "../../utils/utils";
|
|
18
|
-
|
|
19
|
-
export const selectTypesEnumValues = getStorybookEnumValues(
|
|
20
|
-
SelectTypes,
|
|
21
|
-
"SelectTypes"
|
|
22
|
-
);
|
|
23
|
-
export const labelPositionsEnumValues = getStorybookEnumValues(
|
|
24
|
-
LabelPositions,
|
|
25
|
-
"LabelPositions"
|
|
26
|
-
);
|
|
27
16
|
|
|
28
17
|
<Meta
|
|
29
18
|
title={getCategory("Select")}
|
|
@@ -49,9 +38,7 @@ export const labelPositionsEnumValues = getStorybookEnumValues(
|
|
|
49
38
|
table: { defaultValue: { summary: false } },
|
|
50
39
|
},
|
|
51
40
|
labelPosition: {
|
|
52
|
-
|
|
53
|
-
table: { defaultValue: { summary: "LabelPositions.Default" } },
|
|
54
|
-
options: labelPositionsEnumValues.options,
|
|
41
|
+
table: { defaultValue: { summary: "default" } },
|
|
55
42
|
},
|
|
56
43
|
name: { control: false },
|
|
57
44
|
key: { table: { disable: true } },
|
|
@@ -68,7 +55,7 @@ export const labelPositionsEnumValues = getStorybookEnumValues(
|
|
|
68
55
|
},
|
|
69
56
|
selectType: {
|
|
70
57
|
control: false,
|
|
71
|
-
table: { defaultValue: { summary: "
|
|
58
|
+
table: { defaultValue: { summary: "default" } },
|
|
72
59
|
},
|
|
73
60
|
value: { control: false },
|
|
74
61
|
}}
|
|
@@ -79,7 +66,7 @@ export const labelPositionsEnumValues = getStorybookEnumValues(
|
|
|
79
66
|
| Component Version | DS Version |
|
|
80
67
|
| ----------------- | ---------- |
|
|
81
68
|
| Added | `0.7.0` |
|
|
82
|
-
| Latest | `0.
|
|
69
|
+
| Latest | `0.28.0` |
|
|
83
70
|
|
|
84
71
|
## Table of Contents
|
|
85
72
|
|
|
@@ -115,22 +102,19 @@ is left blank, a value will be generated for you.
|
|
|
115
102
|
isDisabled: false,
|
|
116
103
|
isInvalid: false,
|
|
117
104
|
isRequired: false,
|
|
118
|
-
labelPosition: "
|
|
105
|
+
labelPosition: "default",
|
|
119
106
|
labelText: "What is your favorite color?",
|
|
120
107
|
name: "color",
|
|
121
108
|
onChange: undefined,
|
|
122
109
|
showHelperInvalidText: undefined,
|
|
123
110
|
showLabel: true,
|
|
124
111
|
showRequiredLabel: true,
|
|
125
|
-
selectType:
|
|
112
|
+
selectType: "default",
|
|
126
113
|
value: undefined,
|
|
127
114
|
}}
|
|
128
115
|
>
|
|
129
116
|
{(args) => (
|
|
130
|
-
<Select
|
|
131
|
-
{...args}
|
|
132
|
-
labelPosition={labelPositionsEnumValues.getValue(args.labelPosition)}
|
|
133
|
-
>
|
|
117
|
+
<Select {...args}>
|
|
134
118
|
<option value="red">Red</option>
|
|
135
119
|
<option value="green">Green</option>
|
|
136
120
|
<option value="blue">Blue</option>
|
|
@@ -248,10 +232,11 @@ can be used to show or hide the "Required" text within the `label` element.
|
|
|
248
232
|
</Select>
|
|
249
233
|
<Select
|
|
250
234
|
helperText="Display the label inline"
|
|
235
|
+
id="label-example5"
|
|
251
236
|
isRequired
|
|
252
237
|
labelText="What is your favorite color?"
|
|
253
238
|
name="color"
|
|
254
|
-
labelPosition=
|
|
239
|
+
labelPosition="inline"
|
|
255
240
|
>
|
|
256
241
|
<option value="red">Red</option>
|
|
257
242
|
<option value="green">Green</option>
|
|
@@ -309,9 +294,9 @@ can be used to show or hide the "Required" text within the `label` element.
|
|
|
309
294
|
|
|
310
295
|
### Controlled Component using `value` and `onChange` props
|
|
311
296
|
|
|
312
|
-
If your application uses controlled React components and the Reservoir Design
|
|
297
|
+
If your application uses controlled React components and the Reservoir Design
|
|
313
298
|
System (DS) `Select` component must be controlled, you can pass and extract the
|
|
314
|
-
value through the `value` and `onChange` props. This will be called every time
|
|
299
|
+
value through the `value` and `onChange` props. This will be called every time
|
|
315
300
|
a new `option` value is selected.
|
|
316
301
|
|
|
317
302
|
Try it out: open up the browser's console to see new values being logged on
|
|
@@ -4,7 +4,6 @@ import { axe } from "jest-axe";
|
|
|
4
4
|
import renderer from "react-test-renderer";
|
|
5
5
|
|
|
6
6
|
import Select from "./Select";
|
|
7
|
-
import { LabelPositions } from "./SelectTypes";
|
|
8
7
|
|
|
9
8
|
const baseProps = {
|
|
10
9
|
helperText: "This is the helper text.",
|
|
@@ -178,23 +177,23 @@ describe("Select", () => {
|
|
|
178
177
|
</Select>
|
|
179
178
|
);
|
|
180
179
|
|
|
181
|
-
expect(selectRef.current
|
|
180
|
+
expect(selectRef.current?.value).toEqual("red");
|
|
182
181
|
|
|
183
182
|
fireEvent.change(screen.getByRole("combobox"), {
|
|
184
183
|
target: { value: "blue" },
|
|
185
184
|
});
|
|
186
|
-
expect(selectRef.current
|
|
185
|
+
expect(selectRef.current?.value).toEqual("blue");
|
|
187
186
|
|
|
188
187
|
fireEvent.change(screen.getByRole("combobox"), {
|
|
189
188
|
target: { value: "white" },
|
|
190
189
|
});
|
|
191
|
-
expect(selectRef.current
|
|
190
|
+
expect(selectRef.current?.value).toEqual("white");
|
|
192
191
|
});
|
|
193
192
|
|
|
194
193
|
it("calls the onChange callback function", () => {
|
|
195
194
|
let value = "";
|
|
196
|
-
const changeCallback = (e) => {
|
|
197
|
-
value = e.target.value;
|
|
195
|
+
const changeCallback = (e: React.FormEvent) => {
|
|
196
|
+
value = (e.target as HTMLInputElement).value;
|
|
198
197
|
};
|
|
199
198
|
render(
|
|
200
199
|
<Select {...baseProps} onChange={changeCallback} value={value}>
|
|
@@ -300,7 +299,7 @@ describe("Select", () => {
|
|
|
300
299
|
<Select
|
|
301
300
|
id="select"
|
|
302
301
|
isRequired
|
|
303
|
-
labelPosition=
|
|
302
|
+
labelPosition="inline"
|
|
304
303
|
labelText="Which Succession sibling are you?"
|
|
305
304
|
name="succession-sibling"
|
|
306
305
|
>
|
|
@@ -10,12 +10,12 @@ import HelperErrorText, {
|
|
|
10
10
|
HelperErrorTextType,
|
|
11
11
|
} from "../HelperErrorText/HelperErrorText";
|
|
12
12
|
import Icon from "../Icons/Icon";
|
|
13
|
-
import { IconNames, IconSizes } from "../Icons/IconTypes";
|
|
14
13
|
import Label from "../Label/Label";
|
|
15
|
-
import {
|
|
14
|
+
import { AriaAttributes } from "../../utils/interfaces";
|
|
15
|
+
|
|
16
|
+
export type SelectTypes = "default" | "searchbar";
|
|
17
|
+
export type LabelPositions = "default" | "inline";
|
|
16
18
|
export interface SelectProps {
|
|
17
|
-
/** Optionally pass in additional Chakra-based styles. */
|
|
18
|
-
additionalStyles?: { [key: string]: any };
|
|
19
19
|
/** A class name for the `div` parent element. */
|
|
20
20
|
className?: string;
|
|
21
21
|
/** Optional string to populate the `HelperErrorText` for the standard state. */
|
|
@@ -69,7 +69,6 @@ export const Select = chakra(
|
|
|
69
69
|
React.forwardRef<HTMLSelectElement, React.PropsWithChildren<SelectProps>>(
|
|
70
70
|
(props: React.PropsWithChildren<SelectProps>, ref?) => {
|
|
71
71
|
const {
|
|
72
|
-
additionalStyles = {},
|
|
73
72
|
children,
|
|
74
73
|
className,
|
|
75
74
|
helperText,
|
|
@@ -78,36 +77,37 @@ export const Select = chakra(
|
|
|
78
77
|
isDisabled = false,
|
|
79
78
|
isInvalid = false,
|
|
80
79
|
isRequired = false,
|
|
81
|
-
labelPosition =
|
|
80
|
+
labelPosition = "default",
|
|
82
81
|
labelText,
|
|
83
82
|
name,
|
|
84
83
|
onChange,
|
|
85
84
|
placeholder,
|
|
86
|
-
selectType =
|
|
85
|
+
selectType = "default",
|
|
87
86
|
showHelperInvalidText = true,
|
|
88
87
|
showLabel = true,
|
|
89
88
|
showRequiredLabel = true,
|
|
90
89
|
value = "",
|
|
91
90
|
...rest
|
|
92
91
|
} = props;
|
|
93
|
-
const ariaAttributes = {};
|
|
92
|
+
const ariaAttributes: AriaAttributes = {};
|
|
94
93
|
const [labelWidth, setLabelWidth] = useState<number>(0);
|
|
95
|
-
const labelRef = useRef<
|
|
94
|
+
const labelRef = useRef<HTMLDivElement>(null);
|
|
96
95
|
const styles = useMultiStyleConfig("CustomSelect", {
|
|
97
96
|
variant: selectType,
|
|
98
97
|
labelPosition,
|
|
99
|
-
labelWidth,
|
|
100
98
|
});
|
|
101
99
|
const finalInvalidText = invalidText
|
|
102
100
|
? invalidText
|
|
103
101
|
: "There is an error related to this field.";
|
|
104
|
-
const footnote
|
|
105
|
-
? finalInvalidText
|
|
106
|
-
: helperText;
|
|
102
|
+
const footnote = isInvalid ? finalInvalidText : helperText;
|
|
107
103
|
// To control the `Select` component, both `onChange` and `value`
|
|
108
104
|
// must be passed.
|
|
109
105
|
const controlledProps = onChange ? { onChange, value } : {};
|
|
110
106
|
|
|
107
|
+
// The number of pixels between the label and select elements
|
|
108
|
+
// when the labelPosition is inline (equivalent to --nypl-space-xs).
|
|
109
|
+
const labelSelectGap = 8;
|
|
110
|
+
|
|
111
111
|
if (!showLabel) {
|
|
112
112
|
ariaAttributes["aria-label"] =
|
|
113
113
|
labelText && footnote ? `${labelText} - ${footnote}` : labelText;
|
|
@@ -122,21 +122,19 @@ export const Select = chakra(
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
useEffect(() => {
|
|
125
|
-
if (labelPosition ===
|
|
125
|
+
if (labelPosition === "inline") {
|
|
126
126
|
if (labelRef.current) {
|
|
127
|
-
const width = labelRef.current.clientWidth +
|
|
127
|
+
const width = labelRef.current.clientWidth + labelSelectGap;
|
|
128
128
|
setLabelWidth(width);
|
|
129
129
|
}
|
|
130
|
+
} else {
|
|
131
|
+
setLabelWidth(0);
|
|
130
132
|
}
|
|
131
133
|
}, [labelPosition]);
|
|
132
134
|
|
|
133
135
|
return (
|
|
134
|
-
<Box
|
|
135
|
-
|
|
136
|
-
__css={{ ...styles, ...additionalStyles }}
|
|
137
|
-
{...rest}
|
|
138
|
-
>
|
|
139
|
-
<Box __css={labelPosition === LabelPositions.Inline && styles.inline}>
|
|
136
|
+
<Box className={className} __css={styles} {...rest}>
|
|
137
|
+
<Box __css={labelPosition === "inline" && styles.inline}>
|
|
140
138
|
{showLabel && (
|
|
141
139
|
<Box ref={labelRef}>
|
|
142
140
|
<Label
|
|
@@ -160,25 +158,20 @@ export const Select = chakra(
|
|
|
160
158
|
ref={ref}
|
|
161
159
|
{...controlledProps}
|
|
162
160
|
{...ariaAttributes}
|
|
163
|
-
icon={
|
|
164
|
-
<Icon
|
|
165
|
-
id={`${id}-icon`}
|
|
166
|
-
name={IconNames.Arrow}
|
|
167
|
-
size={IconSizes.Medium}
|
|
168
|
-
/>
|
|
169
|
-
}
|
|
161
|
+
icon={<Icon id={`${id}-icon`} name="arrow" size="medium" />}
|
|
170
162
|
__css={styles.select}
|
|
171
163
|
>
|
|
172
164
|
{children}
|
|
173
165
|
</ChakraSelect>
|
|
174
|
-
{footnote && showHelperInvalidText && (
|
|
175
|
-
<HelperErrorText
|
|
176
|
-
id={`${id}-helperText`}
|
|
177
|
-
isInvalid={isInvalid}
|
|
178
|
-
text={footnote}
|
|
179
|
-
/>
|
|
180
|
-
)}
|
|
181
166
|
</Box>
|
|
167
|
+
{footnote && showHelperInvalidText && (
|
|
168
|
+
<HelperErrorText
|
|
169
|
+
id={`${id}-helperText`}
|
|
170
|
+
isInvalid={isInvalid}
|
|
171
|
+
text={footnote}
|
|
172
|
+
ml={{ sm: "auto", md: `${labelWidth}px` }}
|
|
173
|
+
/>
|
|
174
|
+
)}
|
|
182
175
|
</Box>
|
|
183
176
|
);
|
|
184
177
|
}
|
|
@@ -280,19 +280,19 @@ exports[`Select Renders the UI snapshot correctly 3`] = `
|
|
|
280
280
|
</svg>
|
|
281
281
|
</div>
|
|
282
282
|
</div>
|
|
283
|
-
<div
|
|
284
|
-
aria-atomic={true}
|
|
285
|
-
aria-live="polite"
|
|
286
|
-
className="css-1xdhyk6"
|
|
287
|
-
dangerouslySetInnerHTML={
|
|
288
|
-
Object {
|
|
289
|
-
"__html": "Tom doesn't count as a sibling :(.",
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
data-isinvalid={true}
|
|
293
|
-
id="select-helperText"
|
|
294
|
-
/>
|
|
295
283
|
</div>
|
|
284
|
+
<div
|
|
285
|
+
aria-atomic={true}
|
|
286
|
+
aria-live="polite"
|
|
287
|
+
className="css-1mpebub"
|
|
288
|
+
dangerouslySetInnerHTML={
|
|
289
|
+
Object {
|
|
290
|
+
"__html": "Tom doesn't count as a sibling :(.",
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
data-isinvalid={true}
|
|
294
|
+
id="select-helperText"
|
|
295
|
+
/>
|
|
296
296
|
</div>
|
|
297
297
|
`;
|
|
298
298
|
|
|
@@ -387,19 +387,19 @@ exports[`Select Renders the UI snapshot correctly 4`] = `
|
|
|
387
387
|
</svg>
|
|
388
388
|
</div>
|
|
389
389
|
</div>
|
|
390
|
-
<div
|
|
391
|
-
aria-atomic={true}
|
|
392
|
-
aria-live="off"
|
|
393
|
-
className="css-1xdhyk6"
|
|
394
|
-
dangerouslySetInnerHTML={
|
|
395
|
-
Object {
|
|
396
|
-
"__html": "Remember, Logan will judge you no matter who you pick.",
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
data-isinvalid={false}
|
|
400
|
-
id="select-helperText"
|
|
401
|
-
/>
|
|
402
390
|
</div>
|
|
391
|
+
<div
|
|
392
|
+
aria-atomic={true}
|
|
393
|
+
aria-live="off"
|
|
394
|
+
className="css-1mpebub"
|
|
395
|
+
dangerouslySetInnerHTML={
|
|
396
|
+
Object {
|
|
397
|
+
"__html": "Remember, Logan will judge you no matter who you pick.",
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
data-isinvalid={false}
|
|
401
|
+
id="select-helperText"
|
|
402
|
+
/>
|
|
403
403
|
</div>
|
|
404
404
|
`;
|
|
405
405
|
|
|
@@ -10,19 +10,7 @@ import { withDesign } from "storybook-addon-designs";
|
|
|
10
10
|
|
|
11
11
|
import SimpleGrid from "../Grid/SimpleGrid";
|
|
12
12
|
import SkeletonLoader from "./SkeletonLoader";
|
|
13
|
-
import { SkeletonLoaderImageRatios } from "./SkeletonLoaderTypes";
|
|
14
|
-
import { LayoutTypes } from "../../helpers/enums";
|
|
15
13
|
import { getCategory } from "../../utils/componentCategories";
|
|
16
|
-
import { getStorybookEnumValues } from "../../utils/utils";
|
|
17
|
-
|
|
18
|
-
export const imageRatiosEnumValues = getStorybookEnumValues(
|
|
19
|
-
SkeletonLoaderImageRatios,
|
|
20
|
-
"SkeletonLoaderImageRatios"
|
|
21
|
-
);
|
|
22
|
-
export const layoutsEnumValues = getStorybookEnumValues(
|
|
23
|
-
LayoutTypes,
|
|
24
|
-
"LayoutTypes"
|
|
25
|
-
);
|
|
26
14
|
|
|
27
15
|
<Meta
|
|
28
16
|
title={getCategory("SkeletonLoader")}
|
|
@@ -40,16 +28,13 @@ export const layoutsEnumValues = getStorybookEnumValues(
|
|
|
40
28
|
contentSize: { table: { defaultValue: { summary: "3" } } },
|
|
41
29
|
headingSize: { table: { defaultValue: { summary: "1" } } },
|
|
42
30
|
imageAspectRatio: {
|
|
43
|
-
control: { type: "select" },
|
|
44
31
|
table: {
|
|
45
|
-
defaultValue: { summary: "
|
|
32
|
+
defaultValue: { summary: "square" },
|
|
46
33
|
},
|
|
47
|
-
options: imageRatiosEnumValues.options,
|
|
48
34
|
},
|
|
49
35
|
isBordered: { table: { defaultValue: { summary: "false" } } },
|
|
50
36
|
layout: {
|
|
51
|
-
table: { defaultValue: { summary: "
|
|
52
|
-
options: layoutsEnumValues.options,
|
|
37
|
+
table: { defaultValue: { summary: "column" } },
|
|
53
38
|
},
|
|
54
39
|
showButton: { table: { defaultValue: { summary: "false" } } },
|
|
55
40
|
showContent: { table: { defaultValue: { summary: "true" } } },
|
|
@@ -63,7 +48,7 @@ export const layoutsEnumValues = getStorybookEnumValues(
|
|
|
63
48
|
| Component Version | DS Version |
|
|
64
49
|
| ----------------- | ---------- |
|
|
65
50
|
| Added | `0.17.3` |
|
|
66
|
-
| Latest | `0.
|
|
51
|
+
| Latest | `0.28.0` |
|
|
67
52
|
|
|
68
53
|
## Table of Contents
|
|
69
54
|
|
|
@@ -92,9 +77,9 @@ to better view the example. The default value is `100%`.
|
|
|
92
77
|
className: undefined,
|
|
93
78
|
contentSize: 3,
|
|
94
79
|
headingSize: 1,
|
|
95
|
-
imageAspectRatio: "
|
|
80
|
+
imageAspectRatio: "square",
|
|
96
81
|
isBordered: false,
|
|
97
|
-
layout: "
|
|
82
|
+
layout: "column",
|
|
98
83
|
showButton: false,
|
|
99
84
|
showContent: true,
|
|
100
85
|
showHeading: true,
|
|
@@ -102,13 +87,7 @@ to better view the example. The default value is `100%`.
|
|
|
102
87
|
width: "300px",
|
|
103
88
|
}}
|
|
104
89
|
>
|
|
105
|
-
{(args) =>
|
|
106
|
-
<SkeletonLoader
|
|
107
|
-
{...args}
|
|
108
|
-
imageAspectRatio={imageRatiosEnumValues.getValue(args.imageAspectRatio)}
|
|
109
|
-
layout={layoutsEnumValues.getValue(args.layout)}
|
|
110
|
-
/>
|
|
111
|
-
)}
|
|
90
|
+
{(args) => <SkeletonLoader {...args} />}
|
|
112
91
|
</Story>
|
|
113
92
|
</Canvas>
|
|
114
93
|
|
|
@@ -138,30 +117,12 @@ Resources:
|
|
|
138
117
|
<Canvas>
|
|
139
118
|
<Story name="Placeholders in a Grid">
|
|
140
119
|
<SimpleGrid columns={3}>
|
|
141
|
-
<SkeletonLoader
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
/>
|
|
145
|
-
<SkeletonLoader
|
|
146
|
-
|
|
147
|
-
isBordered
|
|
148
|
-
/>
|
|
149
|
-
<SkeletonLoader
|
|
150
|
-
imageAspectRatio={SkeletonLoaderImageRatios.Landscape}
|
|
151
|
-
isBordered
|
|
152
|
-
/>
|
|
153
|
-
<SkeletonLoader
|
|
154
|
-
imageAspectRatio={SkeletonLoaderImageRatios.Landscape}
|
|
155
|
-
isBordered
|
|
156
|
-
/>
|
|
157
|
-
<SkeletonLoader
|
|
158
|
-
imageAspectRatio={SkeletonLoaderImageRatios.Landscape}
|
|
159
|
-
isBordered
|
|
160
|
-
/>
|
|
161
|
-
<SkeletonLoader
|
|
162
|
-
imageAspectRatio={SkeletonLoaderImageRatios.Landscape}
|
|
163
|
-
isBordered
|
|
164
|
-
/>
|
|
120
|
+
<SkeletonLoader imageAspectRatio="landscape" isBordered />
|
|
121
|
+
<SkeletonLoader imageAspectRatio="landscape" isBordered />
|
|
122
|
+
<SkeletonLoader imageAspectRatio="landscape" isBordered />
|
|
123
|
+
<SkeletonLoader imageAspectRatio="landscape" isBordered />
|
|
124
|
+
<SkeletonLoader imageAspectRatio="landscape" isBordered />
|
|
125
|
+
<SkeletonLoader imageAspectRatio="landscape" isBordered />
|
|
165
126
|
</SimpleGrid>
|
|
166
127
|
</Story>
|
|
167
128
|
</Canvas>
|
|
@@ -171,11 +132,11 @@ Resources:
|
|
|
171
132
|
<Canvas>
|
|
172
133
|
<Story name="Placeholders in a List">
|
|
173
134
|
<SimpleGrid columns={1}>
|
|
174
|
-
<SkeletonLoader layout=
|
|
175
|
-
<SkeletonLoader layout=
|
|
176
|
-
<SkeletonLoader layout=
|
|
177
|
-
<SkeletonLoader layout=
|
|
178
|
-
<SkeletonLoader layout=
|
|
135
|
+
<SkeletonLoader layout="row" showImage={false} />
|
|
136
|
+
<SkeletonLoader layout="row" showImage={false} />
|
|
137
|
+
<SkeletonLoader layout="row" showImage={false} />
|
|
138
|
+
<SkeletonLoader layout="row" showImage={false} />
|
|
139
|
+
<SkeletonLoader layout="row" showImage={false} />
|
|
179
140
|
</SimpleGrid>
|
|
180
141
|
</Story>
|
|
181
142
|
</Canvas>
|
|
@@ -4,8 +4,6 @@ import { axe } from "jest-axe";
|
|
|
4
4
|
import renderer from "react-test-renderer";
|
|
5
5
|
|
|
6
6
|
import SkeletonLoader from "./SkeletonLoader";
|
|
7
|
-
import { SkeletonLoaderImageRatios } from "./SkeletonLoaderTypes";
|
|
8
|
-
import { LayoutTypes } from "../../helpers/enums";
|
|
9
7
|
|
|
10
8
|
describe("SkeletonLoader Accessibility", () => {
|
|
11
9
|
it("passes axe accessibility test", async () => {
|
|
@@ -24,13 +22,11 @@ describe("SkeletonLoader", () => {
|
|
|
24
22
|
});
|
|
25
23
|
|
|
26
24
|
it("renders in the column or row layout", () => {
|
|
27
|
-
const { container, rerender } = render(
|
|
28
|
-
<SkeletonLoader layout={LayoutTypes.Column} />
|
|
29
|
-
);
|
|
25
|
+
const { container, rerender } = render(<SkeletonLoader layout="column" />);
|
|
30
26
|
|
|
31
27
|
expect(container.querySelector(".column")).toBeInTheDocument();
|
|
32
28
|
|
|
33
|
-
rerender(<SkeletonLoader layout=
|
|
29
|
+
rerender(<SkeletonLoader layout="row" />);
|
|
34
30
|
expect(container.querySelector(".row")).toBeInTheDocument();
|
|
35
31
|
});
|
|
36
32
|
|
|
@@ -72,11 +68,9 @@ describe("SkeletonLoader", () => {
|
|
|
72
68
|
|
|
73
69
|
it("renders the UI snapshot correctly", () => {
|
|
74
70
|
const basic = renderer.create(<SkeletonLoader />).toJSON();
|
|
75
|
-
const rowLayout = renderer
|
|
76
|
-
.create(<SkeletonLoader layout={LayoutTypes.Row} />)
|
|
77
|
-
.toJSON();
|
|
71
|
+
const rowLayout = renderer.create(<SkeletonLoader layout="row" />).toJSON();
|
|
78
72
|
const columnLayout = renderer
|
|
79
|
-
.create(<SkeletonLoader layout=
|
|
73
|
+
.create(<SkeletonLoader layout="column" />)
|
|
80
74
|
.toJSON();
|
|
81
75
|
const noImage = renderer
|
|
82
76
|
.create(<SkeletonLoader showImage={false} />)
|
|
@@ -91,21 +85,13 @@ describe("SkeletonLoader", () => {
|
|
|
91
85
|
.create(<SkeletonLoader showButton={true} />)
|
|
92
86
|
.toJSON();
|
|
93
87
|
const landscape = renderer
|
|
94
|
-
.create(
|
|
95
|
-
<SkeletonLoader
|
|
96
|
-
imageAspectRatio={SkeletonLoaderImageRatios.Landscape}
|
|
97
|
-
/>
|
|
98
|
-
)
|
|
88
|
+
.create(<SkeletonLoader imageAspectRatio="landscape" />)
|
|
99
89
|
.toJSON();
|
|
100
90
|
const portrait = renderer
|
|
101
|
-
.create(
|
|
102
|
-
<SkeletonLoader imageAspectRatio={SkeletonLoaderImageRatios.Portrait} />
|
|
103
|
-
)
|
|
91
|
+
.create(<SkeletonLoader imageAspectRatio="portrait" />)
|
|
104
92
|
.toJSON();
|
|
105
93
|
const square = renderer
|
|
106
|
-
.create(
|
|
107
|
-
<SkeletonLoader imageAspectRatio={SkeletonLoaderImageRatios.Square} />
|
|
108
|
-
)
|
|
94
|
+
.create(<SkeletonLoader imageAspectRatio="square" />)
|
|
109
95
|
.toJSON();
|
|
110
96
|
const withChakraProps = renderer
|
|
111
97
|
.create(<SkeletonLoader p="20px" color="ui.error.primary" />)
|
|
@@ -6,8 +6,9 @@ import {
|
|
|
6
6
|
} from "@chakra-ui/react";
|
|
7
7
|
import * as React from "react";
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
|
|
9
|
+
import { LayoutTypes } from "../../helpers/types";
|
|
10
|
+
|
|
11
|
+
export type SkeletonLoaderImageRatios = "landscape" | "portrait" | "square";
|
|
11
12
|
|
|
12
13
|
export interface SkeletonLoaderProps {
|
|
13
14
|
/** Additional class name for the Skeleton component. */
|
|
@@ -19,12 +20,12 @@ export interface SkeletonLoaderProps {
|
|
|
19
20
|
* placeholder; default value is `1`. */
|
|
20
21
|
headingSize?: number;
|
|
21
22
|
/** Optional value to control the aspect ratio of the image placeholder;
|
|
22
|
-
* default value is `
|
|
23
|
+
* default value is `"square"`. */
|
|
23
24
|
imageAspectRatio?: SkeletonLoaderImageRatios;
|
|
24
25
|
/** Optional boolean value to control visibility of border around skeleton loader. */
|
|
25
26
|
isBordered?: boolean;
|
|
26
27
|
/** Optional value to control the position of the image placeholder;
|
|
27
|
-
* default value is `
|
|
28
|
+
* default value is `"column"`. */
|
|
28
29
|
layout?: LayoutTypes;
|
|
29
30
|
/** Optional boolean value to control visibility of button placeholder. */
|
|
30
31
|
showButton?: boolean;
|
|
@@ -50,9 +51,9 @@ export const SkeletonLoader = chakra(
|
|
|
50
51
|
className,
|
|
51
52
|
contentSize = 3,
|
|
52
53
|
headingSize = 1,
|
|
53
|
-
imageAspectRatio =
|
|
54
|
+
imageAspectRatio = "square",
|
|
54
55
|
isBordered = false,
|
|
55
|
-
layout =
|
|
56
|
+
layout = "column",
|
|
56
57
|
showButton = false,
|
|
57
58
|
showContent = true,
|
|
58
59
|
showHeading = true,
|
|
@@ -72,11 +73,11 @@ export const SkeletonLoader = chakra(
|
|
|
72
73
|
* "heading" and "content" areas defined by the `type` argument. The last
|
|
73
74
|
* element will have width of `lastWidth`.
|
|
74
75
|
*/
|
|
75
|
-
const getSkeletonElements = (type, size = 1, lastWidth = "80%") => {
|
|
76
|
+
const getSkeletonElements = (type: string, size = 1, lastWidth = "80%") => {
|
|
76
77
|
return new Array(size).fill(null).map((_, i) => {
|
|
77
78
|
const width = i === size - 1 ? lastWidth : "100%";
|
|
78
79
|
const marginBottomValue =
|
|
79
|
-
i === size - 1 && type === "content" ? "0" :
|
|
80
|
+
i === size - 1 && type === "content" ? "0" : undefined;
|
|
80
81
|
return (
|
|
81
82
|
<ChakraSkeleton key={`${type}-${i}`} width={width}>
|
|
82
83
|
<Box
|