@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
|
@@ -83,16 +83,18 @@ describe("StructuredContent Accessibility", () => {
|
|
|
83
83
|
it("passes axe accessibility for HTML string text content", async () => {
|
|
84
84
|
const { container } = render(
|
|
85
85
|
<StructuredContent
|
|
86
|
+
bodyContent={htmlStringBodyContent}
|
|
86
87
|
calloutText="This is the callout text"
|
|
87
88
|
headingText="Heading text"
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
imageProps={{
|
|
90
|
+
alt: "Image alt text",
|
|
91
|
+
aspectRatio: ImageRatios.Original,
|
|
92
|
+
caption: "Image caption",
|
|
93
|
+
credit: "Image credit",
|
|
94
|
+
position: StructuredContentImagePosition.Left,
|
|
95
|
+
size: ImageSizes.Medium,
|
|
96
|
+
src: "https://placeimg.com/400/300/animals",
|
|
97
|
+
}}
|
|
96
98
|
/>
|
|
97
99
|
);
|
|
98
100
|
expect(await axe(container)).toHaveNoViolations();
|
|
@@ -101,16 +103,18 @@ describe("StructuredContent Accessibility", () => {
|
|
|
101
103
|
it("passes axe accessibility for HTML DOM text content", async () => {
|
|
102
104
|
const { container } = render(
|
|
103
105
|
<StructuredContent
|
|
106
|
+
bodyContent={htmlDOMBodyContent}
|
|
104
107
|
calloutText="This is the callout text"
|
|
105
108
|
headingText="Heading text"
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
109
|
+
imageProps={{
|
|
110
|
+
alt: "Image alt text",
|
|
111
|
+
aspectRatio: ImageRatios.Original,
|
|
112
|
+
caption: "Image caption",
|
|
113
|
+
credit: "Image credit",
|
|
114
|
+
position: StructuredContentImagePosition.Left,
|
|
115
|
+
size: ImageSizes.Medium,
|
|
116
|
+
src: "https://placeimg.com/400/300/animals",
|
|
117
|
+
}}
|
|
114
118
|
/>
|
|
115
119
|
);
|
|
116
120
|
expect(await axe(container)).toHaveNoViolations();
|
|
@@ -119,9 +123,9 @@ describe("StructuredContent Accessibility", () => {
|
|
|
119
123
|
it("passes axe accessibility without an image", async () => {
|
|
120
124
|
const { container } = render(
|
|
121
125
|
<StructuredContent
|
|
126
|
+
bodyContent={htmlStringBodyContent}
|
|
122
127
|
calloutText="This is the callout text"
|
|
123
128
|
headingText="Heading text"
|
|
124
|
-
bodyContent={htmlStringBodyContent}
|
|
125
129
|
/>
|
|
126
130
|
);
|
|
127
131
|
expect(await axe(container)).toHaveNoViolations();
|
|
@@ -132,16 +136,18 @@ describe("StructuredContent", () => {
|
|
|
132
136
|
it("renders two headings, an image, and body text", () => {
|
|
133
137
|
render(
|
|
134
138
|
<StructuredContent
|
|
139
|
+
bodyContent={htmlStringBodyContent}
|
|
135
140
|
calloutText="This is the callout text"
|
|
136
141
|
headingText="Heading text"
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
imageProps={{
|
|
143
|
+
alt: "Image alt text",
|
|
144
|
+
aspectRatio: ImageRatios.Original,
|
|
145
|
+
caption: "Image caption",
|
|
146
|
+
credit: "Image credit",
|
|
147
|
+
position: StructuredContentImagePosition.Left,
|
|
148
|
+
size: ImageSizes.Medium,
|
|
149
|
+
src: "https://placeimg.com/400/300/animals",
|
|
150
|
+
}}
|
|
145
151
|
/>
|
|
146
152
|
);
|
|
147
153
|
const mainHeading = screen.getByRole("heading", { level: 2 });
|
|
@@ -156,14 +162,16 @@ describe("StructuredContent", () => {
|
|
|
156
162
|
it("optionally renders without the headings", () => {
|
|
157
163
|
render(
|
|
158
164
|
<StructuredContent
|
|
159
|
-
imageAlt="Image alt text"
|
|
160
|
-
imageAspectRatio={ImageRatios.Original}
|
|
161
|
-
imageCaption="Image caption"
|
|
162
|
-
imageCredit="Image credit"
|
|
163
|
-
imagePosition={StructuredContentImagePosition.Left}
|
|
164
|
-
imageSize={ImageSizes.Medium}
|
|
165
|
-
imageSrc="https://placeimg.com/400/300/animals"
|
|
166
165
|
bodyContent={htmlStringBodyContent}
|
|
166
|
+
imageProps={{
|
|
167
|
+
alt: "Image alt text",
|
|
168
|
+
aspectRatio: ImageRatios.Original,
|
|
169
|
+
caption: "Image caption",
|
|
170
|
+
credit: "Image credit",
|
|
171
|
+
position: StructuredContentImagePosition.Left,
|
|
172
|
+
size: ImageSizes.Medium,
|
|
173
|
+
src: "https://placeimg.com/400/300/animals",
|
|
174
|
+
}}
|
|
167
175
|
/>
|
|
168
176
|
);
|
|
169
177
|
const mainHeading = screen.queryByRole("heading", { level: 2 });
|
|
@@ -178,9 +186,9 @@ describe("StructuredContent", () => {
|
|
|
178
186
|
it("optionally renders without the image", () => {
|
|
179
187
|
render(
|
|
180
188
|
<StructuredContent
|
|
189
|
+
bodyContent={htmlStringBodyContent}
|
|
181
190
|
calloutText="This is the callout text"
|
|
182
191
|
headingText="Heading text"
|
|
183
|
-
bodyContent={htmlStringBodyContent}
|
|
184
192
|
/>
|
|
185
193
|
);
|
|
186
194
|
const mainHeading = screen.getByRole("heading", { level: 2 });
|
|
@@ -192,24 +200,27 @@ describe("StructuredContent", () => {
|
|
|
192
200
|
expect(screen.getByText(/Lorem ipsum dolor sit amet/i)).toBeInTheDocument();
|
|
193
201
|
});
|
|
194
202
|
|
|
195
|
-
it("logs a warning when an image is used but no alt text is passed to `
|
|
203
|
+
it("logs a warning when an image is used but no alt text is passed to `imageProps.alt`", () => {
|
|
196
204
|
const warn = jest.spyOn(console, "warn");
|
|
197
205
|
render(
|
|
198
206
|
<StructuredContent
|
|
207
|
+
bodyContent={htmlStringBodyContent}
|
|
199
208
|
calloutText="This is the callout text"
|
|
200
209
|
headingText="Heading text"
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
210
|
+
imageProps={{
|
|
211
|
+
aspectRatio: ImageRatios.Original,
|
|
212
|
+
caption: "Image caption",
|
|
213
|
+
credit: "Image credit",
|
|
214
|
+
position: StructuredContentImagePosition.Left,
|
|
215
|
+
size: ImageSizes.Medium,
|
|
216
|
+
src: "https://placeimg.com/400/300/animals",
|
|
217
|
+
}}
|
|
208
218
|
/>
|
|
209
219
|
);
|
|
210
220
|
|
|
211
221
|
expect(warn).toHaveBeenCalledWith(
|
|
212
|
-
"StructuredContent: `
|
|
222
|
+
"NYPL Reservoir StructuredContent: The `imageProps.alt` prop is required " +
|
|
223
|
+
"when using an image."
|
|
213
224
|
);
|
|
214
225
|
expect(screen.getByRole("img")).toBeInTheDocument();
|
|
215
226
|
});
|
|
@@ -217,16 +228,18 @@ describe("StructuredContent", () => {
|
|
|
217
228
|
it("renders an image wrapped in figure when provided an image caption or credit", () => {
|
|
218
229
|
const { rerender } = render(
|
|
219
230
|
<StructuredContent
|
|
231
|
+
bodyContent={htmlStringBodyContent}
|
|
220
232
|
calloutText="This is the callout text"
|
|
221
233
|
headingText="Heading text"
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
234
|
+
imageProps={{
|
|
235
|
+
alt: "Image alt text",
|
|
236
|
+
aspectRatio: ImageRatios.Original,
|
|
237
|
+
caption: "Image caption",
|
|
238
|
+
credit: "Image credit",
|
|
239
|
+
position: StructuredContentImagePosition.Left,
|
|
240
|
+
size: ImageSizes.Medium,
|
|
241
|
+
src: "https://placeimg.com/400/300/animals",
|
|
242
|
+
}}
|
|
230
243
|
/>
|
|
231
244
|
);
|
|
232
245
|
expect(screen.getByRole("img")).toBeInTheDocument();
|
|
@@ -237,15 +250,17 @@ describe("StructuredContent", () => {
|
|
|
237
250
|
// Not passing in the image's caption
|
|
238
251
|
rerender(
|
|
239
252
|
<StructuredContent
|
|
253
|
+
bodyContent={htmlStringBodyContent}
|
|
240
254
|
calloutText="This is the callout text"
|
|
241
255
|
headingText="Heading text"
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
256
|
+
imageProps={{
|
|
257
|
+
alt: "Image alt text",
|
|
258
|
+
aspectRatio: ImageRatios.Original,
|
|
259
|
+
credit: "Image credit",
|
|
260
|
+
position: StructuredContentImagePosition.Left,
|
|
261
|
+
size: ImageSizes.Medium,
|
|
262
|
+
src: "https://placeimg.com/400/300/animals",
|
|
263
|
+
}}
|
|
249
264
|
/>
|
|
250
265
|
);
|
|
251
266
|
expect(screen.getByRole("img")).toBeInTheDocument();
|
|
@@ -257,14 +272,16 @@ describe("StructuredContent", () => {
|
|
|
257
272
|
it("renders a simple image element when no image caption or credit are provided", () => {
|
|
258
273
|
render(
|
|
259
274
|
<StructuredContent
|
|
275
|
+
bodyContent={htmlStringBodyContent}
|
|
260
276
|
calloutText="This is the callout text"
|
|
261
277
|
headingText="Heading text"
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
278
|
+
imageProps={{
|
|
279
|
+
alt: "Image alt text",
|
|
280
|
+
aspectRatio: ImageRatios.Original,
|
|
281
|
+
position: StructuredContentImagePosition.Left,
|
|
282
|
+
size: ImageSizes.Medium,
|
|
283
|
+
src: "https://placeimg.com/400/300/animals",
|
|
284
|
+
}}
|
|
268
285
|
/>
|
|
269
286
|
);
|
|
270
287
|
expect(screen.getByRole("img")).toBeInTheDocument();
|
|
@@ -277,91 +294,101 @@ describe("StructuredContent", () => {
|
|
|
277
294
|
const withHTMLStringContent = renderer
|
|
278
295
|
.create(
|
|
279
296
|
<StructuredContent
|
|
297
|
+
bodyContent={htmlStringBodyContent}
|
|
280
298
|
calloutText="This is the callout text"
|
|
281
299
|
headingText="Heading text"
|
|
282
300
|
id="withHTMLStringContent"
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
301
|
+
imageProps={{
|
|
302
|
+
alt: "Image alt text",
|
|
303
|
+
aspectRatio: ImageRatios.Original,
|
|
304
|
+
caption: "Image caption",
|
|
305
|
+
credit: "Image credit",
|
|
306
|
+
position: StructuredContentImagePosition.Left,
|
|
307
|
+
size: ImageSizes.Medium,
|
|
308
|
+
src: "https://placeimg.com/400/300/animals",
|
|
309
|
+
}}
|
|
291
310
|
/>
|
|
292
311
|
)
|
|
293
312
|
.toJSON();
|
|
294
313
|
const withHTMLDOMContent = renderer
|
|
295
314
|
.create(
|
|
296
315
|
<StructuredContent
|
|
316
|
+
bodyContent={htmlDOMBodyContent}
|
|
297
317
|
calloutText="This is the callout text"
|
|
298
318
|
headingText="Heading text"
|
|
299
319
|
id="withHTMLDOMContent"
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
320
|
+
imageProps={{
|
|
321
|
+
alt: "Image alt text",
|
|
322
|
+
aspectRatio: ImageRatios.Original,
|
|
323
|
+
caption: "Image caption",
|
|
324
|
+
credit: "Image credit",
|
|
325
|
+
position: StructuredContentImagePosition.Left,
|
|
326
|
+
size: ImageSizes.Medium,
|
|
327
|
+
src: "https://placeimg.com/400/300/animals",
|
|
328
|
+
}}
|
|
308
329
|
/>
|
|
309
330
|
)
|
|
310
331
|
.toJSON();
|
|
311
332
|
const withoutAnImage = renderer
|
|
312
333
|
.create(
|
|
313
334
|
<StructuredContent
|
|
335
|
+
bodyContent={htmlStringBodyContent}
|
|
314
336
|
calloutText="This is the callout text"
|
|
315
337
|
headingText="Heading text"
|
|
316
338
|
id="withoutAnImage"
|
|
317
|
-
bodyContent={htmlStringBodyContent}
|
|
318
339
|
/>
|
|
319
340
|
)
|
|
320
341
|
.toJSON();
|
|
321
342
|
const withImageWithoutCaptionOrCredit = renderer
|
|
322
343
|
.create(
|
|
323
344
|
<StructuredContent
|
|
345
|
+
bodyContent={htmlStringBodyContent}
|
|
324
346
|
calloutText="This is the callout text"
|
|
325
347
|
headingText="Heading text"
|
|
326
348
|
id="withImageWithoutCaptionOrCredit"
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
349
|
+
imageProps={{
|
|
350
|
+
alt: "Image alt text",
|
|
351
|
+
aspectRatio: ImageRatios.Original,
|
|
352
|
+
position: StructuredContentImagePosition.Left,
|
|
353
|
+
size: ImageSizes.Medium,
|
|
354
|
+
src: "https://placeimg.com/400/300/animals",
|
|
355
|
+
}}
|
|
333
356
|
/>
|
|
334
357
|
)
|
|
335
358
|
.toJSON();
|
|
336
359
|
const withoutHeading = renderer
|
|
337
360
|
.create(
|
|
338
361
|
<StructuredContent
|
|
362
|
+
bodyContent={htmlStringBodyContent}
|
|
339
363
|
calloutText="This is the callout text"
|
|
340
364
|
id="withoutHeading"
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
365
|
+
imageProps={{
|
|
366
|
+
alt: "Image alt text",
|
|
367
|
+
aspectRatio: ImageRatios.Original,
|
|
368
|
+
caption: "Image caption",
|
|
369
|
+
credit: "Image credit",
|
|
370
|
+
position: StructuredContentImagePosition.Left,
|
|
371
|
+
size: ImageSizes.Medium,
|
|
372
|
+
src: "https://placeimg.com/400/300/animals",
|
|
373
|
+
}}
|
|
349
374
|
/>
|
|
350
375
|
)
|
|
351
376
|
.toJSON();
|
|
352
377
|
const withoutCalloutText = renderer
|
|
353
378
|
.create(
|
|
354
379
|
<StructuredContent
|
|
380
|
+
bodyContent={htmlStringBodyContent}
|
|
355
381
|
headingText="Heading text"
|
|
356
382
|
id="withoutCalloutText"
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
383
|
+
imageProps={{
|
|
384
|
+
alt: "Image alt text",
|
|
385
|
+
aspectRatio: ImageRatios.Original,
|
|
386
|
+
caption: "Image caption",
|
|
387
|
+
credit: "Image credit",
|
|
388
|
+
position: StructuredContentImagePosition.Left,
|
|
389
|
+
size: ImageSizes.Medium,
|
|
390
|
+
src: "https://placeimg.com/400/300/animals",
|
|
391
|
+
}}
|
|
365
392
|
/>
|
|
366
393
|
)
|
|
367
394
|
.toJSON();
|
|
@@ -2,12 +2,18 @@ import * as React from "react";
|
|
|
2
2
|
import { Box, useMultiStyleConfig } from "@chakra-ui/react";
|
|
3
3
|
|
|
4
4
|
import Heading from "../Heading/Heading";
|
|
5
|
-
import {
|
|
6
|
-
import Image, { ImageProps } from "../Image/Image";
|
|
5
|
+
import { HeadingSizes, HeadingLevels } from "../Heading/HeadingTypes";
|
|
6
|
+
import Image, { ComponentImageProps, ImageProps } from "../Image/Image";
|
|
7
7
|
import { ImageRatios, ImageSizes } from "../Image/ImageTypes";
|
|
8
8
|
import { StructuredContentImagePosition } from "./StructuredContentTypes";
|
|
9
9
|
import generateUUID from "../../helpers/generateUUID";
|
|
10
10
|
|
|
11
|
+
interface StructuredContentImageProps extends ComponentImageProps {
|
|
12
|
+
/** Optional value to control the positioning of the internal `Image` component.
|
|
13
|
+
* Defaults to `StructuredContentImagePosition.Left`. */
|
|
14
|
+
position?: StructuredContentImagePosition;
|
|
15
|
+
}
|
|
16
|
+
|
|
11
17
|
export interface StructuredContentProps {
|
|
12
18
|
/** Optional value to set the text for the callout heading text. */
|
|
13
19
|
calloutText?: string;
|
|
@@ -17,27 +23,8 @@ export interface StructuredContentProps {
|
|
|
17
23
|
headingText?: string;
|
|
18
24
|
/** ID that other components can cross reference for accessibility purposes. */
|
|
19
25
|
id?: string;
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
imageAlt?: string;
|
|
23
|
-
/** Optional value to control the aspect ratio of the internal `Image` component.
|
|
24
|
-
* Defaults to `ImageRatios.Square`. */
|
|
25
|
-
imageAspectRatio?: ImageRatios;
|
|
26
|
-
/** Optional value to render as a caption for the internal `Image` component. */
|
|
27
|
-
imageCaption?: string;
|
|
28
|
-
/** Optional DOM element to use instead of the DS `Image` component. */
|
|
29
|
-
imageComponent?: JSX.Element;
|
|
30
|
-
/** Optional value to render as a credit for the internal `Image` component. */
|
|
31
|
-
imageCredit?: string;
|
|
32
|
-
/** Optional value to control the positioning of the internal `Image` component.
|
|
33
|
-
* Defaults to `StructuredContentImagePosition.Left`. */
|
|
34
|
-
imagePosition?: StructuredContentImagePosition;
|
|
35
|
-
/** Optional value to control the size of the internal `Image` component.
|
|
36
|
-
* Defaults to `ImageSizes.Medium`. */
|
|
37
|
-
imageSize?: ImageSizes;
|
|
38
|
-
/** Optional value that contains the path to an image. If omitted, the internal
|
|
39
|
-
* DS `Image` component will not render. */
|
|
40
|
-
imageSrc?: string;
|
|
26
|
+
/** Object used to create and render the `Image` component. */
|
|
27
|
+
imageProps?: StructuredContentImageProps;
|
|
41
28
|
/** Required value to set the text for the body content. */
|
|
42
29
|
bodyContent: string | JSX.Element;
|
|
43
30
|
}
|
|
@@ -52,11 +39,11 @@ function StructuredContentImage(props: ImageProps) {
|
|
|
52
39
|
additionalImageStyles,
|
|
53
40
|
additionalWrapperStyles,
|
|
54
41
|
alt,
|
|
42
|
+
aspectRatio,
|
|
43
|
+
caption,
|
|
55
44
|
component,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
imageCredit,
|
|
59
|
-
imageSize,
|
|
45
|
+
credit,
|
|
46
|
+
size,
|
|
60
47
|
src,
|
|
61
48
|
} = props;
|
|
62
49
|
return (
|
|
@@ -66,10 +53,10 @@ function StructuredContentImage(props: ImageProps) {
|
|
|
66
53
|
additionalWrapperStyles={additionalWrapperStyles}
|
|
67
54
|
alt={alt}
|
|
68
55
|
component={component}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
56
|
+
aspectRatio={aspectRatio}
|
|
57
|
+
size={size}
|
|
58
|
+
caption={caption}
|
|
59
|
+
credit={credit}
|
|
73
60
|
src={src}
|
|
74
61
|
/>
|
|
75
62
|
);
|
|
@@ -87,22 +74,24 @@ export default function StructuredContent(
|
|
|
87
74
|
className,
|
|
88
75
|
headingText,
|
|
89
76
|
id = generateUUID(),
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
77
|
+
imageProps = {
|
|
78
|
+
alt: "",
|
|
79
|
+
aspectRatio: ImageRatios.Square,
|
|
80
|
+
caption: undefined,
|
|
81
|
+
component: undefined,
|
|
82
|
+
credit: undefined,
|
|
83
|
+
position: StructuredContentImagePosition.Left,
|
|
84
|
+
size: ImageSizes.Medium,
|
|
85
|
+
src: "",
|
|
86
|
+
},
|
|
98
87
|
bodyContent,
|
|
99
88
|
} = props;
|
|
100
|
-
const hasImage =
|
|
101
|
-
const hasFigureImage =
|
|
89
|
+
const hasImage = imageProps.src || imageProps.component;
|
|
90
|
+
const hasFigureImage = imageProps.caption || imageProps.credit;
|
|
102
91
|
const styles = useMultiStyleConfig("StructuredContent", {
|
|
103
92
|
hasFigureImage,
|
|
104
|
-
imageAspectRatio,
|
|
105
|
-
imagePosition,
|
|
93
|
+
imageAspectRatio: imageProps.aspectRatio,
|
|
94
|
+
imagePosition: imageProps.position,
|
|
106
95
|
});
|
|
107
96
|
const finalBodyContent =
|
|
108
97
|
typeof bodyContent === "string" ? (
|
|
@@ -111,9 +100,10 @@ export default function StructuredContent(
|
|
|
111
100
|
<Box>{bodyContent}</Box>
|
|
112
101
|
);
|
|
113
102
|
|
|
114
|
-
if (hasImage && !
|
|
103
|
+
if (hasImage && !imageProps.alt) {
|
|
115
104
|
console.warn(
|
|
116
|
-
"StructuredContent: `
|
|
105
|
+
"NYPL Reservoir StructuredContent: The `imageProps.alt` prop is required " +
|
|
106
|
+
"when using an image."
|
|
117
107
|
);
|
|
118
108
|
}
|
|
119
109
|
|
|
@@ -126,9 +116,9 @@ export default function StructuredContent(
|
|
|
126
116
|
)}
|
|
127
117
|
{calloutText && (
|
|
128
118
|
<Heading
|
|
129
|
-
displaySize={HeadingDisplaySizes.Callout}
|
|
130
119
|
id={`${id}-callout`}
|
|
131
120
|
level={HeadingLevels.Three}
|
|
121
|
+
size={HeadingSizes.Callout}
|
|
132
122
|
>
|
|
133
123
|
{calloutText}
|
|
134
124
|
</Heading>
|
|
@@ -138,13 +128,13 @@ export default function StructuredContent(
|
|
|
138
128
|
additionalFigureStyles={styles.imageFigure}
|
|
139
129
|
additionalImageStyles={styles.image}
|
|
140
130
|
additionalWrapperStyles={styles.imageWrapper}
|
|
141
|
-
alt={
|
|
142
|
-
component={
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
src={
|
|
131
|
+
alt={imageProps.alt}
|
|
132
|
+
component={imageProps.component}
|
|
133
|
+
aspectRatio={imageProps.aspectRatio}
|
|
134
|
+
caption={imageProps.caption}
|
|
135
|
+
credit={imageProps.credit}
|
|
136
|
+
size={imageProps.size}
|
|
137
|
+
src={imageProps.src ? imageProps.src : null}
|
|
148
138
|
/>
|
|
149
139
|
)}
|
|
150
140
|
{finalBodyContent}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
|
|
3
3
|
import Card from "../Card/Card";
|
|
4
|
-
import { CardLayouts } from "../Card/CardTypes";
|
|
5
4
|
import Heading from "../Heading/Heading";
|
|
6
5
|
import { HeadingLevels } from "../Heading/HeadingTypes";
|
|
6
|
+
import { LayoutTypes } from "../../helpers/enums";
|
|
7
7
|
|
|
8
8
|
export interface ColorCardProps {
|
|
9
9
|
/** backgroundColor of the color card */
|
|
@@ -25,9 +25,9 @@ export default function ColorCard(
|
|
|
25
25
|
<div style={{ display: "flex", alignItems: "center" }}>
|
|
26
26
|
<Card
|
|
27
27
|
backgroundColor={backgroundColor}
|
|
28
|
-
center
|
|
29
|
-
layout={CardLayouts.Column}
|
|
30
28
|
border
|
|
29
|
+
isCentered
|
|
30
|
+
layout={LayoutTypes.Column}
|
|
31
31
|
/>
|
|
32
32
|
<div style={{ marginLeft: "1rem" }}>
|
|
33
33
|
<Heading level={HeadingLevels.Four}>{colorName}</Heading>
|
|
@@ -2,11 +2,11 @@ import { Canvas, Meta } from "@storybook/addon-docs";
|
|
|
2
2
|
import { withDesign } from "storybook-addon-designs";
|
|
3
3
|
|
|
4
4
|
import Heading from "../Heading/Heading";
|
|
5
|
-
import {
|
|
5
|
+
import { HeadingSizes, HeadingLevels } from "../Heading/HeadingTypes";
|
|
6
6
|
import List from "../List/List";
|
|
7
7
|
import { ListTypes } from "../List/ListTypes";
|
|
8
8
|
import Text from "../Text/Text";
|
|
9
|
-
import {
|
|
9
|
+
import { TextSizes } from "../Text/TextTypes";
|
|
10
10
|
import { getCategory } from "../../utils/componentCategories";
|
|
11
11
|
import DSProvider from "../../theme/provider";
|
|
12
12
|
|
|
@@ -59,9 +59,14 @@ Use the NYPL Design System [Heading](/docs/components-typography-styles-heading-
|
|
|
59
59
|
|
|
60
60
|
<DSProvider>
|
|
61
61
|
|
|
62
|
-
Each heading level has a default style and size, but those styles can be overridden
|
|
62
|
+
Each heading level has a default style and size, but those styles can be overridden
|
|
63
|
+
using the `size` prop. The display sizes are separate from semantic elements and
|
|
64
|
+
may be used to override the default size and styling of the semantic HTML heading
|
|
65
|
+
elements. For example, the `h1` element has the `Primary` style applied by default,
|
|
66
|
+
but a new style can be applied through the `size` prop. Any `size` style can be
|
|
67
|
+
applied to any `Heading` element.
|
|
63
68
|
|
|
64
|
-
<Heading level={HeadingLevels.One}
|
|
69
|
+
<Heading level={HeadingLevels.One} size={HeadingSizes.Primary}>
|
|
65
70
|
Primary Heading
|
|
66
71
|
</Heading>
|
|
67
72
|
|
|
@@ -71,7 +76,7 @@ Each heading level has a default style and size, but those styles can be overrid
|
|
|
71
76
|
| **Font Weight** | `300` | `fontWeight: "heading.primary"` | `font-weight: var(--nypl-fontWeights-heading-primary)` |
|
|
72
77
|
| **Line Height** | `1.1` | n/a | n/a |
|
|
73
78
|
|
|
74
|
-
<Heading level={HeadingLevels.One}
|
|
79
|
+
<Heading level={HeadingLevels.One} size={HeadingSizes.Secondary}>
|
|
75
80
|
Secondary Heading
|
|
76
81
|
</Heading>
|
|
77
82
|
|
|
@@ -81,7 +86,7 @@ Each heading level has a default style and size, but those styles can be overrid
|
|
|
81
86
|
| **Font Weight** | `500` | `fontWeight: "heading.secondary"` | `font-weight: var(--nypl-fontWeights-heading-secondary)` |
|
|
82
87
|
| **Line Height** | `1.25` | n/a | n/a |
|
|
83
88
|
|
|
84
|
-
<Heading level={HeadingLevels.One}
|
|
89
|
+
<Heading level={HeadingLevels.One} size={HeadingSizes.Tertiary}>
|
|
85
90
|
Tertiary Heading
|
|
86
91
|
</Heading>
|
|
87
92
|
|
|
@@ -91,7 +96,7 @@ Each heading level has a default style and size, but those styles can be overrid
|
|
|
91
96
|
| **Font Weight** | `500` | `fontWeight: "heading.tertiary"` | `font-weight: var(--nypl-fontWeights-heading-tertiary)` |
|
|
92
97
|
| **Line Height** | `1.25` | n/a | n/a |
|
|
93
98
|
|
|
94
|
-
<Heading level={HeadingLevels.One}
|
|
99
|
+
<Heading level={HeadingLevels.One} size={HeadingSizes.Callout}>
|
|
95
100
|
Callout Heading
|
|
96
101
|
</Heading>
|
|
97
102
|
|
|
@@ -122,12 +127,12 @@ Use the NYPL Design System [Text](/docs/components-typography-styles-text--text)
|
|
|
122
127
|
|
|
123
128
|
<DSProvider>
|
|
124
129
|
|
|
125
|
-
The `
|
|
130
|
+
The `size` prop can be used to render a specific style from the DS default text styles.
|
|
126
131
|
|
|
127
132
|
- [Typography: Body Styles](https://www.figma.com/file/qShodlfNCJHb8n03IFyApM/Main?node-id=10975%3A52)
|
|
128
133
|
- [Typography: Other Styles](https://www.figma.com/file/qShodlfNCJHb8n03IFyApM/Main?node-id=10975%3A100)
|
|
129
134
|
|
|
130
|
-
<Text
|
|
135
|
+
<Text size={TextSizes.Default}>Default</Text>
|
|
131
136
|
|
|
132
137
|
| | Value | JS Theme Object | CSS Variable |
|
|
133
138
|
| --------------- | ------ | ---------------------------- | --------------------------------------------------- |
|
|
@@ -135,7 +140,7 @@ The `displaySize` prop can be used to render a specific style from the DS defaul
|
|
|
135
140
|
| **Font Weight** | `300` | `fontWeight: "text.default"` | `font-weight: var(--nypl-fontWeights-text-default)` |
|
|
136
141
|
| **Line Height** | `1.5` | `fontWeight: 1.5` | `font-weight: 1.5` |
|
|
137
142
|
|
|
138
|
-
<Text
|
|
143
|
+
<Text size={TextSizes.Caption}>Caption</Text>
|
|
139
144
|
|
|
140
145
|
| | Value | JS Theme Object | CSS Variable |
|
|
141
146
|
| --------------- | ---------- | ---------------------------- | --------------------------------------------------- |
|
|
@@ -143,7 +148,7 @@ The `displaySize` prop can be used to render a specific style from the DS defaul
|
|
|
143
148
|
| **Font Weight** | `300` | `fontWeight: "text.caption"` | `font-weight: var(--nypl-fontWeights-text-caption)` |
|
|
144
149
|
| **Line Height** | `1.25` | `fontWeight: 1.25` | `font-weight: 1.25` |
|
|
145
150
|
|
|
146
|
-
<Text
|
|
151
|
+
<Text size={TextSizes.Tag}>Tag</Text>
|
|
147
152
|
|
|
148
153
|
| | Value | JS Theme Object | CSS Variable |
|
|
149
154
|
| --------------- | --------- | ------------------------ | ----------------------------------------------- |
|
|
@@ -151,7 +156,7 @@ The `displaySize` prop can be used to render a specific style from the DS defaul
|
|
|
151
156
|
| **Font Weight** | `400` | `fontWeight: "text.tag"` | `font-weight: var(--nypl-fontWeights-text-tag)` |
|
|
152
157
|
| **Line Height** | `1.5` | `fontWeight: 1.5` | `font-weight: 1.5` |
|
|
153
158
|
|
|
154
|
-
<Text
|
|
159
|
+
<Text size={TextSizes.Mini}>Mini</Text>
|
|
155
160
|
|
|
156
161
|
| | Value | JS Theme Object | CSS Variable |
|
|
157
162
|
| --------------- | ---------- | ------------------------- | ------------------------------------------------ |
|