@nypl/design-system-react-components 0.23.4 → 0.25.1
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 +98 -1
- package/README.md +46 -11
- package/dist/components/Accordion/Accordion.d.ts +14 -14
- package/dist/components/Autosuggest/Autosuggest.stories.d.ts +1 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +11 -14
- package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +6 -0
- package/dist/components/Button/Button.d.ts +6 -13
- package/dist/components/Button/ButtonTypes.d.ts +5 -3
- package/dist/components/Card/Card.d.ts +59 -10
- package/dist/components/Card/CardTypes.d.ts +19 -0
- package/dist/components/CardEdition/CardEdition.d.ts +21 -0
- package/dist/components/{StyleGuide/Colors.stories.d.ts → CardEdition/CardEdition.stories.d.ts} +5 -2
- package/dist/components/Checkbox/Checkbox.d.ts +21 -16
- package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +43 -0
- package/dist/components/CheckboxGroup/CheckboxGroupLayoutTypes.d.ts +4 -0
- package/dist/components/DatePicker/DatePicker.d.ts +79 -0
- package/dist/components/DatePicker/DatePickerTypes.d.ts +5 -0
- package/dist/components/Form/Form.d.ts +16 -8
- package/dist/components/Form/FormTypes.d.ts +2 -0
- package/dist/components/Grid/GridTypes.d.ts +9 -0
- package/dist/components/Grid/SimpleGrid.d.ts +14 -0
- package/dist/components/Heading/Heading.d.ts +9 -11
- package/dist/components/Heading/{HeadingDisplaySizes.d.ts → HeadingTypes.d.ts} +8 -0
- package/dist/components/HelperErrorText/HelperErrorText.stories.d.ts +2 -1
- package/dist/components/Hero/Hero.d.ts +19 -14
- package/dist/components/Hero/HeroTypes.d.ts +10 -5
- package/dist/components/Icons/Icon.d.ts +13 -16
- package/dist/components/Icons/IconSvgs.d.ts +4 -0
- package/dist/components/Icons/IconTypes.d.ts +78 -60
- package/dist/components/Image/Image.stories.d.ts +2 -1
- package/dist/components/Label/Label.d.ts +10 -26
- package/dist/components/Link/Link.d.ts +8 -12
- package/dist/components/List/List.stories.d.ts +1 -0
- package/dist/components/Radio/Radio.d.ts +30 -24
- package/dist/components/RadioGroup/RadioGroup.d.ts +40 -0
- package/dist/components/RadioGroup/RadioGroupLayoutTypes.d.ts +4 -0
- package/dist/components/SearchBar/SearchBar.d.ts +45 -27
- package/dist/components/Select/Select.d.ts +34 -35
- package/dist/components/Select/SelectTypes.d.ts +4 -0
- package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +1 -1
- package/dist/components/SkeletonLoader/SkeletonLoaderTypes.d.ts +2 -2
- package/dist/components/StatusBadge/StatusBadge.d.ts +8 -6
- package/dist/components/StatusBadge/StatusBadgeTypes.d.ts +5 -0
- package/dist/components/Tabs/Tabs.d.ts +25 -0
- package/dist/components/Template/Template.d.ts +91 -0
- package/dist/components/Text/Text.d.ts +16 -0
- package/dist/components/Text/TextTypes.d.ts +6 -0
- package/dist/components/TextInput/TextInput.d.ts +37 -30
- package/dist/components/TextInput/TextInputTypes.d.ts +5 -0
- package/dist/design-system-react-components.cjs.development.js +4102 -917
- 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 +4023 -920
- package/dist/design-system-react-components.esm.js.map +1 -1
- package/dist/index.d.ts +23 -5
- package/dist/resources.scss +133 -24
- package/dist/styles.css +1 -1
- package/dist/theme/components/accordion.d.ts +25 -0
- package/dist/theme/components/breadcrumb.d.ts +90 -0
- package/dist/theme/components/button.d.ts +109 -0
- package/dist/theme/components/checkbox.d.ts +91 -0
- package/dist/theme/components/customCheckboxGroup.d.ts +18 -0
- package/dist/theme/components/customRadioGroup.d.ts +18 -0
- package/dist/theme/components/global.d.ts +55 -0
- package/dist/theme/components/globalMixins.d.ts +15 -0
- package/dist/theme/components/heading.d.ts +110 -0
- package/dist/theme/components/hero.d.ts +492 -0
- package/dist/theme/components/icon.d.ts +13 -0
- package/dist/theme/components/label.d.ts +16 -0
- package/dist/theme/components/link.d.ts +45 -0
- package/dist/theme/components/radio.d.ts +95 -0
- package/dist/theme/components/searchBar.d.ts +20 -0
- package/dist/theme/components/select.d.ts +58 -0
- package/dist/theme/components/statusBadge.d.ts +25 -0
- package/dist/theme/components/tabs.d.ts +85 -0
- package/dist/theme/components/template.d.ts +105 -0
- package/dist/theme/components/text.d.ts +20 -0
- package/dist/theme/components/textInput.d.ts +105 -0
- package/dist/theme/foundations/breakpoints.d.ts +23 -0
- package/dist/theme/foundations/colors.d.ts +3 -0
- package/dist/theme/foundations/global.d.ts +23 -0
- package/dist/theme/foundations/shadows.d.ts +4 -0
- package/dist/theme/foundations/spacing.d.ts +77 -0
- package/dist/theme/foundations/typography.d.ts +8 -0
- package/dist/theme/index.d.ts +20 -0
- package/dist/theme/provider.d.ts +5 -0
- package/dist/theme/types.d.ts +1 -0
- package/dist/utils/utils.d.ts +6 -0
- package/package.json +9 -2
- package/src/components/Accordion/Accordion.stories.mdx +233 -33
- package/src/components/Accordion/Accordion.test.tsx +135 -19
- package/src/components/Accordion/Accordion.tsx +81 -56
- package/src/components/Autosuggest/Autosuggest.stories.mdx +4 -3
- package/src/components/Autosuggest/Autosuggest.stories.tsx +1 -1
- package/src/components/Autosuggest/_Autosuggest.scss +2 -2
- package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +57 -56
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +31 -25
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +71 -73
- package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +6 -0
- package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +100 -0
- package/src/components/Button/Button.stories.mdx +125 -138
- package/src/components/Button/Button.test.tsx +65 -11
- package/src/components/Button/Button.tsx +72 -68
- package/src/components/Button/ButtonTypes.tsx +4 -2
- package/src/components/Button/_Button.scss +7 -92
- package/src/components/Button/__snapshots__/Button.test.tsx.snap +58 -3
- package/src/components/Card/Card.stories.mdx +694 -0
- package/src/components/Card/Card.test.tsx +97 -102
- package/src/components/Card/Card.tsx +182 -31
- package/src/components/Card/CardTypes.tsx +21 -0
- package/src/components/Card/_Card.scss +234 -49
- package/src/components/{Card/Card.stories.tsx → CardEdition/CardEdition.stories.tsx} +32 -22
- package/src/components/CardEdition/CardEdition.test.tsx +395 -0
- package/src/components/CardEdition/CardEdition.tsx +60 -0
- package/src/components/CardEdition/_CardEdition.scss +138 -0
- package/src/components/Chakra/Box.stories.mdx +57 -0
- package/src/components/Chakra/Center.stories.mdx +99 -0
- package/src/components/Chakra/Grid.stories.mdx +79 -0
- package/src/components/Chakra/Stack.stories.mdx +93 -0
- package/src/components/Checkbox/Checkbox.stories.mdx +57 -35
- package/src/components/Checkbox/Checkbox.test.tsx +117 -147
- package/src/components/Checkbox/Checkbox.tsx +76 -50
- package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +325 -0
- package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +249 -0
- package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +345 -0
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +148 -0
- package/src/components/CheckboxGroup/CheckboxGroupLayoutTypes.tsx +4 -0
- package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +1360 -0
- package/src/components/DatePicker/DatePicker.stories.mdx +284 -0
- package/src/components/DatePicker/DatePicker.test.tsx +657 -0
- package/src/components/DatePicker/DatePicker.tsx +396 -0
- package/src/components/DatePicker/DatePickerTypes.tsx +5 -0
- package/src/components/DatePicker/_DatePicker.scss +76 -0
- package/src/components/Form/Form.stories.mdx +130 -27
- package/src/components/Form/Form.test.tsx +78 -36
- package/src/components/Form/Form.tsx +53 -19
- package/src/components/Form/FormTypes.tsx +3 -0
- package/src/components/Form/__snapshots__/Form.test.tsx.snap +38 -0
- package/src/components/Grid/GridTypes.tsx +9 -0
- package/src/components/Grid/SimpleGrid.stories.mdx +275 -0
- package/src/components/Grid/SimpleGrid.test.tsx +66 -0
- package/src/components/Grid/SimpleGrid.tsx +37 -0
- package/src/components/Grid/__snapshots__/SimpleGrid.test.tsx.snap +8 -0
- package/src/components/Heading/Heading.stories.mdx +63 -33
- package/src/components/Heading/Heading.test.tsx +24 -16
- package/src/components/Heading/Heading.tsx +54 -38
- package/src/components/Heading/{HeadingDisplaySizes.tsx → HeadingTypes.tsx} +9 -0
- package/src/components/HelperErrorText/HelperErrorText.stories.tsx +2 -1
- package/src/components/HelperErrorText/_HelperErrorText.scss +1 -1
- package/src/components/Hero/Hero.stories.mdx +195 -85
- package/src/components/Hero/Hero.test.tsx +544 -113
- package/src/components/Hero/Hero.tsx +80 -93
- package/src/components/Hero/HeroTypes.tsx +17 -5
- package/src/components/Hero/__snapshots__/Hero.test.tsx.snap +307 -0
- package/src/components/HorizontalRule/HorizontalRule.stories.mdx +6 -1
- package/src/components/HorizontalRule/_HorizontalRule.scss +1 -1
- package/src/components/Icons/Icon.stories.mdx +89 -74
- package/src/components/Icons/Icon.test.tsx +30 -22
- package/src/components/Icons/Icon.tsx +63 -61
- package/src/components/Icons/IconSvgs.tsx +8 -0
- package/src/components/Icons/IconTypes.tsx +80 -60
- package/src/components/Image/Image.stories.tsx +2 -1
- package/src/components/Input/_Input.scss +2 -2
- package/src/components/Label/Label.stories.mdx +77 -0
- package/src/components/Label/Label.test.tsx +43 -12
- package/src/components/Label/Label.tsx +28 -45
- package/src/components/Label/__snapshots__/Label.test.tsx.snap +41 -0
- package/src/components/Link/Link.stories.mdx +47 -41
- package/src/components/Link/Link.test.tsx +33 -44
- package/src/components/Link/Link.tsx +114 -100
- package/src/components/List/List.stories.mdx +7 -3
- package/src/components/List/List.stories.tsx +14 -9
- package/src/components/List/List.test.tsx +12 -8
- package/src/components/List/List.tsx +9 -7
- package/src/components/List/_List.scss +3 -3
- package/src/components/Modal/Modal.stories.mdx +7 -3
- package/src/components/Modal/_Modal.scss +1 -1
- package/src/components/Notification/Notification.stories.mdx +99 -65
- package/src/components/Notification/Notification.test.tsx +3 -16
- package/src/components/Notification/Notification.tsx +12 -12
- package/src/components/Notification/_Notification.scss +5 -4
- package/src/components/Notification/__snapshots__/Notification.test.tsx.snap +1 -1
- package/src/components/Pagination/Pagination.stories.mdx +7 -1
- package/src/components/Pagination/Pagination.test.tsx +16 -10
- package/src/components/Radio/Radio.stories.mdx +57 -46
- package/src/components/Radio/Radio.test.tsx +92 -138
- package/src/components/Radio/Radio.tsx +70 -69
- package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +250 -0
- package/src/components/RadioGroup/RadioGroup.stories.mdx +247 -0
- package/src/components/RadioGroup/RadioGroup.test.tsx +327 -0
- package/src/components/RadioGroup/RadioGroup.tsx +154 -0
- package/src/components/RadioGroup/RadioGroupLayoutTypes.tsx +4 -0
- package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +1101 -0
- package/src/components/SearchBar/SearchBar.Test.tsx +151 -16
- package/src/components/SearchBar/SearchBar.stories.mdx +196 -224
- package/src/components/SearchBar/SearchBar.tsx +151 -46
- package/src/components/Select/Select.stories.mdx +193 -168
- package/src/components/Select/Select.test.tsx +129 -324
- package/src/components/Select/Select.tsx +120 -160
- package/src/components/Select/SelectTypes.tsx +4 -0
- package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +18 -29
- package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +7 -7
- package/src/components/SkeletonLoader/SkeletonLoader.tsx +4 -2
- package/src/components/SkeletonLoader/SkeletonLoaderTypes.tsx +2 -2
- package/src/components/SkeletonLoader/_SkeletonLoader.scss +3 -3
- package/src/components/StatusBadge/StatusBadge.stories.mdx +91 -0
- package/src/components/StatusBadge/StatusBadge.test.tsx +35 -7
- package/src/components/StatusBadge/StatusBadge.tsx +24 -25
- package/src/components/StatusBadge/StatusBadgeTypes.tsx +5 -0
- package/src/components/StatusBadge/__snapshots__/StatusBadge.test.tsx.snap +28 -0
- package/src/components/StyleGuide/Bidirectionality.stories.mdx +112 -90
- package/src/components/StyleGuide/Buttons.stories.mdx +98 -100
- package/src/components/StyleGuide/Colors.stories.mdx +336 -0
- package/src/components/StyleGuide/Forms.stories.mdx +85 -0
- package/src/components/StyleGuide/Iconography.stories.mdx +86 -93
- package/src/components/StyleGuide/Spacing.stories.mdx +0 -1
- package/src/components/StyleGuide/Typography.stories.mdx +164 -166
- package/src/components/StyleGuide/UIDocCard.tsx +4 -4
- package/src/components/Tabs/Tabs.stories.mdx +221 -0
- package/src/components/Tabs/Tabs.test.tsx +264 -0
- package/src/components/Tabs/Tabs.tsx +220 -0
- package/src/components/Template/Template.stories.mdx +574 -0
- package/src/components/Template/Template.test.tsx +124 -0
- package/src/components/Template/Template.tsx +226 -0
- package/src/components/Text/Text.stories.mdx +70 -0
- package/src/components/Text/Text.test.tsx +63 -0
- package/src/components/Text/Text.tsx +55 -0
- package/src/components/Text/TextTypes.tsx +6 -0
- package/src/components/Text/__snapshots__/Text.test.tsx.snap +33 -0
- package/src/components/TextInput/TextInput.stories.mdx +90 -90
- package/src/components/TextInput/TextInput.test.tsx +103 -83
- package/src/components/TextInput/TextInput.tsx +108 -91
- package/src/components/TextInput/TextInputTypes.tsx +6 -0
- package/src/components/VideoPlayer/VideoPlayer.stories.mdx +2 -1
- package/src/components/VideoPlayer/VideoPlayer.tsx +4 -2
- package/src/components/VideoPlayer/_VideoPlayer.scss +1 -1
- package/src/docs/Chakra.stories.mdx +341 -0
- package/src/docs/Intro.stories.mdx +31 -24
- package/src/index.ts +70 -5
- package/src/styles/01-colors/_colors-brand.scss +6 -4
- package/src/styles/01-colors/_colors-utility.scss +14 -15
- package/src/styles/03-space/_space-inline.scss +47 -7
- package/src/styles/03-space/_space-inset.scss +33 -5
- package/src/styles/03-space/_space-stack.scss +48 -8
- package/src/styles/base/_02-breakpoints.scss +5 -4
- package/src/styles/base/_04-base.scss +2 -1
- package/src/styles/base/_place-holder.scss +1 -1
- package/src/styles/base/_typography.scss +1 -29
- package/src/styles.scss +22 -25
- package/src/theme/components/accordion.ts +30 -0
- package/src/theme/components/breadcrumb.ts +77 -0
- package/src/theme/components/button.ts +125 -0
- package/src/theme/components/checkbox.ts +107 -0
- package/src/theme/components/customCheckboxGroup.ts +12 -0
- package/src/theme/components/customRadioGroup.ts +12 -0
- package/src/theme/components/global.ts +71 -0
- package/src/theme/components/globalMixins.ts +16 -0
- package/src/theme/components/heading.ts +72 -0
- package/src/theme/components/hero.ts +239 -0
- package/src/theme/components/icon.ts +79 -0
- package/src/theme/components/label.ts +17 -0
- package/src/theme/components/link.ts +47 -0
- package/src/theme/components/radio.ts +106 -0
- package/src/theme/components/searchBar.ts +21 -0
- package/src/theme/components/select.ts +50 -0
- package/src/theme/components/statusBadge.ts +27 -0
- package/src/theme/components/tabs.ts +79 -0
- package/src/theme/components/template.ts +114 -0
- package/src/theme/components/text.ts +31 -0
- package/src/theme/components/textInput.ts +61 -0
- package/src/theme/foundations/breakpoints.ts +24 -0
- package/src/theme/foundations/colors.ts +208 -0
- package/src/theme/foundations/global.ts +26 -0
- package/src/theme/foundations/shadows.ts +5 -0
- package/src/theme/foundations/spacing.ts +85 -0
- package/src/theme/foundations/typography.ts +35 -0
- package/src/theme/index.ts +88 -0
- package/src/theme/provider.tsx +9 -0
- package/src/theme/types.ts +1 -0
- package/src/utils/componentCategories.ts +56 -21
- package/src/utils/utils.ts +13 -0
- package/dist/components/Accordion/Accordion.stories.d.ts +0 -5
- package/dist/components/Card/Card.stories.d.ts +0 -27
- package/dist/components/Label/Label.stories.d.ts +0 -12
- package/dist/components/StatusBadge/StatusBadge.stories.d.ts +0 -8
- package/dist/components/Template/Template.stories.d.ts +0 -29
- package/src/components/Accordion/Accordion.stories.tsx +0 -65
- package/src/components/Accordion/_Accordion.scss +0 -81
- package/src/components/Breadcrumbs/_Breadcrumbs.scss +0 -97
- package/src/components/Checkbox/_Checkbox.scss +0 -97
- package/src/components/Form/_Form.scss +0 -28
- package/src/components/Heading/_Heading.scss +0 -163
- package/src/components/Hero/_Hero.scss +0 -256
- package/src/components/Icons/_Icons.scss +0 -116
- package/src/components/Label/Label.stories.tsx +0 -30
- package/src/components/Label/_Label.scss +0 -22
- package/src/components/Link/_Link.scss +0 -73
- package/src/components/Radio/_Radio.scss +0 -84
- package/src/components/SearchBar/_SearchBar.scss +0 -16
- package/src/components/Select/_Select.scss +0 -82
- package/src/components/StatusBadge/StatusBadge.stories.tsx +0 -33
- package/src/components/StatusBadge/_StatusBadge.scss +0 -23
- package/src/components/StyleGuide/Colors.stories.tsx +0 -288
- package/src/components/Template/Template.stories.tsx +0 -85
- package/src/components/Template/_Template.scss +0 -63
- package/src/components/TextInput/_TextInput.scss +0 -59
|
@@ -2,24 +2,28 @@ import * as React from "react";
|
|
|
2
2
|
import { render, screen } from "@testing-library/react";
|
|
3
3
|
import { axe } from "jest-axe";
|
|
4
4
|
|
|
5
|
-
import Card from "./Card";
|
|
5
|
+
import Card, { CardHeading, CardContent, CardActions } from "./Card";
|
|
6
6
|
import Link from "../Link/Link";
|
|
7
7
|
import { LinkTypes } from "../Link/LinkTypes";
|
|
8
|
-
import Heading from "../Heading/Heading";
|
|
9
|
-
import Image from "../Image/Image";
|
|
10
8
|
import Button from "../Button/Button";
|
|
11
9
|
import { ButtonTypes } from "../Button/ButtonTypes";
|
|
10
|
+
import { HeadingLevels } from "../Heading/HeadingTypes";
|
|
12
11
|
import Icon from "../Icons/Icon";
|
|
13
|
-
import { IconRotationTypes, IconNames } from "../Icons/IconTypes";
|
|
12
|
+
import { IconRotationTypes, IconNames, IconAlign } from "../Icons/IconTypes";
|
|
14
13
|
|
|
15
14
|
describe("Card Accessibility", () => {
|
|
16
15
|
it("passes axe accessibility test", async () => {
|
|
17
16
|
const { container } = render(
|
|
18
17
|
<Card
|
|
19
18
|
id="cardID"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
imageSrc="https://placeimg.com/400/200/arch"
|
|
20
|
+
imageAlt="Alt text"
|
|
21
|
+
>
|
|
22
|
+
<CardHeading level={HeadingLevels.Three} id="heading1">
|
|
23
|
+
The Card Heading
|
|
24
|
+
</CardHeading>
|
|
25
|
+
<CardContent>middle column content</CardContent>
|
|
26
|
+
<CardActions>
|
|
23
27
|
<Button
|
|
24
28
|
onClick={function () {
|
|
25
29
|
console.log(this);
|
|
@@ -30,10 +34,7 @@ describe("Card Accessibility", () => {
|
|
|
30
34
|
>
|
|
31
35
|
Example CTA
|
|
32
36
|
</Button>
|
|
33
|
-
|
|
34
|
-
footer={<>Optional footer</>}
|
|
35
|
-
>
|
|
36
|
-
middle column content
|
|
37
|
+
</CardActions>
|
|
37
38
|
</Card>
|
|
38
39
|
);
|
|
39
40
|
expect(await axe(container)).toHaveNoViolations();
|
|
@@ -44,9 +45,14 @@ describe("Card", () => {
|
|
|
44
45
|
const regularCard = (
|
|
45
46
|
<Card
|
|
46
47
|
id="cardID"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
imageSrc="https://placeimg.com/400/200/arch"
|
|
49
|
+
imageAlt="Alt text"
|
|
50
|
+
>
|
|
51
|
+
<CardHeading level={HeadingLevels.Three} id="heading1">
|
|
52
|
+
The Card Heading
|
|
53
|
+
</CardHeading>
|
|
54
|
+
<CardContent>middle column content</CardContent>
|
|
55
|
+
<CardActions>
|
|
50
56
|
<Button
|
|
51
57
|
onClick={function () {
|
|
52
58
|
console.log(this);
|
|
@@ -57,145 +63,134 @@ describe("Card", () => {
|
|
|
57
63
|
>
|
|
58
64
|
Example CTA
|
|
59
65
|
</Button>
|
|
60
|
-
|
|
61
|
-
footer={<>Optional footer</>}
|
|
62
|
-
>
|
|
63
|
-
middle column content
|
|
66
|
+
</CardActions>
|
|
64
67
|
</Card>
|
|
65
68
|
);
|
|
66
69
|
const cardWithExtendedStyles = (
|
|
67
70
|
<Card
|
|
68
71
|
id="card#1"
|
|
69
72
|
className="edition-card"
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
imageSrc="https://placeimg.com/300/400/arch"
|
|
74
|
+
imageAlt="Alt text"
|
|
75
|
+
>
|
|
76
|
+
<CardHeading level={HeadingLevels.Two} id="editioncardheading1">
|
|
77
|
+
The Card Heading
|
|
78
|
+
</CardHeading>
|
|
79
|
+
<CardContent>
|
|
80
|
+
<div>Published in New York by Random House</div>
|
|
81
|
+
<div>Written in English</div>
|
|
82
|
+
<div>
|
|
83
|
+
License: Creative Commons Attribution-NonCommercial-NoDerivatives 4.0
|
|
84
|
+
International
|
|
85
|
+
</div>
|
|
86
|
+
</CardContent>
|
|
87
|
+
<CardActions>
|
|
88
|
+
<div className="edition-card-actions">
|
|
76
89
|
<Link type={LinkTypes.Button} href="blah">
|
|
77
90
|
Read Online
|
|
78
91
|
</Link>
|
|
79
92
|
<div className="edition-card__download">
|
|
80
93
|
<Link href="#url" type={LinkTypes.Action}>
|
|
81
94
|
<Icon
|
|
82
|
-
name={IconNames.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
iconRotation={IconRotationTypes.rotate0}
|
|
87
|
-
></Icon>
|
|
95
|
+
name={IconNames.Download}
|
|
96
|
+
align={IconAlign.Left}
|
|
97
|
+
iconRotation={IconRotationTypes.Rotate0}
|
|
98
|
+
/>
|
|
88
99
|
Download
|
|
89
100
|
</Link>
|
|
90
101
|
</div>
|
|
91
102
|
</div>
|
|
92
|
-
|
|
93
|
-
>
|
|
94
|
-
<>
|
|
95
|
-
<div>Published in New York by Random House</div>
|
|
96
|
-
<div>Written in English</div>
|
|
97
|
-
<div>
|
|
98
|
-
License: Creative Commons Attribution-NonCommercial-NoDerivatives 4.0
|
|
99
|
-
International
|
|
100
|
-
</div>
|
|
101
|
-
</>
|
|
103
|
+
</CardActions>
|
|
102
104
|
</Card>
|
|
103
105
|
);
|
|
104
106
|
const cardWithNoCTAs = (
|
|
105
107
|
<Card
|
|
106
108
|
id="card#1"
|
|
107
|
-
image={<Image src="https://placeimg.com/300/400/arch" alt="" />}
|
|
108
109
|
className="edition-card"
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
110
|
+
imageSrc="https://placeimg.com/300/400/arch"
|
|
111
|
+
imageAlt="Alt text"
|
|
112
112
|
>
|
|
113
|
-
|
|
113
|
+
<CardHeading level={HeadingLevels.Two} id="editioncardheading1">
|
|
114
|
+
The Card Heading
|
|
115
|
+
</CardHeading>
|
|
116
|
+
<CardContent>
|
|
114
117
|
<div>Published in New York by Random House</div>
|
|
115
118
|
<div>Written in English</div>
|
|
116
119
|
<div>Under Creative Commons License</div>
|
|
117
|
-
|
|
120
|
+
</CardContent>
|
|
118
121
|
</Card>
|
|
119
122
|
);
|
|
120
123
|
const cardWithNoContent = (
|
|
121
124
|
<Card
|
|
122
125
|
id="card#1"
|
|
123
126
|
className="edition-card"
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
127
|
+
imageSrc="https://placeimg.com/300/400/arch"
|
|
128
|
+
imageAlt="Alt text"
|
|
129
|
+
>
|
|
130
|
+
<CardHeading
|
|
131
|
+
level={HeadingLevels.Two}
|
|
132
|
+
id="editioncardheading1"
|
|
133
|
+
url="#edition-link"
|
|
134
|
+
>
|
|
135
|
+
The Card Heading
|
|
136
|
+
</CardHeading>
|
|
137
|
+
<CardActions>
|
|
138
|
+
<div className="edition-card-actions">
|
|
135
139
|
<Link type={LinkTypes.Button} href="blah">
|
|
136
140
|
Read Online
|
|
137
141
|
</Link>
|
|
138
142
|
<div className="edition-card__download">
|
|
139
143
|
<Link href="#url" type={LinkTypes.Action}>
|
|
140
144
|
<Icon
|
|
141
|
-
name={IconNames.
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
iconRotation={IconRotationTypes.rotate0}
|
|
146
|
-
></Icon>
|
|
145
|
+
name={IconNames.Download}
|
|
146
|
+
align={IconAlign.Left}
|
|
147
|
+
iconRotation={IconRotationTypes.Rotate0}
|
|
148
|
+
/>
|
|
147
149
|
Download
|
|
148
150
|
</Link>
|
|
149
151
|
</div>
|
|
150
152
|
</div>
|
|
151
|
-
|
|
152
|
-
|
|
153
|
+
</CardActions>
|
|
154
|
+
</Card>
|
|
153
155
|
);
|
|
154
156
|
const cardWithNoImage = (
|
|
155
|
-
<Card
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
ctas={
|
|
167
|
-
<div className="edition-card__ctas">
|
|
157
|
+
<Card id="card#1" className="edition-card">
|
|
158
|
+
<CardHeading
|
|
159
|
+
level={HeadingLevels.Two}
|
|
160
|
+
id="editioncardheading1"
|
|
161
|
+
url="#edition-link"
|
|
162
|
+
>
|
|
163
|
+
The Card Heading
|
|
164
|
+
</CardHeading>
|
|
165
|
+
<CardContent>middle column content</CardContent>
|
|
166
|
+
<CardActions>
|
|
167
|
+
<div className="edition-card-actions">
|
|
168
168
|
<Link type={LinkTypes.Button} href="blah">
|
|
169
169
|
Read Online
|
|
170
170
|
</Link>
|
|
171
171
|
<div className="edition-card__download">
|
|
172
172
|
<Link href="#url" type={LinkTypes.Action}>
|
|
173
173
|
<Icon
|
|
174
|
-
name={IconNames.
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
iconRotation={IconRotationTypes.rotate0}
|
|
179
|
-
></Icon>
|
|
174
|
+
name={IconNames.Download}
|
|
175
|
+
align={IconAlign.Left}
|
|
176
|
+
iconRotation={IconRotationTypes.Rotate0}
|
|
177
|
+
/>
|
|
180
178
|
Download
|
|
181
179
|
</Link>
|
|
182
180
|
</div>
|
|
183
181
|
</div>
|
|
184
|
-
|
|
185
|
-
>
|
|
186
|
-
middle column content
|
|
182
|
+
</CardActions>
|
|
187
183
|
</Card>
|
|
188
184
|
);
|
|
189
185
|
let container;
|
|
190
186
|
|
|
191
|
-
it("Generates a Card with a header,
|
|
187
|
+
it("Generates a Card with a header, image, content, and CTAs", () => {
|
|
192
188
|
const utils = render(regularCard);
|
|
193
189
|
container = utils.container;
|
|
194
|
-
expect(container.querySelector(".
|
|
190
|
+
expect(container.querySelector(".chakra-heading")).toBeInTheDocument();
|
|
195
191
|
expect(container.querySelector(".card__image")).toBeInTheDocument();
|
|
196
|
-
expect(container.querySelector(".
|
|
197
|
-
expect(container.querySelector(".
|
|
198
|
-
expect(container.querySelector(".card__footer")).toBeInTheDocument();
|
|
192
|
+
expect(container.querySelector(".card-content")).toBeInTheDocument();
|
|
193
|
+
expect(container.querySelector(".card-actions")).toBeInTheDocument();
|
|
199
194
|
});
|
|
200
195
|
|
|
201
196
|
it("Generates a Card with variable data", () => {
|
|
@@ -203,7 +198,7 @@ describe("Card", () => {
|
|
|
203
198
|
container = utils.container;
|
|
204
199
|
|
|
205
200
|
expect(container.querySelector("h2")).toBeInTheDocument();
|
|
206
|
-
expect(container.querySelector(".
|
|
201
|
+
expect(container.querySelector(".card-content")).toBeInTheDocument();
|
|
207
202
|
expect(screen.getAllByRole("link")).toHaveLength(2);
|
|
208
203
|
});
|
|
209
204
|
|
|
@@ -211,29 +206,29 @@ describe("Card", () => {
|
|
|
211
206
|
const utils = render(cardWithNoCTAs);
|
|
212
207
|
container = utils.container;
|
|
213
208
|
|
|
214
|
-
expect(container.querySelector(".
|
|
209
|
+
expect(container.querySelector(".chakra-heading")).toBeInTheDocument();
|
|
215
210
|
expect(container.querySelector(".card__image")).toBeInTheDocument();
|
|
216
|
-
expect(container.querySelector(".
|
|
217
|
-
expect(container.querySelector(".
|
|
211
|
+
expect(container.querySelector(".card-content")).toBeInTheDocument();
|
|
212
|
+
expect(container.querySelector(".card-actions")).not.toBeInTheDocument();
|
|
218
213
|
});
|
|
219
214
|
|
|
220
215
|
it("Generates a card without a content block if one isn't provided", () => {
|
|
221
216
|
const utils = render(cardWithNoContent);
|
|
222
217
|
container = utils.container;
|
|
223
218
|
|
|
224
|
-
expect(container.querySelector(".
|
|
219
|
+
expect(container.querySelector(".chakra-heading")).toBeInTheDocument();
|
|
225
220
|
expect(container.querySelector(".card__image")).toBeInTheDocument();
|
|
226
|
-
expect(container.querySelector(".
|
|
227
|
-
expect(container.querySelector(".
|
|
221
|
+
expect(container.querySelector(".card-content")).not.toBeInTheDocument();
|
|
222
|
+
expect(container.querySelector(".card-actions")).toBeInTheDocument();
|
|
228
223
|
});
|
|
229
224
|
|
|
230
225
|
it("Generates a card without an image block if no image is provided", () => {
|
|
231
226
|
const utils = render(cardWithNoImage);
|
|
232
227
|
container = utils.container;
|
|
233
228
|
|
|
234
|
-
expect(container.querySelector(".
|
|
229
|
+
expect(container.querySelector(".chakra-heading")).toBeInTheDocument();
|
|
235
230
|
expect(container.querySelector(".card__image")).not.toBeInTheDocument();
|
|
236
|
-
expect(container.querySelector(".
|
|
237
|
-
expect(container.querySelector(".
|
|
231
|
+
expect(container.querySelector(".card-content")).toBeInTheDocument();
|
|
232
|
+
expect(container.querySelector(".card-actions")).toBeInTheDocument();
|
|
238
233
|
});
|
|
239
234
|
});
|
|
@@ -1,58 +1,209 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import bem from "../../utils/bem";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { CardImageRatios, CardImageSizes, CardLayouts } from "./CardTypes";
|
|
5
|
+
import Heading from "../Heading/Heading";
|
|
6
|
+
import Image from "../Image/Image";
|
|
7
|
+
|
|
8
|
+
interface CardImageProps {
|
|
9
|
+
/** Text description of the image */
|
|
10
|
+
alt: string;
|
|
11
|
+
/** Custom image component used in place of DS `Image` component */
|
|
12
|
+
component?: React.ReactNode;
|
|
13
|
+
/** ClassName you can add in addition to 'image' */
|
|
14
|
+
className?: string;
|
|
15
|
+
/** Optional value to control the aspect ratio of the cartd image; default value is `square` */
|
|
16
|
+
imageAspectRatio?: CardImageRatios;
|
|
17
|
+
/** Optional value to control the size of the card image */
|
|
18
|
+
imageSize?: CardImageSizes;
|
|
19
|
+
/** The src attribute is required, and contains the path to the image you want to embed. */
|
|
20
|
+
src: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface CardContentProps {
|
|
24
|
+
/** Optional className that would be applied to the `card-content` element */
|
|
6
25
|
className?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface CardActionsProps {
|
|
29
|
+
/** Optional boolean value to control visibility of border on the bottom edge of the card actions element */
|
|
30
|
+
bottomBorder?: boolean;
|
|
31
|
+
/** Optional className that would be applied to the `card-actions` element */
|
|
32
|
+
className?: string;
|
|
33
|
+
/** Modifiers array for use with BEM. See how to work with modifiers and BEM here: http://getbem.com/introduction/ */
|
|
34
|
+
modifiers?: string[];
|
|
35
|
+
/** Optional boolean value to control visibility of border on the top edge of the card actions element */
|
|
36
|
+
topBorder?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface CardProps {
|
|
40
|
+
/** Optional hex color value used to set the card background color */
|
|
41
|
+
backgroundColor?: string;
|
|
7
42
|
/** BlockName for use with BEM. See how to work with blockNames and BEM here: http://getbem.com/introduction/ */
|
|
8
43
|
blockName?: string;
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
|
|
44
|
+
/** Optional boolean value to control the visibility of a border around the card */
|
|
45
|
+
border?: boolean;
|
|
46
|
+
/** Optional boolean value to control the alignment of the text and elements within the card */
|
|
47
|
+
center?: boolean;
|
|
48
|
+
/** ClassName that appears in addition to "card" */
|
|
49
|
+
className?: string;
|
|
50
|
+
/** Optional hex color value used to override the default text color */
|
|
51
|
+
foregroundColor?: string;
|
|
15
52
|
/** ID that other components can cross reference for accessibility purposes */
|
|
16
53
|
id?: string;
|
|
17
|
-
/**
|
|
18
|
-
|
|
54
|
+
/** Text description of the image; to follow best practices for accessibility, this prop should not be left blank if `imageSrc` is passed */
|
|
55
|
+
imageAlt?: string;
|
|
56
|
+
/** Optional value to control the aspect ratio of the card image; default value is `square` */
|
|
57
|
+
imageAspectRatio?: CardImageRatios;
|
|
58
|
+
/** Optional boolean value to control the position of the card image */
|
|
59
|
+
imageAtEnd?: boolean;
|
|
60
|
+
/** Custom image component used in place of DS `Image` component */
|
|
61
|
+
imageComponent?: React.ReactNode;
|
|
62
|
+
/** Optional value to control the size of the card image */
|
|
63
|
+
imageSize?: CardImageSizes;
|
|
64
|
+
/** The path to the image displayed with the card */
|
|
65
|
+
imageSrc?: string;
|
|
66
|
+
/** Optional value to control the position of the image placeholder; default value is `column` */
|
|
67
|
+
layout?: CardLayouts;
|
|
19
68
|
/** Modifiers array for use with BEM. See how to work with modifiers and BEM here: http://getbem.com/introduction/ */
|
|
20
69
|
modifiers?: string[];
|
|
70
|
+
/** Optional padding value. This value should be entered with the same formatting as a CSS padding attribute (ex. `5%`, `20px`, `2rem`). If omitted, the Card will use the default padding. */
|
|
71
|
+
padding?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// CardImage component
|
|
75
|
+
export function CardImage(props: React.PropsWithChildren<CardImageProps>) {
|
|
76
|
+
const { src, alt, className, imageAspectRatio, imageSize, component } = props;
|
|
77
|
+
const classNames = ["image-wrap"];
|
|
78
|
+
imageAspectRatio && classNames.push(`image-wrap--` + imageAspectRatio);
|
|
79
|
+
const imageModifiers = [];
|
|
80
|
+
imageSize && imageModifiers.push(imageSize);
|
|
81
|
+
return (
|
|
82
|
+
(src || component) && (
|
|
83
|
+
<>
|
|
84
|
+
<div className={bem("image", imageModifiers, "card", [])}>
|
|
85
|
+
<div className={classNames.join(" ")}>
|
|
86
|
+
<div className="image-crop">
|
|
87
|
+
{component ? (
|
|
88
|
+
component
|
|
89
|
+
) : (
|
|
90
|
+
<Image className={className} src={src} alt={alt} />
|
|
91
|
+
)}
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
</div>
|
|
95
|
+
</>
|
|
96
|
+
)
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// CardHeading child-component
|
|
101
|
+
export const CardHeading = (props) => <Heading {...props} />;
|
|
102
|
+
|
|
103
|
+
// CardContent child-component
|
|
104
|
+
export function CardContent(props: React.PropsWithChildren<CardContentProps>) {
|
|
105
|
+
const { children, className } = props;
|
|
106
|
+
return (
|
|
107
|
+
children && (
|
|
108
|
+
<div className={bem("card-content", [], "", [className])}>{children}</div>
|
|
109
|
+
)
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// CardActions child-component
|
|
114
|
+
export function CardActions(props: React.PropsWithChildren<CardActionsProps>) {
|
|
115
|
+
const {
|
|
116
|
+
bottomBorder,
|
|
117
|
+
children,
|
|
118
|
+
className,
|
|
119
|
+
modifiers = [],
|
|
120
|
+
topBorder,
|
|
121
|
+
} = props;
|
|
122
|
+
|
|
123
|
+
bottomBorder && modifiers.push("bottom-border");
|
|
124
|
+
topBorder && modifiers.push("top-border");
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
children && (
|
|
128
|
+
<div className={bem("card-actions", modifiers, "", [className])}>
|
|
129
|
+
{children}
|
|
130
|
+
</div>
|
|
131
|
+
)
|
|
132
|
+
);
|
|
21
133
|
}
|
|
22
134
|
|
|
23
135
|
export default function Card(props: React.PropsWithChildren<CardProps>) {
|
|
24
136
|
const {
|
|
137
|
+
backgroundColor,
|
|
25
138
|
blockName,
|
|
139
|
+
center,
|
|
26
140
|
children,
|
|
27
141
|
className,
|
|
28
|
-
|
|
29
|
-
footer,
|
|
30
|
-
heading,
|
|
142
|
+
foregroundColor,
|
|
31
143
|
id,
|
|
32
|
-
|
|
144
|
+
imageAtEnd,
|
|
145
|
+
layout,
|
|
146
|
+
border,
|
|
147
|
+
padding,
|
|
33
148
|
modifiers = [],
|
|
149
|
+
imageAlt,
|
|
150
|
+
imageComponent,
|
|
151
|
+
imageAspectRatio,
|
|
152
|
+
imageSize,
|
|
153
|
+
imageSrc,
|
|
34
154
|
} = props;
|
|
35
155
|
const baseClass = "card";
|
|
36
156
|
|
|
157
|
+
const styles = {};
|
|
158
|
+
let imageCount = 0;
|
|
159
|
+
const cardContents = [];
|
|
160
|
+
|
|
161
|
+
layout && modifiers.push(layout);
|
|
162
|
+
border && modifiers.push("with-border");
|
|
163
|
+
center && modifiers.push("center");
|
|
164
|
+
(imageSrc || imageComponent) && modifiers.push("has-image");
|
|
165
|
+
imageAtEnd && modifiers.push("at-end");
|
|
166
|
+
|
|
167
|
+
padding && (styles["padding"] = padding);
|
|
168
|
+
backgroundColor && (styles["backgroundColor"] = backgroundColor);
|
|
169
|
+
foregroundColor && (styles["color"] = foregroundColor);
|
|
170
|
+
|
|
171
|
+
React.Children.map(children, (child: React.ReactElement) => {
|
|
172
|
+
if (
|
|
173
|
+
child.type === CardHeading ||
|
|
174
|
+
child.props.mdxType === "CardHeading" ||
|
|
175
|
+
child.type === CardContent ||
|
|
176
|
+
child.props.mdxType === "CardContent" ||
|
|
177
|
+
child.type === CardActions ||
|
|
178
|
+
child.props.mdxType === "CardActions"
|
|
179
|
+
) {
|
|
180
|
+
cardContents.push(child);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
if (imageCount > 1) {
|
|
185
|
+
console.error(`Only one CardIimage child component may be passed to Card.`);
|
|
186
|
+
cardContents.length = 0;
|
|
187
|
+
cardContents.push(
|
|
188
|
+
"Error: Only one CardImage child component may be passed to Card."
|
|
189
|
+
);
|
|
190
|
+
}
|
|
37
191
|
return (
|
|
38
|
-
<div
|
|
39
|
-
{
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
)}
|
|
52
|
-
</div>
|
|
53
|
-
{footer && (
|
|
54
|
-
<div className={bem("footer", modifiers, baseClass)}>{footer}</div>
|
|
192
|
+
<div
|
|
193
|
+
className={bem(baseClass, modifiers, blockName, [className])}
|
|
194
|
+
id={id}
|
|
195
|
+
style={styles}
|
|
196
|
+
>
|
|
197
|
+
{(imageSrc || imageComponent) && (
|
|
198
|
+
<CardImage
|
|
199
|
+
src={imageSrc ? imageSrc : null}
|
|
200
|
+
component={imageComponent ? imageComponent : null}
|
|
201
|
+
alt={imageAlt ? imageAlt : null}
|
|
202
|
+
imageSize={imageSize ? imageSize : null}
|
|
203
|
+
imageAspectRatio={imageAspectRatio ? imageAspectRatio : null}
|
|
204
|
+
/>
|
|
55
205
|
)}
|
|
206
|
+
<div className={bem("body", [], baseClass)}>{cardContents}</div>
|
|
56
207
|
</div>
|
|
57
208
|
);
|
|
58
209
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export enum CardLayouts {
|
|
2
|
+
Row = "row",
|
|
3
|
+
Column = "column",
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export enum CardImageRatios {
|
|
7
|
+
FourByThree = "four-by-three",
|
|
8
|
+
OneByTwo = "one-by-two",
|
|
9
|
+
Original = "original",
|
|
10
|
+
SixteenByNine = "sixteen-by-nine",
|
|
11
|
+
Square = "square",
|
|
12
|
+
ThreeByFour = "three-by-four",
|
|
13
|
+
ThreeByTwo = "three-by-two",
|
|
14
|
+
TwoByOne = "two-by-one",
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export enum CardImageSizes {
|
|
18
|
+
Large = "large",
|
|
19
|
+
Medium = "medium",
|
|
20
|
+
Small = "small",
|
|
21
|
+
}
|