Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
fix button type, add disabled button, string enum
Browse files Browse the repository at this point in the history
1. use string enum as button type
2. default to dark mode on start
  • Loading branch information
W3stside committed Nov 19, 2020
1 parent 5dd8264 commit a154c5c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 20 deletions.
19 changes: 13 additions & 6 deletions src/components/common/Button/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,42 @@ const Template: Story<ButtonBaseProps & { label?: string | React.ReactNode }> =
export const PrimaryButton = Template.bind({})
PrimaryButton.args = {
label: 'Main Button',
kind: 'default',
kind: ButtonVariations.default,
}

export const SecondaryButton = Template.bind({})
SecondaryButton.args = {
label: 'Secondary Button',
kind: 'secondary',
kind: ButtonVariations.secondary,
}

export const SuccessButton = Template.bind({})
SuccessButton.args = {
label: 'Success Button',
kind: 'success',
kind: ButtonVariations.success,
}

export const WarningButton = Template.bind({})
WarningButton.args = {
label: 'Warning Button',
kind: 'warning',
kind: ButtonVariations.warning,
}

export const DangerButton = Template.bind({})
DangerButton.args = {
label: 'Danger Button',
kind: 'danger',
kind: ButtonVariations.danger,
}

export const CancelButton = Template.bind({})
CancelButton.args = {
label: 'Cancel Button',
kind: 'cancel',
kind: ButtonVariations.cancel,
}

export const DisabledButton = Template.bind({})
DisabledButton.args = {
label: 'Disabled Button',
kind: ButtonVariations.disabled,
disabled: true,
}
3 changes: 1 addition & 2 deletions src/components/common/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react'
import styled from 'styled-components'
import StyledButton, { ButtonVariations } from 'styles/common/StyledButton'

export interface ButtonBaseProps {
export interface ButtonBaseProps extends React.ButtonHTMLAttributes<Element> {
kind?: keyof typeof ButtonVariations
}

Expand Down Expand Up @@ -52,7 +52,6 @@ const ThemeButtonToggleWrapper = styled.div<{ $mode: boolean }>`

export const ThemeButton: React.FC<
ButtonBaseProps & {
onClick: ((event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void) | undefined
mode: boolean
}
> = (props) => {
Expand Down
7 changes: 4 additions & 3 deletions src/storybook/decorators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import { faMoon, faSun } from '@fortawesome/free-regular-svg-icons'

import { ThemeButton } from 'components/common/Button'

import { ThemeProvider } from 'styled-components'
import COLOURS from 'styles/colours'
import { ThemeProvider } from 'styled-components'
import { ButtonVariations } from 'styles/common/StyledButton'

export const ThemeToggler = (DecoratedStory: () => JSX.Element): JSX.Element => {
const [darkMode, setDarkMode] = React.useState(false)
const [darkMode, setDarkMode] = React.useState(true)
const theme = {
mode: darkMode ? 'dark' : 'light',
}
Expand All @@ -29,7 +30,7 @@ export const ThemeToggler = (DecoratedStory: () => JSX.Element): JSX.Element =>
<ThemeProvider theme={theme}>
<Frame style={{ backgroundColor: darkMode ? COLOURS.bgDark : COLOURS.bgLight }}>{DecoratedStory()}</Frame>
{/* Cheeky use of ButtonBase here :P */}
<ThemeButton kind="theme" onClick={handleDarkMode} mode={darkMode}>
<ThemeButton kind={ButtonVariations.theme} onClick={handleDarkMode} mode={darkMode}>
<FontAwesomeIcon icon={darkMode ? faSun : faMoon} />
</ThemeButton>
<br />
Expand Down
29 changes: 20 additions & 9 deletions src/styles/common/StyledButton.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled, { css } from 'styled-components'
import { variants } from 'styled-theming'
import { ThemeValue, variants } from 'styled-theming'

import ColourSheet from '../colours'
import StyleSheet from '../styles'
Expand All @@ -24,14 +24,15 @@ const { buttonBorder } = StyleSheet
// Used in stories
// Good to keep around altough not required
export enum ButtonVariations {
default,
primary,
secondary,
danger,
success,
warning,
cancel,
theme,
default = 'default',
primary = 'primary',
secondary = 'secondary',
danger = 'danger',
success = 'success',
warning = 'warning',
cancel = 'cancel',
disabled = 'disabled',
theme = 'theme',
}

// Create our variated Button Theme
Expand Down Expand Up @@ -160,6 +161,16 @@ export const ButtonTheme = variants<'kind', keyof typeof ButtonVariations>('mode
}
`,
},
disabled: {
light: css`
color: ${white};
opacity: 0.5;
background: #000;
`,
get dark(): ThemeValue {
return this.light
},
},
theme: {
light: css`
color: ${white};
Expand Down

0 comments on commit a154c5c

Please sign in to comment.