diff --git a/examples/stories/src/tutorial/design/tokens/colors.mdx b/examples/stories/src/tutorial/design/tokens/colors.mdx index 807e1eb4f..b39407ddd 100644 --- a/examples/stories/src/tutorial/design/tokens/colors.mdx +++ b/examples/stories/src/tutorial/design/tokens/colors.mdx @@ -34,6 +34,7 @@ import { LightningColorPalette, LiquidColorPalette, MorningstarColorPalette, + OPatternColorPalette, } from '@component-controls/design-tokens'; # Overview @@ -1240,3 +1241,68 @@ import { MorningstarColorPalette } from '@component-controls/design-tokens'; }, }} /> + + +## OPatternColor + +The [OPatternColor](/api/design-tokens-colors-opatterncolor--overview) component displays the color 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). + +``` +import { OPatternColorPalette } from '@component-controls/design-tokens'; + + +``` + + \ No newline at end of file diff --git a/ui/design-tokens/src/Colors/DuetColor/DuetColor.tsx b/ui/design-tokens/src/Colors/DuetColor/DuetColor.tsx index 80b259cc8..9891a8b68 100644 --- a/ui/design-tokens/src/Colors/DuetColor/DuetColor.tsx +++ b/ui/design-tokens/src/Colors/DuetColor/DuetColor.tsx @@ -114,9 +114,6 @@ export const DuetColorPalette: FC tbody > td': { - px: 1, - }, '& > tbody > tr': { fontSize: 0, transition: 'background .3s ease', diff --git a/ui/design-tokens/src/Colors/MorningstarColor/MorningstarColor.tsx b/ui/design-tokens/src/Colors/MorningstarColor/MorningstarColor.tsx index c422c7f85..510378d8c 100644 --- a/ui/design-tokens/src/Colors/MorningstarColor/MorningstarColor.tsx +++ b/ui/design-tokens/src/Colors/MorningstarColor/MorningstarColor.tsx @@ -92,7 +92,7 @@ export const MorningstarColorPalette: FC ( + +); + +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 = () => ( + +); diff --git a/ui/design-tokens/src/Colors/OPatternColor/OPatternColor.tsx b/ui/design-tokens/src/Colors/OPatternColor/OPatternColor.tsx new file mode 100644 index 000000000..661fa6a34 --- /dev/null +++ b/ui/design-tokens/src/Colors/OPatternColor/OPatternColor.tsx @@ -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 = props => ( + + + + + +); + +const BaseOPatternColor: FC = ({ 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 ( + + + + + + {sass} + + {description ? ( + {description} + ) : ( + + + {hex.toUpperCase()} + + + {`${rgba.r}, ${rgba.g}, ${rgba.b}${ + rgba.a !== 1 ? `, ${rgba.a}` : '' + }`} + + {`${cmyk.c}, ${cmyk.m}, ${cmyk.y}, ${cmyk.k}`} + + )} + + ); +}; + +/** + * + * palette displayed with OPatternColor items + * using a css flex display direction column + */ +export const OPatternColorPalette: FC> = props => ( + 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 }) => ( + + )} + +); diff --git a/ui/design-tokens/src/Colors/OPatternColor/index.ts b/ui/design-tokens/src/Colors/OPatternColor/index.ts new file mode 100644 index 000000000..1b2c84b5d --- /dev/null +++ b/ui/design-tokens/src/Colors/OPatternColor/index.ts @@ -0,0 +1 @@ +export * from './OPatternColor'; diff --git a/ui/design-tokens/src/Colors/index.ts b/ui/design-tokens/src/Colors/index.ts index 2cbc0cc73..a34588896 100644 --- a/ui/design-tokens/src/Colors/index.ts +++ b/ui/design-tokens/src/Colors/index.ts @@ -21,3 +21,4 @@ export * from './IBMDLColor'; export * from './LightningColor'; export * from './LiquidColor'; export * from './MorningstarColor'; +export * from './OPatternColor'; diff --git a/ui/design-tokens/src/components/TableContainer/TableContainer.tsx b/ui/design-tokens/src/components/TableContainer/TableContainer.tsx index 91f7cc0c5..658705968 100644 --- a/ui/design-tokens/src/components/TableContainer/TableContainer.tsx +++ b/ui/design-tokens/src/components/TableContainer/TableContainer.tsx @@ -30,6 +30,8 @@ export const TableContainer: FC = ({ bg: 'background', borderSpacing: 0, borderCollapse: 'separate', + tableLayout: 'fixed', + width: '100%', borderTop: (t: Theme) => ` 1px solid ${t.colors?.shadow}`, borderBottom: (t: Theme) => ` 1px solid ${t.colors?.shadow}`, '& > tbody > tr > td': {
{sass}