-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d45d31
commit e920974
Showing
7 changed files
with
203 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
ui/design-tokens/src/Colors/LiquidColor/LiquidColor.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react'; | ||
import { LiquidColor, LiquidColorPalette } from './LiquidColor'; | ||
import { ColorProps } from '../../types'; | ||
|
||
export default { | ||
title: 'Design Tokens/Colors/LiquidColor', | ||
component: LiquidColor, | ||
}; | ||
|
||
export const overview = ({ name, color }: ColorProps) => ( | ||
<LiquidColor name={name} color={color} /> | ||
); | ||
|
||
overview.controls = { | ||
name: { type: 'text', value: 'Rich Purple' }, | ||
color: { type: 'color', value: '#503291' }, | ||
}; | ||
|
||
export const palette = () => ( | ||
<LiquidColorPalette | ||
palette={{ | ||
'Vibrant Magenta': '#EB3C96', | ||
'Rich Blue': '#0F69AF', | ||
'Vibrant Cyan': '#2DBECD', | ||
'Vibrant Green': '#A5CD50', | ||
'Rich Red': '#E61E50', | ||
'Vibrant Yellow': '#FFC832', | ||
'Rich Green': '#149B5F', | ||
}} | ||
/> | ||
); |
127 changes: 127 additions & 0 deletions
127
ui/design-tokens/src/Colors/LiquidColor/LiquidColor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/** @jsx jsx */ | ||
import { FC } from 'react'; | ||
import { jsx, Theme } from 'theme-ui'; | ||
import tinycolor from 'tinycolor2'; | ||
import { CopyContainer } from '@component-controls/components'; | ||
import { colorToStr, mostReadable } from '../utils'; | ||
import { ColorBlockProps } from '../../types'; | ||
import { GridContainerProps, GridContainer } from '../../components'; | ||
|
||
/** | ||
* Color item displaying the color as a block with values for rgb and a palette of lighter and darker colors. | ||
* Design inspired from [Liquid Design System](https://liquid.emd.design/fundamentals/color/). | ||
*/ | ||
export const LiquidColor: FC<ColorBlockProps> = ({ name, color }) => { | ||
const colorValue = typeof color === 'string' ? color : color.value; | ||
const { hex, rgba } = colorToStr(colorValue); | ||
const textColor = mostReadable(hex); | ||
const palette = [hex]; | ||
let initial = hex; | ||
for (let i = 0; i < 3; i += 1) { | ||
initial = tinycolor(initial) | ||
.lighten() | ||
.toHexString(); | ||
if (!palette.includes(initial)) { | ||
palette.push(initial); | ||
} | ||
} | ||
initial = hex; | ||
for (let i = 0; i < 3; i += 1) { | ||
initial = tinycolor(initial) | ||
.darken() | ||
.toHexString(); | ||
if (!palette.includes(initial)) { | ||
palette.unshift(initial); | ||
} | ||
} | ||
|
||
return ( | ||
<div | ||
sx={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
bg: 'background', | ||
minWidth: 120, | ||
maxWidth: 320, | ||
border: (t: Theme) => `1px solid ${t.colors?.shadow}`, | ||
borderRadius: 1, | ||
boxShadow: (t: Theme) => `0 1px 2px 0 ${t.colors?.shadow}`, | ||
}} | ||
> | ||
<CopyContainer value={hex} name={name}> | ||
<div | ||
sx={{ | ||
bg: colorValue, | ||
position: 'relative', | ||
':after': { | ||
content: '""', | ||
display: 'block', | ||
paddingBottom: '60%', | ||
}, | ||
}} | ||
> | ||
<div | ||
sx={{ | ||
fontSize: 2, | ||
fontWeight: 'bold', | ||
position: 'absolute', | ||
left: 3, | ||
bottom: 3, | ||
color: textColor, | ||
}} | ||
> | ||
{hex.toUpperCase()} | ||
</div> | ||
</div> | ||
</CopyContainer> | ||
<div | ||
sx={{ | ||
height: 25, | ||
width: '100%', | ||
display: 'flex', | ||
flexDirection: 'row', | ||
}} | ||
> | ||
{palette.map(p => ( | ||
<CopyContainer | ||
key={`liquid_color_${p}`} | ||
sx={{ flex: 1, bg: p }} | ||
name={name} | ||
value={p} | ||
></CopyContainer> | ||
))} | ||
</div> | ||
<div | ||
sx={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
p: 2, | ||
fontSize: 2, | ||
}} | ||
> | ||
<div sx={{ fontSize: 3 }}>{name || hex}</div> | ||
<div> | ||
{`RGB (${rgba.r},${rgba.g},${rgba.b}${ | ||
rgba.a !== 1 ? `,${rgba.a}` : '' | ||
})`} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
/** | ||
* | ||
* palette displayed with LiquidColor items | ||
* using a css grid for the dsplay | ||
*/ | ||
export const LiquidColorPalette: FC<Omit< | ||
GridContainerProps, | ||
'children' | ||
>> = props => ( | ||
<GridContainer width={170} gap={3} {...props}> | ||
{({ name, value }) => ( | ||
<LiquidColor key={`color_item_${name}}`} name={name} color={value} /> | ||
)} | ||
</GridContainer> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './LiquidColor'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters