@nypl/design-system-react-components 0.25.3 → 0.25.7

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 (135) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/README.md +47 -11
  3. package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +4 -0
  4. package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +1 -0
  5. package/dist/components/Button/Button.d.ts +9 -6
  6. package/dist/components/Button/ButtonTypes.d.ts +2 -1
  7. package/dist/components/Card/Card.d.ts +0 -25
  8. package/dist/components/Icons/IconSvgs.d.ts +3 -0
  9. package/dist/components/Icons/IconTypes.d.ts +3 -0
  10. package/dist/components/Notification/Notification.d.ts +6 -4
  11. package/dist/components/ProgressIndicator/ProgressIndicator.d.ts +29 -0
  12. package/dist/components/ProgressIndicator/ProgressIndicatorTypes.d.ts +8 -0
  13. package/dist/components/SearchBar/SearchBar.d.ts +3 -3
  14. package/dist/components/Slider/Slider.d.ts +57 -0
  15. package/dist/components/Tabs/Tabs.d.ts +1 -1
  16. package/dist/components/TextInput/TextInput.d.ts +6 -0
  17. package/dist/design-system-react-components.cjs.development.js +1022 -455
  18. package/dist/design-system-react-components.cjs.development.js.map +1 -1
  19. package/dist/design-system-react-components.cjs.production.min.js +1 -1
  20. package/dist/design-system-react-components.cjs.production.min.js.map +1 -1
  21. package/dist/design-system-react-components.esm.js +1015 -444
  22. package/dist/design-system-react-components.esm.js.map +1 -1
  23. package/dist/index.d.ts +8 -3
  24. package/dist/resources.scss +180 -170
  25. package/dist/styles.css +1 -1
  26. package/dist/theme/components/breadcrumb.d.ts +9 -0
  27. package/dist/theme/components/button.d.ts +10 -0
  28. package/dist/theme/components/progressIndicator.d.ts +50 -0
  29. package/dist/theme/components/slider.d.ts +51 -0
  30. package/dist/theme/foundations/breakpoints.d.ts +8 -8
  31. package/dist/theme/foundations/global.d.ts +6 -1
  32. package/package.json +71 -83
  33. package/src/__tests__/setup.ts +2 -2
  34. package/src/components/Accordion/Accordion.stories.mdx +30 -34
  35. package/src/components/Autosuggest/Autosuggest.stories.mdx +3 -3
  36. package/src/components/Autosuggest/Autosuggest.stories.tsx +1 -0
  37. package/src/components/Autosuggest/_Autosuggest.scss +5 -5
  38. package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +24 -8
  39. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +33 -0
  40. package/src/components/Breadcrumbs/Breadcrumbs.tsx +5 -1
  41. package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +1 -0
  42. package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +297 -1
  43. package/src/components/Button/Button.stories.mdx +8 -6
  44. package/src/components/Button/Button.test.tsx +20 -0
  45. package/src/components/Button/Button.tsx +14 -23
  46. package/src/components/Button/ButtonTypes.tsx +1 -0
  47. package/src/components/Button/__snapshots__/Button.test.tsx.snap +29 -4
  48. package/src/components/Card/Card.stories.mdx +1 -1
  49. package/src/components/Card/Card.tsx +3 -3
  50. package/src/components/CardEdition/CardEdition.stories.tsx +15 -47
  51. package/src/components/CardEdition/_CardEdition.scss +22 -23
  52. package/src/components/Chakra/Box.stories.mdx +14 -15
  53. package/src/components/Chakra/Center.stories.mdx +15 -8
  54. package/src/components/Chakra/Grid.stories.mdx +16 -7
  55. package/src/components/Chakra/Stack.stories.mdx +35 -18
  56. package/src/components/DatePicker/DatePicker.test.tsx +31 -30
  57. package/src/components/DatePicker/DatePicker.tsx +7 -4
  58. package/src/components/DatePicker/_DatePicker.scss +4 -4
  59. package/src/components/DatePicker/__snapshots__/DatePicker.test.tsx.snap +19 -5
  60. package/src/components/Form/Form.stories.mdx +4 -5
  61. package/src/components/Grid/SimpleGrid.stories.mdx +1 -0
  62. package/src/components/Hero/HeroTypes.tsx +1 -0
  63. package/src/components/HorizontalRule/HorizontalRule.stories.mdx +2 -3
  64. package/src/components/Icons/Icon.stories.mdx +2 -3
  65. package/src/components/Icons/IconSvgs.tsx +6 -0
  66. package/src/components/Icons/IconTypes.tsx +3 -0
  67. package/src/components/Image/Image.stories.mdx +2 -3
  68. package/src/components/Input/Input.stories.tsx +20 -64
  69. package/src/components/Input/_Input.scss +23 -14
  70. package/src/components/Modal/Modal.stories.mdx +3 -3
  71. package/src/components/Modal/_Modal.scss +2 -2
  72. package/src/components/Notification/Notification.stories.mdx +1 -1
  73. package/src/components/Notification/Notification.tsx +13 -4
  74. package/src/components/Pagination/Pagination.stories.mdx +3 -2
  75. package/src/components/Pagination/Pagination.stories.tsx +1 -2
  76. package/src/components/ProgressIndicator/ProgressIndicator.stories.mdx +292 -0
  77. package/src/components/ProgressIndicator/ProgressIndicator.test.tsx +225 -0
  78. package/src/components/ProgressIndicator/ProgressIndicator.tsx +126 -0
  79. package/src/components/ProgressIndicator/ProgressIndicatorTypes.ts +8 -0
  80. package/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap +357 -0
  81. package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +3 -0
  82. package/src/components/RadioGroup/RadioGroup.stories.mdx +2 -3
  83. package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +4 -0
  84. package/src/components/SearchBar/SearchBar.Test.tsx +66 -21
  85. package/src/components/SearchBar/SearchBar.stories.mdx +110 -11
  86. package/src/components/SearchBar/SearchBar.tsx +15 -5
  87. package/src/components/Select/SelectTypes.tsx +1 -0
  88. package/src/components/Slider/Slider.stories.mdx +529 -0
  89. package/src/components/Slider/Slider.test.tsx +653 -0
  90. package/src/components/Slider/Slider.tsx +303 -0
  91. package/src/components/Slider/__snapshots__/Slider.test.tsx.snap +1946 -0
  92. package/src/components/StyleGuide/Bidirectionality.stories.mdx +1 -1
  93. package/src/components/StyleGuide/Breakpoints.stories.mdx +21 -7
  94. package/src/components/StyleGuide/Buttons.stories.mdx +9 -2
  95. package/src/components/StyleGuide/DesignTokens.stories.mdx +170 -0
  96. package/src/components/Tabs/Tabs.tsx +5 -5
  97. package/src/components/Template/Template.stories.mdx +6 -6
  98. package/src/components/TextInput/TextInput.stories.mdx +1 -1
  99. package/src/components/TextInput/TextInput.tsx +15 -2
  100. package/src/components/TextInput/TextInputTypes.tsx +2 -0
  101. package/src/components/VideoPlayer/VideoPlayer.stories.mdx +2 -3
  102. package/src/docs/Chakra.stories.mdx +2 -2
  103. package/src/index.ts +12 -6
  104. package/src/resources.scss +5 -5
  105. package/src/styles/base/{_02-breakpoints.scss → _01-breakpoints.scss} +9 -10
  106. package/src/styles/base/{_03-mixins.scss → _02-mixins.scss} +16 -5
  107. package/src/styles/base/{_04-base.scss → _03-base.scss} +7 -2
  108. package/src/styles/base/{_05-focus.scss → _04-focus.scss} +0 -15
  109. package/src/styles/base/_place-holder.scss +14 -3
  110. package/src/styles/{03-space → space}/_space-inline.scss +14 -14
  111. package/src/styles/{03-space → space}/_space-inset.scss +10 -10
  112. package/src/styles/space/_space-stack.scss +116 -0
  113. package/src/styles.scss +13 -44
  114. package/src/theme/components/breadcrumb.ts +10 -0
  115. package/src/theme/components/button.ts +10 -2
  116. package/src/theme/components/card.ts +11 -9
  117. package/src/theme/components/datePicker.ts +1 -1
  118. package/src/theme/components/list.ts +2 -2
  119. package/src/theme/components/notification.ts +5 -3
  120. package/src/theme/components/progressIndicator.ts +62 -0
  121. package/src/theme/components/skeletonLoader.ts +1 -1
  122. package/src/theme/components/slider.ts +79 -0
  123. package/src/theme/foundations/breakpoints.ts +8 -8
  124. package/src/theme/foundations/global.ts +6 -1
  125. package/src/theme/index.ts +4 -0
  126. package/src/utils/componentCategories.ts +3 -3
  127. package/src/styles/01-colors/_colors-brand.scss +0 -62
  128. package/src/styles/01-colors/_colors-utility.scss +0 -67
  129. package/src/styles/02-typography/_type-scale.css +0 -11
  130. package/src/styles/02-typography/_type-weight.css +0 -7
  131. package/src/styles/02-typography/_typefaces.css +0 -4
  132. package/src/styles/03-space/_space-stack.scss +0 -116
  133. package/src/styles/03-space/_space.css +0 -30
  134. package/src/styles/base/_card-grid.scss +0 -77
  135. package/src/styles/base/_typography.scss +0 -11
@@ -0,0 +1,303 @@
1
+ import * as React from "react";
2
+ import {
3
+ Box,
4
+ RangeSlider as ChakraRangeSlider,
5
+ RangeSliderTrack as ChakraRangeSliderTrack,
6
+ RangeSliderFilledTrack as ChakraRangeSliderFilledTrack,
7
+ RangeSliderThumb as ChakraRangeSliderThumb,
8
+ Slider as ChakraSlider,
9
+ SliderTrack as ChakraSliderTrack,
10
+ SliderFilledTrack as ChakraSliderFilledTrack,
11
+ SliderThumb as ChakraSliderThumb,
12
+ useMultiStyleConfig,
13
+ } from "@chakra-ui/react";
14
+
15
+ import generateUUID from "../../helpers/generateUUID";
16
+ import Label from "../Label/Label";
17
+ import HelperErrorText from "../HelperErrorText/HelperErrorText";
18
+ import TextInput from "../TextInput/TextInput";
19
+ import { TextInputTypes } from "../TextInput/TextInputTypes";
20
+
21
+ export interface SliderProps {
22
+ /** Additional class name for the Slider component. */
23
+ className?: string;
24
+ /** The initial value for the single `Slider` or an array of two number
25
+ * values for the `isRangeSlider` case.
26
+ */
27
+ defaultValue?: number | number[];
28
+ /** Optional string to populate the HelperErrorText for standard state */
29
+ helperText?: string;
30
+ /** ID that other components can cross reference for accessibility purposes. */
31
+ id?: string;
32
+ /** Optional string to populate the `HelperErrorText` for the error state
33
+ * when `isInvalid` is true. */
34
+ invalidText?: string;
35
+ /** Adds the 'disabled' state to the slider and text input(s) when true. */
36
+ isDisabled?: boolean;
37
+ /** Adds the 'invalid' state to the slider and text input(s) when true. */
38
+ isInvalid?: boolean;
39
+ /** Offers the ability to render a slider with one value or
40
+ * a range slider with two values. */
41
+ isRangeSlider?: boolean;
42
+ /** Adds the 'required' attribute to the input(s) when true. */
43
+ isRequired?: boolean;
44
+ /** The `Slider`'s label. In the default single slider, this will be linked to
45
+ * the only `TextInput` component. In the range slider, this will be linked to
46
+ * the first `TextInput` component. If `showLabel` is false, then this value
47
+ * will be set in the `Slider`'s `aria-label` attribute. */
48
+ labelText: string;
49
+ /** Maximum value allowed. */
50
+ max?: number;
51
+ /** Minimum value allowed. */
52
+ min?: number;
53
+ /** The name prop indicates into which form this component belongs to. */
54
+ name?: string;
55
+ /** Callback function that gets the value(s) selected. */
56
+ onChange?: (val: number | number[]) => void;
57
+ /** Whether or not to display the "Required"/"Optional" text in the label text. */
58
+ optReqFlag?: boolean;
59
+ /** Offers the ability to hide the `TextInput` boxes. */
60
+ showBoxes?: boolean;
61
+ /** Offers the ability to hide the helper/invalid text. */
62
+ showHelperInvalidText?: boolean;
63
+ /** Offers the ability to show the label onscreen or hide it. Refer
64
+ * to the `labelText` property for more information. */
65
+ showLabel?: boolean;
66
+ /** Offers the ability to hide the static min/max values. */
67
+ showValues?: boolean;
68
+ /** The amount to increase or decrease when using the slider thumb(s). */
69
+ step?: number;
70
+ }
71
+
72
+ /**
73
+ * The `Slider` component renders a singular value slider or a range slider
74
+ * with a min and max value. The value(s) can be updated through the slider
75
+ * thumb(s) or through the text input(s) elements.
76
+ */
77
+ export default function Slider(props: React.PropsWithChildren<SliderProps>) {
78
+ const {
79
+ className,
80
+ defaultValue = 0,
81
+ helperText,
82
+ id = generateUUID(),
83
+ invalidText,
84
+ isDisabled = false,
85
+ isInvalid = false,
86
+ isRangeSlider = false,
87
+ isRequired = false,
88
+ labelText,
89
+ max = 100,
90
+ min = 0,
91
+ name,
92
+ onChange,
93
+ optReqFlag = true,
94
+ showBoxes = true,
95
+ showHelperInvalidText = true,
96
+ showLabel = true,
97
+ showValues = true,
98
+ step = 1,
99
+ } = props;
100
+ const [currentValue, setCurrentValue] = React.useState<typeof defaultValue>(
101
+ defaultValue
102
+ );
103
+ let finalIsInvalid = isInvalid;
104
+ // In the Range Slider, if the first value is bigger than the second value,
105
+ // then set the invalid state.
106
+ if (isRangeSlider && currentValue[0] > currentValue[1]) {
107
+ finalIsInvalid = true;
108
+ }
109
+ const optReqText = isRequired ? "Required" : "Optional";
110
+ const footnote = finalIsInvalid ? invalidText : helperText;
111
+ const styles = useMultiStyleConfig("CustomSlider", {
112
+ isDisabled,
113
+ isInvalid: finalIsInvalid,
114
+ isRangeSlider,
115
+ showBoxes,
116
+ });
117
+ // Props that the `Slider` and `RangeSlider` Chakra
118
+ // components both use.
119
+ const sliderSharedProps = {
120
+ // Don't focus on the thumbs for every small change.
121
+ focusThumbOnChange: false,
122
+ id,
123
+ isDisabled,
124
+ max,
125
+ min,
126
+ name,
127
+ onChange: (val) => setCurrentValue(val),
128
+ // Call the passed in `onChange` function prop to get the
129
+ // *final* value once a user stops dragging the slider.
130
+ onChangeEnd: (val) => onChange(val),
131
+ step,
132
+ };
133
+ // Props that the two `TextInput` components use.
134
+ const textInputSharedProps = {
135
+ attributes: { max, min },
136
+ isDisabled,
137
+ isInvalid: finalIsInvalid,
138
+ isRequired,
139
+ // Never show the label or helper text for the `TextInput` component.
140
+ showHelperInvalidText: false,
141
+ showLabel: false,
142
+ step,
143
+ type: TextInputTypes.number,
144
+ };
145
+ /**
146
+ * This returns either the "start" or "end" `TextInput` component. Note that
147
+ * the "end" `TextInput` component is always rendered but the "start" is
148
+ * only used for the `isRangeSlider` case.
149
+ */
150
+ const getTextInput = (type: "start" | "end") => {
151
+ const inputProps = {
152
+ start: {
153
+ // We only want the value for this box in the `isRangeSlider` case.
154
+ value: isRangeSlider ? currentValue[0].toString() : "",
155
+ onChange: (val) => {
156
+ // If the value is empty, set it to 0.
157
+ let nextValue = parseInt(val.target.value, 10)
158
+ ? parseInt(val.target.value, 10)
159
+ : 0;
160
+ // Only update the first value in the range.
161
+ const newValue = [nextValue, currentValue[1]];
162
+ setCurrentValue(newValue);
163
+ // If the text input was updated directly,
164
+ // send the data back to the user.
165
+ onChange && onChange(newValue);
166
+ },
167
+ ...textInputSharedProps,
168
+ },
169
+ end: {
170
+ // This text input *always* shows. In the default case, we only
171
+ // keep track of one value. For the `isRangeSlider` case, we keep
172
+ // track of an array but only want the second value.
173
+ value: isRangeSlider
174
+ ? currentValue[1].toString()
175
+ : currentValue.toString(),
176
+ onChange: (val) => {
177
+ // If the value is empty, set it to 0.
178
+ let nextValue = parseInt(val.target.value, 10)
179
+ ? parseInt(val.target.value, 10)
180
+ : 0;
181
+ // If the value entered is bigger than the max value,
182
+ // then set it to the max value.
183
+ if (nextValue > max) {
184
+ nextValue = max;
185
+ }
186
+ // Only update the second value in the `isRangeSlider` case,
187
+ // or the single value in the default case.
188
+ const newValue = isRangeSlider
189
+ ? [currentValue[0], nextValue]
190
+ : nextValue;
191
+ setCurrentValue(newValue);
192
+ // If the text input was updated directly,
193
+ // send the data back to the user.
194
+ onChange && onChange(newValue);
195
+ },
196
+ ...textInputSharedProps,
197
+ },
198
+ };
199
+ const updatedLabel = !isRangeSlider
200
+ ? labelText
201
+ : `${labelText} - ${type} value`;
202
+ return (
203
+ <TextInput
204
+ id={`${id}-textInput-${type}`}
205
+ labelText={updatedLabel}
206
+ additionalStyles={{
207
+ ...styles.textInput,
208
+ // Specific margins for each text input to
209
+ // push the elements inside.
210
+ marginRight: type === "start" ? "s" : null,
211
+ marginLeft: type === "end" ? "s" : null,
212
+ }}
213
+ {...inputProps[type]}
214
+ />
215
+ );
216
+ };
217
+ /**
218
+ * Returns a Chakra `Slider` or `RangeSlider` component based on the
219
+ * `isRangeSlider` prop from the DS `Slider` component.
220
+ */
221
+ const getSliderType = () => {
222
+ return isRangeSlider ? (
223
+ <ChakraRangeSlider
224
+ // Both slider thumbs need values and should be in an array.
225
+ aria-label={
226
+ !showLabel
227
+ ? [`${labelText} - start value`, `${labelText} - end value`]
228
+ : null
229
+ }
230
+ // Both slider thumbs need values and should be in an array,
231
+ // even if it's the same label.
232
+ aria-labelledby={showLabel ? [`${id}-label`, `${id}-label`] : null}
233
+ value={currentValue as number[]}
234
+ // Make the thumbs larger.
235
+ size="lg"
236
+ {...sliderSharedProps}
237
+ >
238
+ <ChakraRangeSliderTrack sx={styles.track}>
239
+ <ChakraRangeSliderFilledTrack sx={styles.filledTrack} />
240
+ </ChakraRangeSliderTrack>
241
+ <ChakraRangeSliderThumb index={0} sx={styles.thumb} />
242
+ <ChakraRangeSliderThumb index={1} sx={styles.thumb} />
243
+ </ChakraRangeSlider>
244
+ ) : (
245
+ <ChakraSlider
246
+ aria-label={!showLabel ? labelText : null}
247
+ aria-labelledby={`${id}-label`}
248
+ value={currentValue as number}
249
+ // Make the thumb larger.
250
+ size="lg"
251
+ {...sliderSharedProps}
252
+ >
253
+ <ChakraSliderTrack sx={styles.track}>
254
+ <ChakraSliderFilledTrack sx={styles.filledTrack} />
255
+ </ChakraSliderTrack>
256
+ <ChakraSliderThumb sx={styles.thumb} />
257
+ </ChakraSlider>
258
+ );
259
+ };
260
+
261
+ return (
262
+ <Box className={className} __css={styles}>
263
+ {showLabel && (
264
+ <Label
265
+ id={`${id}-label`}
266
+ // We can't target the slider thumbs since those are divs and we
267
+ // should link the label somewhere. So either target the first
268
+ // input box in a `RangeSlider` or the only input box in a `Slider`.
269
+ // When the input fields are not visible, remove this attribute.
270
+ htmlFor={
271
+ showBoxes
272
+ ? `${id}-textInput-${isRangeSlider ? "start" : "end"}`
273
+ : null
274
+ }
275
+ optReqFlag={optReqFlag && optReqText}
276
+ >
277
+ {labelText}
278
+ </Label>
279
+ )}
280
+
281
+ <Box __css={styles.container}>
282
+ {/* Only show the start input box for the `isRangeSlider` case. */}
283
+ {showBoxes && isRangeSlider && getTextInput("start")}
284
+
285
+ {showValues && <Box __css={styles.leftValue}>{min}</Box>}
286
+
287
+ {getSliderType()}
288
+
289
+ {showValues && <Box __css={styles.rightValue}>{max}</Box>}
290
+
291
+ {showBoxes && getTextInput("end")}
292
+ </Box>
293
+
294
+ {footnote && showHelperInvalidText && (
295
+ <Box __css={styles.helper}>
296
+ <HelperErrorText id={`${id}-helperText`} isInvalid={finalIsInvalid}>
297
+ {footnote}
298
+ </HelperErrorText>
299
+ </Box>
300
+ )}
301
+ </Box>
302
+ );
303
+ }