-
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.
feat: added antd horz/vert color items
- Loading branch information
1 parent
8d8fac9
commit ac450f5
Showing
24 changed files
with
620 additions
and
32 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
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
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,127 @@ | ||
--- | ||
title: Design/Design tokens | ||
route: /tutorial/design/design-tokens | ||
type: tutorial | ||
tags: | ||
- design | ||
- colors | ||
- typography | ||
order: 0 | ||
author: atanasster | ||
--- | ||
import { ColorSwatchPalette, ColorItemHorzPalette, ColorItemVertPalette } from '@component-controls/design-tokens'; | ||
|
||
## Overview | ||
|
||
The [design-tokens](https://github.com/ccontrols/component-controls/tree/master/ui/design-tokens) package contains a collection of design tokens components. | ||
|
||
|
||
## Install | ||
|
||
```sh | ||
yarn add @component-controls/design-tokens --dev | ||
``` | ||
|
||
## Colors | ||
|
||
Components that will display a single color or a palette of colors. The color can be a hex, rgb, or hsl string value. | ||
|
||
### ColorSwatch | ||
|
||
The [ColorSwatch](/api/design-tokens-colorswatch--overview) component design is inspired from [Alta UI](https://www.oracle.com/webfolder/ux/middleware/alta_web_icon_guide/Alta-Colors/UI-Palette.html) and displays the color name and value in a compact block. | ||
|
||
``` | ||
import { ColorSwatchPalette } from '@component-controls/design-tokens'; | ||
<ColorSwatchPalette | ||
palette={{ | ||
'color-1': '#fbce4a', | ||
'color-2': '#fcfbe8', | ||
'color-3': '#fff4d5', | ||
'color-4': '#f6cab7', | ||
'color-5': '#ec96ad', | ||
'color-6': '#ca589d', | ||
}} | ||
/> | ||
``` | ||
|
||
<ColorSwatchPalette | ||
palette={{ | ||
'color-1': '#fbce4a', | ||
'color-2': '#fcfbe8', | ||
'color-3': '#fff4d5', | ||
'color-4': '#f6cab7', | ||
'color-5': '#ec96ad', | ||
'color-6': '#ca589d', | ||
}} | ||
/> | ||
|
||
### ColorItemHorz | ||
|
||
The [ColorItemHorz](/api/design-tokens-coloritemhorz--overview) component design is inspired from [And Design](https://ant.design/docs/spec/colors). and displays a horizontal color block, with the color value visible on hover. | ||
|
||
``` | ||
import { ColorItemHorzPalette } from '@component-controls/design-tokens'; | ||
<ColorItemHorzPalette | ||
palette={{ | ||
'green-1': '#f6ffed', | ||
'green-2': '#d9f7be', | ||
'green-3': '#b7eb8f', | ||
'green-4': '#95de64', | ||
'green-5': '#73d13d', | ||
'green-6': '#52c41a', | ||
'green-7': '#389e0d', | ||
'green-8': '#237804', | ||
'green-9': '#135200', | ||
'green-10': '#092b00', | ||
}} | ||
/> | ||
``` | ||
<ColorItemHorzPalette | ||
palette={{ | ||
'green-1': '#f6ffed', | ||
'green-2': '#d9f7be', | ||
'green-3': '#b7eb8f', | ||
'green-4': '#95de64', | ||
'green-5': '#73d13d', | ||
'green-6': '#52c41a', | ||
'green-7': '#389e0d', | ||
'green-8': '#237804', | ||
'green-9': '#135200', | ||
'green-10': '#092b00', | ||
}} | ||
/> | ||
|
||
### ColorItemVert | ||
|
||
The [ColorItemVert](/api/design-tokens-coloritemvert--overview) component design is inspired from [And Design](https://ant.design/docs/spec/colors). and displays a horizontal color block, with the color value visible on hover. | ||
|
||
``` | ||
import { ColorItemVertPalette } from '@component-controls/design-tokens'; | ||
<ColorItemVertPalette | ||
palette={{ | ||
'red-1': '#fff1f0', | ||
'red-2': '#ffccc7', | ||
'red-3': '#ffa39e', | ||
'red-4': '#ff7875', | ||
'red-5': '#ff4d4f', | ||
'red-6': '#f5222d', | ||
'red-7': '#cf1322', | ||
'red-8': '#a8071a', | ||
}} | ||
/> | ||
``` | ||
<ColorItemVertPalette | ||
palette={{ | ||
'red-1': '#fff1f0', | ||
'red-2': '#ffccc7', | ||
'red-3': '#ffa39e', | ||
'red-4': '#ff7875', | ||
'red-5': '#ff4d4f', | ||
'red-6': '#f5222d', | ||
'red-7': '#cf1322', | ||
'red-8': '#a8071a', | ||
}} | ||
/> |
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,16 @@ | ||
import React from 'react'; | ||
import { CopyContainer } from '.'; | ||
|
||
export default { | ||
title: 'Components/CopyContainer', | ||
component: CopyContainer, | ||
}; | ||
|
||
export const overview = () => ( | ||
<CopyContainer value="some text"> | ||
<div style={{ border: '1px solid black', padding: '5px' }}> | ||
<p>some text.</p> | ||
<p>click to copy</p> | ||
</div> | ||
</CopyContainer> | ||
); |
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
File renamed without changes.
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
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
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
50 changes: 50 additions & 0 deletions
50
ui/design-tokens/src/Colors/ColorItemHorz/ColorItemHorz.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,50 @@ | ||
import React from 'react'; | ||
import { ColorItemHorz, ColorItemHorzPalette } from './ColorItemHorz'; | ||
import { ColorProps } from '../types'; | ||
|
||
export default { | ||
title: 'Design Tokens/ColorItemHorz', | ||
component: ColorItemHorz, | ||
}; | ||
|
||
export const overview = ({ name, color }: ColorProps) => ( | ||
<ColorItemHorz name={name} color={color} /> | ||
); | ||
|
||
overview.controls = { | ||
name: { type: 'text' }, | ||
color: { type: 'color', value: '#cf1322' }, | ||
}; | ||
|
||
export const name = () => <ColorItemHorz name="brand" color="#e95b54" />; | ||
|
||
export const rgb = () => <ColorItemHorz name="text" color="rgb(0, 0, 0)" />; | ||
|
||
export const rgba = () => ( | ||
<ColorItemHorz name="shadow" color="rgba(0, 0, 0, 0.5)" /> | ||
); | ||
|
||
export const hsl = () => ( | ||
<ColorItemHorz name="accent" color="hsl(12, 10%, 50%)" /> | ||
); | ||
|
||
export const hsla = () => ( | ||
<ColorItemHorz name="accent" color="hsl(12, 10%, 50%, .6)" /> | ||
); | ||
|
||
export const palette = () => ( | ||
<ColorItemHorzPalette | ||
palette={{ | ||
'green-1': '#f6ffed', | ||
'green-2': '#d9f7be', | ||
'green-3': '#b7eb8f', | ||
'green-4': '#95de64', | ||
'green-5': '#73d13d', | ||
'green-6': '#52c41a', | ||
'green-7': '#389e0d', | ||
'green-8': '#237804', | ||
'green-9': '#135200', | ||
'green-10': '#092b00', | ||
}} | ||
/> | ||
); |
75 changes: 75 additions & 0 deletions
75
ui/design-tokens/src/Colors/ColorItemHorz/ColorItemHorz.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,75 @@ | ||
/** @jsx jsx */ | ||
import { FC, useState } from 'react'; | ||
import { jsx, Box } from 'theme-ui'; | ||
import { CopyContainer } from '@component-controls/components'; | ||
import { readableColor } from 'polished'; | ||
import { colorToStr } from '../utils'; | ||
import { ColorProps } 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). | ||
*/ | ||
|
||
export const ColorItemHorz: FC<ColorProps> = ({ name, color, hover }) => { | ||
const [hoverMe, setHoverMe] = useState(false); | ||
const { hex, rgba } = colorToStr(color); | ||
const textColor = readableColor(hex, '#000', '#fff', true); | ||
return ( | ||
<Box sx={{ display: 'flex', flex: '1', width: 250 }}> | ||
<CopyContainer value={hex} name={name} sxStyle={{ width: '100%' }}> | ||
<Box | ||
onMouseOver={() => setHoverMe(true)} | ||
onMouseOut={() => setHoverMe(false)} | ||
sx={{ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
bg: color, | ||
color: textColor, | ||
height: 44, | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
fontSize: 0, | ||
transition: 'all .2s', | ||
px: 3, | ||
':hover': { | ||
mr: -3, | ||
}, | ||
}} | ||
> | ||
<Box | ||
sx={{ | ||
fontWeight: 'bold', | ||
mr: 4, | ||
}} | ||
> | ||
{name || hex} | ||
</Box> | ||
<Box | ||
className="item-text" | ||
sx={hover || hoverMe ? undefined : { visibility: 'hidden' }} | ||
> | ||
{!name | ||
? `${rgba.red}, ${rgba.green}, ${rgba.blue}${ | ||
rgba.alpha !== 1 ? `, ${rgba.alpha}` : '' | ||
}` | ||
: hex} | ||
</Box> | ||
</Box> | ||
</CopyContainer> | ||
</Box> | ||
); | ||
}; | ||
|
||
/** | ||
* | ||
* palette displayed with ColorItemHorz items | ||
* using a css flex display direction column | ||
*/ | ||
export const ColorItemHorzPalette: FC<Omit< | ||
FlexContainerProps, | ||
'ColorBlock' | 'direction' | ||
>> = props => ( | ||
<FlexContainer ColorBlock={ColorItemHorz} direction="column" {...props} /> | ||
); |
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 './ColorItemHorz'; |
Oops, something went wrong.