Skip to content

Commit

Permalink
feat #113 - Revamp button styles
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Oct 13, 2020
1 parent 0351f2d commit 5a7fe5d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -67,6 +79,8 @@ export const Button: FC<ButtonProps> = ({
type: primary ? 'primary' : 'default'
}

useStyles()

return loading ? (
<Skeleton height={skeletonHeight} width={skeletonWidth} />
) : (
Expand Down
40 changes: 40 additions & 0 deletions src/components/Button/utils.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
}
5 changes: 3 additions & 2 deletions src/components/assets/styles/colors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { darken } from '@storybook/theming'
import { ColorManipulationTypes, manipulateColor } from 'components/utils'

const { shade, tint } = ColorManipulationTypes
Expand Down Expand Up @@ -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 = {
Expand All @@ -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
11 changes: 7 additions & 4 deletions src/components/assets/styles/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Theme {
secondary: string
}
border: string
hover: string
primary: string
error: string
success: string
Expand All @@ -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: {
Expand All @@ -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
Expand Down Expand Up @@ -89,7 +92,7 @@ const generateThemedStyles = ({
}

const hover = {
borderColor: blues['lighten-10'] // update when defined by Design
borderColor: blues['lighten-10']
}

const focus = {
Expand Down

0 comments on commit 5a7fe5d

Please sign in to comment.