-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathLinkButton.tsx
84 lines (76 loc) · 2.13 KB
/
LinkButton.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import {
Actionable,
ActionableCyberstormLinkProps,
ActionableLinkProps,
} from "../../../primitiveComponents/Actionable/Actionable";
import buttonStyles from "../../../sharedComponentStyles/ButtonStyles/Button.module.css";
import React from "react";
import { classnames } from "../../../utils/utils";
interface Modifiers {
dimmed?: boolean;
subtle?: boolean;
disabled?: boolean;
}
interface LinkProps extends ActionableLinkProps, Modifiers {}
interface CyberstormLinkProps extends ActionableCyberstormLinkProps, Modifiers {}
export const LinkButton = React.forwardRef<
HTMLAnchorElement,
LinkProps | CyberstormLinkProps
>(
(
props: LinkProps | CyberstormLinkProps,
forwardedRef
) => {
const {
children,
rootClasses,
csVariant = "default",
csSize = "m",
csTextStyles,
dimmed,
subtle,
disabled,
...forwardedProps
} = props;
return (
<Actionable
{...forwardedProps}
// disabled={disabled} TODO: Implement disabled for a tags?
rootClasses={classnames(
buttonStyles.button,
getSize(csSize),
getVariant(csVariant),
dimmed ? buttonStyles["button--dimmed"] : null,
subtle ? buttonStyles["button--subtle"] : null,
disabled ? buttonStyles["button--disabled"] : null,
rootClasses
)}
ref={forwardedRef}
>
{children}
</Actionable>
);
}
);
LinkButton.displayName = "LinkButton";
const getVariant = (scheme: string) => {
return {
primary: buttonStyles.button__primary,
secondary: buttonStyles.button__secondary,
tertiary: buttonStyles.button__tertiary,
accent: buttonStyles.button__accent,
special: buttonStyles.button__special,
info: buttonStyles.button__info,
success: buttonStyles.button__success,
warning: buttonStyles.button__warning,
danger: buttonStyles.button__danger,
}[scheme];
};
const getSize = (scheme: string) => {
return {
xs: buttonStyles["button--size-xs"],
s: buttonStyles["button--size-s"],
m: buttonStyles["button--size-m"],
l: buttonStyles["button--size-l"],
}[scheme];
};