-
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
e920974
commit 8ed5097
Showing
5 changed files
with
236 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
63 changes: 63 additions & 0 deletions
63
ui/design-tokens/src/Colors/MorningstarColor/MorningstarColor.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,63 @@ | ||
/* eslint-disable react/display-name */ | ||
import React from 'react'; | ||
import { MorningstarColor, MorningstarColorPalette } from './MorningstarColor'; | ||
import { ColorProps } from '../../types'; | ||
|
||
export default { | ||
title: 'Design Tokens/Colors/MorningstarColor', | ||
component: MorningstarColor, | ||
}; | ||
|
||
export const overview = ({ name, color }: ColorProps) => ( | ||
<MorningstarColor name={name} color={color} /> | ||
); | ||
|
||
overview.controls = { | ||
name: 'Informational', | ||
color: { | ||
type: 'object', | ||
value: { | ||
value: { type: 'color', value: '#f2f2f2' }, | ||
sass: '$mds-feedback-color-info', | ||
}, | ||
}, | ||
}; | ||
|
||
export const palette = () => ( | ||
<MorningstarColorPalette | ||
palette={{ | ||
Informational: { | ||
value: '#c9c7c5', | ||
sass: '$mds-feedback-color-info', | ||
}, | ||
Error: { | ||
value: '#ff0000', | ||
sass: '$mds-feedback-color-error', | ||
}, | ||
'Error Background': { | ||
value: '#ffe5e5', | ||
sass: '$mds-feedback-color-error-background', | ||
}, | ||
Warning: { | ||
value: '#f5c400', | ||
sass: '$mds-feedback-color-warning', | ||
}, | ||
'Warning Background': { | ||
value: '#fef9e5', | ||
sass: '$mds-feedback-color-warning-background', | ||
}, | ||
Success: { | ||
value: '#00af41', | ||
sass: '$mds-feedback-color-success', | ||
}, | ||
'Success Background': { | ||
value: '#e5f7eb', | ||
sass: '$mds-feedback-color-success-background', | ||
}, | ||
Active: { | ||
value: '#004376', | ||
sass: '$mds-interactive-color-primary-active', | ||
}, | ||
}} | ||
/> | ||
); |
108 changes: 108 additions & 0 deletions
108
ui/design-tokens/src/Colors/MorningstarColor/MorningstarColor.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,108 @@ | ||
/** @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 { TableContainerProps, TableContainer } from '../../components'; | ||
|
||
/** | ||
* Color item displaying as a table row, with color, name, sass variable name and hex value. | ||
* Design inspired from [Morningstar Design System](https://designsystem.morningstar.com/visual-language/color/?version=3.0.4&tab=backgrounds). | ||
*/ | ||
|
||
export const MorningstarColor: FC<ColorBlockProps> = props => ( | ||
<table> | ||
<tbody> | ||
<BaseMorningstarColor {...props} /> | ||
</tbody> | ||
</table> | ||
); | ||
|
||
const BaseMorningstarColor: FC<ColorBlockProps> = ({ name, color }) => { | ||
const colorObj: ColorValue = | ||
typeof color === 'string' ? { value: color } : color; | ||
const { value: colorValue, name: colorName = name, sass } = colorObj; | ||
const { hex } = colorToStr(colorValue); | ||
const textColor = mostReadable(hex); | ||
return ( | ||
<tr | ||
sx={{ | ||
fontSize: 0, | ||
bg: hex, | ||
'& > td ': { | ||
p: 2, | ||
}, | ||
}} | ||
> | ||
<td> | ||
<div sx={{ fontSize: 1, fontWeight: 'bold', color: textColor }}> | ||
{colorName} | ||
</div> | ||
</td> | ||
<td> | ||
<div | ||
sx={{ | ||
bg: 'background', | ||
color: 'text', | ||
px: 2, | ||
border: (t: Theme) => `1px solid ${t.colors?.shadow}`, | ||
}} | ||
> | ||
{sass} | ||
</div> | ||
</td> | ||
<td> | ||
<CopyContainer | ||
name={colorName} | ||
value={hex} | ||
sx={{ | ||
bg: 'background', | ||
color: 'text', | ||
px: 2, | ||
border: (t: Theme) => `1px solid ${t.colors?.shadow}`, | ||
}} | ||
> | ||
{hex} | ||
</CopyContainer> | ||
</td> | ||
</tr> | ||
); | ||
}; | ||
|
||
/** | ||
* | ||
* palette displayed with MorningstarColor items | ||
* using a css flex display direction column | ||
*/ | ||
export const MorningstarColorPalette: FC<Omit< | ||
TableContainerProps, | ||
'children' | 'columns' | ||
>> = props => ( | ||
<TableContainer | ||
sx={{ | ||
border: 'none', | ||
'& > thead > tr > th': { | ||
fontSize: 0, | ||
bg: 'background', | ||
textAlign: 'left', | ||
pb: 2, | ||
pl: 2, | ||
}, | ||
}} | ||
columns={[ | ||
{ title: 'Name', sx: { width: '35%' } }, | ||
{ title: 'Constant', sx: { width: '52%' } }, | ||
{ title: 'Color', sx: { width: '15%' } }, | ||
]} | ||
{...props} | ||
> | ||
{({ name, value }) => ( | ||
<BaseMorningstarColor | ||
key={`color_item_${name}}`} | ||
name={name} | ||
color={value} | ||
/> | ||
)} | ||
</TableContainer> | ||
); |
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 './MorningstarColor'; |
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