Skip to content

Commit

Permalink
feat: audi ds color palette
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Sep 21, 2020
1 parent c973790 commit 683b617
Show file tree
Hide file tree
Showing 14 changed files with 236 additions and 30 deletions.
43 changes: 37 additions & 6 deletions examples/stories/src/tutorial/design/tokens/colors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ tags:
order: 1
author: atanasster
---
import { ColorBlock1Palette, ColorBlock2Palette, ColorBlock3Palette, ColorBlock4Palette, ColorBlock5Palette } from '@component-controls/design-tokens';
import { ColorBlock1Palette, ColorBlock2Palette, ColorBlock3Palette,
ColorBlock4Palette, ColorBlock5Palette, ColorBlock6Palette } from '@component-controls/design-tokens';

# Overview

Colors are one of the main [design tokens](/tutorial/design-tokens/intro) elements, and `component-controls` provides multiple components to document your colors and color palettes.

The color can be a hex, rgb, or hsl string value.

## ColorBlock1
## ColorBlock1 (Alta UI)

The [ColorBlock1](/api/design-tokens-colors-colorblock1--overview) component displays the color name and value in a compact block.

Expand Down Expand Up @@ -46,7 +47,7 @@ import { ColorBlock1Palette } from '@component-controls/design-tokens';
}}
/>

## ColorBlock2
## ColorBlock2 (Antd)

The [ColorBlock2](/api/design-tokens-colors-colorblock2--overview) component displays a horizontal color block, with the color value visible on hover.

Expand Down Expand Up @@ -83,7 +84,7 @@ import { ColorBlock2Palette } from '@component-controls/design-tokens';
}}
/>

## ColorBlock3
## ColorBlock3 (Antd)

The [ColorBlock3](/api/design-tokens-colors-colorblock3--overview) component displays a horizontal color block, with the color value visible on hover.

Expand Down Expand Up @@ -117,7 +118,7 @@ import { ColorBlock3Palette } from '@component-controls/design-tokens';
/>


## ColorBlock4
## ColorBlock4 (Anvil)

The [ColorBlock4](/api/design-tokens-colors-colorblock4--overview) component displays a color block with a dot suggesting the best text color and a block of text with the color title, name and value.

Expand Down Expand Up @@ -146,7 +147,7 @@ import { ColorBlock4Palette } from '@component-controls/design-tokens';
}}
/>

## ColorBlock5
## ColorBlock5 (Atlassian DS)

The [ColorBlock5](/api/design-tokens-colors-colorblock5--overview) component displays a color block with [AA](https://www.w3.org/TR/WCAG/) color contrast tests.

Expand Down Expand Up @@ -174,4 +175,34 @@ import { ColorBlock5Palette } from '@component-controls/design-tokens';
"Da' juice": { value: '#6554C0', name: 'P300' },
Critical: { value: '#f94d32', name: 'Red400' },
}}
/>

## ColorBlock6 (Audi DS)

The [ColorBlock6](/api/design-tokens-colors-colorblock6--overview) component displays a color block and color aliases for various standard is Pantone, CMYK.

```
import { ColorBlock6Palette } from '@component-controls/design-tokens';
<ColorBlock6Palette
palette={{
'Poppy surprise': { value: '#FF5630', name: 'R300' },
'Golden state': { value: '#FFAB00', name: 'Y300' },
'Fine pine': { value: '#36B37E', name: 'G300' },
Tamarama: { value: '#00B8D9', name: 'T300' },
"Da' juice": { value: '#6554C0', name: 'P300' },
Critical: { value: '#f94d32', name: 'Red400' },
}}
/>
```

<ColorBlock6Palette
palette={{
'Poppy surprise': { value: '#FF5630', name: 'R300' },
'Golden state': { value: '#FFAB00', name: 'Y300' },
'Fine pine': { value: '#36B37E', name: 'G300' },
Tamarama: { value: '#00B8D9', name: 'T300' },
"Da' juice": { value: '#6554C0', name: 'P300' },
Critical: { value: '#f94d32', name: 'Red400' },
}}
/>
1 change: 1 addition & 0 deletions ui/design-tokens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@primer/octicons-react": "^10.0.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"simple-color-converter": "^2.1.9",
"tinycolor2": "^1.4.1",
"theme-ui": "^0.4.0-rc.1"
},
Expand Down
8 changes: 3 additions & 5 deletions ui/design-tokens/src/Colors/ColorBlock1/ColorBlock1.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
/** @jsx jsx */
import { FC } from 'react';
import { jsx, Box, Theme, SxProps } from 'theme-ui';
import { jsx, Box, Theme } from 'theme-ui';
import { CopyContainer } from '@component-controls/components';
import { colorToStr } from '../utils';
import { ColorProps } from '../types';
import { ColorBlockProps } from '../types';
import { GridContainerProps, GridContainer } from '../GridContainer';

export type ColoBlock1Props = { sx?: SxProps } & ColorProps;

/**
* Color item displaying the color as a block, as well as hex(string) and rgb values.
* Inspired from [Alta UI](https://www.oracle.com/webfolder/ux/middleware/alta_web_icon_guide/Alta-Colors/UI-Palette.html).
*/
export const ColorBlock1: FC<ColoBlock1Props> = ({ name, color, sx }) => {
export const ColorBlock1: FC<ColorBlockProps> = ({ name, color, sx }) => {
const colorValue = typeof color === 'string' ? color : color.value;
const { hex, rgba } = colorToStr(colorValue);
return (
Expand Down
13 changes: 9 additions & 4 deletions ui/design-tokens/src/Colors/ColorBlock2/ColorBlock2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ import { FC, useState, useMemo } from 'react';
import { jsx, Box } from 'theme-ui';
import { CopyContainer } from '@component-controls/components';
import { colorToStr, mostReadable } from '../utils';
import { ColorProps } from '../types';
import { ColorBlockProps } from '../types';
import { FlexContainerProps, FlexContainer } from '../FlexContainer';

/**
* Color item displaying the color as a small block, expanding on hover.
* Design inspired from [And Design](https://ant.design/docs/spec/colors).
* Design inspired from [Antd](https://ant.design/docs/spec/colors).
*/

export const ColorBlock2: FC<ColorProps> = ({ name, color, hover }) => {
export const ColorBlock2: FC<ColorBlockProps> = ({
name,
color,
hover,
sx,
}) => {
const [hoverMe, setHoverMe] = useState(false);
const colorValue = typeof color === 'string' ? color : color.value;
const { hex, rgba } = colorToStr(colorValue);
Expand All @@ -29,7 +34,7 @@ export const ColorBlock2: FC<ColorProps> = ({ name, color, hover }) => {
);

return (
<Box sx={{ display: 'flex', flex: '1', width: 250 }}>
<Box sx={{ display: 'flex', flex: '1', width: 250, ...sx }}>
<CopyContainer value={hex} name={name} sxStyle={{ width: '100%' }}>
<Box
{...onMouseEvents}
Expand Down
13 changes: 9 additions & 4 deletions ui/design-tokens/src/Colors/ColorBlock3/ColorBlock3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ import { FC, useState, useMemo } from 'react';
import { jsx, Box } from 'theme-ui';
import { CopyContainer } from '@component-controls/components';
import { colorToStr, mostReadable } from '../utils';
import { ColorProps } from '../types';
import { ColorBlockProps } from '../types';
import { FlexContainerProps, FlexContainer } from '../FlexContainer';

/**
* Color item displaying the color as a small block, expanding on hover.
* Design inspired from [And Design](https://ant.design/docs/spec/colors).
* Design inspired from [Antd](https://ant.design/docs/spec/colors).
*/

export const ColorBlock3: FC<ColorProps> = ({ name, color, hover }) => {
export const ColorBlock3: FC<ColorBlockProps> = ({
name,
color,
hover,
sx,
}) => {
const [hoverMe, setHoverMe] = useState(false);
const colorValue = typeof color === 'string' ? color : color.value;
const { hex, rgba } = colorToStr(colorValue);
Expand All @@ -29,7 +34,7 @@ export const ColorBlock3: FC<ColorProps> = ({ name, color, hover }) => {
[isContained],
);
return (
<Box sx={{ display: 'flex', flex: '1', height: 90, maxWidth: 120 }}>
<Box sx={{ display: 'flex', flex: '1', height: 90, maxWidth: 120, ...sx }}>
<CopyContainer value={hex} name={name} sxStyle={{ width: '100%' }}>
<Box
{...onMouseEvents}
Expand Down
8 changes: 3 additions & 5 deletions ui/design-tokens/src/Colors/ColorBlock4/ColorBlock4.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
/** @jsx jsx */
import { FC } from 'react';
import { jsx, Box, Heading, SxProps } from 'theme-ui';
import { jsx, Box, Heading } from 'theme-ui';
import { CopyContainer } from '@component-controls/components';
import { colorToStr, mostReadable } from '../utils';
import { ColorProps } from '../types';
import { ColorBlockProps } from '../types';
import { GridContainerProps, GridContainer } from '../GridContainer';

export type ColorBlock4Props = { sx?: SxProps } & ColorProps;

/**
* Color item displaying the color as a block with a title, as well as hex(string) and rgb values.
* Design inspired from [Anvil](https://anvil.servicetitan.com/foundations/color/).
*/
export const ColorBlock4: FC<ColorBlock4Props> = ({ name, color, sx }) => {
export const ColorBlock4: FC<ColorBlockProps> = ({ name, color, sx }) => {
const colorValue = typeof color === 'string' ? color : color.value;
const { hex } = colorToStr(colorValue);
const textColor = mostReadable(hex);
Expand Down
8 changes: 3 additions & 5 deletions ui/design-tokens/src/Colors/ColorBlock5/ColorBlock5.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
/** @jsx jsx */
import { FC } from 'react';
import { jsx, Box, SxProps } from 'theme-ui';
import { jsx, Box } from 'theme-ui';
import { CopyContainer } from '@component-controls/components';
import tinycolor from 'tinycolor2';
import { colorToStr } from '../utils';
import { ColorProps } from '../types';
import { ColorBlockProps } from '../types';
import { GridContainerProps, GridContainer } from '../GridContainer';

export type ColorBlock5Props = { sx?: SxProps } & ColorProps;

const ContrastTest: FC<{
bg: string;
color: string;
Expand Down Expand Up @@ -48,7 +46,7 @@ const ContrastTest: FC<{
* Color item displaying the color as a block with [AA](https://www.w3.org/TR/WCAG/) color contrast tests.
* Design inspired from [Atlassian Design System](https://atlassian.design/foundations/color).
*/
export const ColorBlock5: FC<ColorBlock5Props> = ({ name, color, sx }) => {
export const ColorBlock5: FC<ColorBlockProps> = ({ name, color, sx }) => {
const colorValue = typeof color === 'string' ? color : color.value;
const { hex, rgba } = colorToStr(colorValue);
return (
Expand Down
54 changes: 54 additions & 0 deletions ui/design-tokens/src/Colors/ColorBlock6/ColorBlock6.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
import { ColorBlock6, ColorBlock6Palette } from './ColorBlock6';
import { ColorProps } from '../types';

export default {
title: 'Design Tokens/Colors/ColorBlock6',
component: ColorBlock6,
};

export const overview = ({ name, color }: ColorProps) => (
<ColorBlock6 name={name} color={color} />
);

overview.controls = {
name: { type: 'text', value: 'Brand' },
color: {
type: 'object',
value: {
value: { type: 'color', value: '#2270ee' },
name: { type: 'text', value: 'Blue400' },
},
},
};

export const name = () => (
<ColorBlock6 name="Critical" color={{ name: 'brand', value: '#f94d32' }} />
);

export const rgb = () => <ColorBlock6 name="text" color="rgb(0, 0, 0)" />;

export const rgba = () => (
<ColorBlock6 name="shadow" color="rgba(0, 0, 0, 0.1)" />
);

export const hsl = () => (
<ColorBlock6 name="accent" color="hsl(12, 10%, 50%)" />
);

export const hsla = () => (
<ColorBlock6 name="accent" color="hsl(12, 10%, 50%, .3)" />
);

export const palette = () => (
<ColorBlock6Palette
palette={{
'Poppy surprise': { value: '#FF5630', name: 'R300' },
'Golden state': { value: '#FFAB00', name: 'Y300' },
'Fine pine': { value: '#36B37E', name: 'G300' },
Tamarama: { value: '#00B8D9', name: 'T300' },
"Da' juice": { value: '#6554C0', name: 'P300' },
Critical: { value: '#f94d32', name: 'Red400' },
}}
/>
);
99 changes: 99 additions & 0 deletions ui/design-tokens/src/Colors/ColorBlock6/ColorBlock6.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/** @jsx jsx */
import { FC } from 'react';
import { jsx, Box } from 'theme-ui';
import { CopyContainer } from '@component-controls/components';
import simpleColorConverter from 'simple-color-converter';
import { colorToStr } from '../utils';
import { ColorBlockProps } from '../types';
import { GridContainerProps, GridContainer } from '../GridContainer';

/**
* Color item displaying the color as a block and color aliases for various standard is Pantone, CMYK.
* Design inspired from [Audi Design System](https://www.audi.com/ci/en/intro/basics/colours.html).
*/
export const ColorBlock6: FC<ColorBlockProps> = ({ name, color, sx }) => {
const colorValue = typeof color === 'string' ? color : color.value;
const { hex, rgba } = colorToStr(colorValue);
const { color: cmyk } = new simpleColorConverter({
rgba,
to: 'cmyk',
});
const { color: ral } = new simpleColorConverter({
rgba,
to: 'ral',
});
const { color: pantone } = new simpleColorConverter({
rgba,
to: 'pantone',
});
return (
<Box
sx={{
display: 'flex',
flexDirection: 'column',
minWidth: 180,
maxWidth: 450,
}}
>
<CopyContainer value={hex} name={name}>
<Box
sx={{
bg: colorValue,
':after': {
content: '""',
display: 'block',
paddingBottom: '100%',
},
}}
/>
</CopyContainer>
<Box
sx={{
display: 'flex',
flexDirection: 'column',
lineHeight: '16px',
bg: 'muted',
p: 3,
fontSize: 2,
...sx,
}}
>
<Box
sx={{
display: 'flex',
flexDirection: 'column',
}}
>
<Box sx={{ pt: 1, pb: 2, fontWeight: 'bold' }}>{name || hex}</Box>
</Box>
<div sx={{ lineHeight: 1.5 }}>
<div>
{`RGB: ${rgba.r}/${rgba.g}/${rgba.b}${
rgba.a !== 1 ? `/${rgba.a}` : ''
}`}
</div>
<div>{`HEX: ${hex}`}</div>
<div>{`CMYK: ${cmyk.c}/${cmyk.m}/${cmyk.y}/${cmyk.k}`}</div>
<div sx={{ mb: 1 }}>{`${pantone ? `Pantone ${pantone}` : '--'}`}</div>
<div>{`RAL: ${ral.ral}`}</div>
</div>
</Box>
</Box>
);
};

/**
*
* palette displayed with ColorBlock6 items
* using a css grid for the dsplay
*/
export const ColorBlock6Palette: FC<Omit<
GridContainerProps,
'children'
>> = props => (
<GridContainer {...props}>
{({ name, value }) => (
<ColorBlock6 key={`color_item_${name}}`} name={name} color={value} />
)}
</GridContainer>
);
1 change: 1 addition & 0 deletions ui/design-tokens/src/Colors/ColorBlock6/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ColorBlock6';
1 change: 1 addition & 0 deletions ui/design-tokens/src/Colors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './ColorBlock2';
export * from './ColorBlock3';
export * from './ColorBlock4';
export * from './ColorBlock5';
export * from './ColorBlock6';
Loading

0 comments on commit 683b617

Please sign in to comment.