@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purpurds/promotion-card",
3
- "version": "5.21.1",
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.21.1",
20
- "@purpurds/card": "5.21.1",
21
- "@purpurds/cta-link": "5.21.1",
22
- "@purpurds/heading": "5.21.1",
23
- "@purpurds/button": "5.21.1",
24
- "@purpurds/icon": "5.21.1",
25
- "@purpurds/tokens": "5.21.1"
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/text-spacing": "5.21.1",
51
- "@purpurds/grid": "5.21.1",
52
- "@purpurds/paragraph": "5.21.1"
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",
@@ -1,8 +1,14 @@
1
- import React, { DetailedHTMLProps, HTMLAttributes, ReactNode } from "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 CtaButton = { href?: never; onClick: () => void };
39
- 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);
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<{ label: string } & (CtaButton | CtaLink)>;
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
- export const PromotionCard = ({
59
- ["data-testid"]: dataTestid,
60
- variant = "primary",
61
- badgeText,
62
- badgeIcon,
63
- title,
64
- titleTag = "h2",
65
- titleVariant = "title-300",
66
- enableTitleHyphenation = true,
67
- className,
68
- actions,
69
- children,
70
- style,
71
- ...props
72
- }: PromotionCardProps & DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>) => {
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, href, onClick }, index) =>
150
- href ? (
159
+ {actions.map(({ label, variant, iconOnly = undefined, ...rest }, index) =>
160
+ isCtaLinkProps(rest) ? (
151
161
  <CtaLink
152
- variant={index === 0 ? "primary" : "secondary"}
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
- variant={index === 0 ? "primary" : "secondary"}
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";