Skip to content

Commit bc0dbf8

Browse files
committed
Refactor Button to token system
1 parent 554441b commit bc0dbf8

File tree

6 files changed

+478
-206
lines changed

6 files changed

+478
-206
lines changed

packages/cyberstorm-styles/src/styles/fonts.css

+16
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,19 @@
1515
font-family: Hubot-Sans;
1616
src: url("../fonts/HubotSans.ttf") format("truetype-variations");
1717
}
18+
19+
:root {
20+
--global--line-height--auto: normal;
21+
--global--line-height--body: 170%;
22+
--global--font-size--xxs: 0.625rem;
23+
--global--font-size--xs: 0.75rem;
24+
--global--font-size--s: 0.875rem;
25+
--global--font-size--m: 1rem;
26+
--global--font-size--l: 1.5rem;
27+
--global--font-weight--regular: 400;
28+
--global--font-weight--medium: 500;
29+
--global--font-weight--semiBold: 600;
30+
--global--font-weight--bold: 700;
31+
--global--font-family--inter: inter, sans-serif;
32+
--global--font-family--hubot: Hubot-Sans, sans-serif;
33+
}

packages/cyberstorm/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,4 @@ export {
135135
export { Image } from "./newComponents/Image/Image";
136136
export * as List from "./newComponents/List";
137137
export { AdContainer } from "./newComponents/AdContainer/AdContainer";
138+
import "./sharedComponentStyles/ButtonStyles/ButtonTokens.css";

packages/cyberstorm/src/newComponents/Button/Button.tsx

+45-32
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,36 @@ import { IconProp } from "@fortawesome/fontawesome-svg-core";
1010
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
1111
import { NewIcon } from "../..";
1212

13-
interface ButtonProps extends Omit<ActionableButtonProps, "primitiveType"> {
13+
interface Modifiers {
14+
dimmed?: boolean;
15+
subtle?: boolean;
16+
disabled?: boolean;
17+
}
18+
19+
interface ButtonProps extends Omit<ActionableButtonProps, "primitiveType" | "csVariant">, Modifiers {
1420
csVariant?:
15-
| "default"
16-
| "defaultPeek"
1721
| "primary"
1822
| "secondary"
1923
| "tertiary"
20-
| "minimal"
2124
| "accent"
22-
| "special";
25+
| "special"
26+
| "info"
27+
| "success"
28+
| "warning"
29+
| "danger";
2330
csSize?: "xs" | "s" | "m" | "l";
2431
}
2532

2633
interface IconButtonProps
2734
extends Omit<
2835
ActionableButtonProps,
2936
"primitiveType" | "csVariant" | "csSize" | "children"
30-
> {
37+
>, Modifiers {
3138
csVariant?:
32-
| "default"
33-
| "defaultPeek"
3439
| "primary"
3540
| "secondary"
3641
| "tertiary"
37-
| "tertiaryDimmed"
42+
| "danger"
3843
| "minimal";
3944
csSize?: "xs" | "s" | "m";
4045
icon: IconProp;
@@ -46,12 +51,11 @@ export type ButtonComponentProps =
4651

4752
export const Button = React.forwardRef<HTMLButtonElement, ButtonComponentProps>(
4853
(props: ButtonComponentProps, forwardedRef) => {
49-
const { rootClasses, csTextStyles, icon, ...forwardedProps } = props;
54+
const { rootClasses, csTextStyles, icon, dimmed, subtle, disabled, ...forwardedProps } = props;
5055

5156
if (icon) {
5257
const {
5358
csVariant = "default",
54-
csColor = "purple",
5559
csSize = "m",
5660
...fProps
5761
} = forwardedProps as IconButtonProps;
@@ -61,9 +65,6 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonComponentProps>(
6165
primitiveType="button"
6266
{...fProps}
6367
rootClasses={classnames(iconButtonStyles.iconButton, rootClasses)}
64-
csColor={csColor}
65-
csSize={csSize}
66-
csVariant={csVariant}
6768
ref={forwardedRef}
6869
>
6970
<NewIcon csMode="inline" noWrapper>
@@ -75,36 +76,25 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonComponentProps>(
7576

7677
const {
7778
children,
78-
csVariant = "default",
79-
csColor = "purple",
79+
csVariant = "primary",
8080
csSize = "m",
8181
...fProps
8282
} = forwardedProps as ButtonProps;
8383

84-
// TODO: Turn into a proper resolver function
85-
// Same logic is in LinkButton too
86-
const fontStyles = (size: typeof csSize) => {
87-
if (size === "xs") {
88-
return ["fontSizeXS", "fontWeightBold", "lineHeightAuto"];
89-
} else if (size === "s") {
90-
return ["fontSizeS", "fontWeightBold", "lineHeightAuto"];
91-
} else {
92-
return ["fontSizeM", "fontWeightBold", "lineHeightAuto"];
93-
}
94-
};
95-
9684
return (
9785
<Actionable
9886
primitiveType="button"
9987
{...fProps}
88+
disabled={disabled}
10089
rootClasses={classnames(
101-
...(csTextStyles ? csTextStyles : fontStyles(csSize)),
10290
buttonStyles.button,
91+
getSize(csSize),
92+
getVariant(csVariant),
93+
dimmed ? buttonStyles["button--dimmed"] : null,
94+
subtle ? buttonStyles["button--subtle"] : null,
95+
disabled ? buttonStyles["button--disabled"] : null,
10396
rootClasses
10497
)}
105-
csColor={csColor}
106-
csSize={csSize}
107-
csVariant={csVariant}
10898
ref={forwardedRef}
10999
>
110100
{children}
@@ -114,3 +104,26 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonComponentProps>(
114104
);
115105

116106
Button.displayName = "Button";
107+
108+
const getVariant = (scheme: string) => {
109+
return {
110+
primary: buttonStyles.button__primary,
111+
secondary: buttonStyles.button__secondary,
112+
tertiary: buttonStyles.button__tertiary,
113+
accent: buttonStyles.button__accent,
114+
special: buttonStyles.button__special,
115+
info: buttonStyles.button__info,
116+
success: buttonStyles.button__success,
117+
warning: buttonStyles.button__warning,
118+
danger: buttonStyles.button__danger,
119+
}[scheme];
120+
};
121+
122+
const getSize = (scheme: string) => {
123+
return {
124+
xs: buttonStyles["button--size-xs"],
125+
s: buttonStyles["button--size-s"],
126+
m: buttonStyles["button--size-m"],
127+
l: buttonStyles["button--size-l"],
128+
}[scheme];
129+
};

packages/cyberstorm/src/newComponents/Link/LinkButton/LinkButton.tsx

+46-21
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,53 @@ import {
33
ActionableCyberstormLinkProps,
44
ActionableLinkProps,
55
} from "../../../primitiveComponents/Actionable/Actionable";
6-
import styles from "../../../sharedComponentStyles/ButtonStyles/Button.module.css";
6+
import buttonStyles from "../../../sharedComponentStyles/ButtonStyles/Button.module.css";
77
import React from "react";
88
import { classnames } from "../../../utils/utils";
99

10+
interface Modifiers {
11+
dimmed?: boolean;
12+
subtle?: boolean;
13+
disabled?: boolean;
14+
}
15+
16+
interface LinkProps extends ActionableLinkProps, Modifiers {}
17+
interface CyberstormLinkProps extends ActionableCyberstormLinkProps, Modifiers {}
18+
19+
1020
export const LinkButton = React.forwardRef<
1121
HTMLAnchorElement,
12-
ActionableLinkProps | ActionableCyberstormLinkProps
22+
LinkProps | CyberstormLinkProps
1323
>(
1424
(
15-
props: ActionableLinkProps | ActionableCyberstormLinkProps,
25+
props: LinkProps | CyberstormLinkProps,
1626
forwardedRef
1727
) => {
1828
const {
1929
children,
2030
rootClasses,
2131
csVariant = "default",
22-
csColor = "purple",
2332
csSize = "m",
2433
csTextStyles,
34+
dimmed,
35+
subtle,
36+
disabled,
2537
...forwardedProps
2638
} = props;
2739

28-
// TODO: Turn into a proper resolver function
29-
// Same logic is in LinkButton too
30-
const fontStyles = (size: typeof csSize) => {
31-
if (size === "xs") {
32-
return ["fontSizeXS", "fontWeightBold", "lineHeightAuto"];
33-
} else if (size === "s") {
34-
return ["fontSizeS", "fontWeightBold", "lineHeightAuto"];
35-
} else {
36-
return ["fontSizeM", "fontWeightBold", "lineHeightAuto"];
37-
}
38-
};
39-
4040
return (
4141
<Actionable
4242
{...forwardedProps}
43+
// disabled={disabled} TODO: Implement disabled for a tags?
4344
rootClasses={classnames(
44-
...(csTextStyles ? csTextStyles : fontStyles(csSize)),
45-
styles.button,
45+
buttonStyles.button,
46+
getSize(csSize),
47+
getVariant(csVariant),
48+
dimmed ? buttonStyles["button--dimmed"] : null,
49+
subtle ? buttonStyles["button--subtle"] : null,
50+
disabled ? buttonStyles["button--disabled"] : null,
4651
rootClasses
4752
)}
48-
csColor={csColor}
49-
csSize={csSize}
50-
csVariant={csVariant}
5153
ref={forwardedRef}
5254
>
5355
{children}
@@ -57,3 +59,26 @@ export const LinkButton = React.forwardRef<
5759
);
5860

5961
LinkButton.displayName = "LinkButton";
62+
63+
const getVariant = (scheme: string) => {
64+
return {
65+
primary: buttonStyles.button__primary,
66+
secondary: buttonStyles.button__secondary,
67+
tertiary: buttonStyles.button__tertiary,
68+
accent: buttonStyles.button__accent,
69+
special: buttonStyles.button__special,
70+
info: buttonStyles.button__info,
71+
success: buttonStyles.button__success,
72+
warning: buttonStyles.button__warning,
73+
danger: buttonStyles.button__danger,
74+
}[scheme];
75+
};
76+
77+
const getSize = (scheme: string) => {
78+
return {
79+
xs: buttonStyles["button--size-xs"],
80+
s: buttonStyles["button--size-s"],
81+
m: buttonStyles["button--size-m"],
82+
l: buttonStyles["button--size-l"],
83+
}[scheme];
84+
};

0 commit comments

Comments
 (0)