Skip to content

Commit e9ca7a3

Browse files
jhardyLuke Bowerman
andauthored
Update swatch to have new disabled state (#1603)
* Update swatch to have new disabled state * Apply alpha value to color and not border * Disabled properly suppresses `:hover` on `Swatch` Co-authored-by: Luke Bowerman <[email protected]>
1 parent 8d53fa2 commit e9ca7a3

File tree

7 files changed

+98
-9
lines changed

7 files changed

+98
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929
- InputFilter to support multiline filter tokens
3030
- Reduced & consolidated dependencies on `polished` library
3131
- `ButtonItem` used inside `ButtonToggle` and `ButtonGroup` now uses `body`
32+
- `Swatch` no longer turns gray when disabled, but has a reduced opacity instead
3233

3334
### Fixed
3435

packages/components/src/Form/Inputs/InputColor/Swatch/Swatch.test.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,7 @@ test('Swatch with hex value passed', () => {
4040
test('Swatch with width and height set', () => {
4141
assertSnapshot(<Swatch color="blue" width="50px" height="25px" />)
4242
})
43+
44+
test('Swatch has a disabled state', () => {
45+
assertSnapshot(<Swatch color="blue" width="50px" height="25px" disabled />)
46+
})

packages/components/src/Form/Inputs/InputColor/Swatch/Swatch.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@
2525
*/
2626

2727
import styled from 'styled-components'
28-
import { CompatibleHTMLProps, reset } from '@looker/design-tokens'
28+
import {
29+
CompatibleHTMLProps,
30+
disabledSwatchColor,
31+
reset,
32+
} from '@looker/design-tokens'
2933
import { height, HeightProps, width, WidthProps } from 'styled-system'
3034
import {
3135
inputCSS,
32-
inputTextDisabled,
3336
inputTextHover,
37+
inputTextDisabled,
3438
} from '../../../Inputs/InputText'
3539
import { inputHeight } from '../../height'
3640

@@ -64,16 +68,20 @@ export const Swatch = styled.div<SwatchProps>`
6468
${inputCSS}
6569
${width}
6670
${height}
67-
background-color: ${(props) => props.color};
71+
background-color: ${({ color, disabled }) =>
72+
disabled ? disabledSwatchColor(color) : color};
6873
flex-shrink: 0;
6974
margin-top: auto;
7075
71-
&:hover {
76+
&:disabled {
77+
${inputTextDisabled}
78+
}
79+
80+
&:hover:not([disabled]) {
7281
${inputTextHover}
7382
}
7483
7584
${(props) => props.color === 'transparent' && emptySwatch}
76-
${(props) => (props.disabled ? inputTextDisabled : '')}
7785
`
7886

7987
Swatch.defaultProps = {

packages/components/src/Form/Inputs/InputColor/Swatch/__snapshots__/Swatch.test.tsx.snap

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,17 @@ exports[`Default Swatch 1`] = `
1818
position: relative;
1919
}
2020
21-
.c0:hover {
21+
.c0:disabled {
22+
background: #F5F6F7;
23+
color: #939BA5;
24+
cursor: default;
25+
}
26+
27+
.c0:disabled:hover {
28+
border-color: #DEE1E5;
29+
}
30+
31+
.c0:hover:not([disabled]) {
2232
border-color: #C1C6CC;
2333
}
2434
@@ -44,6 +54,46 @@ exports[`Default Swatch 1`] = `
4454
/>
4555
`;
4656

57+
exports[`Swatch has a disabled state 1`] = `
58+
.c0 {
59+
font-family: 'Roboto','Noto Sans JP','Noto Sans CJK KR','Noto Sans Arabic UI','Noto Sans Devanagari UI','Noto Sans Hebrew','Noto Sans Thai UI','Helvetica','Arial',sans-serif;
60+
background: #FFFFFF;
61+
border: 1px solid #DEE1E5;
62+
border-radius: 0.25rem;
63+
color: #343C42;
64+
font-size: 0.875rem;
65+
width: 50px;
66+
height: 25px;
67+
background-color: rgba(0,0,255,0.85);
68+
-webkit-flex-shrink: 0;
69+
-ms-flex-negative: 0;
70+
flex-shrink: 0;
71+
margin-top: auto;
72+
}
73+
74+
.c0:disabled {
75+
background: #F5F6F7;
76+
color: #939BA5;
77+
cursor: default;
78+
}
79+
80+
.c0:disabled:hover {
81+
border-color: #DEE1E5;
82+
}
83+
84+
.c0:hover:not([disabled]) {
85+
border-color: #C1C6CC;
86+
}
87+
88+
<div
89+
className="c0"
90+
color="blue"
91+
disabled={true}
92+
height="25px"
93+
width="50px"
94+
/>
95+
`;
96+
4797
exports[`Swatch with hex value passed 1`] = `
4898
.c0 {
4999
font-family: 'Roboto','Noto Sans JP','Noto Sans CJK KR','Noto Sans Arabic UI','Noto Sans Devanagari UI','Noto Sans Hebrew','Noto Sans Thai UI','Helvetica','Arial',sans-serif;
@@ -61,7 +111,17 @@ exports[`Swatch with hex value passed 1`] = `
61111
margin-top: auto;
62112
}
63113
64-
.c0:hover {
114+
.c0:disabled {
115+
background: #F5F6F7;
116+
color: #939BA5;
117+
cursor: default;
118+
}
119+
120+
.c0:disabled:hover {
121+
border-color: #DEE1E5;
122+
}
123+
124+
.c0:hover:not([disabled]) {
65125
border-color: #C1C6CC;
66126
}
67127
@@ -90,7 +150,17 @@ exports[`Swatch with width and height set 1`] = `
90150
margin-top: auto;
91151
}
92152
93-
.c0:hover {
153+
.c0:disabled {
154+
background: #F5F6F7;
155+
color: #939BA5;
156+
cursor: default;
157+
}
158+
159+
.c0:disabled:hover {
160+
border-color: #DEE1E5;
161+
}
162+
163+
.c0:hover:not([disabled]) {
94164
border-color: #C1C6CC;
95165
}
96166

packages/design-tokens/src/utils/helpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ export const toggleSwitchShadowColor = () => css`
5757
box-shadow: 0 0 0 0.2rem
5858
${({ theme }) => rgba(theme.colors.keyInteractive, 0.4)};
5959
`
60+
61+
export const disabledSwatchColor = (color?: string) =>
62+
color && color !== 'transparent' ? rgba(color, 0.85) : undefined

storybook/src/Forms/Color.stories.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
import React, { useState } from 'react'
28-
import { FieldColor, FieldSelect } from '@looker/components'
28+
import { FieldColor, FieldSelect, InputColor } from '@looker/components'
2929

3030
export default { title: 'Forms/Color' }
3131

@@ -51,3 +51,5 @@ export const ControlledColor = () => {
5151
</>
5252
)
5353
}
54+
55+
export const InputColorExample = () => <InputColor value="purple" disabled />

www/src/documentation/components/forms/input-color.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ The `InputColor` component has an input to add a color value and a color wheel t
1313
<InputColor value="green" />
1414
<InputColor defaultValue="purple" />
1515
<InputColor disabled />
16+
<InputColor defaultValue="green" disabled />
1617
</SpaceVertical>
1718
```

0 commit comments

Comments
 (0)