From a0e32a6ba89f6ebf9dab8f2d9af1bb8e7f57e12a Mon Sep 17 00:00:00 2001 From: Christian Vuerings Date: Mon, 26 Feb 2024 07:58:10 -0800 Subject: [PATCH] Button / IconButton / LinkButton: add Cambio variants --- .changeset/dull-pandas-build.md | 7 + apps/storybook/stories/Colors.tsx | 14 +- .../syntax-core/src/Button/Button.module.css | 18 ++ .../syntax-core/src/Button/Button.stories.tsx | 5 +- packages/syntax-core/src/Button/Button.tsx | 101 ++++++--- .../src/Button/constants/classicSize.ts | 5 + .../syntax-core/src/Button/constants/color.ts | 66 ++++++ .../src/Button/constants/loadingIconSize.ts | 6 +- .../src/Button/constants/textVariant.ts | 7 +- .../src/IconButton/IconButton.module.css | 48 ++++- .../syntax-core/src/IconButton/IconButton.tsx | 105 ++++++++-- .../syntax-core/src/LinkButton/LinkButton.tsx | 104 +++++++--- .../src/ThemeProvider/ThemeProvider.test.tsx | 30 +++ .../syntax-core/src/colors/backgroundColor.ts | 28 ++- .../syntax-core/src/colors/colors.module.css | 193 ++++++++++++++++++ .../syntax-core/src/colors/foregroundColor.ts | 22 +- packages/syntax-core/src/constants.ts | 20 +- .../tokens/color/base.json | 35 ++++ 18 files changed, 736 insertions(+), 78 deletions(-) create mode 100644 .changeset/dull-pandas-build.md create mode 100644 packages/syntax-core/src/Button/constants/classicSize.ts create mode 100644 packages/syntax-core/src/Button/constants/color.ts create mode 100644 packages/syntax-core/src/ThemeProvider/ThemeProvider.test.tsx diff --git a/.changeset/dull-pandas-build.md b/.changeset/dull-pandas-build.md new file mode 100644 index 00000000..86c8ef73 --- /dev/null +++ b/.changeset/dull-pandas-build.md @@ -0,0 +1,7 @@ +--- +"@cambly/syntax-design-tokens": minor +"@cambly/syntax-core": minor +"@syntax/storybook": minor +--- + +Add ThemeProvider & styles for Button / IconButton & LinkButton diff --git a/apps/storybook/stories/Colors.tsx b/apps/storybook/stories/Colors.tsx index 886c689b..e0d764c6 100644 --- a/apps/storybook/stories/Colors.tsx +++ b/apps/storybook/stories/Colors.tsx @@ -4,7 +4,10 @@ import variables from "../../../packages/syntax-design-tokens/dist/json/variable export default function Colors() { const groupColors = Object.entries(variables).reduce( (acc, [key, value]) => { - if ( + if (key.includes("cambio")) { + // @ts-expect-error + acc["Cambio"].push({ key, value }); + } else if ( key.includes("black") || key.includes("white") || key.includes("gray") @@ -25,6 +28,7 @@ export default function Colors() { return acc; }, { + Cambio: [], Grayscale: [], Primary: [], Destructive: [], @@ -46,6 +50,14 @@ export default function Colors() { style={{ color: [ + "color-cambio-white", + "color-cambio-gray-88", + "color-cambio-gray-96", + "color-cambio-cream", + "color-cambio-pink", + "color-cambio-sky", + "color-cambio-yellow", + "color-cambio-transparent-full", "color-base-gray-10", "color-base-gray-30", "color-base-white", diff --git a/packages/syntax-core/src/Button/Button.module.css b/packages/syntax-core/src/Button/Button.module.css index c1b0fd16..19810620 100644 --- a/packages/syntax-core/src/Button/Button.module.css +++ b/packages/syntax-core/src/Button/Button.module.css @@ -90,6 +90,12 @@ border-radius: 100px; } +.xlCambio { + height: 80px; + padding: 0 40px; + border-radius: 100px; +} + .icon { color: inherit; } @@ -123,6 +129,18 @@ border: 1px solid var(--color-base-destructive-300); } +.cambioSecondaryBorder { + border: 1px solid var(--color-cambio-black); +} + +.cambioSecondaryDestructiveBorder { + border: 1px solid var(--color-cambio-destructive); +} + +.cambioSecondarySuccessBorder { + border: 1px solid var(--color-cambio-success); +} + @keyframes syntaxButtonLoadingRotate { 0% { transform-origin: 50% 50%; diff --git a/packages/syntax-core/src/Button/Button.stories.tsx b/packages/syntax-core/src/Button/Button.stories.tsx index 74f5df43..f1d156e5 100644 --- a/packages/syntax-core/src/Button/Button.stories.tsx +++ b/packages/syntax-core/src/Button/Button.stories.tsx @@ -17,17 +17,20 @@ export default { "primary", "secondary", "tertiary", + "quaternary", "destructive-primary", "destructive-secondary", "destructive-tertiary", "success", + "success-primary", + "success-secondary", "branded", "inverse", ], control: { type: "radio" }, }, size: { - options: ["sm", "md", "lg"], + options: ["sm", "md", "lg", "xl"], control: { type: "radio" }, }, disabled: { diff --git a/packages/syntax-core/src/Button/Button.tsx b/packages/syntax-core/src/Button/Button.tsx index 71df4f00..a5061959 100644 --- a/packages/syntax-core/src/Button/Button.tsx +++ b/packages/syntax-core/src/Button/Button.tsx @@ -1,19 +1,24 @@ import React, { forwardRef } from "react"; import classNames from "classnames"; - -import backgroundColor from "../colors//backgroundColor"; -import foregroundColor from "../colors/foregroundColor"; -import foregroundTypographyColor from "../colors/foregroundTypographyColor"; import { type Size } from "../constants"; import Typography from "../Typography/Typography"; import Box from "../Box/Box"; - import iconSize from "./constants/iconSize"; import textVariant from "./constants/textVariant"; import loadingIconSize from "./constants/loadingIconSize"; import styles from "./Button.module.css"; import useIsHydrated from "../useIsHydrated"; import { useTheme } from "../ThemeProvider/ThemeProvider"; +import { classicColor, cambioColor } from "./constants/color"; +import { + classicBackgroundColor, + cambioBackgroundColor, +} from "../colors/backgroundColor"; +import { + classicForegroundColor, + cambioForegroundColor, +} from "../colors/foregroundColor"; +import classicSize from "./constants/classicSize"; type ButtonProps = { /** @@ -31,25 +36,46 @@ type ButtonProps = { /** * The color of the button * + * Classic only: + * * `success-primary` + * * `success-secondary` + * * `inverse` + * + * Cambio only: + * * `quaternary` + * * `destructive-tertiary` + * * `success-primary` + * * `success-secondary` + * * @defaultValue "primary" */ color?: | "primary" | "secondary" | "tertiary" + | "quaternary" | "destructive-primary" | "destructive-secondary" | "destructive-tertiary" | "branded" | "success" + | "success-primary" + | "success-secondary" | "inverse"; /** * The size of the button * + * Classic: * * `sm`: 32px * * `md`: 40px * * `lg`: 48px * + * Cambio: + * * `sm`: 32px + * * `md`: 48px + * * `lg`: 64px + * * `xl`: 80px + * * @defaultValue "md" */ size?: (typeof Size)[number]; @@ -77,10 +103,12 @@ type ButtonProps = { fullWidth?: boolean; /** * The icon to be displayed at the start of the button. Please use a [Rounded Material Icon](https://material.io/resources/icons/?style=round) + * Note: startIcon is not supported in the Cambio theme */ startIcon?: React.ComponentType<{ className?: string }>; /** * The icon to be displayed at the end of the button. Please use a [Rounded Material Icon](https://material.io/resources/icons/?style=round) + * Note: endIcon is not supported in the Cambio theme */ endIcon?: React.ComponentType<{ className?: string }>; /** @@ -123,6 +151,16 @@ const Button = forwardRef( const isHydrated = useIsHydrated(); const { themeName } = useTheme(); + const foregroundColorClass = + themeName === "classic" + ? classicForegroundColor(classicColor(color)) + : cambioForegroundColor(cambioColor(color)); + + const backgroundColorClass = + themeName === "classic" + ? classicBackgroundColor(classicColor(color)) + : cambioBackgroundColor(cambioColor(color)); + return (