Skip to content

Commit

Permalink
feat: added finestra color token
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Sep 25, 2020
1 parent 4d71cb9 commit 170ff4c
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/core/src/controls-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export const mergeControlValues = (
controls[key],
value[key] === undefined
? controls[key].value
: value[key].value || value[key],
: typeof value[key].value === 'undefined'
? value[key]
: value[key].value,
),
}),
{},
Expand Down
56 changes: 56 additions & 0 deletions examples/stories/src/tutorial/design/tokens/colors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
CometColorPalette,
DuetColorPalette,
ETradeColorPalette,
FinestraColorPalette,
} from '@component-controls/design-tokens';

# Overview
Expand Down Expand Up @@ -717,3 +718,58 @@ import { ETradeColorPalette } from '@component-controls/design-tokens';
}}
/>


## FinestraColor

The [FinestraColor](/api/design-tokens-colors-finestracolor--overview) component displays the color as a small block, with name and hex color on the side. If the color is a primary color, will display as a circle.

Design inspired from [Finestra](https://design.fusionfabric.cloud/foundations/colors).

```
import { FinestraColorPalette } from '@component-controls/design-tokens';
<FinestraColorPalette
palette={{
'C 100 - dark': {
value: '#2D2D2D',
},
'C 100': {
value: '#414141',
name: 'C',
primary: true,
},
'C 75': {
value: '#707070',
},
'C 50': {
value: '#9F9F9F',
},
'C 25': {
value: '#CECECE',
},
}}
/>
```

<FinestraColorPalette
palette={{
'C 100 - dark': {
value: '#2D2D2D',
},
'C 100': {
value: '#414141',
name: 'C',
primary: true,
},
'C 75': {
value: '#707070',
},
'C 50': {
value: '#9F9F9F',
},
'C 25': {
value: '#CECECE',
},
}}
/>

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
import { FinestraColor, FinestraColorPalette } from './FinestraColor';
import { ColorProps } from '../types';

export default {
title: 'Design Tokens/Colors/FinestraColor',
component: FinestraColor,
};

export const overview = ({ name, color }: ColorProps) => (
<FinestraColor name={name} color={color} />
);

overview.controls = {
name: 'V 100',
color: {
type: 'object',
value: {
name: 'V',
value: { type: 'color', value: '#cf1322' },
primary: { type: 'boolean', value: true },
},
},
};

export const palette = () => (
<FinestraColorPalette
palette={{
'C 100 - dark': {
value: '#2D2D2D',
},
'C 100': {
value: '#414141',
name: 'C',
primary: true,
},
'C 75': {
value: '#707070',
},
'C 50': {
value: '#9F9F9F',
},
'C 25': {
value: '#CECECE',
},
'C 10': {
value: '#EAEAEA',
},
'C 2': {
value: '#FAFAFA',
},
}}
/>
);
98 changes: 98 additions & 0 deletions ui/design-tokens/src/Colors/FinestraColor/FinestraColor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/** @jsx jsx */
import { FC } from 'react';
import { jsx } from 'theme-ui';
import { CopyContainer } from '@component-controls/components';
import { CheckIcon } from '@primer/octicons-react';
import { colorToStr, mostReadable } from '../utils';
import { ColorBlockProps, ColorValue } from '../types';
import { FlexContainerProps, FlexContainer } from '../FlexContainer';

/**
* Color item displaying the color as a small block, with name and hex color on the side. If the color is a primary color, will display as a circle.
* Design inspired from [Finestra](https://design.fusionfabric.cloud/foundations/colors).
*/

export const FinestraColor: FC<ColorBlockProps> = ({ name, color }) => {
const colorObj: ColorValue =
typeof color === 'string' ? { value: color } : color;
const { value: colorValue, name: colorName, primary } = colorObj;

const { hex } = colorToStr(colorValue);
const textColor = mostReadable(hex);
return (
<div
sx={{
display: 'flex',
flex: '1',
width: 250,
flexDirection: 'row',
alignItems: 'center',
}}
>
<CopyContainer
value={hex}
name={name}
sxStyle={{ p: primary ? 0 : 2, width: 80 }}
>
<div
sx={{
bg: colorValue,
color: textColor,
position: 'relative',

borderRadius: primary ? '50%' : undefined,
':after': {
content: '""',
display: 'block',
paddingBottom: '100%',
},
}}
>
<div
sx={{
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
}}
>
{primary ? colorName : <CheckIcon />}
</div>
</div>
</CopyContainer>

<div
sx={{
display: 'flex',
flexDirection: 'column',
ml: 4,
lineHeight: '1.4rem',
}}
>
<div>{name}</div>
<div sx={{ opacity: 0.5 }}>{hex}</div>
</div>
</div>
);
};

/**
*
* palette displayed with FinestraColor items
* using a css flex display direction column
*/
export const FinestraColorPalette: FC<Omit<
FlexContainerProps,
'children' | 'direction'
>> = props => (
<FlexContainer direction="column" sx={{ width: 250 }} {...props}>
{({ name, value, hover }) => (
<FinestraColor
key={`color_item_${name}}`}
name={name}
color={value}
hover={hover}
/>
)}
</FlexContainer>
);
1 change: 1 addition & 0 deletions ui/design-tokens/src/Colors/FinestraColor/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './FinestraColor';
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 @@ -13,3 +13,4 @@ export * from './CedarColor';
export * from './CometColor';
export * from './DuetColor';
export * from './ETradeColor';
export * from './FinestraColor';
28 changes: 28 additions & 0 deletions ui/design-tokens/src/Colors/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,42 @@ export type TokenStatus = 'ok' | 'warning' | 'error';
export type ColorValue =
| string
| {
/**
* color sub name
*/
name?: string;
/**
* color string. can be hex, rgb or hsl
*/
value: string;
/**
* if both dark and light variants are displayed
*/
dark?: ColorValue;
/**
* variable name ex var(--theme-ui-colors-palette4,#dc004e)
*/
varName?: string;
/**
* sass variable name ex: $text-input
*/
sass?: string;
/**
* css class name ex .text-input
*/
css?: string;
/**
* full text description of the color usage.
*/
description?: string;
/**
* design token status. can be work in progrss, obsolete etc.
*/
status?: TokenStatus;
/**
* for color palettes were each color palette has a primary color
*/
primary?: boolean;
};
export interface ColorProps {
/**
Expand Down

0 comments on commit 170ff4c

Please sign in to comment.