@nypl/design-system-react-components 0.25.9 → 0.25.12

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 (163) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/README.md +4 -16
  3. package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +1 -0
  4. package/dist/components/DatePicker/DatePicker.d.ts +1 -1
  5. package/dist/components/Fieldset/Fieldset.d.ts +1 -3
  6. package/dist/components/Form/Form.d.ts +13 -12
  7. package/dist/components/Form/FormTypes.d.ts +2 -2
  8. package/dist/components/HorizontalRule/HorizontalRule.d.ts +1 -1
  9. package/dist/components/Icons/IconTypes.d.ts +9 -7
  10. package/dist/components/List/List.d.ts +1 -1
  11. package/dist/components/Logo/LogoSvgs.d.ts +23 -1
  12. package/dist/components/Logo/LogoTypes.d.ts +23 -1
  13. package/dist/components/Notification/Notification.d.ts +2 -0
  14. package/dist/components/Pagination/Pagination.d.ts +6 -2
  15. package/dist/components/RadioGroup/RadioGroup.d.ts +3 -3
  16. package/dist/components/SearchBar/SearchBar.d.ts +6 -6
  17. package/dist/components/Select/Select.d.ts +4 -0
  18. package/dist/components/Table/Table.d.ts +9 -3
  19. package/dist/components/Template/Template.d.ts +24 -5
  20. package/dist/design-system-react-components.cjs.development.js +2063 -548
  21. package/dist/design-system-react-components.cjs.development.js.map +1 -1
  22. package/dist/design-system-react-components.cjs.production.min.js +1 -1
  23. package/dist/design-system-react-components.cjs.production.min.js.map +1 -1
  24. package/dist/design-system-react-components.esm.js +2056 -554
  25. package/dist/design-system-react-components.esm.js.map +1 -1
  26. package/dist/index.d.ts +4 -4
  27. package/dist/resources.scss +0 -2
  28. package/dist/styles.css +1 -1
  29. package/dist/theme/components/breadcrumb.d.ts +4 -1
  30. package/dist/theme/components/checkbox.d.ts +0 -2
  31. package/dist/theme/components/customTable.d.ts +12 -3
  32. package/dist/theme/components/fieldset.d.ts +2 -0
  33. package/dist/theme/components/global.d.ts +15 -14
  34. package/dist/theme/components/globalMixins.d.ts +8 -8
  35. package/dist/theme/components/list.d.ts +6 -0
  36. package/dist/theme/components/notification.d.ts +16 -4
  37. package/dist/theme/components/radio.d.ts +3 -2
  38. package/dist/theme/components/searchBar.d.ts +4 -0
  39. package/dist/theme/components/select.d.ts +2 -9
  40. package/dist/theme/components/slider.d.ts +8 -4
  41. package/dist/theme/components/structuredContent.d.ts +9 -9
  42. package/dist/theme/components/textInput.d.ts +10 -12
  43. package/dist/theme/components/toggle.d.ts +6 -2
  44. package/dist/theme/foundations/global.d.ts +31 -3
  45. package/dist/utils/utils.d.ts +10 -0
  46. package/package.json +40 -36
  47. package/src/components/Accordion/Accordion.stories.mdx +1 -1
  48. package/src/components/Accordion/Accordion.test.tsx +45 -1
  49. package/src/components/Accordion/Accordion.tsx +20 -8
  50. package/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +243 -0
  51. package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +30 -2
  52. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +25 -0
  53. package/src/components/Breadcrumbs/Breadcrumbs.tsx +9 -3
  54. package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +1 -0
  55. package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +104 -5
  56. package/src/components/Card/Card.stories.mdx +1 -1
  57. package/src/components/Card/Card.tsx +4 -1
  58. package/src/components/Card/__snapshots__/Card.test.tsx.snap +1 -1
  59. package/src/components/Chakra/Flex.stories.mdx +113 -0
  60. package/src/components/Checkbox/Checkbox.stories.mdx +1 -1
  61. package/src/components/Checkbox/Checkbox.tsx +1 -0
  62. package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +6 -6
  63. package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +1 -1
  64. package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +18 -18
  65. package/src/components/DatePicker/DatePicker.stories.mdx +1 -1
  66. package/src/components/DatePicker/DatePicker.test.tsx +6 -6
  67. package/src/components/DatePicker/DatePicker.tsx +12 -10
  68. package/src/components/DatePicker/__snapshots__/DatePicker.test.tsx.snap +28 -20
  69. package/src/components/Fieldset/Fieldset.stories.mdx +1 -1
  70. package/src/components/Fieldset/Fieldset.tsx +2 -4
  71. package/src/components/Form/Form.stories.mdx +34 -16
  72. package/src/components/Form/Form.test.tsx +92 -3
  73. package/src/components/Form/Form.tsx +25 -21
  74. package/src/components/Form/FormTypes.tsx +2 -2
  75. package/src/components/Form/__snapshots__/Form.test.tsx.snap +0 -1
  76. package/src/components/HelperErrorText/HelperErrorText.stories.mdx +1 -1
  77. package/src/components/Hero/Hero.stories.mdx +1 -1
  78. package/src/components/HorizontalRule/HorizontalRule.stories.mdx +3 -2
  79. package/src/components/HorizontalRule/HorizontalRule.tsx +2 -2
  80. package/src/components/HorizontalRule/__snapshots__/HorizontalRule.test.tsx.snap +4 -4
  81. package/src/components/Icons/Icon.stories.mdx +1 -1
  82. package/src/components/Icons/Icon.test.tsx +1 -1
  83. package/src/components/Icons/Icon.tsx +1 -1
  84. package/src/components/Icons/IconTypes.tsx +8 -6
  85. package/src/components/List/List.stories.mdx +24 -5
  86. package/src/components/List/List.test.tsx +1 -1
  87. package/src/components/List/List.tsx +2 -2
  88. package/src/components/List/__snapshots__/List.test.tsx.snap +3 -1
  89. package/src/components/Logo/Logo.stories.mdx +7 -5
  90. package/src/components/Logo/LogoSvgs.tsx +45 -1
  91. package/src/components/Logo/LogoTypes.tsx +22 -0
  92. package/src/components/Notification/Notification.stories.mdx +73 -1
  93. package/src/components/Notification/Notification.test.tsx +64 -5
  94. package/src/components/Notification/Notification.tsx +21 -11
  95. package/src/components/Notification/__snapshots__/Notification.test.tsx.snap +103 -8
  96. package/src/components/Pagination/Pagination.stories.mdx +54 -12
  97. package/src/components/Pagination/Pagination.test.tsx +63 -5
  98. package/src/components/Pagination/Pagination.tsx +46 -24
  99. package/src/components/Pagination/__snapshots__/Pagination.test.tsx.snap +3 -3
  100. package/src/components/Radio/Radio.stories.mdx +1 -1
  101. package/src/components/Radio/Radio.tsx +1 -0
  102. package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +5 -5
  103. package/src/components/RadioGroup/RadioGroup.stories.mdx +1 -1
  104. package/src/components/RadioGroup/RadioGroup.test.tsx +13 -11
  105. package/src/components/RadioGroup/RadioGroup.tsx +88 -89
  106. package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +18 -18
  107. package/src/components/SearchBar/SearchBar.Test.tsx +124 -28
  108. package/src/components/SearchBar/SearchBar.stories.mdx +9 -6
  109. package/src/components/SearchBar/SearchBar.tsx +24 -23
  110. package/src/components/Select/Select.stories.mdx +1 -1
  111. package/src/components/Select/Select.test.tsx +89 -0
  112. package/src/components/Select/Select.tsx +11 -2
  113. package/src/components/Select/__snapshots__/Select.test.tsx.snap +545 -0
  114. package/src/components/Slider/Slider.stories.mdx +1 -1
  115. package/src/components/Slider/Slider.tsx +4 -1
  116. package/src/components/Slider/__snapshots__/Slider.test.tsx.snap +7 -0
  117. package/src/components/StructuredContent/StructuredContent.stories.mdx +1 -1
  118. package/src/components/StyleGuide/Bidirectionality.stories.mdx +4 -4
  119. package/src/components/StyleGuide/Colors.stories.mdx +33 -18
  120. package/src/components/Table/Table.stories.mdx +118 -19
  121. package/src/components/Table/Table.test.tsx +80 -3
  122. package/src/components/Table/Table.tsx +26 -16
  123. package/src/components/Table/__snapshots__/Table.test.tsx.snap +1179 -0
  124. package/src/components/Tabs/Tabs.stories.mdx +1 -1
  125. package/src/components/Tabs/Tabs.test.tsx +21 -5
  126. package/src/components/Tabs/Tabs.tsx +35 -20
  127. package/src/components/Tabs/__snapshots__/Tabs.test.tsx.snap +195 -0
  128. package/src/components/Template/Template.stories.mdx +79 -4
  129. package/src/components/Template/Template.test.tsx +65 -3
  130. package/src/components/Template/Template.tsx +60 -14
  131. package/src/components/Template/__snapshots__/Template.test.tsx.snap +94 -1
  132. package/src/components/TextInput/TextInput.stories.mdx +1 -1
  133. package/src/components/Toggle/Toggle.stories.mdx +1 -1
  134. package/src/components/Toggle/Toggle.tsx +2 -1
  135. package/src/components/Toggle/__snapshots__/Toggle.test.tsx.snap +4 -4
  136. package/src/docs/Chakra.stories.mdx +1 -1
  137. package/src/index.ts +8 -2
  138. package/src/styles/base/_place-holder.scss +2 -0
  139. package/src/styles.scss +0 -2
  140. package/src/theme/components/breadcrumb.ts +5 -1
  141. package/src/theme/components/checkbox.ts +3 -7
  142. package/src/theme/components/customTable.ts +16 -3
  143. package/src/theme/components/fieldset.ts +2 -0
  144. package/src/theme/components/global.ts +19 -16
  145. package/src/theme/components/globalMixins.ts +8 -8
  146. package/src/theme/components/list.ts +6 -2
  147. package/src/theme/components/notification.ts +21 -8
  148. package/src/theme/components/radio.ts +3 -6
  149. package/src/theme/components/searchBar.ts +4 -0
  150. package/src/theme/components/select.ts +3 -3
  151. package/src/theme/components/slider.ts +12 -9
  152. package/src/theme/components/structuredContent.ts +26 -6
  153. package/src/theme/components/textInput.ts +3 -2
  154. package/src/theme/components/toggle.ts +42 -38
  155. package/src/theme/foundations/colors.ts +19 -12
  156. package/src/theme/foundations/global.ts +17 -5
  157. package/src/theme/foundations/typography.ts +2 -2
  158. package/src/utils/componentCategories.ts +2 -1
  159. package/src/utils/utils.ts +28 -0
  160. package/dist/components/Pagination/Pagination.stories.d.ts +0 -13
  161. package/src/components/Pagination/Pagination.stories.tsx +0 -54
  162. package/src/styles/base/_03-base.scss +0 -25
  163. package/src/styles/base/_04-focus.scss +0 -22
@@ -60,7 +60,7 @@ import DSProvider from "../../theme/provider";
60
60
  | Component Version | DS Version |
61
61
  | ----------------- | ---------- |
62
62
  | Added | `0.0.4` |
63
- | Latest | `0.25.9` |
63
+ | Latest | `0.25.12` |
64
64
 
65
65
  <Description of={SearchBar} />
66
66
 
@@ -142,14 +142,17 @@ export const optionsGroup = [
142
142
 
143
143
  To render an optional `Select` component, an object must be passed to the
144
144
  `selectProps` prop. It _must_ include `name`, `labelText`, and `optionsData`
145
- properties. The `labelText` value won't be rendered but will be used for its
146
- `aria-label` attribute.
145
+ properties. The `onChange` property is optional. The `labelText` value won't be
146
+ rendered but will be used for its `aria-label` attribute.
147
147
 
148
148
  ```
149
149
  const selectProps = {
150
150
  name: "select-form-name",
151
151
  labelText: "Select a category",
152
152
  optionsData: optionsGroup,
153
+ onChange: (event) => {
154
+ console.log(event.target.value);
155
+ },
153
156
  };
154
157
 
155
158
  // ...
@@ -163,9 +166,9 @@ const selectProps = {
163
166
  ### TextInput Component
164
167
 
165
168
  To render the `TextInput` component, an object must be passed to the
166
- `textInputProps` prop. It _must_ include `labelText`, `name`, and `placeholder`
167
- properties. The `labelText` value won't be rendered but will be used for its
168
- `aria-label` attribute. Optional values to pass include `onChange` and `value`.
169
+ `textInputProps` prop. It _must_ include `labelText` and `name` properties. The
170
+ `labelText` value won't be rendered but will be used for its `aria-label`
171
+ attribute. Optional properties to pass include `onChange`, `placeholder`, and `value`.
169
172
 
170
173
  ```
171
174
  const textInputProps = {
@@ -13,13 +13,7 @@ import TextInput from "../TextInput/TextInput";
13
13
  import { TextInputTypes, TextInputVariants } from "../TextInput/TextInputTypes";
14
14
  import generateUUID from "../../helpers/generateUUID";
15
15
 
16
- // Internal interfaces that are used only for `SearchBar` props.
17
- interface SelectProps {
18
- labelText: string;
19
- name: string;
20
- optionsData: string[];
21
- }
22
- interface TextInputProps {
16
+ interface BaseProps {
23
17
  labelText: string;
24
18
  name: string;
25
19
  onChange?: (
@@ -27,7 +21,13 @@ interface TextInputProps {
27
21
  | React.ChangeEvent<HTMLInputElement>
28
22
  | React.ChangeEvent<HTMLTextAreaElement>
29
23
  ) => void;
30
- placeholder: string;
24
+ }
25
+ // Internal interfaces that are used only for `SearchBar` props.
26
+ export interface SelectProps extends BaseProps {
27
+ optionsData: string[];
28
+ }
29
+ export interface TextInputProps extends BaseProps {
30
+ placeholder?: string;
31
31
  value?: string;
32
32
  }
33
33
 
@@ -97,7 +97,7 @@ export default function SearchBar(props: SearchBarProps) {
97
97
  textInputElement,
98
98
  textInputProps,
99
99
  } = props;
100
- const styles = useMultiStyleConfig("SearchBar", { hasSelect: selectProps });
100
+ const styles = useMultiStyleConfig("SearchBar", {});
101
101
  const stateProps = {
102
102
  helperText: "",
103
103
  isDisabled,
@@ -106,11 +106,10 @@ export default function SearchBar(props: SearchBarProps) {
106
106
  showHelperInvalidText: false,
107
107
  showLabel: false,
108
108
  };
109
- const helperErrorTextID = generateUUID();
110
- const ariaDescribedby = helperErrorTextID;
111
109
  const footnote = isInvalid ? invalidText : helperText;
112
110
  const finalAriaLabel = footnote ? `${labelText} - ${footnote}` : labelText;
113
- const textInputPlaceholder = `${textInputProps?.placeholder} ${
111
+ const inputPlaceholder = textInputProps?.placeholder || "Search terms";
112
+ const textInputPlaceholder = `${inputPlaceholder} ${
114
113
  isRequired ? "(Required)" : ""
115
114
  }`;
116
115
  const buttonType = noBrandButtonType
@@ -125,9 +124,11 @@ export default function SearchBar(props: SearchBarProps) {
125
124
  // Render the `Select` component.
126
125
  const selectElem = selectProps && (
127
126
  <Select
128
- id={generateUUID()}
129
- name={selectProps?.name}
127
+ additionalStyles={styles.select}
128
+ id={`searchbar-select-${id}`}
130
129
  labelText={selectProps?.labelText}
130
+ name={selectProps?.name}
131
+ onChange={selectProps?.onChange}
131
132
  type={SelectTypes.SearchBar}
132
133
  {...stateProps}
133
134
  >
@@ -141,11 +142,11 @@ export default function SearchBar(props: SearchBarProps) {
141
142
  // Render the `TextInput` component.
142
143
  const textInputNative = textInputProps && (
143
144
  <TextInput
144
- id={generateUUID()}
145
+ id={`searchbar-textinput-${id}`}
145
146
  labelText={textInputProps?.labelText}
146
- placeholder={textInputPlaceholder}
147
- onChange={textInputProps?.onChange}
148
147
  name={textInputProps?.name}
148
+ onChange={textInputProps?.onChange}
149
+ placeholder={textInputPlaceholder}
149
150
  type={TextInputTypes.text}
150
151
  variantType={
151
152
  selectElem
@@ -161,21 +162,22 @@ export default function SearchBar(props: SearchBarProps) {
161
162
  <Button
162
163
  additionalStyles={searchBarButtonStyles}
163
164
  buttonType={buttonType}
164
- id={generateUUID()}
165
+ id={`searchbar-button-${id}`}
165
166
  isDisabled={isDisabled}
166
167
  onClick={buttonOnClick}
167
168
  type="submit"
168
169
  >
169
170
  <Icon
171
+ align={IconAlign.Left}
172
+ id={`searchbar-icon-${id}`}
170
173
  name={IconNames.Search}
171
174
  size={IconSizes.Small}
172
- align={IconAlign.Left}
173
175
  />
174
176
  Search
175
177
  </Button>
176
178
  );
177
- // If a custom input element was passed, use that instead of the
178
- // `TextInput` component.
179
+ // If a custom input element was passed, use that element
180
+ // instead of the DS `TextInput` component.
179
181
  const textInputElem = textInputElement || textInputNative;
180
182
 
181
183
  return (
@@ -189,11 +191,10 @@ export default function SearchBar(props: SearchBarProps) {
189
191
  >
190
192
  <Box
191
193
  as="form"
192
- id={`${id}-form`}
194
+ id={`searchbar-form-${id}`}
193
195
  className={className}
194
196
  role="search"
195
197
  aria-label={finalAriaLabel}
196
- aria-describedby={ariaDescribedby}
197
198
  onSubmit={onSubmit}
198
199
  method={method}
199
200
  action={action}
@@ -67,7 +67,7 @@ export const enumValues = getStorybookEnumValues(SelectTypes, "SelectTypes");
67
67
  | Component Version | DS Version |
68
68
  | ----------------- | ---------- |
69
69
  | Added | `0.7.0` |
70
- | Latest | `0.25.9` |
70
+ | Latest | `0.25.12` |
71
71
 
72
72
  <Description of={Select} />
73
73
 
@@ -1,6 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { render, screen, fireEvent } from "@testing-library/react";
3
3
  import { axe } from "jest-axe";
4
+ import renderer from "react-test-renderer";
4
5
 
5
6
  import Select from "./Select";
6
7
 
@@ -255,4 +256,92 @@ describe("Select", () => {
255
256
  "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."
256
257
  );
257
258
  });
259
+
260
+ it("Renders the UI snapshot correctly", () => {
261
+ const siblings = ["Kendall", "Shiv", "Connor", "Roman", "Tom"];
262
+
263
+ const options = siblings.map((sibling) => (
264
+ <option key={sibling}>{sibling}</option>
265
+ ));
266
+
267
+ const primary = renderer
268
+ .create(
269
+ <Select
270
+ id="select"
271
+ labelText="Which Succession sibling are you?"
272
+ name="succession-sibling"
273
+ >
274
+ {options}
275
+ </Select>
276
+ )
277
+ .toJSON();
278
+ const disabled = renderer
279
+ .create(
280
+ <Select
281
+ id="select"
282
+ isDisabled
283
+ labelText="Which Succession sibling are you?"
284
+ name="succession-sibling"
285
+ >
286
+ {options}
287
+ </Select>
288
+ )
289
+ .toJSON();
290
+ const withInvalidText = renderer
291
+ .create(
292
+ <Select
293
+ id="select"
294
+ invalidText="Tom doesn't count as a sibling :(."
295
+ isInvalid
296
+ labelText="Which Succession sibling are you?"
297
+ name="succession-sibling"
298
+ >
299
+ {options}
300
+ </Select>
301
+ )
302
+ .toJSON();
303
+ const withHelperText = renderer
304
+ .create(
305
+ <Select
306
+ helperText="Remember, Logan will judge you no matter who you pick."
307
+ id="select"
308
+ labelText="Which Succession sibling are you?"
309
+ name="succession-sibling"
310
+ >
311
+ {options}
312
+ </Select>
313
+ )
314
+ .toJSON();
315
+ const required = renderer
316
+ .create(
317
+ <Select
318
+ id="select"
319
+ isRequired
320
+ labelText="Which Succession sibling are you?"
321
+ name="succession-sibling"
322
+ >
323
+ {options}
324
+ </Select>
325
+ )
326
+ .toJSON();
327
+ const hasOnChange = renderer
328
+ .create(
329
+ <Select
330
+ id="select"
331
+ labelText="Which Succession sibling are you?"
332
+ name="succession-sibling"
333
+ onChange={jest.fn()}
334
+ >
335
+ {options}
336
+ </Select>
337
+ )
338
+ .toJSON();
339
+
340
+ expect(primary).toMatchSnapshot();
341
+ expect(disabled).toMatchSnapshot();
342
+ expect(withInvalidText).toMatchSnapshot();
343
+ expect(withHelperText).toMatchSnapshot();
344
+ expect(required).toMatchSnapshot();
345
+ expect(hasOnChange).toMatchSnapshot();
346
+ });
258
347
  });
@@ -15,6 +15,8 @@ import { SelectTypes } from "./SelectTypes";
15
15
  import generateUUID from "../../helpers/generateUUID";
16
16
 
17
17
  export interface SelectProps {
18
+ /** Optionally pass in additional Chakra-based styles. */
19
+ additionalStyles?: { [key: string]: any };
18
20
  /** A class name for the `div` parent element. */
19
21
  className?: string;
20
22
  /** Optional string to populate the `HelperErrorText` for the standard state. */
@@ -65,6 +67,7 @@ const Select = React.forwardRef<
65
67
  React.PropsWithChildren<SelectProps>
66
68
  >((props: React.PropsWithChildren<SelectProps>, ref?) => {
67
69
  const {
70
+ additionalStyles = {},
68
71
  children,
69
72
  className,
70
73
  helperText,
@@ -116,7 +119,7 @@ const Select = React.forwardRef<
116
119
  }
117
120
 
118
121
  return (
119
- <Box className={className} __css={styles}>
122
+ <Box className={className} __css={{ ...styles, ...additionalStyles }}>
120
123
  {showLabel && (
121
124
  <Label
122
125
  id={`${id}-label`}
@@ -137,7 +140,13 @@ const Select = React.forwardRef<
137
140
  ref={ref}
138
141
  {...controlledProps}
139
142
  {...ariaAttributes}
140
- icon={<Icon name={IconNames.Arrow} size={IconSizes.Medium} />}
143
+ icon={
144
+ <Icon
145
+ id={`${id}-icon`}
146
+ name={IconNames.Arrow}
147
+ size={IconSizes.Medium}
148
+ />
149
+ }
141
150
  __css={styles.select}
142
151
  >
143
152
  {children}