@purpurds/promotion-card 6.12.4 → 7.0.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 +4 -18
- package/dist/promotion-card.cjs.js +13 -29
- package/dist/promotion-card.cjs.js.map +1 -1
- package/dist/promotion-card.d.ts +3 -8
- package/dist/promotion-card.d.ts.map +1 -1
- package/dist/promotion-card.es.js +577 -1105
- package/dist/promotion-card.es.js.map +1 -1
- package/package.json +11 -11
- package/src/promotion-card.stories.tsx +39 -30
- package/src/promotion-card.test.tsx +18 -0
- package/src/promotion-card.tsx +2 -32
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purpurds/promotion-card",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"main": "./dist/promotion-card.cjs.js",
|
|
6
6
|
"types": "./dist/promotion-card.d.ts",
|
|
@@ -17,14 +17,14 @@
|
|
|
17
17
|
"source": "src/promotion-card.tsx",
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"classnames": "~2.5.0",
|
|
20
|
-
"@purpurds/
|
|
21
|
-
"@purpurds/
|
|
22
|
-
"@purpurds/
|
|
23
|
-
"@purpurds/
|
|
24
|
-
"@purpurds/
|
|
25
|
-
"@purpurds/
|
|
26
|
-
"@purpurds/
|
|
27
|
-
"@purpurds/
|
|
20
|
+
"@purpurds/cta-link": "7.0.0",
|
|
21
|
+
"@purpurds/card": "7.0.0",
|
|
22
|
+
"@purpurds/heading": "7.0.0",
|
|
23
|
+
"@purpurds/button": "7.0.0",
|
|
24
|
+
"@purpurds/paragraph": "7.0.0",
|
|
25
|
+
"@purpurds/icon": "7.0.0",
|
|
26
|
+
"@purpurds/tokens": "7.0.0",
|
|
27
|
+
"@purpurds/badge": "7.0.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"eslint": "9.24.0",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"vite": "^6.2.1",
|
|
46
46
|
"vitest": "^3.1.2",
|
|
47
47
|
"@purpurds/component-rig": "1.0.0",
|
|
48
|
-
"@purpurds/text-spacing": "
|
|
49
|
-
"@purpurds/grid": "
|
|
48
|
+
"@purpurds/text-spacing": "7.0.0",
|
|
49
|
+
"@purpurds/grid": "7.0.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@types/react": "^18 || ^19",
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { Button } from "@purpurds/button";
|
|
3
|
+
import { CtaLink } from "@purpurds/cta-link";
|
|
2
4
|
import { Grid } from "@purpurds/grid";
|
|
3
5
|
import { HeadingTag, TitleVariant } from "@purpurds/heading";
|
|
4
6
|
import { IconCheckmark } from "@purpurds/icon/checkmark";
|
|
@@ -34,16 +36,16 @@ const meta = {
|
|
|
34
36
|
badgeText: "Badge title",
|
|
35
37
|
badgeIcon: <IconOffering size="xs" />,
|
|
36
38
|
title: "Title goes here lorem ipsum",
|
|
37
|
-
actions:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
actions: (
|
|
40
|
+
<>
|
|
41
|
+
<CtaLink variant="primary" href="#" negative>
|
|
42
|
+
Primary link
|
|
43
|
+
</CtaLink>
|
|
44
|
+
<CtaLink variant="secondary" href="#" negative>
|
|
45
|
+
Secondary link
|
|
46
|
+
</CtaLink>
|
|
47
|
+
</>
|
|
48
|
+
),
|
|
47
49
|
additionalText: "Additional texts such as legal ones",
|
|
48
50
|
enableTitleHyphenation: false,
|
|
49
51
|
},
|
|
@@ -185,12 +187,11 @@ export const CardGroup: Story = {
|
|
|
185
187
|
</PromotionCard>
|
|
186
188
|
<PromotionCard
|
|
187
189
|
{...args}
|
|
188
|
-
actions={
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
]}
|
|
190
|
+
actions={
|
|
191
|
+
<CtaLink variant="primary" href="#" negative>
|
|
192
|
+
Primary link
|
|
193
|
+
</CtaLink>
|
|
194
|
+
}
|
|
194
195
|
>
|
|
195
196
|
<Paragraph>
|
|
196
197
|
Get our popular broadband and we'll offer you two months and the initial fee. Or
|
|
@@ -215,20 +216,28 @@ export const Showcase: Story = {
|
|
|
215
216
|
|
|
216
217
|
export const ActionButtons: Story = {
|
|
217
218
|
args: {
|
|
218
|
-
actions:
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
219
|
+
actions: (
|
|
220
|
+
<>
|
|
221
|
+
<Button
|
|
222
|
+
variant="primary"
|
|
223
|
+
onClick={() => {
|
|
224
|
+
alert("Primary button clicked");
|
|
225
|
+
}}
|
|
226
|
+
negative
|
|
227
|
+
>
|
|
228
|
+
Primary button
|
|
229
|
+
</Button>
|
|
230
|
+
<Button
|
|
231
|
+
variant="secondary"
|
|
232
|
+
onClick={() => {
|
|
233
|
+
alert("Secondary button clicked");
|
|
234
|
+
}}
|
|
235
|
+
negative
|
|
236
|
+
>
|
|
237
|
+
Secondary button
|
|
238
|
+
</Button>
|
|
239
|
+
</>
|
|
240
|
+
),
|
|
232
241
|
},
|
|
233
242
|
tags: ["visual:check"],
|
|
234
243
|
};
|
|
@@ -163,4 +163,22 @@ describe("PromotionCard", () => {
|
|
|
163
163
|
|
|
164
164
|
expect(screen.queryByTestId("promotion-card-gradient")).not.toBeInTheDocument();
|
|
165
165
|
});
|
|
166
|
+
|
|
167
|
+
it("should render action elements", async () => {
|
|
168
|
+
render(
|
|
169
|
+
<PromotionCard
|
|
170
|
+
actions={
|
|
171
|
+
<button type="button" data-testid="action">
|
|
172
|
+
Action
|
|
173
|
+
</button>
|
|
174
|
+
}
|
|
175
|
+
{...props}
|
|
176
|
+
>
|
|
177
|
+
<div />
|
|
178
|
+
</PromotionCard>
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
const actionElement = await screen.findByTestId("action");
|
|
182
|
+
expect(actionElement).toBeInTheDocument();
|
|
183
|
+
});
|
|
166
184
|
});
|
package/src/promotion-card.tsx
CHANGED
|
@@ -6,9 +6,7 @@ import React, {
|
|
|
6
6
|
ReactNode,
|
|
7
7
|
} from "react";
|
|
8
8
|
import { Badge } from "@purpurds/badge";
|
|
9
|
-
import { Button, type ButtonProps } from "@purpurds/button";
|
|
10
9
|
import { Card } from "@purpurds/card";
|
|
11
|
-
import { CtaAnchorProps, CtaLink } from "@purpurds/cta-link";
|
|
12
10
|
import { Heading, HeadingTagType, TitleVariantType } from "@purpurds/heading";
|
|
13
11
|
import { Paragraph } from "@purpurds/paragraph";
|
|
14
12
|
import c from "classnames/bind";
|
|
@@ -42,11 +40,6 @@ const colors: StyleRecord = {
|
|
|
42
40
|
type DecorativeImage = { decorativeImage?: ReactNode; hasGradient?: boolean };
|
|
43
41
|
type ProductImage = { productImage?: ReactNode; hasGradient?: never };
|
|
44
42
|
|
|
45
|
-
type Action = { label: string } & (
|
|
46
|
-
| Omit<ButtonProps, "children" | "variant">
|
|
47
|
-
| Omit<CtaAnchorProps, "children" | "variant">
|
|
48
|
-
);
|
|
49
|
-
|
|
50
43
|
export type PromotionCardProps = {
|
|
51
44
|
["data-testid"]?: string;
|
|
52
45
|
variant?: PromotionCardVariant;
|
|
@@ -56,7 +49,7 @@ export type PromotionCardProps = {
|
|
|
56
49
|
enableTitleHyphenation?: boolean;
|
|
57
50
|
badgeText?: string;
|
|
58
51
|
badgeIcon?: ReactNode;
|
|
59
|
-
actions?:
|
|
52
|
+
actions?: ReactNode;
|
|
60
53
|
children: ReactNode;
|
|
61
54
|
alignment?: "space-between" | "flex-end";
|
|
62
55
|
additionalText?: ReactNode;
|
|
@@ -164,26 +157,7 @@ const PromotionCardComponent = (
|
|
|
164
157
|
</Heading>
|
|
165
158
|
<div className={cx(`${rootClassName}__body`)}>
|
|
166
159
|
<div className={cx(`${rootClassName}__child-content`)}>{children}</div>
|
|
167
|
-
{actions &&
|
|
168
|
-
<div className={cx(`${rootClassName}__actions`)}>
|
|
169
|
-
{actions.map(({ label, ...rest }, index) => {
|
|
170
|
-
const actionVariant = index === 0 ? "primary" : "secondary";
|
|
171
|
-
const props = {
|
|
172
|
-
variant: actionVariant,
|
|
173
|
-
negative: variant === "primary",
|
|
174
|
-
...rest,
|
|
175
|
-
children: label,
|
|
176
|
-
} as const;
|
|
177
|
-
if (isValidAnchor(props)) {
|
|
178
|
-
return <CtaLink key={label} {...props} />;
|
|
179
|
-
}
|
|
180
|
-
if ("onClick" in props && !("href" in props)) {
|
|
181
|
-
return <Button key={label} {...props} />;
|
|
182
|
-
}
|
|
183
|
-
return null;
|
|
184
|
-
})}
|
|
185
|
-
</div>
|
|
186
|
-
)}
|
|
160
|
+
{actions && <div className={cx(`${rootClassName}__actions`)}>{actions}</div>}
|
|
187
161
|
{additionalText && (
|
|
188
162
|
<Paragraph
|
|
189
163
|
negative
|
|
@@ -221,9 +195,5 @@ const PromotionCardComponent = (
|
|
|
221
195
|
);
|
|
222
196
|
};
|
|
223
197
|
|
|
224
|
-
const isValidAnchor = (action: object): action is CtaAnchorProps => {
|
|
225
|
-
return "href" in action;
|
|
226
|
-
};
|
|
227
|
-
|
|
228
198
|
export const PromotionCard = forwardRef(PromotionCardComponent);
|
|
229
199
|
PromotionCard.displayName = "PromotionCard";
|