From 5a7fe5dd7c3f735d72716073e180b0317272d26a Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 13 Oct 2020 11:21:49 -0700 Subject: [PATCH] feat #113 - Revamp button styles --- src/components/Button/index.tsx | 14 +++++++++ src/components/Button/utils.ts | 40 ++++++++++++++++++++++++++ src/components/assets/styles/colors.ts | 5 ++-- src/components/assets/styles/themes.ts | 11 ++++--- 4 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 src/components/Button/utils.ts diff --git a/src/components/Button/index.tsx b/src/components/Button/index.tsx index 7764c5de..e8e5fe29 100644 --- a/src/components/Button/index.tsx +++ b/src/components/Button/index.tsx @@ -3,12 +3,24 @@ import 'antd/lib/spin/style/index.css' import { ButtonProps as AntDButtonProps } from 'antd/es/button' import classnames from 'classnames' import { CommonComponentProps } from '../types' +import { createUseStyles } from 'react-jss' +import { generateButtonStyles } from './utils' import { getDataTestAttributeProp } from '../utils' import { LoadingOutlined } from '@ant-design/icons' import { Skeleton } from '../Skeleton' +import { ThemeType } from '../assets/styles/themes' import { Button as AntDButton, Spin } from 'antd' import React, { FC, ReactNode } from 'react' +const { dark, light } = ThemeType + +const useStyles = createUseStyles({ + '@global': { + [`.${dark} button`]: generateButtonStyles(dark), + button: generateButtonStyles(light) + } +}) + export interface ButtonProps extends CommonComponentProps { /** * Required click handler. @@ -67,6 +79,8 @@ export const Button: FC = ({ type: primary ? 'primary' : 'default' } + useStyles() + return loading ? ( ) : ( diff --git a/src/components/Button/utils.ts b/src/components/Button/utils.ts new file mode 100644 index 00000000..4e91d9a1 --- /dev/null +++ b/src/components/Button/utils.ts @@ -0,0 +1,40 @@ +import { themedStyles, themes, ThemeType } from '../assets/styles/themes' + +export const generateButtonStyles = (themeType: ThemeType) => { + const palette = themes[themeType] + const { base, disabled } = themedStyles[themeType] + + const baseButtonStyles = { + borderColor: base.borderColor, + borderRadius: 4, + color: base.color + } + + return { + '&.ant-btn': { + '&:hover': { + borderColor: palette.hover, + color: palette.hover + }, + backgroundColor: base.backgroundColor, + ...baseButtonStyles + }, + '&.ant-btn-disabled, &.ant-btn[disabled]': { + '&:hover': { + backgroundColor: disabled.backgroundColor, + borderColor: disabled.backgroundColor, + color: disabled.color + }, + backgroundColor: disabled.backgroundColor, + borderColor: disabled.backgroundColor, + color: disabled.color + }, + '&.ant-btn-focused, &.ant-btn:focus': { + borderColor: palette.hover, + color: base.color + }, + '&.ant-btn-primary': { + ...baseButtonStyles + } + } +} diff --git a/src/components/assets/styles/colors.ts b/src/components/assets/styles/colors.ts index b6b69efe..d489beec 100644 --- a/src/components/assets/styles/colors.ts +++ b/src/components/assets/styles/colors.ts @@ -1,3 +1,4 @@ +import { darken } from '@storybook/theming' import { ColorManipulationTypes, manipulateColor } from 'components/utils' const { shade, tint } = ColorManipulationTypes @@ -72,7 +73,7 @@ export interface ColorsType { greens: { base: string } oranges: { base: string } reds: { base: string } - whites: { base: string } + whites: { base: string; 'darken-5': string } } const colors: ColorsType = { @@ -81,7 +82,7 @@ const colors: ColorsType = { greens: { base: green }, oranges: { base: orange }, reds: { base: red }, - whites: { base: white } + whites: { base: white, 'darken-5': manipulateColor(white, 5, shade) } } export default colors diff --git a/src/components/assets/styles/themes.ts b/src/components/assets/styles/themes.ts index 4e332198..bfcab645 100644 --- a/src/components/assets/styles/themes.ts +++ b/src/components/assets/styles/themes.ts @@ -18,6 +18,7 @@ export interface Theme { secondary: string } border: string + hover: string primary: string error: string success: string @@ -36,6 +37,7 @@ const lightPalette: Theme = { }, border: blacks['lighten-80'], error: reds.base, + hover: blacks['lighten-30'], primary: blues.base, success: greens.base, text: { @@ -48,18 +50,19 @@ const lightPalette: Theme = { const darkPalette: Theme = { action: { active: whites.base, - disabled: blacks['lighten-20'] // update when defined by Design + disabled: blacks['lighten-10'] // update when defined by Design }, background: { primary: blacks.base, secondary: blacks['darken-20'] }, - border: blacks['darken-20'], + border: blacks['lighten-20'], error: reds.base, + hover: blacks['lighten-60'], primary: blues.base, success: greens.base, text: { - disabled: blacks['lighten-20'], // update when defined by Design + disabled: blacks['lighten-30'], // update when defined by Design primary: blacks['lighten-50'] }, warning: oranges.base @@ -89,7 +92,7 @@ const generateThemedStyles = ({ } const hover = { - borderColor: blues['lighten-10'] // update when defined by Design + borderColor: blues['lighten-10'] } const focus = {