-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c259a5f
commit a16ec4a
Showing
5 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
ui/design-tokens/src/Colors/GovUKColor/GovUKColor.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}} | ||
/> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './GovUKColor'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters