-
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
170ff4c
commit 0be83f2
Showing
5 changed files
with
171 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
53 changes: 53 additions & 0 deletions
53
ui/design-tokens/src/Colors/FishTankColor/FishTankColor.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,53 @@ | ||
import React from 'react'; | ||
import { FishTankColor, FishTankColorPalette } from './FishTankColor'; | ||
import { ColorProps } from '../types'; | ||
|
||
export default { | ||
title: 'Design Tokens/Colors/FishTankColor', | ||
component: FishTankColor, | ||
}; | ||
|
||
export const overview = ({ name, color }: ColorProps) => ( | ||
<FishTankColor name={name} color={color} /> | ||
); | ||
|
||
overview.controls = { | ||
color: { | ||
type: 'object', | ||
value: { | ||
value: { type: 'color', value: '#0A7DAF' }, | ||
sass: { type: 'color', value: '$color-selected-darkest' }, | ||
}, | ||
}, | ||
}; | ||
|
||
export const palette = () => ( | ||
<FishTankColorPalette | ||
palette={{ | ||
'highlight-1': { | ||
sass: '$color-highlight-1', | ||
value: '#FFF8B0', | ||
}, | ||
'highlight-2': { | ||
sass: '$color-highlight-2', | ||
value: '#E3F7FF', | ||
}, | ||
'highlight-3': { | ||
sass: '$color-highlight-3', | ||
value: '#E0FFE0', | ||
}, | ||
action: { | ||
sass: '$color-action', | ||
value: '#3DA774', | ||
}, | ||
warning: { | ||
sass: '$color-warning', | ||
value: '#FFB511', | ||
}, | ||
error: { | ||
sass: '$color-error', | ||
value: '#E1483E', | ||
}, | ||
}} | ||
/> | ||
); |
72 changes: 72 additions & 0 deletions
72
ui/design-tokens/src/Colors/FishTankColor/FishTankColor.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,72 @@ | ||
/** @jsx jsx */ | ||
import { FC } from 'react'; | ||
import { jsx, 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 the color as a row with the sass var name and hex color. | ||
* Design inspired from Blooomberg BNA's [FishTank](https://fishtank.bna.com/colors). | ||
*/ | ||
|
||
export const FishTankColor: FC<ColorBlockProps> = ({ name, color }) => { | ||
const colorObj: ColorValue = | ||
typeof color === 'string' ? { value: color } : color; | ||
const { value: colorValue, sass } = colorObj; | ||
|
||
const { hex } = colorToStr(colorValue); | ||
const textColor = mostReadable(hex); | ||
return ( | ||
<div sx={{ display: 'flex', flex: '1' }}> | ||
<CopyContainer value={hex} name={name} sxStyle={{ width: '100%' }}> | ||
<div | ||
sx={{ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
bg: colorValue, | ||
color: textColor, | ||
height: 50, | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
fontSize: 1, | ||
transition: 'all .2s', | ||
px: 3, | ||
}} | ||
> | ||
<div>{sass}</div> | ||
<div | ||
sx={{ | ||
fontSize: 2, | ||
}} | ||
> | ||
{hex.toUpperCase()} | ||
</div> | ||
</div> | ||
</CopyContainer> | ||
</div> | ||
); | ||
}; | ||
|
||
/** | ||
* | ||
* palette displayed with FishTankColor items | ||
* using a css flex display direction column | ||
*/ | ||
export const FishTankColorPalette: FC<Omit< | ||
FlexContainerProps, | ||
'children' | 'direction' | ||
>> = props => ( | ||
<FlexContainer | ||
direction="column" | ||
sx={{ | ||
boxShadow: (t: Theme) => `0 2px 10px 3px ${t.colors?.shadow}`, | ||
}} | ||
{...props} | ||
> | ||
{({ name, value }) => ( | ||
<FishTankColor 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 './FishTankColor'; |
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