Skip to content

Commit

Permalink
feat: add govuk ds color token
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Sep 25, 2020
1 parent c259a5f commit a16ec4a
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 0 deletions.
53 changes: 53 additions & 0 deletions examples/stories/src/tutorial/design/tokens/colors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
ETradeColorPalette,
FinastraColorPalette,
FishTankColorPalette,
GovUKColorPalette,
} from '@component-controls/design-tokens';

# Overview
Expand Down Expand Up @@ -817,3 +818,55 @@ import { FishTankColorPalette } from '@component-controls/design-tokens';
},
}}
/>

## GovUKColor

The [GovUKColor](/api/design-tokens-colors-govukcolor--overview) component displays the color as a row with a color circle and the sass var name and hex color.

Design inspired from [GOV.UK Design System](https://design-system.service.gov.uk/styles/colour/).

```
import { GovUKColorPalette } from '@component-controls/design-tokens';
<GovUKColorPalette
palette={{
'brand-colour': {
sass: '$govuk-brand-colour',
value: '#1d70b8',
},
'hover-colour': {
sass: '$govuk-link-hover-colour',
value: '#003078',
},
'visited-colour': {
sass: '$govuk-link-visited-colour',
value: '#4c2c92',
},
red: {
varName: 'govuk-colour("red")',
value: '#d4351c',
},
}}
/>
```

<GovUKColorPalette
palette={{
'brand-colour': {
sass: '$govuk-brand-colour',
value: '#1d70b8',
},
'hover-colour': {
sass: '$govuk-link-hover-colour',
value: '#003078',
},
'visited-colour': {
sass: '$govuk-link-visited-colour',
value: '#4c2c92',
},
red: {
varName: 'govuk-colour("red")',
value: '#d4351c',
},
}}
/>
45 changes: 45 additions & 0 deletions ui/design-tokens/src/Colors/GovUKColor/GovUKColor.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import { GovUKColor, GovUKColorPalette } from './GovUKColor';
import { ColorProps } from '../types';

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

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

overview.controls = {
color: {
type: 'object',
value: {
value: { type: 'color', value: '#1d70b8' },
sass: { type: 'color', value: '$govuk-brand-colour' },
},
},
};

export const palette = () => (
<GovUKColorPalette
palette={{
'brand-colour': {
sass: '$govuk-brand-colour',
value: '#1d70b8',
},
'hover-colour': {
sass: '$govuk-link-hover-colour',
value: '#003078',
},
'visited-colour': {
sass: '$govuk-link-visited-colour',
value: '#4c2c92',
},
red: {
varName: 'govuk-colour("red")',
value: '#d4351c',
},
}}
/>
);
74 changes: 74 additions & 0 deletions ui/design-tokens/src/Colors/GovUKColor/GovUKColor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/** @jsx jsx */
import { FC } from 'react';
import { jsx } from 'theme-ui';
import { CopyContainer } from '@component-controls/components';
import { colorToStr } from '../utils';
import { ColorBlockProps, ColorValue } from '../types';
import { FlexContainerProps, FlexContainer } from '../FlexContainer';

/**
* Color item displaying the color as a row with a color circle and the sass var name and hex color.
* Design inspired from [GOV.UK Design System](https://design-system.service.gov.uk/styles/colour/).
*/

export const GovUKColor: FC<ColorBlockProps> = ({ name, color }) => {
const colorObj: ColorValue =
typeof color === 'string' ? { value: color } : color;
const { value: colorValue, sass, varName } = colorObj;

const { hex } = colorToStr(colorValue);
return (
<div sx={{ display: 'flex', flex: '1' }}>
<div
sx={{
width: '100%',
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
fontSize: 2,
p: 2,
}}
>
<CopyContainer value={hex} name={name}>
<div
sx={{
width: 40,
height: 40,
borderRadius: '50%',
bg: colorValue,
mr: 3,
}}
/>
</CopyContainer>
<div
sx={{
justifyContent: 'space-between',
flex: 1,
alignItems: 'center',
display: 'flex',
flexDirection: 'row',
}}
>
<div>{sass || varName}</div>
<div>{hex}</div>
</div>
</div>
</div>
);
};

/**
*
* palette displayed with GovUKDS items
* using a css flex display direction column
*/
export const GovUKColorPalette: FC<Omit<
FlexContainerProps,
'children' | 'direction'
>> = props => (
<FlexContainer direction="column" {...props}>
{({ name, value }) => (
<GovUKColor key={`color_item_${name}}`} name={name} color={value} />
)}
</FlexContainer>
);
1 change: 1 addition & 0 deletions ui/design-tokens/src/Colors/GovUKColor/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './GovUKColor';
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 @@ -15,3 +15,4 @@ export * from './DuetColor';
export * from './ETradeColor';
export * from './FinastraColor';
export * from './FishTankColor';
export * from './GovUKColor';

0 comments on commit a16ec4a

Please sign in to comment.