-
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
8590eb1
commit d3f9157
Showing
7 changed files
with
236 additions
and
23 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
47 changes: 47 additions & 0 deletions
47
ui/design-tokens/src/Colors/CanvasColor/CanvasColor.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,47 @@ | ||
import React from 'react'; | ||
import { CanvasColor, CanvasColorPalette } from './CanvasColor'; | ||
import { ColorProps } from '../types'; | ||
|
||
export default { | ||
title: 'Design Tokens/Colors/CanvasColor', | ||
component: CanvasColor, | ||
}; | ||
|
||
export const overview = ({ name, color }: ColorProps) => ( | ||
<CanvasColor name={name} color={color} /> | ||
); | ||
|
||
overview.controls = { | ||
name: { type: 'text', value: 'Primary' }, | ||
color: { | ||
type: 'object', | ||
value: { | ||
name: { type: 'text', value: 'LORAX' }, | ||
sass: { type: 'text', value: '$color-lorax' }, | ||
value: { type: 'color', value: '#ff7a59' }, | ||
}, | ||
}, | ||
}; | ||
|
||
export const palette = () => ( | ||
<CanvasColorPalette | ||
palette={{ | ||
Primary: { value: '#ff8f59', name: 'SORBET', sass: '$color-sorbet' }, | ||
Shade: { | ||
value: '#e68250', | ||
name: 'SORBET_DARK', | ||
sass: '$color-sorbet-dark', | ||
}, | ||
'Medium Tint': { | ||
value: '#ffc7ac', | ||
name: 'SORBET_MEDIUM', | ||
sass: '$color-sorbet-medium', | ||
}, | ||
'Light Tint': { | ||
value: '#fff3ee', | ||
name: 'SORBET_LIGHT', | ||
sass: '$color-sorbet-light', | ||
}, | ||
}} | ||
/> | ||
); |
104 changes: 104 additions & 0 deletions
104
ui/design-tokens/src/Colors/CanvasColor/CanvasColor.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,104 @@ | ||
/** @jsx jsx */ | ||
import { FC } from 'react'; | ||
import { jsx, Box, Theme } from 'theme-ui'; | ||
import { CopyContainer } from '@component-controls/components'; | ||
import { colorToStr, mostReadable } from '../utils'; | ||
import { ColorBlockProps, ColorValue } from '../types'; | ||
import { FlexContainerProps, FlexContainer } from '../FlexContainer'; | ||
|
||
/** | ||
* Color item displaying as a row, with color, name, sass variable name and hex value | ||
* Design inspired from [Canvas Design System](https://canvas.hubspot.com/styles/colors). | ||
*/ | ||
|
||
export const CanvasColor: FC<ColorBlockProps> = ({ name, color }) => { | ||
const colorObj: ColorValue = | ||
typeof color === 'string' ? { value: color } : color; | ||
const { value: colorValue, name: colorName, sass } = colorObj; | ||
|
||
const { hex } = colorToStr(colorValue); | ||
const textColor = mostReadable(hex); | ||
return ( | ||
<Box sx={{ display: 'flex', flex: '1', mb: 2 }}> | ||
<Box | ||
sx={{ | ||
width: '100%', | ||
display: 'flex', | ||
flexDirection: 'row', | ||
height: 90, | ||
fontSize: 2, | ||
border: (t: Theme) => `1px solid ${t.colors?.shadow}`, | ||
bg: 'background', | ||
}} | ||
> | ||
<CopyContainer | ||
value={hex} | ||
name={name} | ||
sxStyle={{ width: '40%', height: '100%' }} | ||
> | ||
<Box | ||
sx={{ | ||
width: '100%', | ||
height: '100%', | ||
bg: colorValue, | ||
color: textColor, | ||
p: 3, | ||
fontSize: 1, | ||
}} | ||
> | ||
{name} | ||
</Box> | ||
</CopyContainer> | ||
<Box | ||
sx={{ | ||
flex: 1, | ||
}} | ||
> | ||
<div | ||
sx={{ | ||
p: 3, | ||
height: '100%', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
justifyContent: 'space-between', | ||
}} | ||
> | ||
<div | ||
sx={{ | ||
fontSize: 1, | ||
display: 'flex', | ||
flexDirection: 'row', | ||
justifyContent: 'space-between', | ||
}} | ||
> | ||
{colorName} | ||
<div sx={{ bg: 'gray', p: 1 }}>{hex}</div> | ||
</div> | ||
<div sx={{ fontSize: 0 }}>{sass}</div> | ||
</div> | ||
</Box> | ||
</Box> | ||
</Box> | ||
); | ||
}; | ||
|
||
/** | ||
* | ||
* palette displayed with CanvasColor items | ||
* using a css flex display direction column | ||
*/ | ||
export const CanvasColorPalette: FC<Omit< | ||
FlexContainerProps, | ||
'children' | 'direction' | ||
>> = props => ( | ||
<FlexContainer direction="column" {...props}> | ||
{({ name, value, hover }) => ( | ||
<CanvasColor | ||
key={`color_item_${name}}`} | ||
name={name} | ||
color={value} | ||
hover={hover} | ||
/> | ||
)} | ||
</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 './CanvasColor'; |
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