@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.
Files changed (236) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/components/Accordion/Accordion.d.ts +14 -14
  3. package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +11 -14
  4. package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +6 -0
  5. package/dist/components/Button/ButtonTypes.d.ts +2 -1
  6. package/dist/components/Card/Card.d.ts +1 -1
  7. package/dist/components/Card/CardTypes.d.ts +2 -2
  8. package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +43 -0
  9. package/dist/components/CheckboxGroup/CheckboxGroupLayoutTypes.d.ts +4 -0
  10. package/dist/components/DatePicker/DatePicker.d.ts +3 -3
  11. package/dist/components/Form/Form.d.ts +13 -8
  12. package/dist/components/Form/FormTypes.d.ts +2 -8
  13. package/dist/components/Grid/GridTypes.d.ts +9 -0
  14. package/dist/components/Grid/SimpleGrid.d.ts +14 -0
  15. package/dist/components/Heading/Heading.d.ts +4 -4
  16. package/dist/components/Hero/Hero.d.ts +19 -14
  17. package/dist/components/Hero/HeroTypes.d.ts +10 -5
  18. package/dist/components/Icons/Icon.d.ts +13 -16
  19. package/dist/components/Icons/IconTypes.d.ts +78 -64
  20. package/dist/components/Label/Label.d.ts +5 -17
  21. package/dist/components/Link/Link.d.ts +8 -12
  22. package/dist/components/SearchBar/SearchBar.d.ts +45 -27
  23. package/dist/components/Select/Select.d.ts +32 -35
  24. package/dist/components/Select/SelectTypes.d.ts +4 -0
  25. package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +1 -1
  26. package/dist/components/SkeletonLoader/SkeletonLoaderTypes.d.ts +2 -2
  27. package/dist/components/StatusBadge/StatusBadge.d.ts +8 -6
  28. package/dist/components/StatusBadge/StatusBadgeTypes.d.ts +5 -0
  29. package/dist/components/Template/Template.d.ts +91 -0
  30. package/dist/components/Text/Text.d.ts +16 -0
  31. package/dist/components/Text/TextTypes.d.ts +6 -0
  32. package/dist/components/TextInput/TextInput.d.ts +32 -31
  33. package/dist/components/TextInput/TextInputTypes.d.ts +5 -0
  34. package/dist/design-system-react-components.cjs.development.js +2597 -1170
  35. package/dist/design-system-react-components.cjs.development.js.map +1 -1
  36. package/dist/design-system-react-components.cjs.production.min.js +1 -1
  37. package/dist/design-system-react-components.cjs.production.min.js.map +1 -1
  38. package/dist/design-system-react-components.esm.js +2580 -1173
  39. package/dist/design-system-react-components.esm.js.map +1 -1
  40. package/dist/index.d.ts +8 -1
  41. package/dist/styles.css +1 -1
  42. package/dist/theme/components/accordion.d.ts +25 -0
  43. package/dist/theme/components/breadcrumb.d.ts +90 -0
  44. package/dist/theme/components/button.d.ts +17 -7
  45. package/dist/theme/components/checkbox.d.ts +7 -7
  46. package/dist/theme/components/customCheckboxGroup.d.ts +18 -0
  47. package/dist/theme/components/customRadioGroup.d.ts +4 -3
  48. package/dist/theme/components/global.d.ts +55 -0
  49. package/dist/theme/components/globalMixins.d.ts +15 -0
  50. package/dist/theme/components/heading.d.ts +50 -20
  51. package/dist/theme/components/hero.d.ts +492 -0
  52. package/dist/theme/components/icon.d.ts +13 -0
  53. package/dist/theme/components/label.d.ts +16 -0
  54. package/dist/theme/components/link.d.ts +45 -0
  55. package/dist/theme/components/radio.d.ts +8 -7
  56. package/dist/theme/components/searchBar.d.ts +20 -0
  57. package/dist/theme/components/select.d.ts +58 -0
  58. package/dist/theme/components/statusBadge.d.ts +25 -0
  59. package/dist/theme/components/tabs.d.ts +9 -9
  60. package/dist/theme/components/template.d.ts +105 -0
  61. package/dist/theme/components/text.d.ts +20 -0
  62. package/dist/theme/components/textInput.d.ts +105 -0
  63. package/dist/theme/foundations/global.d.ts +3 -0
  64. package/dist/theme/foundations/shadows.d.ts +4 -0
  65. package/dist/utils/utils.d.ts +6 -0
  66. package/package.json +3 -2
  67. package/src/components/Accordion/Accordion.stories.mdx +227 -33
  68. package/src/components/Accordion/Accordion.test.tsx +135 -19
  69. package/src/components/Accordion/Accordion.tsx +81 -56
  70. package/src/components/Autosuggest/Autosuggest.stories.mdx +1 -1
  71. package/src/components/Autosuggest/Autosuggest.stories.tsx +1 -1
  72. package/src/components/Autosuggest/_Autosuggest.scss +2 -2
  73. package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +46 -52
  74. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +31 -25
  75. package/src/components/Breadcrumbs/Breadcrumbs.tsx +71 -73
  76. package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +6 -0
  77. package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +100 -0
  78. package/src/components/Button/Button.stories.mdx +31 -27
  79. package/src/components/Button/Button.test.tsx +17 -5
  80. package/src/components/Button/ButtonTypes.tsx +1 -0
  81. package/src/components/Button/_Button.scss +3 -27
  82. package/src/components/Button/__snapshots__/Button.test.tsx.snap +11 -0
  83. package/src/components/Card/Card.stories.mdx +24 -20
  84. package/src/components/Card/Card.test.tsx +13 -19
  85. package/src/components/Card/Card.tsx +1 -1
  86. package/src/components/Card/CardTypes.tsx +2 -2
  87. package/src/components/Card/_Card.scss +1 -1
  88. package/src/components/CardEdition/CardEdition.stories.tsx +11 -6
  89. package/src/components/CardEdition/CardEdition.test.tsx +23 -31
  90. package/src/components/CardEdition/_CardEdition.scss +2 -2
  91. package/src/components/Chakra/Center.stories.mdx +31 -14
  92. package/src/components/Chakra/Grid.stories.mdx +79 -0
  93. package/src/components/Chakra/Stack.stories.mdx +4 -4
  94. package/src/components/Checkbox/Checkbox.tsx +9 -12
  95. package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +2 -5
  96. package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +249 -0
  97. package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +345 -0
  98. package/src/components/CheckboxGroup/CheckboxGroup.tsx +148 -0
  99. package/src/components/CheckboxGroup/CheckboxGroupLayoutTypes.tsx +4 -0
  100. package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +1360 -0
  101. package/src/components/DatePicker/DatePicker.test.tsx +4 -4
  102. package/src/components/DatePicker/DatePicker.tsx +13 -13
  103. package/src/components/DatePicker/_DatePicker.scss +1 -0
  104. package/src/components/Form/Form.stories.mdx +46 -21
  105. package/src/components/Form/Form.test.tsx +58 -45
  106. package/src/components/Form/Form.tsx +49 -21
  107. package/src/components/Form/FormTypes.tsx +3 -8
  108. package/src/components/Form/__snapshots__/Form.test.tsx.snap +24 -14
  109. package/src/components/Grid/GridTypes.tsx +9 -0
  110. package/src/components/Grid/SimpleGrid.stories.mdx +275 -0
  111. package/src/components/Grid/SimpleGrid.test.tsx +66 -0
  112. package/src/components/Grid/SimpleGrid.tsx +37 -0
  113. package/src/components/Grid/__snapshots__/SimpleGrid.test.tsx.snap +8 -0
  114. package/src/components/Heading/Heading.stories.mdx +1 -0
  115. package/src/components/Heading/Heading.tsx +12 -6
  116. package/src/components/HelperErrorText/_HelperErrorText.scss +1 -1
  117. package/src/components/Hero/Hero.stories.mdx +188 -121
  118. package/src/components/Hero/Hero.test.tsx +537 -107
  119. package/src/components/Hero/Hero.tsx +79 -92
  120. package/src/components/Hero/HeroTypes.tsx +17 -5
  121. package/src/components/Hero/__snapshots__/Hero.test.tsx.snap +307 -0
  122. package/src/components/HorizontalRule/_HorizontalRule.scss +1 -1
  123. package/src/components/Icons/Icon.stories.mdx +83 -74
  124. package/src/components/Icons/Icon.test.tsx +30 -22
  125. package/src/components/Icons/Icon.tsx +63 -61
  126. package/src/components/Icons/IconTypes.tsx +80 -64
  127. package/src/components/Input/_Input.scss +2 -2
  128. package/src/components/Label/Label.stories.mdx +28 -7
  129. package/src/components/Label/Label.test.tsx +43 -12
  130. package/src/components/Label/Label.tsx +21 -34
  131. package/src/components/Label/__snapshots__/Label.test.tsx.snap +41 -0
  132. package/src/components/Link/Link.stories.mdx +41 -41
  133. package/src/components/Link/Link.test.tsx +33 -44
  134. package/src/components/Link/Link.tsx +114 -100
  135. package/src/components/List/List.stories.mdx +0 -2
  136. package/src/components/List/List.stories.tsx +5 -5
  137. package/src/components/List/_List.scss +3 -3
  138. package/src/components/Modal/_Modal.scss +1 -1
  139. package/src/components/Notification/Notification.stories.mdx +12 -1
  140. package/src/components/Notification/Notification.test.tsx +3 -16
  141. package/src/components/Notification/Notification.tsx +9 -10
  142. package/src/components/Notification/_Notification.scss +4 -4
  143. package/src/components/Pagination/Pagination.test.tsx +16 -10
  144. package/src/components/RadioGroup/RadioGroup.stories.mdx +1 -1
  145. package/src/components/RadioGroup/RadioGroup.tsx +2 -10
  146. package/src/components/SearchBar/SearchBar.Test.tsx +151 -16
  147. package/src/components/SearchBar/SearchBar.stories.mdx +189 -219
  148. package/src/components/SearchBar/SearchBar.tsx +151 -46
  149. package/src/components/Select/Select.stories.mdx +188 -170
  150. package/src/components/Select/Select.test.tsx +125 -380
  151. package/src/components/Select/Select.tsx +118 -165
  152. package/src/components/Select/SelectTypes.tsx +4 -0
  153. package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +13 -25
  154. package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +7 -7
  155. package/src/components/SkeletonLoader/SkeletonLoader.tsx +4 -2
  156. package/src/components/SkeletonLoader/SkeletonLoaderTypes.tsx +2 -2
  157. package/src/components/SkeletonLoader/_SkeletonLoader.scss +3 -3
  158. package/src/components/StatusBadge/StatusBadge.stories.mdx +91 -0
  159. package/src/components/StatusBadge/StatusBadge.test.tsx +35 -7
  160. package/src/components/StatusBadge/StatusBadge.tsx +24 -25
  161. package/src/components/StatusBadge/StatusBadgeTypes.tsx +5 -0
  162. package/src/components/StatusBadge/__snapshots__/StatusBadge.test.tsx.snap +28 -0
  163. package/src/components/StyleGuide/Bidirectionality.stories.mdx +16 -16
  164. package/src/components/StyleGuide/Buttons.stories.mdx +15 -15
  165. package/src/components/StyleGuide/Colors.stories.mdx +336 -0
  166. package/src/components/StyleGuide/Iconography.stories.mdx +88 -90
  167. package/src/components/StyleGuide/UIDocCard.tsx +1 -1
  168. package/src/components/Tabs/Tabs.tsx +7 -9
  169. package/src/components/Template/Template.stories.mdx +574 -0
  170. package/src/components/Template/Template.test.tsx +124 -0
  171. package/src/components/Template/Template.tsx +226 -0
  172. package/src/components/Text/Text.stories.mdx +70 -0
  173. package/src/components/Text/Text.test.tsx +63 -0
  174. package/src/components/Text/Text.tsx +55 -0
  175. package/src/components/Text/TextTypes.tsx +6 -0
  176. package/src/components/Text/__snapshots__/Text.test.tsx.snap +33 -0
  177. package/src/components/TextInput/TextInput.stories.mdx +89 -90
  178. package/src/components/TextInput/TextInput.test.tsx +65 -86
  179. package/src/components/TextInput/TextInput.tsx +101 -95
  180. package/src/components/TextInput/TextInputTypes.tsx +6 -0
  181. package/src/components/VideoPlayer/_VideoPlayer.scss +1 -1
  182. package/src/docs/Chakra.stories.mdx +4 -4
  183. package/src/docs/Intro.stories.mdx +15 -13
  184. package/src/index.ts +20 -0
  185. package/src/styles/01-colors/_colors-brand.scss +6 -0
  186. package/src/styles/01-colors/_colors-utility.scss +14 -12
  187. package/src/styles/base/_04-base.scss +2 -1
  188. package/src/styles/base/_place-holder.scss +1 -1
  189. package/src/styles.scss +10 -12
  190. package/src/theme/components/accordion.ts +30 -0
  191. package/src/theme/components/breadcrumb.ts +77 -0
  192. package/src/theme/components/button.ts +77 -63
  193. package/src/theme/components/checkbox.ts +15 -27
  194. package/src/theme/components/customCheckboxGroup.ts +12 -0
  195. package/src/theme/components/customRadioGroup.ts +4 -10
  196. package/src/theme/components/global.ts +71 -0
  197. package/src/theme/components/globalMixins.ts +16 -0
  198. package/src/theme/components/heading.ts +15 -8
  199. package/src/theme/components/hero.ts +239 -0
  200. package/src/theme/components/icon.ts +79 -0
  201. package/src/theme/components/label.ts +17 -0
  202. package/src/theme/components/link.ts +47 -0
  203. package/src/theme/components/radio.ts +20 -31
  204. package/src/theme/components/searchBar.ts +21 -0
  205. package/src/theme/components/select.ts +50 -0
  206. package/src/theme/components/statusBadge.ts +27 -0
  207. package/src/theme/components/tabs.ts +72 -69
  208. package/src/theme/components/template.ts +114 -0
  209. package/src/theme/components/text.ts +31 -0
  210. package/src/theme/components/textInput.ts +61 -0
  211. package/src/theme/foundations/colors.ts +29 -13
  212. package/src/theme/foundations/global.ts +3 -0
  213. package/src/theme/foundations/shadows.ts +5 -0
  214. package/src/theme/index.ts +37 -7
  215. package/src/utils/componentCategories.ts +8 -2
  216. package/src/utils/utils.ts +13 -0
  217. package/dist/components/Accordion/Accordion.stories.d.ts +0 -6
  218. package/dist/components/StatusBadge/StatusBadge.stories.d.ts +0 -8
  219. package/dist/components/StyleGuide/Colors.stories.d.ts +0 -25
  220. package/dist/components/Template/Template.stories.d.ts +0 -30
  221. package/src/components/Accordion/Accordion.stories.tsx +0 -66
  222. package/src/components/Accordion/_Accordion.scss +0 -81
  223. package/src/components/Breadcrumbs/_Breadcrumbs.scss +0 -97
  224. package/src/components/Form/_Form.scss +0 -67
  225. package/src/components/Hero/_Hero.scss +0 -256
  226. package/src/components/Icons/_Icons.scss +0 -116
  227. package/src/components/Label/_Label.scss +0 -22
  228. package/src/components/Link/_Link.scss +0 -73
  229. package/src/components/SearchBar/_SearchBar.scss +0 -16
  230. package/src/components/Select/_Select.scss +0 -82
  231. package/src/components/StatusBadge/StatusBadge.stories.tsx +0 -34
  232. package/src/components/StatusBadge/_StatusBadge.scss +0 -23
  233. package/src/components/StyleGuide/Colors.stories.tsx +0 -289
  234. package/src/components/Template/Template.stories.tsx +0 -86
  235. package/src/components/Template/_Template.scss +0 -63
  236. package/src/components/TextInput/_TextInput.scss +0 -59
@@ -1,192 +1,145 @@
1
1
  import React from "react";
2
- import bem from "../../utils/bem";
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
- /** DEPRECATED - When passed, will populate the aria-label on the select */
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
- children?: React.ReactNode;
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
- /** DEPRECATED - Attribute indicating that an option with a non-empty string value must be selected */
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
- /** DEPRECATED - ID of associated label */
32
- labelId?: string;
33
- /** Provides text for a `Label` component if `showLabel` is set to `true`; populates a `aria-label` attribute on the select input if `showLabel` is set to `false`. */
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
- /** Modifiers array for use with BEM. See how to work with modifiers and BEM here: http://getbem.com/introduction/ */
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
- /** Passes select's current value to the React state handler */
40
- onBlur?: (event: React.FormEvent) => void;
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
- /** Will add `aria-required: true` and native HTML `required` attribute to the select input */
44
- required?: boolean;
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
- const Select = React.forwardRef<HTMLSelectElement, SelectProps>(
54
- (props, ref?) => {
55
- const {
56
- ariaLabel = null,
57
- blockName,
58
- children,
59
- className,
60
- errored,
61
- invalidText,
62
- helperText,
63
- helperTextId,
64
- isRequired,
65
- labelId,
66
- labelText,
67
- onBlur,
68
- onChange,
69
- name,
70
- required,
71
- attributes = {},
72
- disabled = false,
73
- selectedOption,
74
- showLabel,
75
- showOptReqLabel = true,
76
- } = props;
77
-
78
- const modifiers = props.modifiers ? props.modifiers : [];
79
- const id = props.id || generateUUID();
80
- let ariaLabelledBy = null;
81
-
82
- if (!showLabel) attributes["aria-label"] = labelText;
83
-
84
- if (helperText && showLabel)
85
- attributes["aria-describedby"] = `${id}-helperText`;
86
-
87
- if (errored) modifiers.push("error");
88
-
89
- const req = isRequired || required;
90
- const optReqFlag = req ? "Required" : "Optional";
91
-
92
- const errorOutput = invalidText
93
- ? invalidText
94
- : "There is an error related to this field.";
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
- if (isRequired === true || isRequired === false) {
135
- console.warn(
136
- "The isRequired prop has been deprecated in the Select component and will be removed in a future release. Check the documentation for updated props."
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
- if (labelId) {
141
- console.warn(
142
- "The labelId prop has been deprecated in the Select component and will be removed in a future release. Check the documentation for updated props."
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
- return (
147
- <div className="select">
148
- {labelText && showLabel && (
149
- <Label
150
- htmlFor={id}
151
- optReqFlag={showOptReqLabel && optReqFlag}
152
- id={id + `-label`}
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
- {React.Children.map(children, (child, key) => {
173
- return React.cloneElement(child as React.ReactElement<any>, {
174
- "aria-selected": children[key]
175
- ? children[key].props.children === selectedOption
176
- : false,
177
- });
178
- })}
179
- </select>
180
- {(helperText || errored) && (
181
- <HelperErrorText isError={errored} id={id + `-helperText`}>
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
- </div>
186
- );
187
- }
188
- );
189
-
190
- Select.displayName = "Select";
139
+ </Box>
140
+ )}
141
+ </Box>
142
+ );
143
+ });
191
144
 
192
145
  export default Select;
@@ -0,0 +1,4 @@
1
+ export enum SelectTypes {
2
+ Default = "default",
3
+ SearchBar = "searchbar",
4
+ }
@@ -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: "vertical" } },
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 content is loading. The `layout`, `width` and placeholder elements within the `SkeletonLoader` can be customized.
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`. The default value is `100%`.
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
- "grid-template-columns": "repeat(3, 1fr)",
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
- "grid-template-columns": "repeat(1, 1fr)",
138
+ gridTemplateColumns: "repeat(1, 1fr)",
136
139
  }}
137
140
  >
138
- <SkeletonLoader
139
- layout={SkeletonLoaderLayouts.Horizontal}
140
- showImage={false}
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--vertical "
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 vertical layout", () => {
37
+ it("renders column layout", () => {
38
38
  const utils = render(
39
- <SkeletonLoader layout={SkeletonLoaderLayouts.Vertical} />
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--vertical")
45
+ container.querySelector(".skeleton-loader--column")
46
46
  ).toBeInTheDocument();
47
47
  });
48
48
 
49
- it("renders horizontal layout", () => {
49
+ it("renders row layout", () => {
50
50
  const utils = render(
51
- <SkeletonLoader layout={SkeletonLoaderLayouts.Horizontal} />
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--horizontal")
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 `vertical` */
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.Vertical,
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
  export enum SkeletonLoaderLayouts {
2
- Horizontal = "horizontal",
3
- Vertical = "vertical",
2
+ Row = "row",
3
+ Column = "column",
4
4
  }
5
5
 
6
6
  export enum SkeletonLoaderImageRatios {
@@ -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-light);
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
- &--horizontal {
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 level={"low"}>Registration Required</StatusBadge>
12
+ <StatusBadge>Registration Required</StatusBadge>
11
13
  );
12
14
  expect(await axe(container)).toHaveNoViolations();
13
15
  });
14
16
  });
15
17
 
16
- describe("StatusBadge Test", () => {
17
- it("Shows status badge", () => {
18
- render(<StatusBadge level={"low"}>Registration Required</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
- it("Can pass status badge content as child", () => {
22
- render(<StatusBadge level={"medium"}>Cancelled</StatusBadge>);
23
- expect(screen.getByText("Cancelled")).toBeInTheDocument();
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
  });