@purpurds/cta-link 4.1.1 → 4.3.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 +2 -2
- package/dist/cta-link.cjs.js +3 -3
- package/dist/cta-link.cjs.js.map +1 -1
- package/dist/cta-link.d.ts +5 -1
- package/dist/cta-link.d.ts.map +1 -1
- package/dist/cta-link.es.js +88 -66
- package/dist/cta-link.es.js.map +1 -1
- package/package.json +4 -4
- package/src/cta-link.stories.tsx +9 -2
- package/src/cta-link.tsx +22 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purpurds/cta-link",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"main": "./dist/cta-link.cjs.js",
|
|
6
6
|
"types": "./dist/cta-link.d.ts",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"source": "src/cta-link.tsx",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"classnames": "~2.5.0",
|
|
18
|
-
"@purpurds/action": "4.
|
|
19
|
-
"@purpurds/icon": "4.
|
|
20
|
-
"@purpurds/tokens": "4.
|
|
18
|
+
"@purpurds/action": "4.3.0",
|
|
19
|
+
"@purpurds/icon": "4.3.0",
|
|
20
|
+
"@purpurds/tokens": "4.3.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@rushstack/eslint-patch": "~1.7.0",
|
package/src/cta-link.stories.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import { sizes, variants } from "@purpurds/action";
|
|
|
3
3
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
4
4
|
|
|
5
5
|
import "@purpurds/icon/styles";
|
|
6
|
-
import { CtaLink } from "./cta-link";
|
|
6
|
+
import { CtaLink, ctaLinkIcons } from "./cta-link";
|
|
7
7
|
|
|
8
8
|
const meta: Meta<typeof CtaLink> = {
|
|
9
9
|
title: "Components/CtaLink",
|
|
@@ -13,7 +13,8 @@ const meta: Meta<typeof CtaLink> = {
|
|
|
13
13
|
{
|
|
14
14
|
name: "CtaLink",
|
|
15
15
|
type: "figma",
|
|
16
|
-
url:
|
|
16
|
+
url:
|
|
17
|
+
"https://www.figma.com/file/XEaIIFskrrxIBHMZDkIuIg/Purpur-DS---Component-library-%26-guidelines?type=design&node-id=34461%3A39919&mode=design",
|
|
17
18
|
},
|
|
18
19
|
],
|
|
19
20
|
},
|
|
@@ -27,6 +28,10 @@ const meta: Meta<typeof CtaLink> = {
|
|
|
27
28
|
options: variants,
|
|
28
29
|
control: { type: "select" },
|
|
29
30
|
},
|
|
31
|
+
icon: {
|
|
32
|
+
options: ctaLinkIcons,
|
|
33
|
+
control: { type: "select" },
|
|
34
|
+
},
|
|
30
35
|
["data-testid"]: { control: { type: "text" } },
|
|
31
36
|
className: { control: { type: "text" } },
|
|
32
37
|
children: { control: { type: "text" } },
|
|
@@ -41,6 +46,7 @@ export const Showcase: Story = {
|
|
|
41
46
|
children: "CTA Link label",
|
|
42
47
|
fullWidth: false,
|
|
43
48
|
variant: "primary",
|
|
49
|
+
icon: "forward",
|
|
44
50
|
href: "#telia",
|
|
45
51
|
},
|
|
46
52
|
};
|
|
@@ -53,6 +59,7 @@ export const CtaLinkWithOnlyIcon: Story = {
|
|
|
53
59
|
args: {
|
|
54
60
|
variant: "primary",
|
|
55
61
|
iconOnly: true,
|
|
62
|
+
icon: "forward",
|
|
56
63
|
["aria-label"]: "CTA Link label",
|
|
57
64
|
},
|
|
58
65
|
render: ({ ...args }) => <CtaLink {...args} />,
|
package/src/cta-link.tsx
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import React, { AnchorHTMLAttributes } from "react";
|
|
2
2
|
import { ActionProps, SIZE } from "@purpurds/action";
|
|
3
|
-
import { arrowRight, Icon } from "@purpurds/icon";
|
|
3
|
+
import { arrowLeft, arrowRight, external, Icon, phone } from "@purpurds/icon";
|
|
4
4
|
import c from "classnames";
|
|
5
5
|
|
|
6
6
|
import styles from "./cta-link.module.scss";
|
|
7
7
|
|
|
8
8
|
const rootClassName = "purpur-cta-link";
|
|
9
9
|
|
|
10
|
+
export const ctaLinkIcons = ["forward", "external", "back", "phone"] as const;
|
|
11
|
+
|
|
12
|
+
export type CtaLinkIcon = typeof ctaLinkIcons[number];
|
|
13
|
+
|
|
14
|
+
const iconMapping = {
|
|
15
|
+
forward: arrowRight,
|
|
16
|
+
external: external,
|
|
17
|
+
back: arrowLeft,
|
|
18
|
+
phone: phone,
|
|
19
|
+
};
|
|
20
|
+
|
|
10
21
|
export const CtaLink = ({
|
|
11
22
|
children,
|
|
12
23
|
className,
|
|
@@ -15,8 +26,9 @@ export const CtaLink = ({
|
|
|
15
26
|
iconOnly,
|
|
16
27
|
size = SIZE.MD,
|
|
17
28
|
variant,
|
|
29
|
+
icon = "forward",
|
|
18
30
|
...props
|
|
19
|
-
}: ActionProps & AnchorHTMLAttributes<HTMLAnchorElement>) => {
|
|
31
|
+
}: ActionProps & AnchorHTMLAttributes<HTMLAnchorElement> & { icon?: CtaLinkIcon }) => {
|
|
20
32
|
const classes = c(
|
|
21
33
|
[
|
|
22
34
|
className,
|
|
@@ -32,11 +44,17 @@ export const CtaLink = ({
|
|
|
32
44
|
);
|
|
33
45
|
|
|
34
46
|
const Tag = props.href ? "a" : "span";
|
|
47
|
+
const IconComponent = iconMapping[icon];
|
|
35
48
|
|
|
36
49
|
return (
|
|
37
50
|
<Tag className={classes} data-testid={dataTestid} {...props}>
|
|
38
|
-
{
|
|
39
|
-
|
|
51
|
+
{(icon === "back" || icon === "phone") && (
|
|
52
|
+
<Icon svg={IconComponent} size={size === SIZE.LG ? "sm" : "xs"} />
|
|
53
|
+
)}
|
|
54
|
+
{!iconOnly && children}
|
|
55
|
+
{(icon === "forward" || icon === "external") && (
|
|
56
|
+
<Icon svg={IconComponent} size={size === SIZE.LG ? "sm" : "xs"} />
|
|
57
|
+
)}
|
|
40
58
|
</Tag>
|
|
41
59
|
);
|
|
42
60
|
};
|