From 11af1da071251cbb3520e2659da09f8b1e323884 Mon Sep 17 00:00:00 2001 From: Timmy Huang Date: Fri, 28 Jan 2022 17:01:49 -0800 Subject: [PATCH] idea: button color prop --- src/core/Button/index.tsx | 22 ++++++++-------------- src/core/Button/style.ts | 29 +++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/core/Button/index.tsx b/src/core/Button/index.tsx index 8b4d0bcb2..e9ae46d2d 100644 --- a/src/core/Button/index.tsx +++ b/src/core/Button/index.tsx @@ -1,6 +1,7 @@ import { ButtonProps as RawButtonProps } from "@material-ui/core"; import React from "react"; import { + ExtraProps, PrimaryMinimalButton, RoundedButton, SecondaryMinimalButton, @@ -8,18 +9,11 @@ import { StyledButton, } from "./style"; -interface SdsProps { - isAllCaps?: boolean; - isRounded?: boolean; - sdsStyle?: "minimal" | "rounded" | "square"; - sdsType?: "primary" | "secondary"; -} -export type ButtonProps = RawButtonProps & SdsProps; +export type ButtonProps = RawButtonProps & ExtraProps; const Button = React.forwardRef( (props: ButtonProps, ref): JSX.Element | null => { - const sdsStyle = props?.sdsStyle; - const sdsType = props?.sdsType; + const { color = "primary", sdsStyle, sdsType } = props; if (!sdsStyle || !sdsType) { // eslint-disable-next-line no-console @@ -44,7 +38,7 @@ const Button = React.forwardRef( case sdsStyle === "rounded" && sdsType === "primary": return ( ( case sdsStyle === "rounded" && sdsType === "secondary": return ( ( case sdsStyle === "square" && sdsType === "primary": return ( ( case sdsStyle === "square" && sdsType === "secondary": return ( ( case sdsStyle === "minimal" && sdsType === "primary": return ( { - return !sdsPropNames.includes(prop.toString()); + return !doNotForwardProps.includes(prop.toString()); }, -})` +})` box-shadow: none; ${(props) => { - const { variant } = props; + const { variant, color: colorProp } = props; const colors = getColors(props); const spacings = getSpaces(props); @@ -30,13 +45,15 @@ const ButtonBase = styled(Button, { const padding = variant === "outlined" ? outlinedPadding : containedPadding; + const color = (colors && colors[colorProp]) || colors?.primary; + return ` padding: ${padding}; min-width: 120px; height: 34px; &:hover, &:focus { color: white; - background-color: ${colors?.primary[500]}; + background-color: ${color[500]}; box-shadow: none; } &:focus { @@ -45,7 +62,7 @@ const ButtonBase = styled(Button, { } &:active { color: white; - background-color: ${colors?.primary[600]}; + background-color: ${color[600]}; box-shadow: none; } &:disabled {