@purpurds/promotion-card 5.21.1 → 5.23.0
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/LICENSE.txt +5 -5
- package/dist/promotion-card.cjs.js +15 -15
- package/dist/promotion-card.cjs.js.map +1 -1
- package/dist/promotion-card.d.ts +34 -17
- package/dist/promotion-card.d.ts.map +1 -1
- package/dist/promotion-card.es.js +406 -404
- package/dist/promotion-card.es.js.map +1 -1
- package/package.json +11 -11
- package/src/promotion-card.tsx +47 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purpurds/promotion-card",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.23.0",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"main": "./dist/promotion-card.cjs.js",
|
|
6
6
|
"types": "./dist/promotion-card.d.ts",
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
"source": "src/promotion-card.tsx",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"classnames": "~2.5.0",
|
|
19
|
-
"@purpurds/badge": "5.
|
|
20
|
-
"@purpurds/
|
|
21
|
-
"@purpurds/
|
|
22
|
-
"@purpurds/
|
|
23
|
-
"@purpurds/
|
|
24
|
-
"@purpurds/
|
|
25
|
-
"@purpurds/
|
|
19
|
+
"@purpurds/badge": "5.23.0",
|
|
20
|
+
"@purpurds/cta-link": "5.23.0",
|
|
21
|
+
"@purpurds/heading": "5.23.0",
|
|
22
|
+
"@purpurds/button": "5.23.0",
|
|
23
|
+
"@purpurds/icon": "5.23.0",
|
|
24
|
+
"@purpurds/tokens": "5.23.0",
|
|
25
|
+
"@purpurds/card": "5.23.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@rushstack/eslint-patch": "~1.10.0",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"vite": "5.4.8",
|
|
48
48
|
"vitest": "^2.1.2",
|
|
49
49
|
"@purpurds/component-rig": "1.0.0",
|
|
50
|
-
"@purpurds/
|
|
51
|
-
"@purpurds/
|
|
52
|
-
"@purpurds/
|
|
50
|
+
"@purpurds/paragraph": "5.23.0",
|
|
51
|
+
"@purpurds/text-spacing": "5.23.0",
|
|
52
|
+
"@purpurds/grid": "5.23.0"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build:dev": "vite",
|
package/src/promotion-card.tsx
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
DetailedHTMLProps,
|
|
3
|
+
ForwardedRef,
|
|
4
|
+
forwardRef,
|
|
5
|
+
HTMLAttributes,
|
|
6
|
+
ReactNode,
|
|
7
|
+
} from "react";
|
|
2
8
|
import { Badge } from "@purpurds/badge";
|
|
3
|
-
import { Button } from "@purpurds/button";
|
|
9
|
+
import { type ButtonProps, Button } from "@purpurds/button";
|
|
4
10
|
import { Card } from "@purpurds/card";
|
|
5
|
-
import { CtaLink } from "@purpurds/cta-link";
|
|
11
|
+
import { type CtaLinkProps, CtaLink } from "@purpurds/cta-link";
|
|
6
12
|
import { Heading, HeadingTagType, TitleVariantType } from "@purpurds/heading";
|
|
7
13
|
import c from "classnames/bind";
|
|
8
14
|
|
|
@@ -35,8 +41,9 @@ const colors: StyleRecord = {
|
|
|
35
41
|
type DecorativeImage = { decorativeImage?: ReactNode; hasGradient?: boolean };
|
|
36
42
|
type ProductImage = { productImage?: ReactNode; hasGradient?: never };
|
|
37
43
|
|
|
38
|
-
type
|
|
39
|
-
type
|
|
44
|
+
type ButtonPropsWithoutChildren = Omit<ButtonProps, "children">;
|
|
45
|
+
type CtaLinkPropsWithoutChildren = Omit<CtaLinkProps, "children">;
|
|
46
|
+
type Action = { label: string } & (ButtonPropsWithoutChildren | CtaLinkPropsWithoutChildren);
|
|
40
47
|
|
|
41
48
|
export type PromotionCardProps = {
|
|
42
49
|
["data-testid"]?: string;
|
|
@@ -48,28 +55,31 @@ export type PromotionCardProps = {
|
|
|
48
55
|
badgeText?: string;
|
|
49
56
|
badgeIcon?: ReactNode;
|
|
50
57
|
className?: string;
|
|
51
|
-
actions?: Array<
|
|
58
|
+
actions?: Array<Action>;
|
|
52
59
|
children: ReactNode;
|
|
53
60
|
} & (DecorativeImage | ProductImage);
|
|
54
61
|
|
|
55
62
|
const cx = c.bind(styles);
|
|
56
63
|
const rootClassName = "purpur-promotion-card";
|
|
57
64
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
const PromotionCardComponent = (
|
|
66
|
+
{
|
|
67
|
+
["data-testid"]: dataTestid,
|
|
68
|
+
variant = "primary",
|
|
69
|
+
badgeText,
|
|
70
|
+
badgeIcon,
|
|
71
|
+
title,
|
|
72
|
+
titleTag = "h2",
|
|
73
|
+
titleVariant = "title-300",
|
|
74
|
+
enableTitleHyphenation = true,
|
|
75
|
+
className,
|
|
76
|
+
actions,
|
|
77
|
+
children,
|
|
78
|
+
style,
|
|
79
|
+
...props
|
|
80
|
+
}: PromotionCardProps & DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>,
|
|
81
|
+
ref: ForwardedRef<HTMLDivElement>
|
|
82
|
+
) => {
|
|
73
83
|
let rest = props;
|
|
74
84
|
let image;
|
|
75
85
|
let showGradient;
|
|
@@ -97,7 +107,7 @@ export const PromotionCard = ({
|
|
|
97
107
|
} as React.CSSProperties;
|
|
98
108
|
|
|
99
109
|
return (
|
|
100
|
-
<Card className={cx(`${rootClassName}__card`)}>
|
|
110
|
+
<Card ref={ref} className={cx(`${rootClassName}__card`)}>
|
|
101
111
|
<div
|
|
102
112
|
data-testid={dataTestid}
|
|
103
113
|
style={{
|
|
@@ -146,22 +156,24 @@ export const PromotionCard = ({
|
|
|
146
156
|
<div className={cx(`${rootClassName}__child-content`)}>{children}</div>
|
|
147
157
|
{actions && actions.length > 0 && (
|
|
148
158
|
<div className={cx(`${rootClassName}__actions`)}>
|
|
149
|
-
{actions.map(({ label,
|
|
150
|
-
|
|
159
|
+
{actions.map(({ label, variant, iconOnly = undefined, ...rest }, index) =>
|
|
160
|
+
isCtaLinkProps(rest) ? (
|
|
151
161
|
<CtaLink
|
|
152
|
-
|
|
162
|
+
iconOnly={iconOnly}
|
|
163
|
+
variant={variant ?? index === 0 ? "primary" : "secondary"}
|
|
153
164
|
key={label}
|
|
154
|
-
href={href}
|
|
155
165
|
negative={variant === "primary"}
|
|
166
|
+
{...rest}
|
|
156
167
|
>
|
|
157
168
|
{label}
|
|
158
169
|
</CtaLink>
|
|
159
170
|
) : (
|
|
160
171
|
<Button
|
|
161
|
-
|
|
172
|
+
iconOnly={iconOnly}
|
|
173
|
+
variant={variant ?? index === 0 ? "primary" : "secondary"}
|
|
162
174
|
key={label}
|
|
163
|
-
onClick={onClick}
|
|
164
175
|
negative={variant === "primary"}
|
|
176
|
+
{...rest}
|
|
165
177
|
>
|
|
166
178
|
{label}
|
|
167
179
|
</Button>
|
|
@@ -197,4 +209,11 @@ export const PromotionCard = ({
|
|
|
197
209
|
);
|
|
198
210
|
};
|
|
199
211
|
|
|
212
|
+
const isCtaLinkProps = (
|
|
213
|
+
action: Omit<CtaLinkPropsWithoutChildren | ButtonPropsWithoutChildren, "variant">
|
|
214
|
+
): action is Omit<CtaLinkPropsWithoutChildren, "variant"> => {
|
|
215
|
+
return "href" in action;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export const PromotionCard = forwardRef(PromotionCardComponent);
|
|
200
219
|
PromotionCard.displayName = "PromotionCard";
|