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

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 (80) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/components/Icons/IconSvgs.d.ts +1 -0
  3. package/dist/components/Icons/IconTypes.d.ts +1 -0
  4. package/dist/components/Image/ImageTypes.d.ts +3 -1
  5. package/dist/components/Link/LinkTypes.d.ts +1 -0
  6. package/dist/components/Notification/Notification.d.ts +2 -0
  7. package/dist/components/Select/Select.d.ts +2 -0
  8. package/dist/components/Toggle/Toggle.d.ts +47 -0
  9. package/dist/components/Toggle/ToggleSizes.d.ts +4 -0
  10. package/dist/components/VideoPlayer/VideoPlayer.d.ts +5 -3
  11. package/dist/design-system-react-components.cjs.development.js +613 -366
  12. package/dist/design-system-react-components.cjs.development.js.map +1 -1
  13. package/dist/design-system-react-components.cjs.production.min.js +1 -1
  14. package/dist/design-system-react-components.cjs.production.min.js.map +1 -1
  15. package/dist/design-system-react-components.esm.js +606 -354
  16. package/dist/design-system-react-components.esm.js.map +1 -1
  17. package/dist/index.d.ts +3 -0
  18. package/dist/theme/components/notification.d.ts +8 -4
  19. package/dist/theme/components/toggle.d.ts +68 -0
  20. package/dist/theme/foundations/spacing.d.ts +2 -0
  21. package/package.json +1 -1
  22. package/src/components/Accordion/Accordion.stories.mdx +1 -2
  23. package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +1 -1
  24. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +10 -0
  25. package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +99 -0
  26. package/src/components/Button/Button.tsx +0 -1
  27. package/src/components/Card/Card.stories.mdx +74 -7
  28. package/src/components/Card/Card.tsx +9 -8
  29. package/src/components/Card/__snapshots__/Card.test.tsx.snap +67 -35
  30. package/src/components/Chakra/Grid.stories.mdx +11 -14
  31. package/src/components/DatePicker/DatePicker.test.tsx +8 -6
  32. package/src/components/DatePicker/__snapshots__/DatePicker.test.tsx.snap +5 -4
  33. package/src/components/Icons/Icon.stories.mdx +3 -2
  34. package/src/components/Icons/IconSvgs.tsx +2 -0
  35. package/src/components/Icons/IconTypes.tsx +1 -0
  36. package/src/components/Image/Image.stories.mdx +152 -90
  37. package/src/components/Image/Image.test.tsx +10 -0
  38. package/src/components/Image/ImageTypes.ts +2 -0
  39. package/src/components/Image/__snapshots__/Image.test.tsx.snap +24 -8
  40. package/src/components/Label/Label.stories.mdx +1 -1
  41. package/src/components/Link/Link.stories.mdx +2 -3
  42. package/src/components/Link/Link.test.tsx +71 -0
  43. package/src/components/Link/Link.tsx +41 -9
  44. package/src/components/Link/LinkTypes.tsx +1 -0
  45. package/src/components/Link/__snapshots__/Link.test.tsx.snap +201 -0
  46. package/src/components/Notification/Notification.stories.mdx +36 -3
  47. package/src/components/Notification/Notification.test.tsx +62 -16
  48. package/src/components/Notification/Notification.tsx +17 -5
  49. package/src/components/Notification/__snapshots__/Notification.test.tsx.snap +117 -0
  50. package/src/components/Pagination/Pagination.stories.mdx +1 -2
  51. package/src/components/Pagination/__snapshots__/Pagination.test.tsx.snap +42 -0
  52. package/src/components/ProgressIndicator/ProgressIndicator.stories.mdx +2 -3
  53. package/src/components/SearchBar/SearchBar.stories.mdx +1 -1
  54. package/src/components/Select/Select.stories.mdx +132 -55
  55. package/src/components/Select/Select.test.tsx +2 -2
  56. package/src/components/Select/Select.tsx +6 -2
  57. package/src/components/Slider/Slider.stories.mdx +3 -2
  58. package/src/components/Slider/Slider.test.tsx +35 -0
  59. package/src/components/Slider/Slider.tsx +8 -2
  60. package/src/components/Template/Template.stories.mdx +1 -2
  61. package/src/components/Toggle/Toggle.stories.mdx +176 -0
  62. package/src/components/Toggle/Toggle.test.tsx +140 -0
  63. package/src/components/Toggle/Toggle.tsx +118 -0
  64. package/src/components/Toggle/ToggleSizes.tsx +4 -0
  65. package/src/components/Toggle/__snapshots__/Toggle.test.tsx.snap +255 -0
  66. package/src/components/VideoPlayer/VideoPlayer.stories.mdx +39 -18
  67. package/src/components/VideoPlayer/VideoPlayer.test.tsx +103 -1
  68. package/src/components/VideoPlayer/VideoPlayer.tsx +57 -17
  69. package/src/components/VideoPlayer/__snapshots__/VideoPlayer.test.tsx.snap +48 -0
  70. package/src/index.ts +6 -0
  71. package/src/theme/components/breadcrumb.ts +1 -1
  72. package/src/theme/components/card.ts +4 -5
  73. package/src/theme/components/global.ts +1 -1
  74. package/src/theme/components/icon.ts +2 -2
  75. package/src/theme/components/image.ts +8 -0
  76. package/src/theme/components/notification.ts +8 -6
  77. package/src/theme/components/toggle.ts +65 -0
  78. package/src/theme/foundations/spacing.ts +3 -0
  79. package/src/theme/index.ts +2 -0
  80. package/src/utils/componentCategories.ts +3 -1
@@ -0,0 +1,140 @@
1
+ import * as React from "react";
2
+ import { render, screen } from "@testing-library/react";
3
+ import userEvent from "@testing-library/user-event";
4
+ import { axe } from "jest-axe";
5
+ import renderer from "react-test-renderer";
6
+ import * as generateUUID from "../../helpers/generateUUID";
7
+ import Toggle from "./Toggle";
8
+
9
+ describe("Toggle Accessibility", () => {
10
+ it("Passes axe accessibility test", async () => {
11
+ const { container } = render(
12
+ <Toggle id="inputID" onChange={jest.fn()} labelText="Test Label" />
13
+ );
14
+ expect(await axe(container)).toHaveNoViolations();
15
+ });
16
+ });
17
+
18
+ describe("Toggle", () => {
19
+ let changeHandler;
20
+ let generateUUIDSpy;
21
+
22
+ beforeEach(() => {
23
+ changeHandler = jest.fn();
24
+ });
25
+
26
+ it("Renders with a Toggle input and label", () => {
27
+ render(<Toggle id="inputID" labelText="Test Label" />);
28
+ expect(screen.getByLabelText("Test Label")).toBeInTheDocument();
29
+ expect(screen.getByRole("checkbox")).toBeInTheDocument();
30
+ });
31
+
32
+ it("Renders visible helper or error text", () => {
33
+ const { rerender } = render(
34
+ <Toggle
35
+ id="inputID"
36
+ labelText="Test Label"
37
+ helperText="This is the helper text."
38
+ invalidText="This is the error text :("
39
+ />
40
+ );
41
+ expect(screen.getByText("This is the helper text.")).toBeVisible();
42
+ expect(
43
+ screen.queryByText("This is the error text :(")
44
+ ).not.toBeInTheDocument();
45
+
46
+ rerender(
47
+ <Toggle
48
+ id="inputID"
49
+ labelText="Test Label"
50
+ isInvalid
51
+ helperText="This is the helper text."
52
+ invalidText="This is the error text :("
53
+ />
54
+ );
55
+ expect(screen.getByText("This is the error text :(")).toBeVisible();
56
+ expect(
57
+ screen.queryByText("This is the helper text.")
58
+ ).not.toBeInTheDocument();
59
+ });
60
+
61
+ it("Sets the Toggle's ID", () => {
62
+ render(<Toggle id="inputID" labelText="Test Label" />);
63
+ expect(screen.getByRole("checkbox")).toHaveAttribute("id", "inputID");
64
+ });
65
+
66
+ it("Calls the UUID generation function if no id prop value is passed", () => {
67
+ generateUUIDSpy = jest.spyOn(generateUUID, "default");
68
+ expect(generateUUIDSpy).toHaveBeenCalledTimes(0);
69
+ render(<Toggle labelText="Test Label" />);
70
+ expect(generateUUIDSpy).toHaveBeenCalledTimes(1);
71
+ });
72
+
73
+ it("Sets the 'checked' attribute", () => {
74
+ render(<Toggle id="inputID" labelText="Test Label" isChecked />);
75
+ expect(screen.getByRole("checkbox")).toHaveAttribute("checked");
76
+ });
77
+
78
+ it("Sets the 'disabled' attribute", () => {
79
+ render(<Toggle id="inputID" labelText="Test Label" isDisabled />);
80
+ expect(screen.getByRole("checkbox")).toHaveAttribute("disabled");
81
+ });
82
+
83
+ it("Sets the error state", () => {
84
+ render(
85
+ <Toggle
86
+ id="inputID-attributes"
87
+ labelText="onChange test"
88
+ invalidText="This is the error text!"
89
+ isInvalid
90
+ />
91
+ );
92
+ expect(screen.getByRole("checkbox")).toHaveAttribute("aria-invalid");
93
+ expect(screen.getByText("This is the error text!")).toBeInTheDocument();
94
+ });
95
+
96
+ it("does not render the error text when 'isInvalid' is true but 'invalidText' is not passed", () => {
97
+ render(
98
+ <Toggle id="inputID-attributes" labelText="onChange test" isInvalid />
99
+ );
100
+ expect(screen.getByRole("checkbox")).toHaveAttribute("aria-invalid");
101
+ expect(
102
+ screen.queryByText("This is the error text!")
103
+ ).not.toBeInTheDocument();
104
+ });
105
+
106
+ it("Changing the value calls the onChange handler", () => {
107
+ const utils = render(
108
+ <Toggle
109
+ id="onChangeTest"
110
+ onChange={changeHandler}
111
+ labelText="onChangeTest Lab"
112
+ isChecked
113
+ />
114
+ );
115
+
116
+ expect(changeHandler).toHaveBeenCalledTimes(0);
117
+ userEvent.click(utils.getByText("onChangeTest Lab"));
118
+ expect(changeHandler).toHaveBeenCalledTimes(1);
119
+ });
120
+
121
+ it("Renders the UI snapshot correctly", () => {
122
+ const primary = renderer
123
+ .create(<Toggle id="inputID" labelText="Test Label" />)
124
+ .toJSON();
125
+ const isChecked = renderer
126
+ .create(<Toggle id="Toggle-checked" labelText="Test Label" isChecked />)
127
+ .toJSON();
128
+ const isInvalid = renderer
129
+ .create(<Toggle id="Toggle-invalid" labelText="Test Label" isInvalid />)
130
+ .toJSON();
131
+ const isDisabled = renderer
132
+ .create(<Toggle id="Toggle-disabled" labelText="Test Label" isDisabled />)
133
+ .toJSON();
134
+
135
+ expect(primary).toMatchSnapshot();
136
+ expect(isChecked).toMatchSnapshot();
137
+ expect(isInvalid).toMatchSnapshot();
138
+ expect(isDisabled).toMatchSnapshot();
139
+ });
140
+ });
@@ -0,0 +1,118 @@
1
+ import * as React from "react";
2
+ import {
3
+ Box,
4
+ Switch,
5
+ useMultiStyleConfig,
6
+ useStyleConfig,
7
+ } from "@chakra-ui/react";
8
+ import generateUUID from "../../helpers/generateUUID";
9
+ import { ToggleSizes } from "./ToggleSizes";
10
+ import HelperErrorText from "../HelperErrorText/HelperErrorText";
11
+
12
+ export interface ToggleProps {
13
+ /** Optionally pass in additional Chakra-based styles. */
14
+ additionalStyles?: { [key: string]: any };
15
+ /** Used for uncontrolled scenarios. Sets the state of the Toggle when the page first loads.
16
+ * If true, the toggle will be initially set to the "on" position. */
17
+ defaultChecked?: boolean;
18
+ /** Optional string to populate the HelperErrorText for standard state */
19
+ helperText?: string;
20
+ /** ID that other components can cross reference for accessibility purposes */
21
+ id?: string;
22
+ /** Optional string to populate the HelperErrorText for the error state
23
+ * when `isInvalid` is true. */
24
+ invalidText?: string;
25
+ /** When using the Toggle as a "controlled" form element, you can specify
26
+ * the Toggle's checked state using this prop.
27
+ * Learn more about controlled and uncontrolled form fields:
28
+ * https://goshakkk.name/controlled-vs-uncontrolled-inputs-react/ */
29
+ isChecked?: boolean;
30
+ /** Adds the 'disabled' and `aria-disabled` attributes to the input when true.
31
+ * This also makes the text italic and color scheme gray. */
32
+ isDisabled?: boolean;
33
+ /** Adds the 'aria-invalid' attribute to the input when true. This also makes
34
+ * the color theme "NYPL error" red for the button and text. */
35
+ isInvalid?: boolean;
36
+ /** Adds the 'required' attribute to the input when true. */
37
+ isRequired?: boolean;
38
+ /** The checkbox's label. This will serve as the text content for a `<label>`
39
+ * element if `showlabel` is true, or an "aria-label" if `showLabel` is false. */
40
+ labelText: string;
41
+ /** The name prop indicates into which group of checkboxes this checkbox
42
+ * belongs. If none is specified, 'default' will be used */
43
+ name?: string;
44
+ /** The action to perform on the `<input>`'s onChange function */
45
+ onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
46
+ /** Offers the ability to hide the helper/invalid text. */
47
+ size?: ToggleSizes;
48
+ }
49
+
50
+ export const onChangeDefault = () => {
51
+ return;
52
+ };
53
+
54
+ /**
55
+ * Component that renders Chakra's `Switch` component along with NYPL defaults.
56
+ */
57
+ const Toggle = React.forwardRef<HTMLInputElement, ToggleProps>(
58
+ (props, ref?) => {
59
+ const {
60
+ additionalStyles = {},
61
+ defaultChecked = false,
62
+ helperText,
63
+ id = generateUUID(),
64
+ invalidText,
65
+ isChecked,
66
+ isDisabled = false,
67
+ isInvalid = false,
68
+ isRequired = false,
69
+ labelText,
70
+ name,
71
+ onChange = onChangeDefault,
72
+ size = ToggleSizes.Large,
73
+ } = props;
74
+ const footnote = isInvalid ? invalidText : helperText;
75
+ const ariaAttributes = {};
76
+ const styles = useMultiStyleConfig("Toggle", {});
77
+ const switchStyles = useStyleConfig("Switch");
78
+ ariaAttributes["aria-label"] =
79
+ labelText && footnote ? `${labelText} - ${footnote}` : labelText;
80
+
81
+ return (
82
+ <>
83
+ <Box __css={{ ...styles, ...additionalStyles }}>
84
+ <Switch
85
+ id={id}
86
+ name={name || "default"}
87
+ isDisabled={isDisabled}
88
+ isInvalid={isInvalid}
89
+ isRequired={isRequired}
90
+ ref={ref}
91
+ size={size === ToggleSizes.Large ? "lg" : "sm"}
92
+ {...(isChecked !== undefined
93
+ ? {
94
+ isChecked,
95
+ onChange,
96
+ }
97
+ : {
98
+ defaultChecked,
99
+ })}
100
+ {...ariaAttributes}
101
+ __css={switchStyles}
102
+ >
103
+ {labelText}
104
+ </Switch>
105
+ </Box>
106
+ {footnote && (
107
+ <Box __css={styles.helper}>
108
+ <HelperErrorText isInvalid={isInvalid} id={`${id}-helperText`}>
109
+ {footnote}
110
+ </HelperErrorText>
111
+ </Box>
112
+ )}
113
+ </>
114
+ );
115
+ }
116
+ );
117
+
118
+ export default Toggle;
@@ -0,0 +1,4 @@
1
+ export enum ToggleSizes {
2
+ Large = "large",
3
+ Small = "small",
4
+ }
@@ -0,0 +1,255 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Toggle Renders the UI snapshot correctly 1`] = `
4
+ <div
5
+ className="css-0"
6
+ >
7
+ <label
8
+ className="chakra-switch css-u8kezd"
9
+ onClick={[Function]}
10
+ >
11
+ <input
12
+ aria-disabled={false}
13
+ aria-invalid={false}
14
+ aria-label="Test Label"
15
+ checked={false}
16
+ className="chakra-switch__input"
17
+ disabled={false}
18
+ id="inputID"
19
+ name="default"
20
+ onBlur={[Function]}
21
+ onChange={[Function]}
22
+ onFocus={[Function]}
23
+ onKeyDown={[Function]}
24
+ onKeyUp={[Function]}
25
+ required={false}
26
+ style={
27
+ Object {
28
+ "border": "0px",
29
+ "clip": "rect(0px, 0px, 0px, 0px)",
30
+ "height": "1px",
31
+ "margin": "-1px",
32
+ "overflow": "hidden",
33
+ "padding": "0px",
34
+ "position": "absolute",
35
+ "whiteSpace": "nowrap",
36
+ "width": "1px",
37
+ }
38
+ }
39
+ type="checkbox"
40
+ />
41
+ <span
42
+ aria-hidden={true}
43
+ className="chakra-switch__track css-14qxnv8"
44
+ onMouseDown={[Function]}
45
+ onMouseEnter={[Function]}
46
+ onMouseLeave={[Function]}
47
+ onMouseUp={[Function]}
48
+ >
49
+ <span
50
+ className="chakra-switch__thumb css-0"
51
+ />
52
+ </span>
53
+ <span
54
+ className="chakra-switch__label css-1y8kf23"
55
+ onMouseDown={[Function]}
56
+ onTouchStart={[Function]}
57
+ >
58
+ Test Label
59
+ </span>
60
+ </label>
61
+ </div>
62
+ `;
63
+
64
+ exports[`Toggle Renders the UI snapshot correctly 2`] = `
65
+ <div
66
+ className="css-0"
67
+ >
68
+ <label
69
+ className="chakra-switch css-u8kezd"
70
+ data-checked=""
71
+ onClick={[Function]}
72
+ >
73
+ <input
74
+ aria-disabled={false}
75
+ aria-invalid={false}
76
+ aria-label="Test Label"
77
+ checked={true}
78
+ className="chakra-switch__input"
79
+ disabled={false}
80
+ id="Toggle-checked"
81
+ name="default"
82
+ onBlur={[Function]}
83
+ onChange={[Function]}
84
+ onFocus={[Function]}
85
+ onKeyDown={[Function]}
86
+ onKeyUp={[Function]}
87
+ required={false}
88
+ style={
89
+ Object {
90
+ "border": "0px",
91
+ "clip": "rect(0px, 0px, 0px, 0px)",
92
+ "height": "1px",
93
+ "margin": "-1px",
94
+ "overflow": "hidden",
95
+ "padding": "0px",
96
+ "position": "absolute",
97
+ "whiteSpace": "nowrap",
98
+ "width": "1px",
99
+ }
100
+ }
101
+ type="checkbox"
102
+ />
103
+ <span
104
+ aria-hidden={true}
105
+ className="chakra-switch__track css-14qxnv8"
106
+ data-checked=""
107
+ onMouseDown={[Function]}
108
+ onMouseEnter={[Function]}
109
+ onMouseLeave={[Function]}
110
+ onMouseUp={[Function]}
111
+ >
112
+ <span
113
+ className="chakra-switch__thumb css-0"
114
+ data-checked=""
115
+ />
116
+ </span>
117
+ <span
118
+ className="chakra-switch__label css-1y8kf23"
119
+ data-checked=""
120
+ onMouseDown={[Function]}
121
+ onTouchStart={[Function]}
122
+ >
123
+ Test Label
124
+ </span>
125
+ </label>
126
+ </div>
127
+ `;
128
+
129
+ exports[`Toggle Renders the UI snapshot correctly 3`] = `
130
+ <div
131
+ className="css-0"
132
+ >
133
+ <label
134
+ className="chakra-switch css-u8kezd"
135
+ data-invalid=""
136
+ onClick={[Function]}
137
+ >
138
+ <input
139
+ aria-disabled={false}
140
+ aria-invalid={true}
141
+ aria-label="Test Label"
142
+ checked={false}
143
+ className="chakra-switch__input"
144
+ disabled={false}
145
+ id="Toggle-invalid"
146
+ name="default"
147
+ onBlur={[Function]}
148
+ onChange={[Function]}
149
+ onFocus={[Function]}
150
+ onKeyDown={[Function]}
151
+ onKeyUp={[Function]}
152
+ required={false}
153
+ style={
154
+ Object {
155
+ "border": "0px",
156
+ "clip": "rect(0px, 0px, 0px, 0px)",
157
+ "height": "1px",
158
+ "margin": "-1px",
159
+ "overflow": "hidden",
160
+ "padding": "0px",
161
+ "position": "absolute",
162
+ "whiteSpace": "nowrap",
163
+ "width": "1px",
164
+ }
165
+ }
166
+ type="checkbox"
167
+ />
168
+ <span
169
+ aria-hidden={true}
170
+ className="chakra-switch__track css-14qxnv8"
171
+ data-invalid=""
172
+ onMouseDown={[Function]}
173
+ onMouseEnter={[Function]}
174
+ onMouseLeave={[Function]}
175
+ onMouseUp={[Function]}
176
+ >
177
+ <span
178
+ className="chakra-switch__thumb css-0"
179
+ />
180
+ </span>
181
+ <span
182
+ className="chakra-switch__label css-1y8kf23"
183
+ data-invalid=""
184
+ onMouseDown={[Function]}
185
+ onTouchStart={[Function]}
186
+ >
187
+ Test Label
188
+ </span>
189
+ </label>
190
+ </div>
191
+ `;
192
+
193
+ exports[`Toggle Renders the UI snapshot correctly 4`] = `
194
+ <div
195
+ className="css-0"
196
+ >
197
+ <label
198
+ className="chakra-switch css-u8kezd"
199
+ data-disabled=""
200
+ onClick={[Function]}
201
+ >
202
+ <input
203
+ aria-disabled={true}
204
+ aria-invalid={false}
205
+ aria-label="Test Label"
206
+ checked={false}
207
+ className="chakra-switch__input"
208
+ disabled={true}
209
+ id="Toggle-disabled"
210
+ name="default"
211
+ onBlur={[Function]}
212
+ onChange={[Function]}
213
+ onFocus={[Function]}
214
+ onKeyDown={[Function]}
215
+ onKeyUp={[Function]}
216
+ required={false}
217
+ style={
218
+ Object {
219
+ "border": "0px",
220
+ "clip": "rect(0px, 0px, 0px, 0px)",
221
+ "height": "1px",
222
+ "margin": "-1px",
223
+ "overflow": "hidden",
224
+ "padding": "0px",
225
+ "position": "absolute",
226
+ "whiteSpace": "nowrap",
227
+ "width": "1px",
228
+ }
229
+ }
230
+ type="checkbox"
231
+ />
232
+ <span
233
+ aria-hidden={true}
234
+ className="chakra-switch__track css-14qxnv8"
235
+ data-disabled=""
236
+ onMouseDown={[Function]}
237
+ onMouseEnter={[Function]}
238
+ onMouseLeave={[Function]}
239
+ onMouseUp={[Function]}
240
+ >
241
+ <span
242
+ className="chakra-switch__thumb css-0"
243
+ />
244
+ </span>
245
+ <span
246
+ className="chakra-switch__label css-1y8kf23"
247
+ data-disabled=""
248
+ onMouseDown={[Function]}
249
+ onTouchStart={[Function]}
250
+ >
251
+ Test Label
252
+ </span>
253
+ </label>
254
+ </div>
255
+ `;
@@ -37,11 +37,13 @@ import { getCategory } from "../../utils/componentCategories";
37
37
  | Component Version | DS Version |
38
38
  | ----------------- | ---------- |
39
39
  | Added | `0.23.2` |
40
- | Latest | `0.25.2` |
40
+ | Latest | `0.25.8` |
41
41
 
42
42
  <Description of={VideoPlayer} />
43
43
 
44
- The `VideoPlayer` component is used to embed a `Vimeo` or `YouTube` video player on a page. The component requires both the `videoType` and `videoId` props. You can extract the videoId from the video's URL. **IMPORTANT:** Do not try to enter the full video URL as the `videoId` value.
44
+ The `VideoPlayer` component is used to embed a `Vimeo` or `YouTube` video player on a page. The component requires the `embedCode` prop or both the `videoType` and `videoId` props. The component will not function properly if you try to set all of them.
45
+
46
+ You can extract the videoId from the video's URL. **IMPORTANT:** Do not try to enter the full video URL as the `videoId` value.
45
47
 
46
48
  The `aspectRatio` prop is used to control the sizing of the space allotted for the video rendering. Ultimately, the `aspectRatio` prop should be set to match the aspect ratio of the video that is being rendered. The default aspect ratio is `16:9`.
47
49
 
@@ -49,27 +51,15 @@ The `aspectRatio` prop is used to control the sizing of the space allotted for t
49
51
  <Story
50
52
  name="VideoPlayer"
51
53
  args={{
52
- videoType: VideoPlayerTypes.Vimeo,
53
- videoId: "",
54
- headingText: "NYPL Video",
55
54
  descriptionText:
56
55
  "Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.",
56
+ embedCode: `<iframe src="https://player.vimeo.com/video/421404144?h=5467db7edd" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>`,
57
+ headingText: "NYPL Video",
57
58
  helperText:
58
59
  "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.",
59
60
  }}
60
61
  >
61
- {(args) => (
62
- <VideoPlayer
63
- {...args}
64
- videoType={args.videoType}
65
- videoId={
66
- args.videoType === "vimeo"
67
- ? args.videoId || "474719268"
68
- : args.videoId || "nm-dD2tx6bk"
69
- }
70
- aspectRatio={args.aspectRatio}
71
- />
72
- )}
62
+ {(args) => <VideoPlayer {...args} />}
73
63
  </Story>
74
64
  </Canvas>
75
65
 
@@ -94,6 +84,37 @@ https://www.youtube.com/watch?v=[VIDEO_ID]
94
84
  https://www.youtube.com/watch?v=nm-dD2tx6bk
95
85
  ```
96
86
 
87
+ ## Example Embed Code Snippets
88
+
89
+ The examples below are shown with precise HTML formatting. However, often the embed code snippets provided by 3rd party video services are delivered as one long string.
90
+
91
+ ### Vimeo
92
+
93
+ ```html
94
+ <iframe
95
+ src="https://player.vimeo.com/video/421404144?h=5467db7edd"
96
+ width="640"
97
+ height="360"
98
+ frameborder="0"
99
+ allow="autoplay; fullscreen; picture-in-picture"
100
+ allowfullscreen
101
+ ></iframe>
102
+ ```
103
+
104
+ ### YouTube
105
+
106
+ ```html
107
+ <iframe
108
+ width="560"
109
+ height="315"
110
+ src="https://www.youtube.com/embed/nm-dD2tx6bk"
111
+ title="YouTube video player"
112
+ frameborder="0"
113
+ allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
114
+ allowfullscreen
115
+ ></iframe>
116
+ ```
117
+
97
118
  ## Errored
98
119
 
99
120
  If the necessary props are not passed to the `VideoPlayer` component, the component UI will display an error message.
@@ -101,8 +122,8 @@ If the necessary props are not passed to the `VideoPlayer` component, the compon
101
122
  <Canvas>
102
123
  <DSProvider>
103
124
  <VideoPlayer
104
- type={VideoPlayerTypes.Vimeo}
105
125
  videoId="https://vimeo.com/474719268"
126
+ videoType={VideoPlayerTypes.Vimeo}
106
127
  />
107
128
  </DSProvider>
108
129
  </Canvas>