@nypl/design-system-react-components 0.25.12 → 0.25.13
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 +63 -1
- package/dist/components/Accordion/Accordion.d.ts +5 -3
- package/dist/components/Accordion/AccordionTypes.d.ts +5 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +3 -3
- package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +1 -1
- package/dist/components/Card/Card.d.ts +11 -20
- package/dist/components/Checkbox/Checkbox.d.ts +1 -1
- package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +4 -2
- package/dist/components/Heading/Heading.d.ts +4 -4
- package/dist/components/Heading/HeadingTypes.d.ts +1 -1
- package/dist/components/Hero/Hero.d.ts +7 -4
- package/dist/components/Icons/IconTypes.d.ts +1 -0
- package/dist/components/Image/Image.d.ts +25 -7
- package/dist/components/Image/ImageTypes.d.ts +4 -4
- package/dist/components/Logo/LogoTypes.d.ts +2 -2
- package/dist/components/Notification/Notification.d.ts +4 -4
- package/dist/components/Radio/Radio.d.ts +1 -1
- package/dist/components/RadioGroup/RadioGroup.d.ts +4 -2
- package/dist/components/Select/Select.d.ts +2 -2
- package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +4 -3
- package/dist/components/SkeletonLoader/SkeletonLoaderTypes.d.ts +0 -4
- package/dist/components/StructuredContent/StructuredContent.d.ts +9 -22
- package/dist/components/Tabs/Tabs.d.ts +3 -3
- package/dist/components/Template/Template.d.ts +13 -5
- package/dist/components/Text/Text.d.ts +3 -3
- package/dist/components/Text/TextTypes.d.ts +1 -1
- package/dist/components/TextInput/TextInput.d.ts +2 -2
- package/dist/components/Toggle/Toggle.d.ts +6 -7
- package/dist/components/Toggle/{ToggleSizes.d.ts → ToggleTypes.d.ts} +1 -1
- package/dist/design-system-react-components.cjs.development.js +505 -422
- 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 +514 -435
- package/dist/design-system-react-components.esm.js.map +1 -1
- package/dist/helpers/enums.d.ts +4 -0
- package/dist/index.d.ts +7 -8
- package/dist/theme/components/accordion.d.ts +7 -12
- package/dist/theme/components/breadcrumb.d.ts +3 -0
- package/dist/theme/components/card.d.ts +4 -4
- package/dist/theme/components/checkbox.d.ts +1 -0
- package/dist/theme/components/checkboxGroup.d.ts +3 -1
- package/dist/theme/components/global.d.ts +2 -1
- package/dist/theme/components/hero.d.ts +1 -1
- package/dist/theme/components/image.d.ts +1 -1
- package/dist/theme/components/notification.d.ts +4 -4
- package/dist/theme/components/pagination.d.ts +2 -5
- package/dist/theme/components/radio.d.ts +1 -0
- package/dist/theme/components/radioGroup.d.ts +3 -1
- package/dist/theme/components/select.d.ts +3 -0
- package/dist/theme/components/toggle.d.ts +13 -1
- package/package.json +1 -1
- package/src/components/AccessibilityGuide/SkipNavigation.stories.mdx +34 -0
- package/src/components/Accordion/Accordion.stories.mdx +150 -66
- package/src/components/Accordion/Accordion.test.tsx +44 -17
- package/src/components/Accordion/Accordion.tsx +50 -20
- package/src/components/Accordion/AccordionTypes.tsx +5 -0
- package/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +244 -2
- package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +17 -15
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +6 -6
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +6 -6
- package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +1 -1
- package/src/components/Card/Card.stories.mdx +236 -165
- package/src/components/Card/Card.test.tsx +36 -18
- package/src/components/Card/Card.tsx +84 -59
- package/src/components/Card/__snapshots__/Card.test.tsx.snap +25 -65
- package/src/components/Chakra/Center.stories.mdx +2 -2
- package/src/components/Checkbox/Checkbox.stories.mdx +13 -1
- package/src/components/Checkbox/Checkbox.test.tsx +58 -2
- package/src/components/Checkbox/Checkbox.tsx +6 -1
- package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +76 -0
- package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +73 -9
- package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +79 -9
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +10 -7
- package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +169 -0
- package/src/components/ComponentWrapper/ComponentWrapper.tsx +1 -1
- package/src/components/DatePicker/DatePicker.test.tsx +5 -2
- package/src/components/DatePicker/DatePicker.tsx +5 -2
- package/src/components/Form/Form.stories.mdx +47 -9
- package/src/components/Form/Form.test.tsx +1 -1
- package/src/components/Form/Form.tsx +3 -1
- package/src/components/Grid/SimpleGrid.stories.mdx +53 -35
- package/src/components/Grid/SimpleGrid.test.tsx +15 -9
- package/src/components/Heading/Heading.stories.mdx +21 -23
- package/src/components/Heading/Heading.test.tsx +7 -7
- package/src/components/Heading/Heading.tsx +10 -14
- package/src/components/Heading/HeadingTypes.tsx +1 -1
- package/src/components/Heading/__snapshots__/Heading.test.tsx.snap +1 -1
- package/src/components/Hero/Hero.stories.mdx +27 -27
- package/src/components/Hero/Hero.test.tsx +113 -58
- package/src/components/Hero/Hero.tsx +43 -20
- package/src/components/HorizontalRule/HorizontalRule.test.tsx +6 -4
- package/src/components/HorizontalRule/HorizontalRule.tsx +3 -2
- package/src/components/Icons/Icon.stories.mdx +50 -18
- package/src/components/Icons/Icon.test.tsx +13 -2
- package/src/components/Icons/Icon.tsx +11 -6
- package/src/components/Icons/IconTypes.tsx +1 -0
- package/src/components/Image/Image.stories.mdx +133 -68
- package/src/components/Image/Image.test.tsx +32 -48
- package/src/components/Image/Image.tsx +46 -26
- package/src/components/Image/ImageTypes.ts +4 -4
- package/src/components/Image/__snapshots__/Image.test.tsx.snap +60 -13
- package/src/components/Link/Link.tsx +8 -1
- package/src/components/List/List.stories.mdx +1 -1
- package/src/components/List/List.test.tsx +7 -4
- package/src/components/List/List.tsx +7 -4
- package/src/components/Logo/Logo.stories.mdx +13 -13
- package/src/components/Logo/Logo.test.tsx +12 -2
- package/src/components/Logo/Logo.tsx +10 -5
- package/src/components/Logo/LogoTypes.tsx +1 -1
- package/src/components/Notification/Notification.stories.mdx +5 -5
- package/src/components/Notification/Notification.tsx +10 -10
- package/src/components/Pagination/Pagination.stories.mdx +4 -3
- package/src/components/Pagination/Pagination.test.tsx +30 -2
- package/src/components/Pagination/Pagination.tsx +6 -3
- package/src/components/ProgressIndicator/ProgressIndicator.stories.mdx +1 -1
- package/src/components/ProgressIndicator/ProgressIndicator.test.tsx +6 -2
- package/src/components/ProgressIndicator/ProgressIndicator.tsx +3 -1
- package/src/components/Radio/Radio.stories.mdx +13 -1
- package/src/components/Radio/Radio.test.tsx +56 -2
- package/src/components/Radio/Radio.tsx +6 -1
- package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +61 -0
- package/src/components/RadioGroup/RadioGroup.stories.mdx +73 -9
- package/src/components/RadioGroup/RadioGroup.test.tsx +72 -7
- package/src/components/RadioGroup/RadioGroup.tsx +10 -7
- package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +140 -0
- package/src/components/SearchBar/SearchBar.stories.mdx +1 -1
- package/src/components/SearchBar/SearchBar.tsx +3 -3
- package/src/components/Select/Select.stories.mdx +26 -16
- package/src/components/Select/Select.test.tsx +1 -36
- package/src/components/Select/Select.tsx +4 -16
- package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +12 -14
- package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +6 -8
- package/src/components/SkeletonLoader/SkeletonLoader.tsx +5 -7
- package/src/components/SkeletonLoader/SkeletonLoaderTypes.tsx +0 -5
- package/src/components/Slider/Slider.stories.mdx +41 -8
- package/src/components/Slider/Slider.tsx +4 -4
- package/src/components/StatusBadge/StatusBadge.test.tsx +3 -1
- package/src/components/StatusBadge/StatusBadge.tsx +1 -1
- package/src/components/StructuredContent/StructuredContent.stories.mdx +103 -54
- package/src/components/StructuredContent/StructuredContent.test.tsx +129 -102
- package/src/components/StructuredContent/StructuredContent.tsx +43 -53
- package/src/components/StyleGuide/ColorCard.tsx +3 -3
- package/src/components/StyleGuide/Typography.stories.mdx +17 -12
- package/src/components/Table/Table.test.tsx +1 -1
- package/src/components/Table/Table.tsx +3 -1
- package/src/components/Tabs/Tabs.stories.mdx +8 -8
- package/src/components/Tabs/Tabs.test.tsx +13 -11
- package/src/components/Tabs/Tabs.tsx +18 -15
- package/src/components/Template/Template.stories.mdx +62 -25
- package/src/components/Template/Template.test.tsx +35 -5
- package/src/components/Template/Template.tsx +26 -13
- package/src/components/Template/__snapshots__/Template.test.tsx.snap +4 -2
- package/src/components/Text/Text.stories.mdx +13 -15
- package/src/components/Text/Text.test.tsx +6 -15
- package/src/components/Text/Text.tsx +7 -12
- package/src/components/Text/TextTypes.tsx +1 -1
- package/src/components/TextInput/TextInput.stories.mdx +9 -9
- package/src/components/TextInput/TextInput.test.tsx +28 -27
- package/src/components/TextInput/TextInput.tsx +4 -4
- package/src/components/Toggle/Toggle.stories.mdx +12 -22
- package/src/components/Toggle/Toggle.test.tsx +15 -2
- package/src/components/Toggle/Toggle.tsx +8 -9
- package/src/components/Toggle/{ToggleSizes.tsx → ToggleTypes.tsx} +1 -1
- package/src/components/Toggle/__snapshots__/Toggle.test.tsx.snap +64 -0
- package/src/components/VideoPlayer/VideoPlayer.test.tsx +18 -6
- package/src/components/VideoPlayer/VideoPlayer.tsx +14 -7
- package/src/docs/{Intro.stories.mdx → Welcome.stories.mdx} +5 -9
- package/src/{components/Card/CardTypes.tsx → helpers/enums.ts} +2 -2
- package/src/hooks/tests/useNYPLTheme.test.tsx +1 -1
- package/src/hooks/useCarouselStyles.stories.mdx +10 -0
- package/src/hooks/useNYPLTheme.ts +1 -1
- package/src/index.ts +7 -14
- package/src/theme/components/accordion.ts +7 -12
- package/src/theme/components/breadcrumb.ts +3 -0
- package/src/theme/components/card.ts +29 -20
- package/src/theme/components/checkboxGroup.ts +3 -1
- package/src/theme/components/global.ts +4 -3
- package/src/theme/components/hero.ts +1 -1
- package/src/theme/components/icon.ts +5 -2
- package/src/theme/components/image.ts +1 -1
- package/src/theme/components/list.ts +1 -1
- package/src/theme/components/notification.ts +5 -5
- package/src/theme/components/pagination.ts +2 -5
- package/src/theme/components/progressIndicator.ts +3 -3
- package/src/theme/components/radioGroup.ts +3 -1
- package/src/theme/components/select.ts +6 -0
- package/src/theme/components/toggle.ts +26 -3
- package/src/utils/componentCategories.ts +27 -19
- package/dist/components/Card/CardTypes.d.ts +0 -4
- package/dist/components/CheckboxGroup/CheckboxGroupLayoutTypes.d.ts +0 -4
- package/dist/components/RadioGroup/RadioGroupLayoutTypes.d.ts +0 -4
- package/src/components/CheckboxGroup/CheckboxGroupLayoutTypes.tsx +0 -4
- package/src/components/RadioGroup/RadioGroupLayoutTypes.tsx +0 -4
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Flex, Spacer } from "@chakra-ui/react";
|
|
2
2
|
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
3
4
|
import { axe } from "jest-axe";
|
|
5
|
+
import * as React from "react";
|
|
4
6
|
import renderer from "react-test-renderer";
|
|
5
7
|
|
|
6
|
-
// import * as generateUUID from "../../helpers/generateUUID";
|
|
7
8
|
import RadioGroup from "./RadioGroup";
|
|
8
9
|
import Radio from "../Radio/Radio";
|
|
9
|
-
import {
|
|
10
|
-
import userEvent from "@testing-library/user-event";
|
|
10
|
+
import { LayoutTypes } from "../../helpers/enums";
|
|
11
11
|
|
|
12
12
|
describe("Radio Accessibility", () => {
|
|
13
|
-
it("passes axe accessibility", async () => {
|
|
13
|
+
it("passes axe accessibility with string labels", async () => {
|
|
14
14
|
const { container } = render(
|
|
15
15
|
<RadioGroup labelText="RadioGroup example" name="a11y-test">
|
|
16
16
|
<Radio value="2" labelText="Radio 2" />
|
|
@@ -21,6 +21,36 @@ describe("Radio Accessibility", () => {
|
|
|
21
21
|
);
|
|
22
22
|
expect(await axe(container)).toHaveNoViolations();
|
|
23
23
|
});
|
|
24
|
+
|
|
25
|
+
it("passes axe accessibility with jsx labels", async () => {
|
|
26
|
+
const { container } = render(
|
|
27
|
+
<RadioGroup labelText="RadioGroup example" name="a11y-test" isFullWidth>
|
|
28
|
+
<Radio
|
|
29
|
+
id="arts"
|
|
30
|
+
labelText={
|
|
31
|
+
<Flex>
|
|
32
|
+
<span>Arts</span>
|
|
33
|
+
<Spacer />
|
|
34
|
+
<span>4</span>
|
|
35
|
+
</Flex>
|
|
36
|
+
}
|
|
37
|
+
value="arts"
|
|
38
|
+
/>
|
|
39
|
+
<Radio
|
|
40
|
+
id="English"
|
|
41
|
+
labelText={
|
|
42
|
+
<Flex>
|
|
43
|
+
<span>English</span>
|
|
44
|
+
<Spacer />
|
|
45
|
+
<span>23</span>
|
|
46
|
+
</Flex>
|
|
47
|
+
}
|
|
48
|
+
value="English"
|
|
49
|
+
/>
|
|
50
|
+
</RadioGroup>
|
|
51
|
+
);
|
|
52
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
53
|
+
});
|
|
24
54
|
});
|
|
25
55
|
|
|
26
56
|
describe("Radio Button", () => {
|
|
@@ -233,7 +263,7 @@ describe("Radio Button", () => {
|
|
|
233
263
|
labelText="row"
|
|
234
264
|
name="row"
|
|
235
265
|
id="row"
|
|
236
|
-
layout={
|
|
266
|
+
layout={LayoutTypes.Row}
|
|
237
267
|
>
|
|
238
268
|
<Radio value="2" labelText="Radio 2" id="radio-2" />
|
|
239
269
|
<Radio value="3" labelText="Radio 3" id="radio-3" />
|
|
@@ -326,6 +356,39 @@ describe("Radio Button", () => {
|
|
|
326
356
|
</RadioGroup>
|
|
327
357
|
)
|
|
328
358
|
.toJSON();
|
|
359
|
+
const withJSXRadioLabels = renderer
|
|
360
|
+
.create(
|
|
361
|
+
<RadioGroup
|
|
362
|
+
id="jsxLabels"
|
|
363
|
+
isFullWidth
|
|
364
|
+
labelText="RadioGroup example"
|
|
365
|
+
name="a11y-test"
|
|
366
|
+
>
|
|
367
|
+
<Radio
|
|
368
|
+
id="arts"
|
|
369
|
+
labelText={
|
|
370
|
+
<Flex>
|
|
371
|
+
<span>Arts</span>
|
|
372
|
+
<Spacer />
|
|
373
|
+
<span>4</span>
|
|
374
|
+
</Flex>
|
|
375
|
+
}
|
|
376
|
+
value="arts"
|
|
377
|
+
/>
|
|
378
|
+
<Radio
|
|
379
|
+
id="English"
|
|
380
|
+
labelText={
|
|
381
|
+
<Flex>
|
|
382
|
+
<span>English</span>
|
|
383
|
+
<Spacer />
|
|
384
|
+
<span>23</span>
|
|
385
|
+
</Flex>
|
|
386
|
+
}
|
|
387
|
+
value="English"
|
|
388
|
+
/>
|
|
389
|
+
</RadioGroup>
|
|
390
|
+
)
|
|
391
|
+
.toJSON();
|
|
329
392
|
|
|
330
393
|
expect(column).toMatchSnapshot();
|
|
331
394
|
expect(row).toMatchSnapshot();
|
|
@@ -336,6 +399,7 @@ describe("Radio Button", () => {
|
|
|
336
399
|
expect(isRequired).toMatchSnapshot();
|
|
337
400
|
expect(isInvalid).toMatchSnapshot();
|
|
338
401
|
expect(isDisabled).toMatchSnapshot();
|
|
402
|
+
expect(withJSXRadioLabels).toMatchSnapshot();
|
|
339
403
|
});
|
|
340
404
|
|
|
341
405
|
it("should throw warning when a non-Radio component is used as a child", () => {
|
|
@@ -346,7 +410,8 @@ describe("Radio Button", () => {
|
|
|
346
410
|
</RadioGroup>
|
|
347
411
|
);
|
|
348
412
|
expect(warn).toHaveBeenCalledWith(
|
|
349
|
-
"Only `Radio` components are allowed inside
|
|
413
|
+
"NYPL Reservoir RadioGroup: Only `Radio` components are allowed inside " +
|
|
414
|
+
"the `RadioGroup` component."
|
|
350
415
|
);
|
|
351
416
|
});
|
|
352
417
|
});
|
|
@@ -12,7 +12,7 @@ import HelperErrorText, {
|
|
|
12
12
|
} from "../HelperErrorText/HelperErrorText";
|
|
13
13
|
import { spacing } from "../../theme/foundations/spacing";
|
|
14
14
|
import Radio from "../Radio/Radio";
|
|
15
|
-
import {
|
|
15
|
+
import { LayoutTypes } from "../../helpers/enums";
|
|
16
16
|
import generateUUID from "../../helpers/generateUUID";
|
|
17
17
|
|
|
18
18
|
export interface RadioGroupProps {
|
|
@@ -28,6 +28,8 @@ export interface RadioGroupProps {
|
|
|
28
28
|
invalidText?: HelperErrorTextType;
|
|
29
29
|
/** Adds the 'disabled' prop to the input when true. */
|
|
30
30
|
isDisabled?: boolean;
|
|
31
|
+
/** Set's the `Radio`s' wrapper to be full width. */
|
|
32
|
+
isFullWidth?: boolean;
|
|
31
33
|
/** Adds the 'aria-invalid' attribute to the input and
|
|
32
34
|
* sets the error state when true. */
|
|
33
35
|
isInvalid?: boolean;
|
|
@@ -37,7 +39,7 @@ export interface RadioGroupProps {
|
|
|
37
39
|
* true, or an "aria-label" if `showLabel` is false. */
|
|
38
40
|
labelText: string;
|
|
39
41
|
/** Renders the Radio buttons in a row or column (default). */
|
|
40
|
-
layout?:
|
|
42
|
+
layout?: LayoutTypes;
|
|
41
43
|
/** The `name` prop indicates the form group for all the Radio children. */
|
|
42
44
|
name: string;
|
|
43
45
|
/** The action to perform on the `<input>`'s onChange function */
|
|
@@ -68,10 +70,11 @@ const RadioGroup = React.forwardRef<
|
|
|
68
70
|
id = generateUUID(),
|
|
69
71
|
invalidText,
|
|
70
72
|
isDisabled = false,
|
|
73
|
+
isFullWidth = false,
|
|
71
74
|
isInvalid = false,
|
|
72
75
|
isRequired = false,
|
|
73
76
|
labelText,
|
|
74
|
-
layout =
|
|
77
|
+
layout = LayoutTypes.Column,
|
|
75
78
|
name,
|
|
76
79
|
onChange = onChangeDefault,
|
|
77
80
|
optReqFlag = true,
|
|
@@ -79,8 +82,7 @@ const RadioGroup = React.forwardRef<
|
|
|
79
82
|
showLabel = true,
|
|
80
83
|
} = props;
|
|
81
84
|
const footnote: HelperErrorTextType = isInvalid ? invalidText : helperText;
|
|
82
|
-
const spacingProp =
|
|
83
|
-
layout === RadioGroupLayoutTypes.Column ? spacing.s : spacing.l;
|
|
85
|
+
const spacingProp = layout === LayoutTypes.Column ? spacing.s : spacing.l;
|
|
84
86
|
const newChildren = [];
|
|
85
87
|
|
|
86
88
|
// Use Chakra's RadioGroup hook to set and get the proper props
|
|
@@ -100,7 +102,8 @@ const RadioGroup = React.forwardRef<
|
|
|
100
102
|
noop();
|
|
101
103
|
} else {
|
|
102
104
|
console.warn(
|
|
103
|
-
"Only `Radio` components are allowed
|
|
105
|
+
"NYPL Reservoir RadioGroup: Only `Radio` components are allowed " +
|
|
106
|
+
"inside the `RadioGroup` component."
|
|
104
107
|
);
|
|
105
108
|
}
|
|
106
109
|
}
|
|
@@ -121,7 +124,7 @@ const RadioGroup = React.forwardRef<
|
|
|
121
124
|
});
|
|
122
125
|
|
|
123
126
|
// Get the Chakra-based styles for the custom elements in this component.
|
|
124
|
-
const styles = useMultiStyleConfig("RadioGroup", {});
|
|
127
|
+
const styles = useMultiStyleConfig("RadioGroup", { isFullWidth });
|
|
125
128
|
|
|
126
129
|
return (
|
|
127
130
|
<Fieldset
|
|
@@ -1072,3 +1072,143 @@ exports[`Radio Button renders the UI snapshot correctly 9`] = `
|
|
|
1072
1072
|
</div>
|
|
1073
1073
|
</fieldset>
|
|
1074
1074
|
`;
|
|
1075
|
+
|
|
1076
|
+
exports[`Radio Button renders the UI snapshot correctly 10`] = `
|
|
1077
|
+
<fieldset
|
|
1078
|
+
className=" css-0"
|
|
1079
|
+
id="radio-group-jsxLabels"
|
|
1080
|
+
>
|
|
1081
|
+
<legend>
|
|
1082
|
+
RadioGroup example
|
|
1083
|
+
<div
|
|
1084
|
+
className="css-0"
|
|
1085
|
+
>
|
|
1086
|
+
Optional
|
|
1087
|
+
</div>
|
|
1088
|
+
</legend>
|
|
1089
|
+
<div
|
|
1090
|
+
aria-label={null}
|
|
1091
|
+
className="chakra-stack css-1wdv1uh"
|
|
1092
|
+
role="radiogroup"
|
|
1093
|
+
>
|
|
1094
|
+
<label
|
|
1095
|
+
className="chakra-radio css-13p0l12"
|
|
1096
|
+
>
|
|
1097
|
+
<input
|
|
1098
|
+
checked={false}
|
|
1099
|
+
className="chakra-radio__input"
|
|
1100
|
+
disabled={false}
|
|
1101
|
+
id="arts"
|
|
1102
|
+
name="a11y-test"
|
|
1103
|
+
onBlur={[Function]}
|
|
1104
|
+
onChange={[Function]}
|
|
1105
|
+
onFocus={[Function]}
|
|
1106
|
+
onKeyDown={[Function]}
|
|
1107
|
+
onKeyUp={[Function]}
|
|
1108
|
+
required={false}
|
|
1109
|
+
style={
|
|
1110
|
+
Object {
|
|
1111
|
+
"border": "0px",
|
|
1112
|
+
"clip": "rect(0px, 0px, 0px, 0px)",
|
|
1113
|
+
"height": "1px",
|
|
1114
|
+
"margin": "-1px",
|
|
1115
|
+
"overflow": "hidden",
|
|
1116
|
+
"padding": "0px",
|
|
1117
|
+
"position": "absolute",
|
|
1118
|
+
"whiteSpace": "nowrap",
|
|
1119
|
+
"width": "1px",
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
type="radio"
|
|
1123
|
+
value="arts"
|
|
1124
|
+
/>
|
|
1125
|
+
<span
|
|
1126
|
+
aria-hidden={true}
|
|
1127
|
+
className="css-ssalds"
|
|
1128
|
+
onMouseDown={[Function]}
|
|
1129
|
+
onMouseEnter={[Function]}
|
|
1130
|
+
onMouseLeave={[Function]}
|
|
1131
|
+
onMouseUp={[Function]}
|
|
1132
|
+
/>
|
|
1133
|
+
<span
|
|
1134
|
+
className="chakra-radio__label css-1y8kf23"
|
|
1135
|
+
onMouseDown={[Function]}
|
|
1136
|
+
onTouchStart={[Function]}
|
|
1137
|
+
>
|
|
1138
|
+
<div
|
|
1139
|
+
className="css-k008qs"
|
|
1140
|
+
>
|
|
1141
|
+
<span>
|
|
1142
|
+
Arts
|
|
1143
|
+
</span>
|
|
1144
|
+
<div
|
|
1145
|
+
className="css-17xejub"
|
|
1146
|
+
/>
|
|
1147
|
+
<span>
|
|
1148
|
+
4
|
|
1149
|
+
</span>
|
|
1150
|
+
</div>
|
|
1151
|
+
</span>
|
|
1152
|
+
</label>
|
|
1153
|
+
<label
|
|
1154
|
+
className="chakra-radio css-13p0l12"
|
|
1155
|
+
>
|
|
1156
|
+
<input
|
|
1157
|
+
checked={false}
|
|
1158
|
+
className="chakra-radio__input"
|
|
1159
|
+
disabled={false}
|
|
1160
|
+
id="English"
|
|
1161
|
+
name="a11y-test"
|
|
1162
|
+
onBlur={[Function]}
|
|
1163
|
+
onChange={[Function]}
|
|
1164
|
+
onFocus={[Function]}
|
|
1165
|
+
onKeyDown={[Function]}
|
|
1166
|
+
onKeyUp={[Function]}
|
|
1167
|
+
required={false}
|
|
1168
|
+
style={
|
|
1169
|
+
Object {
|
|
1170
|
+
"border": "0px",
|
|
1171
|
+
"clip": "rect(0px, 0px, 0px, 0px)",
|
|
1172
|
+
"height": "1px",
|
|
1173
|
+
"margin": "-1px",
|
|
1174
|
+
"overflow": "hidden",
|
|
1175
|
+
"padding": "0px",
|
|
1176
|
+
"position": "absolute",
|
|
1177
|
+
"whiteSpace": "nowrap",
|
|
1178
|
+
"width": "1px",
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
type="radio"
|
|
1182
|
+
value="English"
|
|
1183
|
+
/>
|
|
1184
|
+
<span
|
|
1185
|
+
aria-hidden={true}
|
|
1186
|
+
className="css-ssalds"
|
|
1187
|
+
onMouseDown={[Function]}
|
|
1188
|
+
onMouseEnter={[Function]}
|
|
1189
|
+
onMouseLeave={[Function]}
|
|
1190
|
+
onMouseUp={[Function]}
|
|
1191
|
+
/>
|
|
1192
|
+
<span
|
|
1193
|
+
className="chakra-radio__label css-1y8kf23"
|
|
1194
|
+
onMouseDown={[Function]}
|
|
1195
|
+
onTouchStart={[Function]}
|
|
1196
|
+
>
|
|
1197
|
+
<div
|
|
1198
|
+
className="css-k008qs"
|
|
1199
|
+
>
|
|
1200
|
+
<span>
|
|
1201
|
+
English
|
|
1202
|
+
</span>
|
|
1203
|
+
<div
|
|
1204
|
+
className="css-17xejub"
|
|
1205
|
+
/>
|
|
1206
|
+
<span>
|
|
1207
|
+
23
|
|
1208
|
+
</span>
|
|
1209
|
+
</div>
|
|
1210
|
+
</span>
|
|
1211
|
+
</label>
|
|
1212
|
+
</div>
|
|
1213
|
+
</fieldset>
|
|
1214
|
+
`;
|
|
@@ -129,7 +129,7 @@ export default function SearchBar(props: SearchBarProps) {
|
|
|
129
129
|
labelText={selectProps?.labelText}
|
|
130
130
|
name={selectProps?.name}
|
|
131
131
|
onChange={selectProps?.onChange}
|
|
132
|
-
|
|
132
|
+
selectType={SelectTypes.SearchBar}
|
|
133
133
|
{...stateProps}
|
|
134
134
|
>
|
|
135
135
|
{selectProps?.optionsData.map((option) => (
|
|
@@ -147,12 +147,12 @@ export default function SearchBar(props: SearchBarProps) {
|
|
|
147
147
|
name={textInputProps?.name}
|
|
148
148
|
onChange={textInputProps?.onChange}
|
|
149
149
|
placeholder={textInputPlaceholder}
|
|
150
|
-
|
|
151
|
-
variantType={
|
|
150
|
+
textInputType={
|
|
152
151
|
selectElem
|
|
153
152
|
? TextInputVariants.SearchBarSelect
|
|
154
153
|
: TextInputVariants.SearchBar
|
|
155
154
|
}
|
|
155
|
+
type={TextInputTypes.text}
|
|
156
156
|
value={textInputProps?.value}
|
|
157
157
|
{...stateProps}
|
|
158
158
|
/>
|
|
@@ -54,7 +54,7 @@ export const enumValues = getStorybookEnumValues(SelectTypes, "SelectTypes");
|
|
|
54
54
|
showOptReqLabel: {
|
|
55
55
|
table: { defaultValue: { summary: true } },
|
|
56
56
|
},
|
|
57
|
-
|
|
57
|
+
selectType: {
|
|
58
58
|
control: false,
|
|
59
59
|
table: { defaultValue: { summary: "SelectTypes.Default" } },
|
|
60
60
|
},
|
|
@@ -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.
|
|
70
|
+
| Latest | `0.25.13` |
|
|
71
71
|
|
|
72
72
|
<Description of={Select} />
|
|
73
73
|
|
|
@@ -77,19 +77,6 @@ prop, regardless of the label visibility. Additionally, while the `id` prop is
|
|
|
77
77
|
optional, a unique `id` attribute is necessary for accessibility. If the prop
|
|
78
78
|
is left blank, a value will be generated for you.
|
|
79
79
|
|
|
80
|
-
The `Select` component renders all the necessary wrapping and associated text
|
|
81
|
-
elements, but the select options _need_ to be child `<option>` HTML elements.
|
|
82
|
-
|
|
83
|
-
```jsx
|
|
84
|
-
<Select labelText="What is your favorite color?" name="color">
|
|
85
|
-
<option value="red">Red</option>
|
|
86
|
-
<option value="green">Green</option>
|
|
87
|
-
<option value="blue">Blue</option>
|
|
88
|
-
<option value="black">Black</option>
|
|
89
|
-
<option value="white">White</option>
|
|
90
|
-
</Select>
|
|
91
|
-
```
|
|
92
|
-
|
|
93
80
|
<Canvas withToolbar>
|
|
94
81
|
<Story
|
|
95
82
|
name="Select with Controls"
|
|
@@ -107,7 +94,7 @@ elements, but the select options _need_ to be child `<option>` HTML elements.
|
|
|
107
94
|
showHelperInvalidText: undefined,
|
|
108
95
|
showLabel: true,
|
|
109
96
|
showOptReqLabel: true,
|
|
110
|
-
|
|
97
|
+
selectType: SelectTypes.Default,
|
|
111
98
|
value: undefined,
|
|
112
99
|
}}
|
|
113
100
|
>
|
|
@@ -125,6 +112,29 @@ elements, but the select options _need_ to be child `<option>` HTML elements.
|
|
|
125
112
|
|
|
126
113
|
<ArgsTable story="Select with Controls" />
|
|
127
114
|
|
|
115
|
+
## Option Elements
|
|
116
|
+
|
|
117
|
+
The `Select` component renders all the necessary wrapping and associated text
|
|
118
|
+
elements, but the select options _need_ to be child `<option>` HTML elements.
|
|
119
|
+
|
|
120
|
+
```jsx
|
|
121
|
+
<Select labelText="What is your favorite color?" name="color">
|
|
122
|
+
<option value="red">Red</option>
|
|
123
|
+
<option value="green">Green</option>
|
|
124
|
+
<option value="blue">Blue</option>
|
|
125
|
+
<option value="black">Black</option>
|
|
126
|
+
<option value="white">White</option>
|
|
127
|
+
</Select>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
There are two NYPL best practices to consider when using the `Select` component
|
|
131
|
+
and `option` HTML elements:
|
|
132
|
+
|
|
133
|
+
- Use no more than 10 options. If more than 10 options are needed, an
|
|
134
|
+
auto-complete text input is a good alternative.
|
|
135
|
+
- Use at least four options. If fewer than three options are needed, a radio
|
|
136
|
+
button group is a good alternative.
|
|
137
|
+
|
|
128
138
|
## Labelling Variations
|
|
129
139
|
|
|
130
140
|
A Select can be rendered with or without a visible label. When `showLabel` is
|
|
@@ -6,8 +6,8 @@ import renderer from "react-test-renderer";
|
|
|
6
6
|
import Select from "./Select";
|
|
7
7
|
|
|
8
8
|
const baseProps = {
|
|
9
|
-
labelText: "What is your favorite color?",
|
|
10
9
|
helperText: "This is the helper text.",
|
|
10
|
+
labelText: "What is your favorite color?",
|
|
11
11
|
name: "color",
|
|
12
12
|
};
|
|
13
13
|
const baseOptions = (
|
|
@@ -222,41 +222,6 @@ describe("Select", () => {
|
|
|
222
222
|
expect(value).toEqual("white");
|
|
223
223
|
});
|
|
224
224
|
|
|
225
|
-
it("should throw warning when fewer than 4 options", () => {
|
|
226
|
-
const warn = jest.spyOn(console, "warn");
|
|
227
|
-
render(
|
|
228
|
-
<Select {...baseProps}>
|
|
229
|
-
<option value="red">Red</option>
|
|
230
|
-
</Select>
|
|
231
|
-
);
|
|
232
|
-
expect(warn).toHaveBeenCalledWith(
|
|
233
|
-
"NYPL DS recommends that <select> fields have at least 4 options; a radio button group is a good alternative for 3 or fewer options."
|
|
234
|
-
);
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
it("should throw warning when there are more than 10 options", () => {
|
|
238
|
-
const warn = jest.spyOn(console, "warn");
|
|
239
|
-
render(
|
|
240
|
-
<Select {...baseProps}>
|
|
241
|
-
<option aria-selected={false}>test1</option>
|
|
242
|
-
<option aria-selected={false}>test2</option>
|
|
243
|
-
<option aria-selected={false}>test3</option>
|
|
244
|
-
<option aria-selected={false}>test4</option>
|
|
245
|
-
<option aria-selected={false}>test5</option>
|
|
246
|
-
<option aria-selected={false}>test6</option>
|
|
247
|
-
<option aria-selected={false}>test7</option>
|
|
248
|
-
<option aria-selected={false}>test8</option>
|
|
249
|
-
<option aria-selected={false}>test9</option>
|
|
250
|
-
<option aria-selected={false}>test10</option>
|
|
251
|
-
<option aria-selected={false}>test11</option>
|
|
252
|
-
</Select>
|
|
253
|
-
);
|
|
254
|
-
|
|
255
|
-
expect(warn).toHaveBeenCalledWith(
|
|
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."
|
|
257
|
-
);
|
|
258
|
-
});
|
|
259
|
-
|
|
260
225
|
it("Renders the UI snapshot correctly", () => {
|
|
261
226
|
const siblings = ["Kendall", "Shiv", "Connor", "Roman", "Tom"];
|
|
262
227
|
|
|
@@ -44,6 +44,8 @@ export interface SelectProps {
|
|
|
44
44
|
onChange?: (event: React.FormEvent) => void;
|
|
45
45
|
/** Placeholder text in the select element. */
|
|
46
46
|
placeholder?: string;
|
|
47
|
+
/** The variant to display. */
|
|
48
|
+
selectType?: SelectTypes;
|
|
47
49
|
/** Offers the ability to hide the helper/invalid text. */
|
|
48
50
|
showHelperInvalidText?: boolean;
|
|
49
51
|
/** Offers the ability to show the select's label onscreen or hide it. Refer
|
|
@@ -51,8 +53,6 @@ export interface SelectProps {
|
|
|
51
53
|
showLabel?: boolean;
|
|
52
54
|
/** Whether or not to display the "Required"/"Optional" text in the label text. */
|
|
53
55
|
showOptReqLabel?: boolean;
|
|
54
|
-
/** The variant to display. */
|
|
55
|
-
type?: SelectTypes;
|
|
56
56
|
/** The value of the selected option.
|
|
57
57
|
* Should be passed along with `onChange` for controlled components. */
|
|
58
58
|
value?: string;
|
|
@@ -83,12 +83,12 @@ const Select = React.forwardRef<
|
|
|
83
83
|
showHelperInvalidText = true,
|
|
84
84
|
showLabel = true,
|
|
85
85
|
showOptReqLabel = true,
|
|
86
|
-
|
|
86
|
+
selectType = SelectTypes.Default,
|
|
87
87
|
value = "",
|
|
88
88
|
} = props;
|
|
89
89
|
const ariaAttributes = {};
|
|
90
90
|
const optReqFlag = isRequired ? "Required" : "Optional";
|
|
91
|
-
const styles = useMultiStyleConfig("CustomSelect", { variant:
|
|
91
|
+
const styles = useMultiStyleConfig("CustomSelect", { variant: selectType });
|
|
92
92
|
const finalInvalidText = invalidText
|
|
93
93
|
? invalidText
|
|
94
94
|
: "There is an error related to this field.";
|
|
@@ -106,18 +106,6 @@ const Select = React.forwardRef<
|
|
|
106
106
|
ariaAttributes["aria-describedby"] = `${id}-helperText`;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
if (React.Children.count(children) > 10) {
|
|
110
|
-
console.warn(
|
|
111
|
-
"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."
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (React.Children.count(children) < 4) {
|
|
116
|
-
console.warn(
|
|
117
|
-
"NYPL DS recommends that <select> fields have at least 4 options; a radio button group is a good alternative for 3 or fewer options."
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
109
|
return (
|
|
122
110
|
<Box className={className} __css={{ ...styles, ...additionalStyles }}>
|
|
123
111
|
{showLabel && (
|
|
@@ -10,10 +10,8 @@ import { withDesign } from "storybook-addon-designs";
|
|
|
10
10
|
|
|
11
11
|
import SimpleGrid from "../Grid/SimpleGrid";
|
|
12
12
|
import SkeletonLoader from "./SkeletonLoader";
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
SkeletonLoaderLayouts,
|
|
16
|
-
} from "./SkeletonLoaderTypes";
|
|
13
|
+
import { SkeletonLoaderImageRatios } from "./SkeletonLoaderTypes";
|
|
14
|
+
import { LayoutTypes } from "../../helpers/enums";
|
|
17
15
|
import { getCategory } from "../../utils/componentCategories";
|
|
18
16
|
import { getStorybookEnumValues } from "../../utils/utils";
|
|
19
17
|
|
|
@@ -22,8 +20,8 @@ export const imageRatiosEnumValues = getStorybookEnumValues(
|
|
|
22
20
|
"SkeletonLoaderImageRatios"
|
|
23
21
|
);
|
|
24
22
|
export const layoutsEnumValues = getStorybookEnumValues(
|
|
25
|
-
|
|
26
|
-
"
|
|
23
|
+
LayoutTypes,
|
|
24
|
+
"LayoutTypes"
|
|
27
25
|
);
|
|
28
26
|
|
|
29
27
|
<Meta
|
|
@@ -49,7 +47,7 @@ export const layoutsEnumValues = getStorybookEnumValues(
|
|
|
49
47
|
options: imageRatiosEnumValues.options,
|
|
50
48
|
},
|
|
51
49
|
layout: {
|
|
52
|
-
table: { defaultValue: { summary: "
|
|
50
|
+
table: { defaultValue: { summary: "LayoutTypes.Column" } },
|
|
53
51
|
options: layoutsEnumValues.options,
|
|
54
52
|
},
|
|
55
53
|
showButton: { table: { defaultValue: { summary: "false" } } },
|
|
@@ -64,7 +62,7 @@ export const layoutsEnumValues = getStorybookEnumValues(
|
|
|
64
62
|
| Component Version | DS Version |
|
|
65
63
|
| ----------------- | ---------- |
|
|
66
64
|
| Added | `0.17.3` |
|
|
67
|
-
| Latest | `0.25.
|
|
65
|
+
| Latest | `0.25.13` |
|
|
68
66
|
|
|
69
67
|
<Description of={SkeletonLoader} />
|
|
70
68
|
|
|
@@ -83,7 +81,7 @@ to better view the example. The default value is `100%`.
|
|
|
83
81
|
contentSize: 3,
|
|
84
82
|
headingSize: 1,
|
|
85
83
|
imageAspectRatio: "SkeletonLoaderImageRatios.Square",
|
|
86
|
-
layout: "
|
|
84
|
+
layout: "LayoutTypes.Column",
|
|
87
85
|
showButton: false,
|
|
88
86
|
showContent: true,
|
|
89
87
|
showHeading: true,
|
|
@@ -141,11 +139,11 @@ to better view the example. The default value is `100%`.
|
|
|
141
139
|
<Canvas>
|
|
142
140
|
<Story name="Placeholders in a List">
|
|
143
141
|
<SimpleGrid columns={1}>
|
|
144
|
-
<SkeletonLoader layout={
|
|
145
|
-
<SkeletonLoader layout={
|
|
146
|
-
<SkeletonLoader layout={
|
|
147
|
-
<SkeletonLoader layout={
|
|
148
|
-
<SkeletonLoader layout={
|
|
142
|
+
<SkeletonLoader layout={LayoutTypes.Row} showImage={false} />
|
|
143
|
+
<SkeletonLoader layout={LayoutTypes.Row} showImage={false} />
|
|
144
|
+
<SkeletonLoader layout={LayoutTypes.Row} showImage={false} />
|
|
145
|
+
<SkeletonLoader layout={LayoutTypes.Row} showImage={false} />
|
|
146
|
+
<SkeletonLoader layout={LayoutTypes.Row} showImage={false} />
|
|
149
147
|
</SimpleGrid>
|
|
150
148
|
</Story>
|
|
151
149
|
</Canvas>
|
|
@@ -4,10 +4,8 @@ import { axe } from "jest-axe";
|
|
|
4
4
|
import renderer from "react-test-renderer";
|
|
5
5
|
|
|
6
6
|
import SkeletonLoader from "./SkeletonLoader";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
SkeletonLoaderLayouts,
|
|
10
|
-
} from "./SkeletonLoaderTypes";
|
|
7
|
+
import { SkeletonLoaderImageRatios } from "./SkeletonLoaderTypes";
|
|
8
|
+
import { LayoutTypes } from "../../helpers/enums";
|
|
11
9
|
|
|
12
10
|
describe("SkeletonLoader Accessibility", () => {
|
|
13
11
|
it("passes axe accessibility test", async () => {
|
|
@@ -27,12 +25,12 @@ describe("SkeletonLoader", () => {
|
|
|
27
25
|
|
|
28
26
|
it("renders in the column or row layout", () => {
|
|
29
27
|
const { container, rerender } = render(
|
|
30
|
-
<SkeletonLoader layout={
|
|
28
|
+
<SkeletonLoader layout={LayoutTypes.Column} />
|
|
31
29
|
);
|
|
32
30
|
|
|
33
31
|
expect(container.querySelector(".column")).toBeInTheDocument();
|
|
34
32
|
|
|
35
|
-
rerender(<SkeletonLoader layout={
|
|
33
|
+
rerender(<SkeletonLoader layout={LayoutTypes.Row} />);
|
|
36
34
|
expect(container.querySelector(".row")).toBeInTheDocument();
|
|
37
35
|
});
|
|
38
36
|
|
|
@@ -75,10 +73,10 @@ describe("SkeletonLoader", () => {
|
|
|
75
73
|
it("renders the UI snapshot correctly", () => {
|
|
76
74
|
const basic = renderer.create(<SkeletonLoader />).toJSON();
|
|
77
75
|
const rowLayout = renderer
|
|
78
|
-
.create(<SkeletonLoader layout={
|
|
76
|
+
.create(<SkeletonLoader layout={LayoutTypes.Row} />)
|
|
79
77
|
.toJSON();
|
|
80
78
|
const columnLayout = renderer
|
|
81
|
-
.create(<SkeletonLoader layout={
|
|
79
|
+
.create(<SkeletonLoader layout={LayoutTypes.Column} />)
|
|
82
80
|
.toJSON();
|
|
83
81
|
const noImage = renderer
|
|
84
82
|
.create(<SkeletonLoader showImage={false} />)
|