Skip to content

Commit

Permalink
fix(Button): render disabled button as span
Browse files Browse the repository at this point in the history
  • Loading branch information
s0ber committed Sep 1, 2020
1 parent 6dec64b commit 9d6f5ba
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 14 deletions.
5 changes: 3 additions & 2 deletions packages/picasso/src/Button/Button.tsx
Expand Up @@ -177,7 +177,8 @@ export const Button = forwardRef<HTMLButtonElement, Props>(function Button(
{...rest}
ref={ref}
classes={{
root: rootClassName
root: rootClassName,
disabled: classes.disabled
}}
onClick={loading ? defaultOnClick : onClick}
className={className}
Expand All @@ -186,7 +187,7 @@ export const Button = forwardRef<HTMLButtonElement, Props>(function Button(
title={title}
value={value}
type={type}
component={as!}
component={disabled && as === 'button' ? 'span' : as!}
>
<Container
as='span'
Expand Down
21 changes: 21 additions & 0 deletions packages/picasso/src/Button/story/DisabledWithEvents.example.tsx
@@ -0,0 +1,21 @@
import React from 'react'
import { Button } from '@toptal/picasso'
import { useNotifications } from '@toptal/picasso/utils'

const Example = () => {
const { showSuccess } = useNotifications()

return (
<div>
<Button
disabled
onMouseEnter={() => showSuccess('Mouse entered')}
onMouseLeave={() => showSuccess('Mouse left')}
>
Disabled
</Button>
</div>
)
}

export default Example
6 changes: 5 additions & 1 deletion packages/picasso/src/Button/story/index.jsx
Expand Up @@ -188,10 +188,14 @@ page
.addExample('Button/story/Basic.example.jsx', 'Basic')
.addExample('Button/story/Variants.example.jsx', 'Variants')
.addExample('Button/story/States.example.jsx', 'States')
.addExample('Button/story/Disabled.example.jsx', {
.addExample('Button/story/Disabled.example.tsx', {
title: 'Disabled',
description: 'The button shows that currently unable to be interacted with'
})
.addExample('Button/story/DisabledWithEvents.example.tsx', {
title: 'Disabled with mouse events',
description: 'The button is disabled, but event handlers can be added'
})
.addExample('Button/story/Sizes.example.jsx', 'Sizes')
.addExample('Button/story/FullWidth.example.jsx', 'Full width')
.addExample('Button/story/IconButtons.example.jsx', 'Button with Icon')
Expand Down
43 changes: 32 additions & 11 deletions packages/picasso/src/Button/styles.ts
Expand Up @@ -3,39 +3,47 @@ import { lighten, darken, alpha } from '@toptal/picasso-shared'

const ICON_SPACING = '0.4em'

const primary = (mainColor: string, secondaryColor: string) => ({
const primary = (
mainColor: string,
secondaryColor: string,
disabled = false
) => ({
border: 'none',
color: secondaryColor,
backgroundColor: mainColor,

'&:focus, &focused': {
'&:focus, &focused': !disabled && {
backgroundColor: darken(mainColor, 0.2)
},

'&:hover, &$hovered': {
'&:hover, &$hovered': !disabled && {
backgroundColor: darken(mainColor, 0.2)
},

'&:active, &$active': {
'&:active, &$active': !disabled && {
backgroundColor: darken(mainColor, 0.2)
}
})

const secondary = (mainColor: string, secondaryColor: string) => ({
const secondary = (
mainColor: string,
secondaryColor: string,
disabled = false
) => ({
color: mainColor,
backgroundColor: secondaryColor,

'&:focus, &focused': {
'&:focus, &focused': !disabled && {
backgroundColor: lighten(mainColor, 0.84),
borderColor: mainColor
},

'&:hover, &$hovered': {
'&:hover, &$hovered': !disabled && {
backgroundColor: lighten(mainColor, 0.84),
borderColor: mainColor
},

'&:active, &$active': {
'&:active, &$active': !disabled && {
backgroundColor: lighten(mainColor, 0.84),
borderColor: mainColor
}
Expand Down Expand Up @@ -69,6 +77,15 @@ export default ({ palette, sizes, transitions, typography }: Theme) =>
marginLeft: '0.5em'
}
},
disabled: {
'&$disabled': {
pointerEvents: 'inherit',

'&:focus, &focused': {
textDecoration: 'none'
}
}
},
content: {
lineHeight: '1.5em',
fontWeight: typography.fontWeights.semibold,
Expand Down Expand Up @@ -182,10 +199,14 @@ export default ({ palette, sizes, transitions, typography }: Theme) =>
transparentGreen: {
...transparent(palette.green.main)
},
primaryDisabled: primary(palette.grey.light!, palette.common.white),
secondaryDisabled: secondary(palette.grey.light!, palette.common.white),
primaryDisabled: primary(palette.grey.light!, palette.common.white, true),
secondaryDisabled: secondary(
palette.grey.light!,
palette.common.white,
true
),
flatDisabled: {
...secondary(palette.grey.light!, palette.common.white),
...secondary(palette.grey.light!, palette.common.white, true),
border: 'none'
},

Expand Down

0 comments on commit 9d6f5ba

Please sign in to comment.