-
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
c303439
commit 8553fd1
Showing
5 changed files
with
192 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import { ControlTypes } from '@component-controls/core'; | ||
import { XColor, XColorPalette } from './XColor'; | ||
import { ColorProps } from '../../types'; | ||
|
||
export default { | ||
title: 'Design Tokens/Colors/XColor', | ||
component: XColor, | ||
}; | ||
|
||
export const overview = ({ name, color }: ColorProps) => ( | ||
<XColor name={name} color={color} /> | ||
); | ||
|
||
overview.controls = { | ||
name: 'Lady Black', | ||
color: { type: ControlTypes.COLOR, value: '#3C3C3B' }, | ||
}; | ||
|
||
export const palette = () => ( | ||
<XColorPalette | ||
palette={{ | ||
'Dame Tangerine': '#FF5000', | ||
'Señor Purple': '#5F285A', | ||
'Baron Von Teal': '#1DE9B6', | ||
'Agent Cyan': '#18FFFF', | ||
'Madam Yellow': '#FFF500', | ||
'Pastor Pink': '#FF96B4', | ||
'Brigadier Blue': '#000A47', | ||
}} | ||
/> | ||
); |
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,122 @@ | ||
/** @jsx jsx */ | ||
import { FC } from 'react'; | ||
import { jsx, Theme } from 'theme-ui'; | ||
import { CopyContainer } from '@component-controls/components'; | ||
import simpleColorConverter from 'simple-color-converter'; | ||
import { colorToStr } from '../utils'; | ||
import { ColorBlockProps, ColorValue } from '../../types'; | ||
import { GridContainerProps, GridContainer } from '../../components'; | ||
|
||
/** | ||
* Color item displaying the color as a cirlce with the variable name, hev, rgb, cmyk and pantone values below. | ||
* Design inspired from Biteable's Design System [X](https://x.biteable.com/brand/). | ||
*/ | ||
export const XColor: FC<ColorBlockProps> = ({ name, color }) => { | ||
const colorObj: ColorValue = | ||
typeof color === 'string' ? { value: color } : color; | ||
const { value: colorValue, name: colorName = name } = colorObj; | ||
|
||
const { hex, rgba } = colorToStr(colorValue); | ||
const { color: cmyk } = new simpleColorConverter({ | ||
rgba, | ||
to: 'cmyk', | ||
}); | ||
const { color: pantone } = new simpleColorConverter({ | ||
rgba, | ||
to: 'pantone', | ||
}); | ||
return ( | ||
<div | ||
sx={{ | ||
px: 2, | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
minWidth: 120, | ||
maxWidth: 320, | ||
fontSize: 2, | ||
}} | ||
> | ||
<CopyContainer value={hex} name={name} sx={{ px: 2, pt: 2 }}> | ||
<div | ||
sx={{ | ||
border: (t: Theme) => `1px solid ${t.colors?.shadow}`, | ||
width: 80, | ||
height: 80, | ||
bg: colorValue, | ||
borderRadius: '50%', | ||
}} | ||
/> | ||
</CopyContainer> | ||
<div sx={{ textAlign: 'center', mt: 1, mb: 2, fontWeight: 'heading' }}> | ||
{colorName} | ||
</div> | ||
<div | ||
sx={{ | ||
width: '100%', | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
}} | ||
> | ||
<div>HEX</div> | ||
<div>{hex.split('#')[1].toUpperCase()}</div> | ||
</div> | ||
<div | ||
sx={{ | ||
width: '100%', | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
}} | ||
> | ||
<div>RGB</div> | ||
<div> | ||
{`${rgba.r},${rgba.g},${rgba.b}${rgba.a !== 1 ? `,${rgba.a}` : ''}`} | ||
</div> | ||
</div> | ||
<div | ||
sx={{ | ||
width: '100%', | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
}} | ||
> | ||
<div>CMYK</div> | ||
<div>{`${cmyk.c},${cmyk.m},${cmyk.y},${cmyk.k}`}</div> | ||
</div> | ||
<div | ||
sx={{ | ||
width: '100%', | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
}} | ||
> | ||
<div>Pantone</div> | ||
<div>{pantone}</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
/** | ||
* | ||
* palette displayed with XColor items | ||
* using a css grid for the dsplay | ||
*/ | ||
export const XColorPalette: FC<Omit< | ||
GridContainerProps, | ||
'children' | ||
>> = props => ( | ||
<GridContainer width={180} gap={2} {...props}> | ||
{({ name, value }) => ( | ||
<XColor 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 './XColor'; |
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