@nypl/design-system-react-components 0.25.0 → 0.25.1
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 +30 -0
- package/dist/components/Accordion/Accordion.d.ts +14 -14
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +11 -14
- package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +6 -0
- package/dist/components/Button/ButtonTypes.d.ts +2 -1
- package/dist/components/Card/Card.d.ts +1 -1
- package/dist/components/Card/CardTypes.d.ts +2 -2
- package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +43 -0
- package/dist/components/CheckboxGroup/CheckboxGroupLayoutTypes.d.ts +4 -0
- package/dist/components/DatePicker/DatePicker.d.ts +3 -3
- package/dist/components/Form/Form.d.ts +13 -8
- package/dist/components/Form/FormTypes.d.ts +2 -8
- package/dist/components/Grid/GridTypes.d.ts +9 -0
- package/dist/components/Grid/SimpleGrid.d.ts +14 -0
- package/dist/components/Heading/Heading.d.ts +4 -4
- package/dist/components/Hero/Hero.d.ts +19 -14
- package/dist/components/Hero/HeroTypes.d.ts +10 -5
- package/dist/components/Icons/Icon.d.ts +13 -16
- package/dist/components/Icons/IconTypes.d.ts +78 -64
- package/dist/components/Label/Label.d.ts +5 -17
- package/dist/components/Link/Link.d.ts +8 -12
- package/dist/components/SearchBar/SearchBar.d.ts +45 -27
- package/dist/components/Select/Select.d.ts +32 -35
- package/dist/components/Select/SelectTypes.d.ts +4 -0
- package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +1 -1
- package/dist/components/SkeletonLoader/SkeletonLoaderTypes.d.ts +2 -2
- package/dist/components/StatusBadge/StatusBadge.d.ts +8 -6
- package/dist/components/StatusBadge/StatusBadgeTypes.d.ts +5 -0
- package/dist/components/Template/Template.d.ts +91 -0
- package/dist/components/Text/Text.d.ts +16 -0
- package/dist/components/Text/TextTypes.d.ts +6 -0
- package/dist/components/TextInput/TextInput.d.ts +32 -31
- package/dist/components/TextInput/TextInputTypes.d.ts +5 -0
- package/dist/design-system-react-components.cjs.development.js +2597 -1170
- 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 +2580 -1173
- package/dist/design-system-react-components.esm.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/styles.css +1 -1
- package/dist/theme/components/accordion.d.ts +25 -0
- package/dist/theme/components/breadcrumb.d.ts +90 -0
- package/dist/theme/components/button.d.ts +17 -7
- package/dist/theme/components/checkbox.d.ts +7 -7
- package/dist/theme/components/customCheckboxGroup.d.ts +18 -0
- package/dist/theme/components/customRadioGroup.d.ts +4 -3
- package/dist/theme/components/global.d.ts +55 -0
- package/dist/theme/components/globalMixins.d.ts +15 -0
- package/dist/theme/components/heading.d.ts +50 -20
- package/dist/theme/components/hero.d.ts +492 -0
- package/dist/theme/components/icon.d.ts +13 -0
- package/dist/theme/components/label.d.ts +16 -0
- package/dist/theme/components/link.d.ts +45 -0
- package/dist/theme/components/radio.d.ts +8 -7
- package/dist/theme/components/searchBar.d.ts +20 -0
- package/dist/theme/components/select.d.ts +58 -0
- package/dist/theme/components/statusBadge.d.ts +25 -0
- package/dist/theme/components/tabs.d.ts +9 -9
- package/dist/theme/components/template.d.ts +105 -0
- package/dist/theme/components/text.d.ts +20 -0
- package/dist/theme/components/textInput.d.ts +105 -0
- package/dist/theme/foundations/global.d.ts +3 -0
- package/dist/theme/foundations/shadows.d.ts +4 -0
- package/dist/utils/utils.d.ts +6 -0
- package/package.json +3 -2
- package/src/components/Accordion/Accordion.stories.mdx +227 -33
- package/src/components/Accordion/Accordion.test.tsx +135 -19
- package/src/components/Accordion/Accordion.tsx +81 -56
- package/src/components/Autosuggest/Autosuggest.stories.mdx +1 -1
- package/src/components/Autosuggest/Autosuggest.stories.tsx +1 -1
- package/src/components/Autosuggest/_Autosuggest.scss +2 -2
- package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +46 -52
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +31 -25
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +71 -73
- package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +6 -0
- package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +100 -0
- package/src/components/Button/Button.stories.mdx +31 -27
- package/src/components/Button/Button.test.tsx +17 -5
- package/src/components/Button/ButtonTypes.tsx +1 -0
- package/src/components/Button/_Button.scss +3 -27
- package/src/components/Button/__snapshots__/Button.test.tsx.snap +11 -0
- package/src/components/Card/Card.stories.mdx +24 -20
- package/src/components/Card/Card.test.tsx +13 -19
- package/src/components/Card/Card.tsx +1 -1
- package/src/components/Card/CardTypes.tsx +2 -2
- package/src/components/Card/_Card.scss +1 -1
- package/src/components/CardEdition/CardEdition.stories.tsx +11 -6
- package/src/components/CardEdition/CardEdition.test.tsx +23 -31
- package/src/components/CardEdition/_CardEdition.scss +2 -2
- package/src/components/Chakra/Center.stories.mdx +31 -14
- package/src/components/Chakra/Grid.stories.mdx +79 -0
- package/src/components/Chakra/Stack.stories.mdx +4 -4
- package/src/components/Checkbox/Checkbox.tsx +9 -12
- package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +2 -5
- package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +249 -0
- package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +345 -0
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +148 -0
- package/src/components/CheckboxGroup/CheckboxGroupLayoutTypes.tsx +4 -0
- package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +1360 -0
- package/src/components/DatePicker/DatePicker.test.tsx +4 -4
- package/src/components/DatePicker/DatePicker.tsx +13 -13
- package/src/components/DatePicker/_DatePicker.scss +1 -0
- package/src/components/Form/Form.stories.mdx +46 -21
- package/src/components/Form/Form.test.tsx +58 -45
- package/src/components/Form/Form.tsx +49 -21
- package/src/components/Form/FormTypes.tsx +3 -8
- package/src/components/Form/__snapshots__/Form.test.tsx.snap +24 -14
- package/src/components/Grid/GridTypes.tsx +9 -0
- package/src/components/Grid/SimpleGrid.stories.mdx +275 -0
- package/src/components/Grid/SimpleGrid.test.tsx +66 -0
- package/src/components/Grid/SimpleGrid.tsx +37 -0
- package/src/components/Grid/__snapshots__/SimpleGrid.test.tsx.snap +8 -0
- package/src/components/Heading/Heading.stories.mdx +1 -0
- package/src/components/Heading/Heading.tsx +12 -6
- package/src/components/HelperErrorText/_HelperErrorText.scss +1 -1
- package/src/components/Hero/Hero.stories.mdx +188 -121
- package/src/components/Hero/Hero.test.tsx +537 -107
- package/src/components/Hero/Hero.tsx +79 -92
- package/src/components/Hero/HeroTypes.tsx +17 -5
- package/src/components/Hero/__snapshots__/Hero.test.tsx.snap +307 -0
- package/src/components/HorizontalRule/_HorizontalRule.scss +1 -1
- package/src/components/Icons/Icon.stories.mdx +83 -74
- package/src/components/Icons/Icon.test.tsx +30 -22
- package/src/components/Icons/Icon.tsx +63 -61
- package/src/components/Icons/IconTypes.tsx +80 -64
- package/src/components/Input/_Input.scss +2 -2
- package/src/components/Label/Label.stories.mdx +28 -7
- package/src/components/Label/Label.test.tsx +43 -12
- package/src/components/Label/Label.tsx +21 -34
- package/src/components/Label/__snapshots__/Label.test.tsx.snap +41 -0
- package/src/components/Link/Link.stories.mdx +41 -41
- package/src/components/Link/Link.test.tsx +33 -44
- package/src/components/Link/Link.tsx +114 -100
- package/src/components/List/List.stories.mdx +0 -2
- package/src/components/List/List.stories.tsx +5 -5
- package/src/components/List/_List.scss +3 -3
- package/src/components/Modal/_Modal.scss +1 -1
- package/src/components/Notification/Notification.stories.mdx +12 -1
- package/src/components/Notification/Notification.test.tsx +3 -16
- package/src/components/Notification/Notification.tsx +9 -10
- package/src/components/Notification/_Notification.scss +4 -4
- package/src/components/Pagination/Pagination.test.tsx +16 -10
- package/src/components/RadioGroup/RadioGroup.stories.mdx +1 -1
- package/src/components/RadioGroup/RadioGroup.tsx +2 -10
- package/src/components/SearchBar/SearchBar.Test.tsx +151 -16
- package/src/components/SearchBar/SearchBar.stories.mdx +189 -219
- package/src/components/SearchBar/SearchBar.tsx +151 -46
- package/src/components/Select/Select.stories.mdx +188 -170
- package/src/components/Select/Select.test.tsx +125 -380
- package/src/components/Select/Select.tsx +118 -165
- package/src/components/Select/SelectTypes.tsx +4 -0
- package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +13 -25
- package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +7 -7
- package/src/components/SkeletonLoader/SkeletonLoader.tsx +4 -2
- package/src/components/SkeletonLoader/SkeletonLoaderTypes.tsx +2 -2
- package/src/components/SkeletonLoader/_SkeletonLoader.scss +3 -3
- package/src/components/StatusBadge/StatusBadge.stories.mdx +91 -0
- package/src/components/StatusBadge/StatusBadge.test.tsx +35 -7
- package/src/components/StatusBadge/StatusBadge.tsx +24 -25
- package/src/components/StatusBadge/StatusBadgeTypes.tsx +5 -0
- package/src/components/StatusBadge/__snapshots__/StatusBadge.test.tsx.snap +28 -0
- package/src/components/StyleGuide/Bidirectionality.stories.mdx +16 -16
- package/src/components/StyleGuide/Buttons.stories.mdx +15 -15
- package/src/components/StyleGuide/Colors.stories.mdx +336 -0
- package/src/components/StyleGuide/Iconography.stories.mdx +88 -90
- package/src/components/StyleGuide/UIDocCard.tsx +1 -1
- package/src/components/Tabs/Tabs.tsx +7 -9
- package/src/components/Template/Template.stories.mdx +574 -0
- package/src/components/Template/Template.test.tsx +124 -0
- package/src/components/Template/Template.tsx +226 -0
- package/src/components/Text/Text.stories.mdx +70 -0
- package/src/components/Text/Text.test.tsx +63 -0
- package/src/components/Text/Text.tsx +55 -0
- package/src/components/Text/TextTypes.tsx +6 -0
- package/src/components/Text/__snapshots__/Text.test.tsx.snap +33 -0
- package/src/components/TextInput/TextInput.stories.mdx +89 -90
- package/src/components/TextInput/TextInput.test.tsx +65 -86
- package/src/components/TextInput/TextInput.tsx +101 -95
- package/src/components/TextInput/TextInputTypes.tsx +6 -0
- package/src/components/VideoPlayer/_VideoPlayer.scss +1 -1
- package/src/docs/Chakra.stories.mdx +4 -4
- package/src/docs/Intro.stories.mdx +15 -13
- package/src/index.ts +20 -0
- package/src/styles/01-colors/_colors-brand.scss +6 -0
- package/src/styles/01-colors/_colors-utility.scss +14 -12
- package/src/styles/base/_04-base.scss +2 -1
- package/src/styles/base/_place-holder.scss +1 -1
- package/src/styles.scss +10 -12
- package/src/theme/components/accordion.ts +30 -0
- package/src/theme/components/breadcrumb.ts +77 -0
- package/src/theme/components/button.ts +77 -63
- package/src/theme/components/checkbox.ts +15 -27
- package/src/theme/components/customCheckboxGroup.ts +12 -0
- package/src/theme/components/customRadioGroup.ts +4 -10
- package/src/theme/components/global.ts +71 -0
- package/src/theme/components/globalMixins.ts +16 -0
- package/src/theme/components/heading.ts +15 -8
- package/src/theme/components/hero.ts +239 -0
- package/src/theme/components/icon.ts +79 -0
- package/src/theme/components/label.ts +17 -0
- package/src/theme/components/link.ts +47 -0
- package/src/theme/components/radio.ts +20 -31
- package/src/theme/components/searchBar.ts +21 -0
- package/src/theme/components/select.ts +50 -0
- package/src/theme/components/statusBadge.ts +27 -0
- package/src/theme/components/tabs.ts +72 -69
- package/src/theme/components/template.ts +114 -0
- package/src/theme/components/text.ts +31 -0
- package/src/theme/components/textInput.ts +61 -0
- package/src/theme/foundations/colors.ts +29 -13
- package/src/theme/foundations/global.ts +3 -0
- package/src/theme/foundations/shadows.ts +5 -0
- package/src/theme/index.ts +37 -7
- package/src/utils/componentCategories.ts +8 -2
- package/src/utils/utils.ts +13 -0
- package/dist/components/Accordion/Accordion.stories.d.ts +0 -6
- package/dist/components/StatusBadge/StatusBadge.stories.d.ts +0 -8
- package/dist/components/StyleGuide/Colors.stories.d.ts +0 -25
- package/dist/components/Template/Template.stories.d.ts +0 -30
- package/src/components/Accordion/Accordion.stories.tsx +0 -66
- package/src/components/Accordion/_Accordion.scss +0 -81
- package/src/components/Breadcrumbs/_Breadcrumbs.scss +0 -97
- package/src/components/Form/_Form.scss +0 -67
- package/src/components/Hero/_Hero.scss +0 -256
- package/src/components/Icons/_Icons.scss +0 -116
- package/src/components/Label/_Label.scss +0 -22
- package/src/components/Link/_Link.scss +0 -73
- package/src/components/SearchBar/_SearchBar.scss +0 -16
- package/src/components/Select/_Select.scss +0 -82
- package/src/components/StatusBadge/StatusBadge.stories.tsx +0 -34
- package/src/components/StatusBadge/_StatusBadge.scss +0 -23
- package/src/components/StyleGuide/Colors.stories.tsx +0 -289
- package/src/components/Template/Template.stories.tsx +0 -86
- package/src/components/Template/_Template.scss +0 -63
- package/src/components/TextInput/_TextInput.scss +0 -59
|
@@ -1,192 +1,145 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
Box,
|
|
4
|
+
Select as ChakraSelect,
|
|
5
|
+
useMultiStyleConfig,
|
|
6
|
+
} from "@chakra-ui/react";
|
|
7
|
+
|
|
3
8
|
import Label from "../Label/Label";
|
|
4
9
|
import HelperErrorText from "../HelperErrorText/HelperErrorText";
|
|
5
10
|
import generateUUID from "../../helpers/generateUUID";
|
|
11
|
+
import { IconNames, IconSizes } from "../Icons/IconTypes";
|
|
12
|
+
import Icon from "../Icons/Icon";
|
|
13
|
+
import { SelectTypes } from "./SelectTypes";
|
|
6
14
|
|
|
7
15
|
export interface SelectProps {
|
|
8
|
-
/**
|
|
9
|
-
ariaLabel?: string;
|
|
10
|
-
/** Additional attributes passed to the <select> tag */
|
|
11
|
-
attributes?: { [key: string]: any };
|
|
12
|
-
/** BlockName for use with BEM. See how to work with modifiers and BEM here: http://getbem.com/introduction/ */
|
|
13
|
-
blockName?: string;
|
|
14
|
-
/** ClassName you can add in addition to 'select' */
|
|
16
|
+
/** A class name for the `div` parent element. */
|
|
15
17
|
className?: string;
|
|
16
|
-
|
|
17
|
-
/** When true, disables the select */
|
|
18
|
-
disabled?: boolean;
|
|
19
|
-
/** Helper for modifiers array; adds 'errored' styling */
|
|
20
|
-
errored?: boolean;
|
|
21
|
-
/** Populates the HelperErrorText for error state */
|
|
22
|
-
invalidText?: string;
|
|
23
|
-
/** DEPRECATED - ID of associated HelperText */
|
|
24
|
-
helperTextId?: string;
|
|
25
|
-
/** Populates the HelperErrorText for standard state */
|
|
18
|
+
/** Optional string to populate the `HelperErrorText` for the standard state. */
|
|
26
19
|
helperText?: string;
|
|
27
20
|
/** ID that other components can cross reference for accessibility purposes */
|
|
28
21
|
id?: string;
|
|
29
|
-
/**
|
|
22
|
+
/** Optional string to populate the `HelperErrorText` for the error state
|
|
23
|
+
* when `isInvalid` is true. */
|
|
24
|
+
invalidText?: string;
|
|
25
|
+
/** Adds the `disabled` and `aria-disabled` attributes to the select when true */
|
|
26
|
+
isDisabled?: boolean;
|
|
27
|
+
/** Adds the `aria-invalid` attribute to the select when true. This also makes
|
|
28
|
+
* the color theme "NYPL error" red for the select and text. */
|
|
29
|
+
isInvalid?: boolean;
|
|
30
|
+
/** Adds the `required` and `aria-required` attributes to the input when true. */
|
|
30
31
|
isRequired?: boolean;
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
/** Provides text for a `Label` component if `showLabel` is set to `true`;
|
|
33
|
+
* populates an `aria-label` attribute on the select input if `showLabel` is
|
|
34
|
+
* set to `false`. */
|
|
34
35
|
labelText: string;
|
|
35
|
-
/**
|
|
36
|
-
modifiers?: string[];
|
|
37
|
-
/** The name of the select element to use in form submission */
|
|
36
|
+
/** Used to reference the select element in forms. */
|
|
38
37
|
name: string;
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
/** Passes selects' current value to the React state handler */
|
|
38
|
+
/** The callback function to get the selected value.
|
|
39
|
+
* Should be passed along with `value` for controlled components. */
|
|
42
40
|
onChange?: (event: React.FormEvent) => void;
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
-
/** The value of the selected option */
|
|
46
|
-
selectedOption?: string;
|
|
47
|
-
/** Offers the ability to show the label onscreen or hide it. Refer to the `labelText` property for more information. */
|
|
41
|
+
/** Offers the ability to show the select's label onscreen or hide it. Refer
|
|
42
|
+
* to the `labelText` property for more information. */
|
|
48
43
|
showLabel?: boolean;
|
|
49
44
|
/** Whether or not to display the "Required"/"Optional" text in the label text. */
|
|
50
45
|
showOptReqLabel?: boolean;
|
|
46
|
+
/** The variant to display. */
|
|
47
|
+
type?: SelectTypes;
|
|
48
|
+
/** The value of the selected option.
|
|
49
|
+
* Should be passed along with `onChange` for controlled components. */
|
|
50
|
+
value?: string;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const footnote = errored ? errorOutput : helperText;
|
|
97
|
-
|
|
98
|
-
// Support for deprecated prop
|
|
99
|
-
if (ariaLabel) attributes["aria-label"] = ariaLabel;
|
|
100
|
-
|
|
101
|
-
// Support for deprecated props
|
|
102
|
-
if (labelId && !helperTextId) {
|
|
103
|
-
ariaLabelledBy = labelId;
|
|
104
|
-
} else if (helperTextId && !labelId) {
|
|
105
|
-
ariaLabelledBy = helperTextId;
|
|
106
|
-
} else if (labelId && helperTextId) {
|
|
107
|
-
ariaLabelledBy = labelId + " " + helperTextId;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (React.Children.count(children) > 10) {
|
|
111
|
-
console.warn(
|
|
112
|
-
"NYPL DS recommends that <select> fields have no more than 10 options; an auto-complete text input is a good alternative for 11 or more options."
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (React.Children.count(children) < 4) {
|
|
117
|
-
console.warn(
|
|
118
|
-
"NYPL DS recommends that <select> fields have at least 4 options; a radio button group is a good alternative for 3 or fewer options."
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (ariaLabel) {
|
|
123
|
-
console.warn(
|
|
124
|
-
"The ariaLabel prop has been deprecated in the Select component and will be removed in a future release. Check the documentation for updated props."
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (helperTextId) {
|
|
129
|
-
console.warn(
|
|
130
|
-
"The helperTextId prop has been deprecated in the Select component and will be removed in a future release. Check the documentation for updated props."
|
|
131
|
-
);
|
|
132
|
-
}
|
|
53
|
+
/**
|
|
54
|
+
* Component that renders Chakra's `Select` component along with an accessible
|
|
55
|
+
* `Label` and optional `HelperErrorText` component.
|
|
56
|
+
*/
|
|
57
|
+
const Select = React.forwardRef<
|
|
58
|
+
HTMLSelectElement,
|
|
59
|
+
React.PropsWithChildren<SelectProps>
|
|
60
|
+
>((props: React.PropsWithChildren<SelectProps>, ref?) => {
|
|
61
|
+
const {
|
|
62
|
+
children,
|
|
63
|
+
className,
|
|
64
|
+
helperText,
|
|
65
|
+
id = generateUUID(),
|
|
66
|
+
invalidText,
|
|
67
|
+
isDisabled = false,
|
|
68
|
+
isInvalid = false,
|
|
69
|
+
isRequired = false,
|
|
70
|
+
labelText,
|
|
71
|
+
name,
|
|
72
|
+
onChange,
|
|
73
|
+
showLabel = true,
|
|
74
|
+
showOptReqLabel = true,
|
|
75
|
+
type = SelectTypes.Default,
|
|
76
|
+
value,
|
|
77
|
+
} = props;
|
|
78
|
+
const ariaAttributes = {};
|
|
79
|
+
const optReqFlag = isRequired ? "Required" : "Optional";
|
|
80
|
+
const styles = useMultiStyleConfig("CustomSelect", { variant: type });
|
|
81
|
+
const finalInvalidText = invalidText
|
|
82
|
+
? invalidText
|
|
83
|
+
: "There is an error related to this field.";
|
|
84
|
+
const footnote = isInvalid ? finalInvalidText : helperText;
|
|
85
|
+
// To control the `Select` component, both `onChange` and `value`
|
|
86
|
+
// must be passed.
|
|
87
|
+
const controlledProps = onChange && value ? { onChange, value } : {};
|
|
88
|
+
|
|
89
|
+
if (!showLabel) {
|
|
90
|
+
ariaAttributes["aria-label"] =
|
|
91
|
+
labelText && footnote ? `${labelText} - ${footnote}` : labelText;
|
|
92
|
+
} else if (helperText) {
|
|
93
|
+
ariaAttributes["aria-describedby"] = `${id}-helperText`;
|
|
94
|
+
}
|
|
133
95
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
96
|
+
if (React.Children.count(children) > 10) {
|
|
97
|
+
console.warn(
|
|
98
|
+
"NYPL DS recommends that <select> fields have no more than 10 options; an auto-complete text input is a good alternative for 11 or more options."
|
|
99
|
+
);
|
|
100
|
+
}
|
|
139
101
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
102
|
+
if (React.Children.count(children) < 4) {
|
|
103
|
+
console.warn(
|
|
104
|
+
"NYPL DS recommends that <select> fields have at least 4 options; a radio button group is a good alternative for 3 or fewer options."
|
|
105
|
+
);
|
|
106
|
+
}
|
|
145
107
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
>
|
|
154
|
-
{labelText}
|
|
155
|
-
</Label>
|
|
156
|
-
)}
|
|
157
|
-
<select
|
|
158
|
-
name={name}
|
|
159
|
-
id={id}
|
|
160
|
-
className={bem("selectfield", modifiers, blockName, [className])}
|
|
161
|
-
aria-required={req}
|
|
162
|
-
required={req}
|
|
163
|
-
disabled={disabled}
|
|
164
|
-
aria-label={ariaLabel}
|
|
165
|
-
aria-labelledby={ariaLabelledBy}
|
|
166
|
-
value={selectedOption}
|
|
167
|
-
ref={ref}
|
|
168
|
-
onBlur={onBlur}
|
|
169
|
-
onChange={onChange}
|
|
170
|
-
{...attributes}
|
|
108
|
+
return (
|
|
109
|
+
<Box className={className} __css={styles}>
|
|
110
|
+
{showLabel && (
|
|
111
|
+
<Label
|
|
112
|
+
id={`${id}-label`}
|
|
113
|
+
htmlFor={id}
|
|
114
|
+
optReqFlag={showOptReqLabel && optReqFlag}
|
|
171
115
|
>
|
|
172
|
-
{
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
{
|
|
181
|
-
|
|
116
|
+
{labelText}
|
|
117
|
+
</Label>
|
|
118
|
+
)}
|
|
119
|
+
<ChakraSelect
|
|
120
|
+
id={id}
|
|
121
|
+
variant="outline"
|
|
122
|
+
isRequired={isRequired}
|
|
123
|
+
isDisabled={isDisabled}
|
|
124
|
+
isInvalid={isInvalid}
|
|
125
|
+
name={name}
|
|
126
|
+
ref={ref}
|
|
127
|
+
{...controlledProps}
|
|
128
|
+
{...ariaAttributes}
|
|
129
|
+
icon={<Icon name={IconNames.Arrow} size={IconSizes.Medium} />}
|
|
130
|
+
__css={styles.select}
|
|
131
|
+
>
|
|
132
|
+
{children}
|
|
133
|
+
</ChakraSelect>
|
|
134
|
+
{footnote && (
|
|
135
|
+
<Box __css={styles.helper} aria-disabled={isDisabled}>
|
|
136
|
+
<HelperErrorText isError={isInvalid} id={id + `-helperText`}>
|
|
182
137
|
{footnote}
|
|
183
138
|
</HelperErrorText>
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
);
|
|
189
|
-
|
|
190
|
-
Select.displayName = "Select";
|
|
139
|
+
</Box>
|
|
140
|
+
)}
|
|
141
|
+
</Box>
|
|
142
|
+
);
|
|
143
|
+
});
|
|
191
144
|
|
|
192
145
|
export default Select;
|
|
@@ -33,7 +33,7 @@ import { getCategory } from "../../utils/componentCategories";
|
|
|
33
33
|
className: { table: { disable: true } },
|
|
34
34
|
modifiers: { table: { disable: true } },
|
|
35
35
|
layout: {
|
|
36
|
-
table: { defaultValue: { summary: "
|
|
36
|
+
table: { defaultValue: { summary: "column" } },
|
|
37
37
|
},
|
|
38
38
|
showImage: {
|
|
39
39
|
table: { defaultValue: { summary: "true" } },
|
|
@@ -68,9 +68,12 @@ import { getCategory } from "../../utils/componentCategories";
|
|
|
68
68
|
|
|
69
69
|
<Description of={SkeletonLoader} />
|
|
70
70
|
|
|
71
|
-
The `SkeletonLoader` component renders a placeholder to be used while dynamic
|
|
71
|
+
The `SkeletonLoader` component renders a placeholder to be used while dynamic
|
|
72
|
+
content is loading. The `layout`, `width` and placeholder elements within the
|
|
73
|
+
`SkeletonLoader` can be customized.
|
|
72
74
|
|
|
73
|
-
Please note that the initial rendering below has the `width` prop set to `300px`.
|
|
75
|
+
Please note that the initial rendering below has the `width` prop set to `300px`.
|
|
76
|
+
The default value is `100%`.
|
|
74
77
|
|
|
75
78
|
<Preview withToolbar>
|
|
76
79
|
<Story
|
|
@@ -93,7 +96,7 @@ Please note that the initial rendering below has the `width` prop set to `300px`
|
|
|
93
96
|
style={{
|
|
94
97
|
display: "grid",
|
|
95
98
|
gap: "2rem",
|
|
96
|
-
|
|
99
|
+
gridTemplateColumns: "repeat(3, 1fr)",
|
|
97
100
|
}}
|
|
98
101
|
>
|
|
99
102
|
<SkeletonLoader
|
|
@@ -132,29 +135,14 @@ Please note that the initial rendering below has the `width` prop set to `300px`
|
|
|
132
135
|
style={{
|
|
133
136
|
display: "grid",
|
|
134
137
|
gap: "2rem",
|
|
135
|
-
|
|
138
|
+
gridTemplateColumns: "repeat(1, 1fr)",
|
|
136
139
|
}}
|
|
137
140
|
>
|
|
138
|
-
<SkeletonLoader
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
/>
|
|
142
|
-
<SkeletonLoader
|
|
143
|
-
layout={SkeletonLoaderLayouts.Horizontal}
|
|
144
|
-
showImage={false}
|
|
145
|
-
/>
|
|
146
|
-
<SkeletonLoader
|
|
147
|
-
layout={SkeletonLoaderLayouts.Horizontal}
|
|
148
|
-
showImage={false}
|
|
149
|
-
/>
|
|
150
|
-
<SkeletonLoader
|
|
151
|
-
layout={SkeletonLoaderLayouts.Horizontal}
|
|
152
|
-
showImage={false}
|
|
153
|
-
/>
|
|
154
|
-
<SkeletonLoader
|
|
155
|
-
layout={SkeletonLoaderLayouts.Horizontal}
|
|
156
|
-
showImage={false}
|
|
157
|
-
/>
|
|
141
|
+
<SkeletonLoader layout={SkeletonLoaderLayouts.Row} showImage={false} />
|
|
142
|
+
<SkeletonLoader layout={SkeletonLoaderLayouts.Row} showImage={false} />
|
|
143
|
+
<SkeletonLoader layout={SkeletonLoaderLayouts.Row} showImage={false} />
|
|
144
|
+
<SkeletonLoader layout={SkeletonLoaderLayouts.Row} showImage={false} />
|
|
145
|
+
<SkeletonLoader layout={SkeletonLoaderLayouts.Row} showImage={false} />
|
|
158
146
|
</div>
|
|
159
147
|
</Story>
|
|
160
148
|
</Preview>
|
|
@@ -26,7 +26,7 @@ describe("SkeletonLoader", () => {
|
|
|
26
26
|
expect(container.querySelector(".skeleton-loader")).toBeInTheDocument();
|
|
27
27
|
expect(container.querySelector(".skeleton-loader")).toHaveAttribute(
|
|
28
28
|
"class",
|
|
29
|
-
"skeleton-loader skeleton-loader--
|
|
29
|
+
"skeleton-loader skeleton-loader--column "
|
|
30
30
|
);
|
|
31
31
|
expect(container.querySelector(".skeleton-loader")).not.toHaveAttribute(
|
|
32
32
|
"class",
|
|
@@ -34,27 +34,27 @@ describe("SkeletonLoader", () => {
|
|
|
34
34
|
);
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
it("renders
|
|
37
|
+
it("renders column layout", () => {
|
|
38
38
|
const utils = render(
|
|
39
|
-
<SkeletonLoader layout={SkeletonLoaderLayouts.
|
|
39
|
+
<SkeletonLoader layout={SkeletonLoaderLayouts.Column} />
|
|
40
40
|
);
|
|
41
41
|
container = utils.container;
|
|
42
42
|
|
|
43
43
|
expect(container.querySelector(".skeleton-loader")).toBeInTheDocument();
|
|
44
44
|
expect(
|
|
45
|
-
container.querySelector(".skeleton-loader--
|
|
45
|
+
container.querySelector(".skeleton-loader--column")
|
|
46
46
|
).toBeInTheDocument();
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
it("renders
|
|
49
|
+
it("renders row layout", () => {
|
|
50
50
|
const utils = render(
|
|
51
|
-
<SkeletonLoader layout={SkeletonLoaderLayouts.
|
|
51
|
+
<SkeletonLoader layout={SkeletonLoaderLayouts.Row} />
|
|
52
52
|
);
|
|
53
53
|
container = utils.container;
|
|
54
54
|
|
|
55
55
|
expect(container.querySelector(".skeleton-loader")).toBeInTheDocument();
|
|
56
56
|
expect(
|
|
57
|
-
container.querySelector(".skeleton-loader--
|
|
57
|
+
container.querySelector(".skeleton-loader--row")
|
|
58
58
|
).toBeInTheDocument();
|
|
59
59
|
});
|
|
60
60
|
});
|
|
@@ -16,7 +16,7 @@ export interface SkeletonLoaderProps {
|
|
|
16
16
|
headingSize?: number;
|
|
17
17
|
/** Optional value to control the aspect ratio of the image placeholder; default value is `square` */
|
|
18
18
|
imageAspectRatio?: SkeletonLoaderImageRatios;
|
|
19
|
-
/** Optional value to control the position of the image placeholder; default value is `
|
|
19
|
+
/** Optional value to control the position of the image placeholder; default value is `column` */
|
|
20
20
|
layout?: SkeletonLoaderLayouts;
|
|
21
21
|
/** Modifiers array for use with BEM. See how to work with modifiers and BEM here: http://getbem.com/introduction/ */
|
|
22
22
|
modifiers?: string[];
|
|
@@ -41,7 +41,7 @@ export default function SkeletonLoader(
|
|
|
41
41
|
contentSize = 3,
|
|
42
42
|
headingSize = 1,
|
|
43
43
|
imageAspectRatio = SkeletonLoaderImageRatios.Square,
|
|
44
|
-
layout = SkeletonLoaderLayouts.
|
|
44
|
+
layout = SkeletonLoaderLayouts.Column,
|
|
45
45
|
showButton = false,
|
|
46
46
|
showContent = true,
|
|
47
47
|
showImage = true,
|
|
@@ -61,6 +61,7 @@ export default function SkeletonLoader(
|
|
|
61
61
|
for (let i = 0; i < headingSize; i++) {
|
|
62
62
|
headingItems.push(
|
|
63
63
|
<div
|
|
64
|
+
key={`heading-${i}`}
|
|
64
65
|
className={bem("skeleton-loader-heading", imageModifiers, "", [
|
|
65
66
|
"skeleton-element",
|
|
66
67
|
])}
|
|
@@ -72,6 +73,7 @@ export default function SkeletonLoader(
|
|
|
72
73
|
for (let i = 0; i < contentSize; i++) {
|
|
73
74
|
contentItems.push(
|
|
74
75
|
<div
|
|
76
|
+
key={`content-${i}`}
|
|
75
77
|
className={bem("skeleton-loader-content", imageModifiers, "", [
|
|
76
78
|
"skeleton-element",
|
|
77
79
|
])}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
@mixin skeleton-highlight {
|
|
2
2
|
animation: Pulsate 1000ms cubic-bezier(0.25, -0.5, 1, 0) infinite;
|
|
3
|
-
background: var(--ui-gray-warm
|
|
3
|
+
background: var(--ui-gray-light-warm);
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
.skeleton-loader {
|
|
@@ -79,11 +79,11 @@
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
&--border {
|
|
82
|
-
border: 1px solid var(--ui-gray-light);
|
|
82
|
+
border: 1px solid var(--ui-gray-light-cool);
|
|
83
83
|
padding: var(--space-s);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
&--
|
|
86
|
+
&--row {
|
|
87
87
|
@include breakpoint($breakpoint-medium) {
|
|
88
88
|
display: flex;
|
|
89
89
|
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Meta,
|
|
3
|
+
Story,
|
|
4
|
+
Canvas,
|
|
5
|
+
ArgsTable,
|
|
6
|
+
Description,
|
|
7
|
+
} from "@storybook/addon-docs/blocks";
|
|
8
|
+
import { withDesign } from "storybook-addon-designs";
|
|
9
|
+
import { VStack } from "@chakra-ui/react";
|
|
10
|
+
|
|
11
|
+
import StatusBadge from "./StatusBadge";
|
|
12
|
+
import { StatusBadgeTypes } from "./StatusBadgeTypes";
|
|
13
|
+
import getCSSVariable from "../../helpers/getCSSVariable";
|
|
14
|
+
import { getCategory } from "../../utils/componentCategories";
|
|
15
|
+
import DSProvider from "../../theme/provider";
|
|
16
|
+
|
|
17
|
+
<Meta
|
|
18
|
+
title={getCategory("StatusBadge")}
|
|
19
|
+
component={StatusBadge}
|
|
20
|
+
decorators={[withDesign]}
|
|
21
|
+
parameters={{
|
|
22
|
+
design: {
|
|
23
|
+
type: "figma",
|
|
24
|
+
url:
|
|
25
|
+
"https://www.figma.com/file/qShodlfNCJHb8n03IFyApM/Main?node-id=11256%3A0",
|
|
26
|
+
},
|
|
27
|
+
jest: ["StatusBadge.test.tsx"],
|
|
28
|
+
}}
|
|
29
|
+
argTypes={{
|
|
30
|
+
className: { table: { disable: true } },
|
|
31
|
+
id: { table: { disable: true } },
|
|
32
|
+
level: {
|
|
33
|
+
control: {
|
|
34
|
+
type: "select",
|
|
35
|
+
},
|
|
36
|
+
options: Object.values(StatusBadgeTypes).map((value) => value),
|
|
37
|
+
},
|
|
38
|
+
}}
|
|
39
|
+
/>
|
|
40
|
+
|
|
41
|
+
# StatusBadge
|
|
42
|
+
|
|
43
|
+
| Component Version | DS Version |
|
|
44
|
+
| ----------------- | ---------- |
|
|
45
|
+
| Added | `0.18.7` |
|
|
46
|
+
| Latest | `0.25.1` |
|
|
47
|
+
|
|
48
|
+
<Description of={StatusBadge} />
|
|
49
|
+
|
|
50
|
+
<Canvas withToolbar>
|
|
51
|
+
<Story
|
|
52
|
+
name="Basic with props"
|
|
53
|
+
args={{ level: StatusBadgeTypes.Low, text: "Registration Required" }}
|
|
54
|
+
>
|
|
55
|
+
{(args) => <StatusBadge {...args}>{args.text}</StatusBadge>}
|
|
56
|
+
</Story>
|
|
57
|
+
</Canvas>
|
|
58
|
+
|
|
59
|
+
<ArgsTable story="Basic with props" />
|
|
60
|
+
|
|
61
|
+
## Patterns
|
|
62
|
+
|
|
63
|
+
### Higher Barrier
|
|
64
|
+
|
|
65
|
+
Used in instances where the associated message is the highest barrier. Use
|
|
66
|
+
`"high"` and `"medium"` for these levels.
|
|
67
|
+
|
|
68
|
+
<Canvas>
|
|
69
|
+
<DSProvider>
|
|
70
|
+
<VStack spacing="s" align="stretch">
|
|
71
|
+
<StatusBadge level={StatusBadgeTypes.High}>
|
|
72
|
+
On-Site Access Only
|
|
73
|
+
</StatusBadge>
|
|
74
|
+
<StatusBadge level={StatusBadgeTypes.Medium}>Cancelled</StatusBadge>
|
|
75
|
+
</VStack>
|
|
76
|
+
</DSProvider>
|
|
77
|
+
</Canvas>
|
|
78
|
+
|
|
79
|
+
### Lower Barrier
|
|
80
|
+
|
|
81
|
+
Used in instances where the associated message is the lower barrier. Use
|
|
82
|
+
`"low"` for this level which is the default.
|
|
83
|
+
|
|
84
|
+
<Canvas>
|
|
85
|
+
<DSProvider>
|
|
86
|
+
<VStack spacing="s" align="stretch">
|
|
87
|
+
<StatusBadge>Library Card Required</StatusBadge>
|
|
88
|
+
<StatusBadge>Registration Required</StatusBadge>
|
|
89
|
+
</VStack>
|
|
90
|
+
</DSProvider>
|
|
91
|
+
</Canvas>
|
|
@@ -1,25 +1,53 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { render, screen } from "@testing-library/react";
|
|
3
3
|
import { axe } from "jest-axe";
|
|
4
|
+
import renderer from "react-test-renderer";
|
|
4
5
|
|
|
5
6
|
import StatusBadge from "./StatusBadge";
|
|
7
|
+
import { StatusBadgeTypes } from "./StatusBadgeTypes";
|
|
6
8
|
|
|
7
9
|
describe("StatusBadge Accessibility", () => {
|
|
8
10
|
it("passes axe accessibility test", async () => {
|
|
9
11
|
const { container } = render(
|
|
10
|
-
<StatusBadge
|
|
12
|
+
<StatusBadge>Registration Required</StatusBadge>
|
|
11
13
|
);
|
|
12
14
|
expect(await axe(container)).toHaveNoViolations();
|
|
13
15
|
});
|
|
14
16
|
});
|
|
15
17
|
|
|
16
|
-
describe("StatusBadge
|
|
17
|
-
it("
|
|
18
|
-
render(<StatusBadge
|
|
18
|
+
describe("StatusBadge", () => {
|
|
19
|
+
it("renders a status badge and text", () => {
|
|
20
|
+
render(<StatusBadge>Registration Required</StatusBadge>);
|
|
19
21
|
expect(screen.getByText("Registration Required")).toBeInTheDocument();
|
|
20
22
|
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
|
|
24
|
+
it("throws a warning when no children are passed", () => {
|
|
25
|
+
const warn = jest.spyOn(console, "warn");
|
|
26
|
+
render(<StatusBadge></StatusBadge>);
|
|
27
|
+
expect(warn).toHaveBeenCalledWith("Status Badge has no children.");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("renders the UI snapshot correctly", () => {
|
|
31
|
+
const low = renderer
|
|
32
|
+
.create(<StatusBadge id="low">Registration Required</StatusBadge>)
|
|
33
|
+
.toJSON();
|
|
34
|
+
const medium = renderer
|
|
35
|
+
.create(
|
|
36
|
+
<StatusBadge id="medium" level={StatusBadgeTypes.Medium}>
|
|
37
|
+
Registration Required
|
|
38
|
+
</StatusBadge>
|
|
39
|
+
)
|
|
40
|
+
.toJSON();
|
|
41
|
+
const high = renderer
|
|
42
|
+
.create(
|
|
43
|
+
<StatusBadge id="high" level={StatusBadgeTypes.High}>
|
|
44
|
+
Registration Required
|
|
45
|
+
</StatusBadge>
|
|
46
|
+
)
|
|
47
|
+
.toJSON();
|
|
48
|
+
|
|
49
|
+
expect(low).toMatchSnapshot();
|
|
50
|
+
expect(medium).toMatchSnapshot();
|
|
51
|
+
expect(high).toMatchSnapshot();
|
|
24
52
|
});
|
|
25
53
|
});
|