Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Button to token system #1228

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/cyberstorm-styles/src/styles/fonts.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,19 @@
font-family: Hubot-Sans;
src: url("../fonts/HubotSans.ttf") format("truetype-variations");
}

:root {
--global--line-height--auto: normal;
--global--line-height--body: 170%;
--global--font-size--xxs: 0.625rem;
--global--font-size--xs: 0.75rem;
--global--font-size--s: 0.875rem;
--global--font-size--m: 1rem;
--global--font-size--l: 1.5rem;
--global--font-weight--regular: 400;
--global--font-weight--medium: 500;
--global--font-weight--semiBold: 600;
--global--font-weight--bold: 700;
--global--font-family--inter: inter, sans-serif;
--global--font-family--hubot: Hubot-Sans, sans-serif;
}
1 change: 1 addition & 0 deletions packages/cyberstorm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,4 @@ export {
export { Image } from "./newComponents/Image/Image";
export * as List from "./newComponents/List";
export { AdContainer } from "./newComponents/AdContainer/AdContainer";
import "./sharedComponentStyles/ButtonStyles/ButtonTokens.css";
77 changes: 45 additions & 32 deletions packages/cyberstorm/src/newComponents/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,36 @@
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { NewIcon } from "../..";

interface ButtonProps extends Omit<ActionableButtonProps, "primitiveType"> {
interface Modifiers {
dimmed?: boolean;
subtle?: boolean;
disabled?: boolean;
}

interface ButtonProps extends Omit<ActionableButtonProps, "primitiveType" | "csVariant">, Modifiers {

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Replace ·extends·Omit<ActionableButtonProps,·"primitiveType"·|·"csVariant">, with ⏎··extends·Omit<ActionableButtonProps,·"primitiveType"·|·"csVariant">,⏎···
csVariant?:
| "default"
| "defaultPeek"
| "primary"
| "secondary"
| "tertiary"
| "minimal"
| "accent"
| "special";
| "special"
| "info"
| "success"
| "warning"
| "danger";
csSize?: "xs" | "s" | "m" | "l";
}

interface IconButtonProps
extends Omit<
ActionableButtonProps,
"primitiveType" | "csVariant" | "csSize" | "children"
> {
>, Modifiers {

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Replace >, with ··>,⏎···
csVariant?:
| "default"
| "defaultPeek"
| "primary"
| "secondary"
| "tertiary"
| "tertiaryDimmed"
| "danger"
| "minimal";
csSize?: "xs" | "s" | "m";
icon: IconProp;
Expand All @@ -46,12 +51,11 @@

export const Button = React.forwardRef<HTMLButtonElement, ButtonComponentProps>(
(props: ButtonComponentProps, forwardedRef) => {
const { rootClasses, csTextStyles, icon, ...forwardedProps } = props;
const { rootClasses, csTextStyles, icon, dimmed, subtle, disabled, ...forwardedProps } = props;

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Replace ·rootClasses,·csTextStyles,·icon,·dimmed,·subtle,·disabled,··...forwardedProps with ⏎······rootClasses,⏎······csTextStyles,⏎······icon,⏎······dimmed,⏎······subtle,⏎······disabled,⏎······...forwardedProps⏎···

if (icon) {
const {
csVariant = "default",
csColor = "purple",
csSize = "m",
...fProps
} = forwardedProps as IconButtonProps;
Expand All @@ -61,9 +65,6 @@
primitiveType="button"
{...fProps}
rootClasses={classnames(iconButtonStyles.iconButton, rootClasses)}
csColor={csColor}
csSize={csSize}
csVariant={csVariant}
ref={forwardedRef}
>
<NewIcon csMode="inline" noWrapper>
Expand All @@ -75,36 +76,25 @@

const {
children,
csVariant = "default",
csColor = "purple",
csVariant = "primary",
csSize = "m",
...fProps
} = forwardedProps as ButtonProps;

// TODO: Turn into a proper resolver function
// Same logic is in LinkButton too
const fontStyles = (size: typeof csSize) => {
if (size === "xs") {
return ["fontSizeXS", "fontWeightBold", "lineHeightAuto"];
} else if (size === "s") {
return ["fontSizeS", "fontWeightBold", "lineHeightAuto"];
} else {
return ["fontSizeM", "fontWeightBold", "lineHeightAuto"];
}
};

return (
<Actionable
primitiveType="button"
{...fProps}
disabled={disabled}
rootClasses={classnames(
...(csTextStyles ? csTextStyles : fontStyles(csSize)),
buttonStyles.button,
getSize(csSize),
getVariant(csVariant),
dimmed ? buttonStyles["button--dimmed"] : null,
subtle ? buttonStyles["button--subtle"] : null,
disabled ? buttonStyles["button--disabled"] : null,
rootClasses
)}
csColor={csColor}
csSize={csSize}
csVariant={csVariant}
ref={forwardedRef}
>
{children}
Expand All @@ -114,3 +104,26 @@
);

Button.displayName = "Button";

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];
};

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Insert ⏎
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,53 @@
ActionableCyberstormLinkProps,
ActionableLinkProps,
} from "../../../primitiveComponents/Actionable/Actionable";
import styles from "../../../sharedComponentStyles/ButtonStyles/Button.module.css";
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 {}

Comment on lines +17 to +18

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Replace ·extends·ActionableCyberstormLinkProps,·Modifiers·{}⏎ with ⏎··extends·ActionableCyberstormLinkProps,⏎····Modifiers·{}

export const LinkButton = React.forwardRef<
HTMLAnchorElement,
ActionableLinkProps | ActionableCyberstormLinkProps
LinkProps | CyberstormLinkProps
>(
(
props: ActionableLinkProps | ActionableCyberstormLinkProps,
props: LinkProps | CyberstormLinkProps,
forwardedRef
) => {
const {
children,
rootClasses,
csVariant = "default",
csColor = "purple",
csSize = "m",
csTextStyles,
dimmed,

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Delete ··
subtle,

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Replace ······ with ····
disabled,

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Delete ··
...forwardedProps
} = props;

// TODO: Turn into a proper resolver function
// Same logic is in LinkButton too
const fontStyles = (size: typeof csSize) => {
if (size === "xs") {
return ["fontSizeXS", "fontWeightBold", "lineHeightAuto"];
} else if (size === "s") {
return ["fontSizeS", "fontWeightBold", "lineHeightAuto"];
} else {
return ["fontSizeM", "fontWeightBold", "lineHeightAuto"];
}
};

return (
<Actionable
{...forwardedProps}
// disabled={disabled} TODO: Implement disabled for a tags?

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Delete ··
rootClasses={classnames(
...(csTextStyles ? csTextStyles : fontStyles(csSize)),
styles.button,
buttonStyles.button,

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Delete ··
getSize(csSize),

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Delete ··
getVariant(csVariant),

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Delete ··
dimmed ? buttonStyles["button--dimmed"] : null,

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Delete ··
subtle ? buttonStyles["button--subtle"] : null,

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Replace ·········· with ········
disabled ? buttonStyles["button--disabled"] : null,

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Delete ··
rootClasses
)}
csColor={csColor}
csSize={csSize}
csVariant={csVariant}
ref={forwardedRef}
>
{children}
Expand All @@ -57,3 +59,26 @@
);

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];
};

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Insert ⏎
Loading
Loading