diff --git a/examples/stories/src/tutorial/design/tokens/colors.mdx b/examples/stories/src/tutorial/design/tokens/colors.mdx index 21cc62676..4553ab04b 100644 --- a/examples/stories/src/tutorial/design/tokens/colors.mdx +++ b/examples/stories/src/tutorial/design/tokens/colors.mdx @@ -20,6 +20,7 @@ import { BoltColorPalette, CanvasColorPalette, CedarColorPalette, + CometColorPalette, } from '@component-controls/design-tokens'; # Overview @@ -462,4 +463,65 @@ import { CedarColorPalette } from '@component-controls/design-tokens'; description: 'Color of warning messages', }, }} +/> + + +## CometColor + +The [CometColor](/api/design-tokens-colors-cometcolor--overview) component displays the color as a row, with color, name sass variable name and AA/AAA tests. + +Design inspired from [Comet](https://comet.discoveryeducation.com/visual-language/color.html). + +``` +import { CometColorPalette } from '@component-controls/design-tokens'; + + +``` + + \ No newline at end of file diff --git a/ui/design-tokens/src/Colors/BaseWebColor/BaseWebColor.tsx b/ui/design-tokens/src/Colors/BaseWebColor/BaseWebColor.tsx index d6e60af95..363e272e1 100644 --- a/ui/design-tokens/src/Colors/BaseWebColor/BaseWebColor.tsx +++ b/ui/design-tokens/src/Colors/BaseWebColor/BaseWebColor.tsx @@ -55,7 +55,7 @@ export const BaseWebColor: FC = ({ name, color }) => { /** * - * palette displayed with ColorBlock8 items + * palette displayed with BaseWebColor items * using a css flex display direction column */ export const BaseWebColorPalette: FC ( + +); + +overview.controls = { + name: { type: 'text', value: 'emerald-40' }, + color: { + type: 'object', + value: { + name: { type: 'text', value: '40' }, + sass: { type: 'text', value: '$comet-color-emerald-40' }, + value: { type: 'color', value: '#2F9D89' }, + }, + }, +}; + +export const palette = () => ( + +); diff --git a/ui/design-tokens/src/Colors/CometColor/CometColor.tsx b/ui/design-tokens/src/Colors/CometColor/CometColor.tsx new file mode 100644 index 000000000..bc0cb5144 --- /dev/null +++ b/ui/design-tokens/src/Colors/CometColor/CometColor.tsx @@ -0,0 +1,100 @@ +/** @jsx jsx */ +import { FC } from 'react'; +import { jsx, Box, SxStyleProp } from 'theme-ui'; +import tinycolor from 'tinycolor2'; +import { CopyContainer } from '@component-controls/components'; +import { colorToStr, mostReadable } from '../utils'; +import { ColorBlockProps, ColorValue } from '../types'; +import { FlexContainerProps, FlexContainer } from '../FlexContainer'; + +/** + * Color item displaying as a row, with color, name sass variable name and AA/AAA tests + * Design inspired from [Comet](https://comet.discoveryeducation.com/visual-language/color.html). + */ + +export const CometColor: FC = ({ name, color }) => { + const colorObj: ColorValue = + typeof color === 'string' ? { value: color, name } : color; + const { value: colorValue, name: colorName = name, sass } = colorObj; + + const { hex } = colorToStr(colorValue); + const textColor = mostReadable(hex); + const contrast = tinycolor.readability(hex, textColor); + + let accessibilityTest; + const testProps: SxStyleProp = { + ml: 3, + width: '40px', + textAlign: 'center', + color: 'black', + fontSize: 1, + }; + if (contrast >= 7) { + accessibilityTest =
AAA
; + } else if (contrast >= 4.5) { + accessibilityTest =
AA
; + } else if (contrast >= 3) { + accessibilityTest =
AA18
; + } else { + accessibilityTest = ( +
DNP
+ ); + } + return ( + + +
+
+ {colorName} +
+ +
+ {sass} +
+
+
{hex.toUpperCase()}
+ {accessibilityTest} +
+
+
+
+ ); +}; + +/** + * + * palette displayed with CometColor items + * using a css flex display direction column + */ +export const CometColorPalette: FC> = props => ( + + {({ name, value }) => ( + + )} + +); diff --git a/ui/design-tokens/src/Colors/CometColor/index.ts b/ui/design-tokens/src/Colors/CometColor/index.ts new file mode 100644 index 000000000..5c8376312 --- /dev/null +++ b/ui/design-tokens/src/Colors/CometColor/index.ts @@ -0,0 +1 @@ +export * from './CometColor'; diff --git a/ui/design-tokens/src/Colors/index.ts b/ui/design-tokens/src/Colors/index.ts index b3cdcefb8..e21edf695 100644 --- a/ui/design-tokens/src/Colors/index.ts +++ b/ui/design-tokens/src/Colors/index.ts @@ -9,3 +9,4 @@ export * from './BaseWebColor'; export * from './BoltColor'; export * from './CanvasColor'; export * from './CedarColor'; +export * from './CometColor';