@purpurds/promotion-card 7.6.0 → 7.7.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": "7.6.0",
3
+ "version": "7.7.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,15 @@
17
17
  "source": "src/promotion-card.tsx",
18
18
  "dependencies": {
19
19
  "classnames": "~2.5.0",
20
- "@purpurds/badge": "7.6.0",
21
- "@purpurds/button": "7.6.0",
22
- "@purpurds/card": "7.6.0",
23
- "@purpurds/cta-link": "7.6.0",
24
- "@purpurds/heading": "7.6.0",
25
- "@purpurds/paragraph": "7.6.0",
26
- "@purpurds/icon": "7.6.0",
27
- "@purpurds/tokens": "7.6.0"
20
+ "@purpurds/badge": "7.7.0",
21
+ "@purpurds/button": "7.7.0",
22
+ "@purpurds/common-types": "7.7.0",
23
+ "@purpurds/card": "7.7.0",
24
+ "@purpurds/cta-link": "7.7.0",
25
+ "@purpurds/heading": "7.7.0",
26
+ "@purpurds/paragraph": "7.7.0",
27
+ "@purpurds/icon": "7.7.0",
28
+ "@purpurds/tokens": "7.7.0"
28
29
  },
29
30
  "devDependencies": {
30
31
  "eslint": "9.24.0",
@@ -45,8 +46,8 @@
45
46
  "vite": "^6.2.1",
46
47
  "vitest": "^3.1.2",
47
48
  "@purpurds/component-rig": "1.0.0",
48
- "@purpurds/text-spacing": "7.6.0",
49
- "@purpurds/grid": "7.6.0"
49
+ "@purpurds/text-spacing": "7.7.0",
50
+ "@purpurds/grid": "7.7.0"
50
51
  },
51
52
  "peerDependencies": {
52
53
  "@types/react": "^18 || ^19",
@@ -126,7 +126,7 @@ export const WithDecorativeImage: Story = {
126
126
  decorativeImage: (
127
127
  <img
128
128
  src="https://www.telia.se/images/i15skfqwpurk/5YYelnwdIJGush05RYsE6A/04d4eeb571bca6d5c72b557f6da92c92/Telia_Company_Reinvention_69.jpg?fit=scale&w=536&fm=jpg&q=70"
129
- alt="Familjens unga ser tv tillsammans mysig stämning men spännande"
129
+ alt="The family's young ones are watching TV together in a cozy but exciting atmosphere"
130
130
  />
131
131
  ),
132
132
  },
@@ -150,11 +150,11 @@ export const WithProductImage: Story = {
150
150
  >
151
151
  <source
152
152
  type="image/webp"
153
- srcSet="https://www.telia.se/images/j6b4qnxw7ufu/5E89mxmBBAYshpycYSoPFD/1912f041265530726efb07097f035b91/101023__160_b2ddd755-1bb7-415c-83f8-cbcd4bf7eb0c?fit=scale&w=500&fm=webp&q=99"
153
+ srcSet="https://www.telia.se/images/j6b4qnxw7ufu/5SQlvYckTDsTPdrdxzUbHD/1d6ca31184938d248d4db82f2c126cd4/115282__160_14ab6ec8-98f7-4a84-a630-6c89cc9b9859?fit=scale&w=500&fm=webp&q=99"
154
154
  />
155
155
  <img
156
- src="https://www.telia.se/images/j6b4qnxw7ufu/5E89mxmBBAYshpycYSoPFD/1912f041265530726efb07097f035b91/101023__160_b2ddd755-1bb7-415c-83f8-cbcd4bf7eb0c?fit=scale&w=500&fm=webp&q=99"
157
- alt="Familjens unga ser på tv tillsammans"
156
+ src="https://www.telia.se/images/j6b4qnxw7ufu/5SQlvYckTDsTPdrdxzUbHD/1d6ca31184938d248d4db82f2c126cd4/115282__160_14ab6ec8-98f7-4a84-a630-6c89cc9b9859?fit=scale&w=500&fm=png&q=99"
157
+ alt="Iphone 16"
158
158
  />
159
159
  </picture>
160
160
  ),
@@ -175,7 +175,7 @@ export const CardGroup: Story = {
175
175
  decorativeImage: (
176
176
  <img
177
177
  src="https://www.telia.se/images/i15skfqwpurk/5YYelnwdIJGush05RYsE6A/04d4eeb571bca6d5c72b557f6da92c92/Telia_Company_Reinvention_69.jpg?fit=scale&w=536&fm=jpg&q=70"
178
- alt="Familjens unga ser tv tillsammans mysig stämning men spännande"
178
+ alt="The family's young ones are watching TV together in a cozy but exciting atmosphere"
179
179
  />
180
180
  ),
181
181
  },
@@ -1,12 +1,7 @@
1
- import React, {
2
- type DetailedHTMLProps,
3
- type ForwardedRef,
4
- forwardRef,
5
- type HTMLAttributes,
6
- type ReactNode,
7
- } from "react";
1
+ import React, { forwardRef, type ReactNode } from "react";
8
2
  import { Badge } from "@purpurds/badge";
9
3
  import { Card } from "@purpurds/card";
4
+ import type { BaseProps } from "@purpurds/common-types";
10
5
  import { Heading, type HeadingTagType, type TitleVariantType } from "@purpurds/heading";
11
6
  import { Paragraph } from "@purpurds/paragraph";
12
7
  import c from "classnames/bind";
@@ -40,8 +35,7 @@ const colors: StyleRecord = {
40
35
  type DecorativeImage = { decorativeImage?: ReactNode; hasGradient?: boolean };
41
36
  type ProductImage = { productImage?: ReactNode; hasGradient?: never };
42
37
 
43
- export type PromotionCardProps = {
44
- ["data-testid"]?: string;
38
+ export type PromotionCardProps = Omit<BaseProps, "children"> & {
45
39
  variant?: PromotionCardVariant;
46
40
  title: string;
47
41
  titleTag?: HeadingTagType;
@@ -58,142 +52,132 @@ export type PromotionCardProps = {
58
52
  const cx = c.bind(styles);
59
53
  const rootClassName = "purpur-promotion-card";
60
54
 
61
- const PromotionCardComponent = (
62
- {
63
- ["data-testid"]: dataTestid,
64
- variant = "primary",
65
- badgeText,
66
- badgeIcon,
67
- title,
68
- titleTag = "h2",
69
- titleVariant = "title-300",
70
- enableTitleHyphenation = false,
71
- className,
72
- actions,
73
- children,
74
- style,
75
- alignment = "space-between",
76
- additionalText,
77
- ...props
78
- }: PromotionCardProps & DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>,
79
- ref: ForwardedRef<HTMLDivElement>
80
- ) => {
81
- let rest = props;
82
- let image;
83
- let showGradient;
84
-
85
- if ("decorativeImage" in props) {
86
- const { hasGradient, decorativeImage, ...spread } = props;
87
- image = decorativeImage;
88
- showGradient = hasGradient;
89
- rest = spread;
90
- } else if ("productImage" in props) {
91
- const { hasGradient, productImage, ...spread } = props;
92
- image = productImage;
93
- showGradient = hasGradient;
94
- rest = spread;
95
- } else if ("hasGradient" in props) {
96
- const { hasGradient, ...spread } = props;
97
- showGradient = hasGradient;
98
- rest = spread;
99
- }
100
-
101
- const customProperties = {
102
- "--promotion-card-background": backgrounds[variant],
103
- "--promotion-card-color": colors[variant],
104
- "--promotion-card-background-image": backgroundImages[variant],
105
- } as React.CSSProperties;
106
-
107
- return (
108
- <Card ref={ref} className={cx(`${rootClassName}__card`)} fullHeight>
109
- <div
110
- data-testid={dataTestid}
111
- style={{
112
- ...customProperties,
113
- ...style,
114
- }}
115
- className={cx([
116
- className,
117
- rootClassName,
118
- `${rootClassName}--${variant}`,
119
- {
55
+ export const PromotionCard = forwardRef<HTMLDivElement, PromotionCardProps>(
56
+ (
57
+ {
58
+ ["data-testid"]: dataTestid,
59
+ variant = "primary",
60
+ badgeText,
61
+ badgeIcon,
62
+ title,
63
+ titleTag = "h2",
64
+ titleVariant = "title-300",
65
+ enableTitleHyphenation = false,
66
+ className,
67
+ actions,
68
+ children,
69
+ style,
70
+ alignment = "space-between",
71
+ additionalText,
72
+ ...props
73
+ },
74
+ ref
75
+ ) => {
76
+ let rest = props;
77
+ let image;
78
+ let showGradient;
79
+
80
+ if ("decorativeImage" in props) {
81
+ const { hasGradient, decorativeImage, ...spread } = props;
82
+ image = decorativeImage;
83
+ showGradient = hasGradient;
84
+ rest = spread;
85
+ } else if ("productImage" in props) {
86
+ const { hasGradient, productImage, ...spread } = props;
87
+ image = productImage;
88
+ showGradient = hasGradient;
89
+ rest = spread;
90
+ } else if ("hasGradient" in props) {
91
+ const { hasGradient, ...spread } = props;
92
+ showGradient = hasGradient;
93
+ rest = spread;
94
+ }
95
+
96
+ const customProperties = {
97
+ "--promotion-card-background": backgrounds[variant],
98
+ "--promotion-card-color": colors[variant],
99
+ "--promotion-card-background-image": backgroundImages[variant],
100
+ } as React.CSSProperties;
101
+
102
+ return (
103
+ <Card ref={ref} className={cx(`${rootClassName}__card`)} fullHeight>
104
+ <div
105
+ data-testid={dataTestid}
106
+ style={{
107
+ ...customProperties,
108
+ ...style,
109
+ }}
110
+ className={cx(className, rootClassName, `${rootClassName}--${variant}`, {
120
111
  [`${rootClassName}--with-image`]: image,
121
112
  [`${rootClassName}--without-image`]: !image,
122
- },
123
- ])}
124
- {...rest}
125
- >
126
- <div
127
- className={cx([
128
- `${rootClassName}__content`,
129
- {
130
- [`${rootClassName}__content--with-image`]: image,
131
- [`${rootClassName}__content--without-image`]: !image,
132
- },
133
- ])}
113
+ })}
114
+ {...rest}
134
115
  >
135
- {badgeText && (
136
- <div data-testid="badgeWrapper" className={cx(`${rootClassName}__badge-wrapper`)}>
137
- <Badge variant={variant === "primary" ? "special" : "attention"} showIcon={false}>
138
- {badgeIcon && badgeIcon}
139
- {badgeText}
140
- </Badge>
141
- </div>
142
- )}
143
-
144
116
  <div
145
- className={cx(
146
- `${rootClassName}__main-content`,
147
- `${rootClassName}__main-content--${alignment}`
148
- )}
117
+ className={cx(`${rootClassName}__content`, {
118
+ [`${rootClassName}__content--with-image`]: image,
119
+ [`${rootClassName}__content--without-image`]: !image,
120
+ })}
149
121
  >
150
- <Heading
151
- tag={titleTag}
152
- variant={titleVariant}
153
- enableHyphenation={enableTitleHyphenation}
154
- className={cx(`${rootClassName}__heading`)}
155
- >
156
- {title}
157
- </Heading>
158
- <div className={cx(`${rootClassName}__body`)}>
159
- <div className={cx(`${rootClassName}__child-content`)}>{children}</div>
160
- {actions && <div className={cx(`${rootClassName}__actions`)}>{actions}</div>}
161
- {additionalText && (
162
- <Paragraph
163
- negative
164
- variant="additional-100"
165
- className={cx(`${rootClassName}__additional-text`)}
166
- >
167
- {additionalText}
168
- </Paragraph>
122
+ {badgeText && (
123
+ <div data-testid="badgeWrapper" className={cx(`${rootClassName}__badge-wrapper`)}>
124
+ <Badge variant={variant === "primary" ? "special" : "attention"} showIcon={false}>
125
+ {badgeIcon && badgeIcon}
126
+ {badgeText}
127
+ </Badge>
128
+ </div>
129
+ )}
130
+
131
+ <div
132
+ className={cx(
133
+ `${rootClassName}__main-content`,
134
+ `${rootClassName}__main-content--${alignment}`
169
135
  )}
136
+ >
137
+ <Heading
138
+ tag={titleTag}
139
+ variant={titleVariant}
140
+ enableHyphenation={enableTitleHyphenation}
141
+ className={cx(`${rootClassName}__heading`)}
142
+ >
143
+ {title}
144
+ </Heading>
145
+ <div className={cx(`${rootClassName}__body`)}>
146
+ <div className={cx(`${rootClassName}__child-content`)}>{children}</div>
147
+ {actions && <div className={cx(`${rootClassName}__actions`)}>{actions}</div>}
148
+ {additionalText && (
149
+ <Paragraph
150
+ negative
151
+ variant="additional-100"
152
+ className={cx(`${rootClassName}__additional-text`)}
153
+ >
154
+ {additionalText}
155
+ </Paragraph>
156
+ )}
157
+ </div>
170
158
  </div>
171
159
  </div>
172
- </div>
173
160
 
174
- {image && (
175
- <div
176
- className={cx([
177
- `${rootClassName}__image-wrapper`,
178
- {
161
+ {image && (
162
+ <div
163
+ className={cx(`${rootClassName}__image-wrapper`, {
179
164
  [`${rootClassName}__image-wrapper--product`]: "productImage" in props,
180
165
  [`${rootClassName}__image-wrapper--decorative`]: "decorativeImage" in props,
181
- },
182
- ])}
183
- >
184
- {image}
185
- {showGradient && (
186
- <div
187
- className={cx(`${rootClassName}__image-gradient`)}
188
- data-testid="promotion-card-gradient"
189
- />
190
- )}
191
- </div>
192
- )}
193
- </div>
194
- </Card>
195
- );
196
- };
166
+ })}
167
+ >
168
+ {image}
169
+ {showGradient && (
170
+ <div
171
+ className={cx(`${rootClassName}__image-gradient`)}
172
+ data-testid="promotion-card-gradient"
173
+ />
174
+ )}
175
+ </div>
176
+ )}
177
+ </div>
178
+ </Card>
179
+ );
180
+ }
181
+ );
197
182
 
198
- export const PromotionCard = forwardRef(PromotionCardComponent);
199
183
  PromotionCard.displayName = "PromotionCard";