-
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
8ed5097
commit 1316e10
Showing
8 changed files
with
236 additions
and
4 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
52 changes: 52 additions & 0 deletions
52
ui/design-tokens/src/Colors/OPatternColor/OPatternColor.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,52 @@ | ||
import React from 'react'; | ||
import { OPatternColor, OPatternColorPalette } from './OPatternColor'; | ||
import { ColorProps } from '../../types'; | ||
|
||
export default { | ||
title: 'Design Tokens/Colors/OPatternColor', | ||
component: OPatternColor, | ||
}; | ||
|
||
export const overview = ({ name, color }: ColorProps) => ( | ||
<OPatternColor name={name} color={color} /> | ||
); | ||
|
||
overview.controls = { | ||
name: { type: 'text', value: 'Weather' }, | ||
color: { | ||
type: 'object', | ||
value: { | ||
value: { type: 'color', value: '#990099' }, | ||
sass: { type: 'text', value: '$weather-color' }, | ||
}, | ||
}, | ||
}; | ||
|
||
export const palette = () => ( | ||
<OPatternColorPalette | ||
palette={{ | ||
Primary: { | ||
value: '#107CB2', | ||
sass: '$primary-color', | ||
}, | ||
PrimaryLight: { | ||
value: '#b7d8e8', | ||
description: '30% of $primary-color', | ||
sass: '$primary-color-light', | ||
}, | ||
Alert: { | ||
value: '#D8400F', | ||
sass: '$alert-color', | ||
}, | ||
AlertLight: { | ||
value: '#f3c6b7', | ||
description: '30% of $alert-color', | ||
sass: '$alert-color-light', | ||
}, | ||
Weather: { | ||
value: '#990099', | ||
sass: '$weather-color', | ||
}, | ||
}} | ||
/> | ||
); |
113 changes: 113 additions & 0 deletions
113
ui/design-tokens/src/Colors/OPatternColor/OPatternColor.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,113 @@ | ||
/** @jsx jsx */ | ||
import { FC, Fragment } from 'react'; | ||
import { jsx } 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 { TableContainerProps, TableContainer } from '../../components'; | ||
|
||
/** | ||
* Color item displaying as a table row, with color block, sass name, andhex, rgb and cmyk color values. | ||
* Design inspired from [OPattern](https://ux.opower.com/opattern/color.html). | ||
*/ | ||
|
||
export const OPatternColor: FC<ColorBlockProps> = props => ( | ||
<table> | ||
<tbody> | ||
<BaseOPatternColor {...props} /> | ||
</tbody> | ||
</table> | ||
); | ||
|
||
const BaseOPatternColor: FC<ColorBlockProps> = ({ name, color }) => { | ||
const colorObj: ColorValue = | ||
typeof color === 'string' ? { value: color } : color; | ||
const { | ||
value: colorValue, | ||
name: colorName = name, | ||
sass, | ||
description, | ||
} = colorObj; | ||
const { hex, rgba } = colorToStr(colorValue); | ||
const { color: cmyk } = new simpleColorConverter({ | ||
rgba, | ||
to: 'cmyk', | ||
}); | ||
|
||
return ( | ||
<tr> | ||
<td sx={{ border: 'none !important' }}> | ||
<CopyContainer | ||
value={hex} | ||
name={colorName} | ||
sx={{ bg: colorValue, width: '100%', minWidth: 100, height: '100%' }} | ||
/> | ||
</td> | ||
<td> | ||
<code sx={{ bg: 'gray' }}>{sass}</code> | ||
</td> | ||
{description ? ( | ||
<td colSpan={3}>{description}</td> | ||
) : ( | ||
<Fragment> | ||
<td> | ||
<div>{hex.toUpperCase()}</div> | ||
</td> | ||
<td> | ||
<div>{`${rgba.r}, ${rgba.g}, ${rgba.b}${ | ||
rgba.a !== 1 ? `, ${rgba.a}` : '' | ||
}`}</div> | ||
</td> | ||
<td>{`${cmyk.c}, ${cmyk.m}, ${cmyk.y}, ${cmyk.k}`}</td> | ||
</Fragment> | ||
)} | ||
</tr> | ||
); | ||
}; | ||
|
||
/** | ||
* | ||
* palette displayed with OPatternColor items | ||
* using a css flex display direction column | ||
*/ | ||
export const OPatternColorPalette: FC<Omit< | ||
TableContainerProps, | ||
'children' | 'columns' | ||
>> = props => ( | ||
<TableContainer | ||
columns={[ | ||
{ title: 'Color', sx: { width: '25%' } }, | ||
{ title: 'Variable', sx: { width: '30%' } }, | ||
{ title: 'Hex', sx: { width: '15%' } }, | ||
{ title: 'RGB', sx: { width: '15%' } }, | ||
{ title: 'CMYK', sx: { width: '15%' } }, | ||
]} | ||
sx={{ | ||
'& > tbody > tr > td': { | ||
height: 80, | ||
px: 2, | ||
py: 0, | ||
}, | ||
'& > tbody > tr': { | ||
fontSize: 0, | ||
}, | ||
'& > thead > tr > th': { | ||
textAlign: 'left', | ||
fontSize: 1, | ||
fontWeight: 'bold', | ||
pb: 2, | ||
px: 2, | ||
}, | ||
}} | ||
{...props} | ||
> | ||
{({ name, value }) => ( | ||
<BaseOPatternColor | ||
key={`color_item_${name}}`} | ||
name={name} | ||
color={value} | ||
/> | ||
)} | ||
</TableContainer> | ||
); |
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 './OPatternColor'; |
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