@coopdigital/react 1.14.0 → 1.15.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/dist/components/Card/Card.d.ts +26 -11
- package/dist/components/Card/Card.js +16 -10
- package/dist/components/Signpost/Signpost.d.ts +3 -0
- package/dist/components/Signpost/Signpost.js +3 -0
- package/package.json +12 -12
- package/src/components/Card/Card.tsx +48 -16
- package/src/components/Signpost/Signpost.tsx +3 -0
|
@@ -3,6 +3,13 @@ import "../Image/index.js";
|
|
|
3
3
|
import React, { ForwardRefExoticComponent, HTMLAttributes, JSX, Ref } from "react";
|
|
4
4
|
//#region src/components/Card/Card.d.ts
|
|
5
5
|
interface CardProps extends HTMLAttributes<HTMLDivElement> {
|
|
6
|
+
/** **(Optional)** Specify how the card behaves across screen sizes.
|
|
7
|
+
*
|
|
8
|
+
* When this is true, horizontal cards will switch to vertical on small screens, and vertical cards will switch to horizontal on small screens.
|
|
9
|
+
*
|
|
10
|
+
* Default: false
|
|
11
|
+
*/
|
|
12
|
+
adaptive?: boolean;
|
|
6
13
|
/** **(Optional)** Specify whether chevron is visible. */
|
|
7
14
|
chevron?: boolean;
|
|
8
15
|
/** **(Optional)** Content inside the component. Children that are not assigned to a slot will be grouped together and rendered under the main Card content. */
|
|
@@ -13,12 +20,17 @@ interface CardProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
13
20
|
href?: string;
|
|
14
21
|
/** **(Optional)** Specify a custom element to use instead of `a`. */
|
|
15
22
|
hrefAs?: React.FC<any> | ForwardRefExoticComponent<any> | string;
|
|
16
|
-
/** **(Optional)** Specify the
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
/** **(Optional)** Specify the orientation of the Card.
|
|
24
|
+
*
|
|
25
|
+
* Default: vertical
|
|
26
|
+
*/
|
|
19
27
|
orientation?: "vertical" | "horizontal";
|
|
20
28
|
/** **(Optional)** Specify a custom React ref for this component. */
|
|
21
29
|
ref?: Ref<HTMLDivElement>;
|
|
30
|
+
/** **(Optional)** Enable additional styles to use the Card as a signpost.
|
|
31
|
+
*
|
|
32
|
+
* Text is vertically aligned centrally and the chevron is enlarged. */
|
|
33
|
+
signpost?: boolean;
|
|
22
34
|
}
|
|
23
35
|
interface CardLabelProps extends HTMLAttributes<HTMLSpanElement> {
|
|
24
36
|
/** **(Optional)** Content inside the Label. */
|
|
@@ -48,20 +60,23 @@ interface CardBadgeProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
48
60
|
/** **(Optional)** Specify badge position relative to top right corner. */
|
|
49
61
|
position?: "inset" | "popout";
|
|
50
62
|
}
|
|
51
|
-
type CardImageProps = ImageProps
|
|
63
|
+
type CardImageProps = ImageProps & {
|
|
64
|
+
/** **(Optional)** Specify on which side the Image should appear. */
|
|
65
|
+
align?: "left" | "right";
|
|
66
|
+
};
|
|
52
67
|
declare const Card: {
|
|
53
|
-
({ chevron, children, className, href, hrefAs,
|
|
68
|
+
({ adaptive, chevron, children, className, href, hrefAs, orientation, ref, signpost, ...props }: CardProps): JSX.Element;
|
|
54
69
|
slot: {
|
|
55
70
|
name: string;
|
|
56
71
|
};
|
|
57
72
|
Label: {
|
|
58
|
-
({ children, className }: CardLabelProps): JSX.Element;
|
|
73
|
+
({ children, className, ...props }: CardLabelProps): JSX.Element;
|
|
59
74
|
slot: {
|
|
60
75
|
name: string;
|
|
61
76
|
};
|
|
62
77
|
};
|
|
63
78
|
Heading: {
|
|
64
|
-
({ as, children, className }: CardHeadingProps): JSX.Element;
|
|
79
|
+
({ as, children, className, ...props }: CardHeadingProps): JSX.Element;
|
|
65
80
|
slot: {
|
|
66
81
|
name: string;
|
|
67
82
|
};
|
|
@@ -79,20 +94,20 @@ declare const Card: {
|
|
|
79
94
|
};
|
|
80
95
|
};
|
|
81
96
|
Image: {
|
|
82
|
-
(props: CardImageProps): JSX.Element;
|
|
97
|
+
({ align, crop, ...props }: CardImageProps): JSX.Element;
|
|
83
98
|
slot: {
|
|
84
99
|
name: string;
|
|
85
100
|
};
|
|
86
101
|
};
|
|
87
102
|
};
|
|
88
103
|
declare const CardHeading: {
|
|
89
|
-
({ as, children, className }: CardHeadingProps): JSX.Element;
|
|
104
|
+
({ as, children, className, ...props }: CardHeadingProps): JSX.Element;
|
|
90
105
|
slot: {
|
|
91
106
|
name: string;
|
|
92
107
|
};
|
|
93
108
|
};
|
|
94
109
|
declare const CardLabel: {
|
|
95
|
-
({ children, className }: CardLabelProps): JSX.Element;
|
|
110
|
+
({ children, className, ...props }: CardLabelProps): JSX.Element;
|
|
96
111
|
slot: {
|
|
97
112
|
name: string;
|
|
98
113
|
};
|
|
@@ -110,7 +125,7 @@ declare const CardBody: {
|
|
|
110
125
|
};
|
|
111
126
|
};
|
|
112
127
|
declare const CardImage: {
|
|
113
|
-
(props: CardImageProps): JSX.Element;
|
|
128
|
+
({ align, crop, ...props }: CardImageProps): JSX.Element;
|
|
114
129
|
slot: {
|
|
115
130
|
name: string;
|
|
116
131
|
};
|
|
@@ -23,21 +23,22 @@ function getCardLinkElement(as, href) {
|
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
const Card = ({ chevron = false, children, className, href, hrefAs,
|
|
26
|
+
const Card = ({ adaptive, chevron = false, children, className, href, hrefAs, orientation, ref, signpost, ...props }) => {
|
|
27
27
|
const { element: linkElement, props: linkProps } = getCardLinkElement(hrefAs, href);
|
|
28
28
|
const slots = { ...useSlots(componentSlots, children) };
|
|
29
29
|
const innerProps = { className: "coop-card--inner" };
|
|
30
30
|
const hasLinkWrapper = href && !slots.CardHeading;
|
|
31
31
|
const componentProps = {
|
|
32
32
|
className: clsx("coop-card", !hasUserBg(className) && "bg-white", className),
|
|
33
|
-
"data-
|
|
34
|
-
"data-orientation": orientation
|
|
33
|
+
"data-adaptive": adaptive ?? void 0,
|
|
34
|
+
"data-orientation": orientation ?? void 0,
|
|
35
|
+
"data-signpost": signpost ?? void 0,
|
|
35
36
|
...props
|
|
36
37
|
};
|
|
37
38
|
if (href && slots.CardHeading) slots.CardHeading = React.createElement(linkElement, linkProps, slots.CardHeading);
|
|
38
39
|
return /* @__PURE__ */ jsxs("article", {
|
|
39
|
-
...componentProps,
|
|
40
40
|
ref,
|
|
41
|
+
...componentProps,
|
|
41
42
|
children: [
|
|
42
43
|
slots.CardImage,
|
|
43
44
|
slots.CardBadge,
|
|
@@ -52,7 +53,7 @@ const Card = ({ chevron = false, children, className, href, hrefAs, imagePositio
|
|
|
52
53
|
slots.CardBody,
|
|
53
54
|
slots.Children
|
|
54
55
|
]
|
|
55
|
-
}), chevron && /* @__PURE__ */ jsx("span", {
|
|
56
|
+
}), (chevron || signpost) && /* @__PURE__ */ jsx("span", {
|
|
56
57
|
"aria-hidden": "true",
|
|
57
58
|
className: "coop-card--icon",
|
|
58
59
|
role: "presentation",
|
|
@@ -61,12 +62,16 @@ const Card = ({ chevron = false, children, className, href, hrefAs, imagePositio
|
|
|
61
62
|
]
|
|
62
63
|
});
|
|
63
64
|
};
|
|
64
|
-
const CardHeading = ({ as = "h3", children, className }) => {
|
|
65
|
-
return React.createElement(as, {
|
|
65
|
+
const CardHeading = ({ as = "h3", children, className, ...props }) => {
|
|
66
|
+
return React.createElement(as, {
|
|
67
|
+
className: clsx("coop-card--heading", className),
|
|
68
|
+
...props
|
|
69
|
+
}, children);
|
|
66
70
|
};
|
|
67
|
-
const CardLabel = ({ children, className }) => {
|
|
71
|
+
const CardLabel = ({ children, className, ...props }) => {
|
|
68
72
|
return /* @__PURE__ */ jsx("span", {
|
|
69
73
|
className: clsx("coop-card--label", className),
|
|
74
|
+
...props,
|
|
70
75
|
children
|
|
71
76
|
});
|
|
72
77
|
};
|
|
@@ -82,10 +87,11 @@ const CardBadge = ({ align = "right", children, position = "popout", ...props })
|
|
|
82
87
|
const CardBody = ({ children }) => {
|
|
83
88
|
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
84
89
|
};
|
|
85
|
-
const CardImage = (props) => {
|
|
90
|
+
const CardImage = ({ align, crop, ...props }) => {
|
|
86
91
|
return /* @__PURE__ */ jsx(Image, {
|
|
87
92
|
...props,
|
|
88
|
-
crop:
|
|
93
|
+
crop: crop ?? "wide",
|
|
94
|
+
"data-align": align ?? void 0
|
|
89
95
|
});
|
|
90
96
|
};
|
|
91
97
|
Card.slot = { name: "Card" };
|
|
@@ -18,6 +18,9 @@ interface SignpostProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
18
18
|
/** **(Optional)** Specify a custom React ref for this component. */
|
|
19
19
|
ref?: Ref<HTMLDivElement>;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Use a Card with `signpost` prop instead
|
|
23
|
+
*/
|
|
21
24
|
declare const Signpost: {
|
|
22
25
|
({ as, children, className, headingLevel, href, image, ref, ...props }: SignpostProps): JSX.Element;
|
|
23
26
|
slot: {
|
|
@@ -4,6 +4,9 @@ import clsx from "clsx";
|
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
import React from "react";
|
|
6
6
|
//#region src/components/Signpost/Signpost.tsx
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use a Card with `signpost` prop instead
|
|
9
|
+
*/
|
|
7
10
|
const Signpost = ({ as, children, className, headingLevel = "h3", href, image, ref, ...props }) => {
|
|
8
11
|
const element = as ?? "a";
|
|
9
12
|
return /* @__PURE__ */ jsxs("div", {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coopdigital/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.15.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -64,21 +64,21 @@
|
|
|
64
64
|
"description": "React components for the Experience Library design system",
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@axe-core/playwright": "^4.12.1",
|
|
67
|
-
"@playwright/test": "^1.
|
|
68
|
-
"@storybook/addon-a11y": "^10.5.
|
|
69
|
-
"@storybook/addon-docs": "^10.5.
|
|
70
|
-
"@storybook/addon-onboarding": "^10.5.
|
|
71
|
-
"@storybook/react-vite": "^10.5.
|
|
67
|
+
"@playwright/test": "^1.62.1",
|
|
68
|
+
"@storybook/addon-a11y": "^10.5.5",
|
|
69
|
+
"@storybook/addon-docs": "^10.5.5",
|
|
70
|
+
"@storybook/addon-onboarding": "^10.5.5",
|
|
71
|
+
"@storybook/react-vite": "^10.5.5",
|
|
72
72
|
"@testing-library/jest-dom": "^7.0.0",
|
|
73
73
|
"@testing-library/react": "^16.3.2",
|
|
74
|
-
"@types/react": "^19.2.
|
|
75
|
-
"@types/react-dom": "^19.2.
|
|
74
|
+
"@types/react": "^19.2.18",
|
|
75
|
+
"@types/react-dom": "^19.2.4",
|
|
76
76
|
"@whitespace/storybook-addon-html": "^9.0.0",
|
|
77
77
|
"react": "^19.2.8",
|
|
78
78
|
"react-dom": "^19.2.8",
|
|
79
79
|
"resize-observer-polyfill": "^1.5.1",
|
|
80
80
|
"serve": "^14.2.6",
|
|
81
|
-
"storybook": "^10.5.
|
|
81
|
+
"storybook": "^10.5.5",
|
|
82
82
|
"storybook-addon-tag-badges": "^3.1.0"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
@@ -102,12 +102,12 @@
|
|
|
102
102
|
"storybook": "$storybook"
|
|
103
103
|
},
|
|
104
104
|
"dependencies": {
|
|
105
|
-
"@coopdigital/styles": "^1.
|
|
106
|
-
"@radix-ui/react-popover": "^1.1.
|
|
105
|
+
"@coopdigital/styles": "^1.11.1",
|
|
106
|
+
"@radix-ui/react-popover": "^1.1.23",
|
|
107
107
|
"clsx": "^2.1.1",
|
|
108
108
|
"date-fns": "^4.4.0",
|
|
109
109
|
"merge-refs": "^2.0.0",
|
|
110
110
|
"react-day-picker": "^10.0.1"
|
|
111
111
|
},
|
|
112
|
-
"gitHead": "
|
|
112
|
+
"gitHead": "ab7ccc5e48cd028be0e46645d0a8b942f690939b"
|
|
113
113
|
}
|
|
@@ -9,6 +9,13 @@ import { ChevronRightIcon } from "../icons/ChevronRightIcon"
|
|
|
9
9
|
import { Image, ImageProps } from "../Image"
|
|
10
10
|
|
|
11
11
|
export interface CardProps extends HTMLAttributes<HTMLDivElement> {
|
|
12
|
+
/** **(Optional)** Specify how the card behaves across screen sizes.
|
|
13
|
+
*
|
|
14
|
+
* When this is true, horizontal cards will switch to vertical on small screens, and vertical cards will switch to horizontal on small screens.
|
|
15
|
+
*
|
|
16
|
+
* Default: false
|
|
17
|
+
*/
|
|
18
|
+
adaptive?: boolean
|
|
12
19
|
/** **(Optional)** Specify whether chevron is visible. */
|
|
13
20
|
chevron?: boolean
|
|
14
21
|
/** **(Optional)** Content inside the component. Children that are not assigned to a slot will be grouped together and rendered under the main Card content. */
|
|
@@ -20,12 +27,17 @@ export interface CardProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
20
27
|
/** **(Optional)** Specify a custom element to use instead of `a`. */
|
|
21
28
|
// oxlint-disable-next-line typescript/no-explicit-any
|
|
22
29
|
hrefAs?: React.FC<any> | ForwardRefExoticComponent<any> | string
|
|
23
|
-
/** **(Optional)** Specify the
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
/** **(Optional)** Specify the orientation of the Card.
|
|
31
|
+
*
|
|
32
|
+
* Default: vertical
|
|
33
|
+
*/
|
|
26
34
|
orientation?: "vertical" | "horizontal"
|
|
27
35
|
/** **(Optional)** Specify a custom React ref for this component. */
|
|
28
36
|
ref?: Ref<HTMLDivElement>
|
|
37
|
+
/** **(Optional)** Enable additional styles to use the Card as a signpost.
|
|
38
|
+
*
|
|
39
|
+
* Text is vertically aligned centrally and the chevron is enlarged. */
|
|
40
|
+
signpost?: boolean
|
|
29
41
|
}
|
|
30
42
|
|
|
31
43
|
interface CardLabelProps extends HTMLAttributes<HTMLSpanElement> {
|
|
@@ -60,7 +72,10 @@ interface CardBadgeProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
60
72
|
position?: "inset" | "popout"
|
|
61
73
|
}
|
|
62
74
|
|
|
63
|
-
type CardImageProps = ImageProps
|
|
75
|
+
type CardImageProps = ImageProps & {
|
|
76
|
+
/** **(Optional)** Specify on which side the Image should appear. */
|
|
77
|
+
align?: "left" | "right"
|
|
78
|
+
}
|
|
64
79
|
|
|
65
80
|
const componentSlots = {
|
|
66
81
|
CardBadge: null,
|
|
@@ -82,14 +97,16 @@ function getCardLinkElement(as: CardProps["hrefAs"], href?: string) {
|
|
|
82
97
|
}
|
|
83
98
|
|
|
84
99
|
const Card = ({
|
|
100
|
+
adaptive,
|
|
101
|
+
// behaviour,
|
|
85
102
|
chevron = false,
|
|
86
103
|
children,
|
|
87
104
|
className,
|
|
88
105
|
href,
|
|
89
106
|
hrefAs,
|
|
90
|
-
|
|
91
|
-
orientation = "vertical",
|
|
107
|
+
orientation,
|
|
92
108
|
ref,
|
|
109
|
+
signpost,
|
|
93
110
|
...props
|
|
94
111
|
}: CardProps): JSX.Element => {
|
|
95
112
|
const { element: linkElement, props: linkProps } = getCardLinkElement(hrefAs, href)
|
|
@@ -100,8 +117,10 @@ const Card = ({
|
|
|
100
117
|
|
|
101
118
|
const componentProps = {
|
|
102
119
|
className: clsx("coop-card", !hasUserBg(className) && "bg-white", className),
|
|
103
|
-
"data-
|
|
104
|
-
"data-
|
|
120
|
+
// "data-behaviour": behaviour ?? undefined,
|
|
121
|
+
"data-adaptive": adaptive ?? undefined,
|
|
122
|
+
"data-orientation": orientation ?? undefined,
|
|
123
|
+
"data-signpost": signpost ?? undefined,
|
|
105
124
|
...props,
|
|
106
125
|
}
|
|
107
126
|
|
|
@@ -110,7 +129,7 @@ const Card = ({
|
|
|
110
129
|
}
|
|
111
130
|
|
|
112
131
|
return (
|
|
113
|
-
<article
|
|
132
|
+
<article ref={ref} {...componentProps}>
|
|
114
133
|
{slots.CardImage}
|
|
115
134
|
{slots.CardBadge}
|
|
116
135
|
{React.createElement(
|
|
@@ -122,7 +141,7 @@ const Card = ({
|
|
|
122
141
|
{slots.CardBody}
|
|
123
142
|
{slots.Children}
|
|
124
143
|
</div>,
|
|
125
|
-
chevron && (
|
|
144
|
+
(chevron || signpost) && (
|
|
126
145
|
<span aria-hidden="true" className="coop-card--icon" role="presentation">
|
|
127
146
|
<ChevronRightIcon />
|
|
128
147
|
</span>
|
|
@@ -132,12 +151,25 @@ const Card = ({
|
|
|
132
151
|
)
|
|
133
152
|
}
|
|
134
153
|
|
|
135
|
-
const CardHeading = ({
|
|
136
|
-
|
|
154
|
+
const CardHeading = ({
|
|
155
|
+
as = "h3",
|
|
156
|
+
children,
|
|
157
|
+
className,
|
|
158
|
+
...props
|
|
159
|
+
}: CardHeadingProps): JSX.Element => {
|
|
160
|
+
return React.createElement(
|
|
161
|
+
as,
|
|
162
|
+
{ className: clsx("coop-card--heading", className), ...props },
|
|
163
|
+
children
|
|
164
|
+
)
|
|
137
165
|
}
|
|
138
166
|
|
|
139
|
-
const CardLabel = ({ children, className }: CardLabelProps): JSX.Element => {
|
|
140
|
-
return
|
|
167
|
+
const CardLabel = ({ children, className, ...props }: CardLabelProps): JSX.Element => {
|
|
168
|
+
return (
|
|
169
|
+
<span className={clsx("coop-card--label", className)} {...props}>
|
|
170
|
+
{children}
|
|
171
|
+
</span>
|
|
172
|
+
)
|
|
141
173
|
}
|
|
142
174
|
|
|
143
175
|
const CardBadge = ({
|
|
@@ -157,8 +189,8 @@ const CardBody = ({ children }: CardBodyProps): JSX.Element => {
|
|
|
157
189
|
return <>{children}</>
|
|
158
190
|
}
|
|
159
191
|
|
|
160
|
-
const CardImage = (props: CardImageProps): JSX.Element => {
|
|
161
|
-
return <Image {...{ ...props, crop:
|
|
192
|
+
const CardImage = ({ align, crop, ...props }: CardImageProps): JSX.Element => {
|
|
193
|
+
return <Image {...{ ...props, crop: crop ?? "wide", "data-align": align ?? undefined }} />
|
|
162
194
|
}
|
|
163
195
|
|
|
164
196
|
Card.slot = { name: "Card" }
|