Skip to content

Commit

Permalink
feat: added liquid coor token
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Sep 29, 2020
1 parent 8d45d31 commit e920974
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 5 deletions.
43 changes: 41 additions & 2 deletions examples/stories/src/tutorial/design/tokens/colors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
ColorTabs,
IBMDLColorPalette,
LightningColorPalette,
LiquidColorPalette,
} from '@component-controls/design-tokens';

# Overview
Expand Down Expand Up @@ -957,7 +958,7 @@ import { ColorTabs, IBMDLColorPalette } from '@component-controls/design-tokens'

The [LightningColor](/api/design-tokens-colors-lightningcolor--overview) component displays the color as a row, with color, name, description, var and sas variables and contrast ratio. allows for custom columns.

Design inspired from racle's [Lightning Design System](https://www.lightningdesignsystem.com/design-tokens/#category-color).
Design inspired from Oracle's [Lightning Design System](https://www.lightningdesignsystem.com/design-tokens/#category-color).

```
import { LightningColorPalette } from '@component-controls/design-tokens';
Expand Down Expand Up @@ -1137,4 +1138,42 @@ import { LightningColorPalette } from '@component-controls/design-tokens';
support: 'GA',
},
}}
/>
/>




## LiquidColor

The [LiquidColor](/api/design-tokens-colors-liquidcolor--overview) component displays the color as a block with values for rgb and a palette of lighter and darker colors.

Design inspired from [Liquid Design System](https://liquid.emd.design/fundamentals/color/).

```
import { LiquidColorPalette } from '@component-controls/design-tokens';
<LiquidColorPalette
palette={{
'Vibrant Magenta': '#EB3C96',
'Rich Blue': '#0F69AF',
'Vibrant Cyan': '#2DBECD',
'Vibrant Green': '#A5CD50',
'Rich Red': '#E61E50',
'Vibrant Yellow': '#FFC832',
'Rich Green': '#149B5F',
}}
/>
```

<LiquidColorPalette
palette={{
'Vibrant Magenta': '#EB3C96',
'Rich Blue': '#0F69AF',
'Vibrant Cyan': '#2DBECD',
'Vibrant Green': '#A5CD50',
'Rich Red': '#E61E50',
'Vibrant Yellow': '#FFC832',
'Rich Green': '#149B5F',
}}
/>
3 changes: 1 addition & 2 deletions ui/design-tokens/src/Colors/BeelineColor/BeelineColor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const BeelineColor: FC<ColorBlockProps> = ({ name, color }) => {
}}
>
<div sx={{ fontWeight: 'bold', mr: 1 }}>HEX:</div>
<div>{hex}:</div>
<div>{hex}</div>
</div>
<div
sx={{
Expand All @@ -82,7 +82,6 @@ export const BeelineColor: FC<ColorBlockProps> = ({ name, color }) => {
{`rgb(${rgba.r},${rgba.g},${rgba.b}${
rgba.a !== 1 ? `,${rgba.a}` : ''
})`}
:
</div>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type LightningColorProps = {
} & ColorBlockProps;
/**
* Color item displaying as a row, with color, name, description, var and sas variables and contrast ratio. allows for custom columns.
* Design inspired from racle's [Lightning Design System](https://www.lightningdesignsystem.com/design-tokens/#category-color).
* Design inspired from Oracle's [Lightning Design System](https://www.lightningdesignsystem.com/design-tokens/#category-color).
*/

export const LightningColor: FC<LightningColorProps> = props => (
Expand Down
31 changes: 31 additions & 0 deletions ui/design-tokens/src/Colors/LiquidColor/LiquidColor.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import { LiquidColor, LiquidColorPalette } from './LiquidColor';
import { ColorProps } from '../../types';

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

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

overview.controls = {
name: { type: 'text', value: 'Rich Purple' },
color: { type: 'color', value: '#503291' },
};

export const palette = () => (
<LiquidColorPalette
palette={{
'Vibrant Magenta': '#EB3C96',
'Rich Blue': '#0F69AF',
'Vibrant Cyan': '#2DBECD',
'Vibrant Green': '#A5CD50',
'Rich Red': '#E61E50',
'Vibrant Yellow': '#FFC832',
'Rich Green': '#149B5F',
}}
/>
);
127 changes: 127 additions & 0 deletions ui/design-tokens/src/Colors/LiquidColor/LiquidColor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/** @jsx jsx */
import { FC } from 'react';
import { jsx, Theme } from 'theme-ui';
import tinycolor from 'tinycolor2';
import { CopyContainer } from '@component-controls/components';
import { colorToStr, mostReadable } from '../utils';
import { ColorBlockProps } from '../../types';
import { GridContainerProps, GridContainer } from '../../components';

/**
* Color item displaying the color as a block with values for rgb and a palette of lighter and darker colors.
* Design inspired from [Liquid Design System](https://liquid.emd.design/fundamentals/color/).
*/
export const LiquidColor: FC<ColorBlockProps> = ({ name, color }) => {
const colorValue = typeof color === 'string' ? color : color.value;
const { hex, rgba } = colorToStr(colorValue);
const textColor = mostReadable(hex);
const palette = [hex];
let initial = hex;
for (let i = 0; i < 3; i += 1) {
initial = tinycolor(initial)
.lighten()
.toHexString();
if (!palette.includes(initial)) {
palette.push(initial);
}
}
initial = hex;
for (let i = 0; i < 3; i += 1) {
initial = tinycolor(initial)
.darken()
.toHexString();
if (!palette.includes(initial)) {
palette.unshift(initial);
}
}

return (
<div
sx={{
display: 'flex',
flexDirection: 'column',
bg: 'background',
minWidth: 120,
maxWidth: 320,
border: (t: Theme) => `1px solid ${t.colors?.shadow}`,
borderRadius: 1,
boxShadow: (t: Theme) => `0 1px 2px 0 ${t.colors?.shadow}`,
}}
>
<CopyContainer value={hex} name={name}>
<div
sx={{
bg: colorValue,
position: 'relative',
':after': {
content: '""',
display: 'block',
paddingBottom: '60%',
},
}}
>
<div
sx={{
fontSize: 2,
fontWeight: 'bold',
position: 'absolute',
left: 3,
bottom: 3,
color: textColor,
}}
>
{hex.toUpperCase()}
</div>
</div>
</CopyContainer>
<div
sx={{
height: 25,
width: '100%',
display: 'flex',
flexDirection: 'row',
}}
>
{palette.map(p => (
<CopyContainer
key={`liquid_color_${p}`}
sx={{ flex: 1, bg: p }}
name={name}
value={p}
></CopyContainer>
))}
</div>
<div
sx={{
display: 'flex',
flexDirection: 'column',
p: 2,
fontSize: 2,
}}
>
<div sx={{ fontSize: 3 }}>{name || hex}</div>
<div>
{`RGB (${rgba.r},${rgba.g},${rgba.b}${
rgba.a !== 1 ? `,${rgba.a}` : ''
})`}
</div>
</div>
</div>
);
};

/**
*
* palette displayed with LiquidColor items
* using a css grid for the dsplay
*/
export const LiquidColorPalette: FC<Omit<
GridContainerProps,
'children'
>> = props => (
<GridContainer width={170} gap={3} {...props}>
{({ name, value }) => (
<LiquidColor key={`color_item_${name}}`} name={name} color={value} />
)}
</GridContainer>
);
1 change: 1 addition & 0 deletions ui/design-tokens/src/Colors/LiquidColor/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './LiquidColor';
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 @@ -19,3 +19,4 @@ export * from './GovUKColor';
export * from './HelpScoutColor';
export * from './IBMDLColor';
export * from './LightningColor';
export * from './LiquidColor';

0 comments on commit e920974

Please sign in to comment.