Skip to content

Commit

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

# Overview
Expand Down Expand Up @@ -773,3 +774,46 @@ import { FinestraColorPalette } from '@component-controls/design-tokens';
}}
/>

## FishTankColor

The [FishTankColor](/api/design-tokens-colors-fishtankcolor--overview) component displays 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).

```
import { FishTankColorPalette } from '@component-controls/design-tokens';
<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',
},
}}
/>
```

<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',
},
}}
/>
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 ui/design-tokens/src/Colors/FishTankColor/FishTankColor.tsx
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>
);
1 change: 1 addition & 0 deletions ui/design-tokens/src/Colors/FishTankColor/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './FishTankColor';
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 @@ -14,3 +14,4 @@ export * from './CometColor';
export * from './DuetColor';
export * from './ETradeColor';
export * from './FinestraColor';
export * from './FishTankColor';

0 comments on commit 0be83f2

Please sign in to comment.