@purpurds/promotion-card 5.22.0 → 5.24.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purpurds/promotion-card",
3
- "version": "5.22.0",
3
+ "version": "5.24.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.22.0",
20
- "@purpurds/card": "5.22.0",
21
- "@purpurds/heading": "5.22.0",
22
- "@purpurds/cta-link": "5.22.0",
23
- "@purpurds/icon": "5.22.0",
24
- "@purpurds/tokens": "5.22.0",
25
- "@purpurds/button": "5.22.0"
19
+ "@purpurds/card": "5.24.0",
20
+ "@purpurds/cta-link": "5.24.0",
21
+ "@purpurds/badge": "5.24.0",
22
+ "@purpurds/heading": "5.24.0",
23
+ "@purpurds/button": "5.24.0",
24
+ "@purpurds/icon": "5.24.0",
25
+ "@purpurds/tokens": "5.24.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/paragraph": "5.22.0",
51
- "@purpurds/text-spacing": "5.22.0",
52
- "@purpurds/grid": "5.22.0"
50
+ "@purpurds/paragraph": "5.24.0",
51
+ "@purpurds/text-spacing": "5.24.0",
52
+ "@purpurds/grid": "5.24.0"
53
53
  },
54
54
  "scripts": {
55
55
  "build:dev": "vite",
@@ -6,9 +6,9 @@ import React, {
6
6
  ReactNode,
7
7
  } from "react";
8
8
  import { Badge } from "@purpurds/badge";
9
- import { Button } from "@purpurds/button";
9
+ import { type ButtonProps, Button } from "@purpurds/button";
10
10
  import { Card } from "@purpurds/card";
11
- import { CtaLink } from "@purpurds/cta-link";
11
+ import { type CtaLinkProps, CtaLink } from "@purpurds/cta-link";
12
12
  import { Heading, HeadingTagType, TitleVariantType } from "@purpurds/heading";
13
13
  import c from "classnames/bind";
14
14
 
@@ -41,8 +41,9 @@ const colors: StyleRecord = {
41
41
  type DecorativeImage = { decorativeImage?: ReactNode; hasGradient?: boolean };
42
42
  type ProductImage = { productImage?: ReactNode; hasGradient?: never };
43
43
 
44
- type CtaButton = { href?: never; onClick: () => void };
45
- type CtaLink = { href: string; onClick?: never };
44
+ type ButtonPropsWithoutChildren = Omit<ButtonProps, "children">;
45
+ type CtaLinkPropsWithoutChildren = Omit<CtaLinkProps, "children">;
46
+ type Action = { label: string } & (ButtonPropsWithoutChildren | CtaLinkPropsWithoutChildren);
46
47
 
47
48
  export type PromotionCardProps = {
48
49
  ["data-testid"]?: string;
@@ -54,7 +55,7 @@ export type PromotionCardProps = {
54
55
  badgeText?: string;
55
56
  badgeIcon?: ReactNode;
56
57
  className?: string;
57
- actions?: Array<{ label: string } & (CtaButton | CtaLink)>;
58
+ actions?: Array<Action>;
58
59
  children: ReactNode;
59
60
  } & (DecorativeImage | ProductImage);
60
61
 
@@ -155,22 +156,24 @@ const PromotionCardComponent = (
155
156
  <div className={cx(`${rootClassName}__child-content`)}>{children}</div>
156
157
  {actions && actions.length > 0 && (
157
158
  <div className={cx(`${rootClassName}__actions`)}>
158
- {actions.map(({ label, href, onClick }, index) =>
159
- href ? (
159
+ {actions.map(({ label, variant, iconOnly = undefined, ...rest }, index) =>
160
+ isCtaLinkProps(rest) ? (
160
161
  <CtaLink
161
- variant={index === 0 ? "primary" : "secondary"}
162
+ iconOnly={iconOnly}
163
+ variant={variant ?? index === 0 ? "primary" : "secondary"}
162
164
  key={label}
163
- href={href}
164
165
  negative={variant === "primary"}
166
+ {...rest}
165
167
  >
166
168
  {label}
167
169
  </CtaLink>
168
170
  ) : (
169
171
  <Button
170
- variant={index === 0 ? "primary" : "secondary"}
172
+ iconOnly={iconOnly}
173
+ variant={variant ?? index === 0 ? "primary" : "secondary"}
171
174
  key={label}
172
- onClick={onClick}
173
175
  negative={variant === "primary"}
176
+ {...rest}
174
177
  >
175
178
  {label}
176
179
  </Button>
@@ -206,5 +209,11 @@ const PromotionCardComponent = (
206
209
  );
207
210
  };
208
211
 
212
+ const isCtaLinkProps = (
213
+ action: Omit<CtaLinkPropsWithoutChildren | ButtonPropsWithoutChildren, "variant">
214
+ ): action is Omit<CtaLinkPropsWithoutChildren, "variant"> => {
215
+ return "href" in action;
216
+ };
217
+
209
218
  export const PromotionCard = forwardRef(PromotionCardComponent);
210
219
  PromotionCard.displayName = "PromotionCard";