Display palette and colors for dark and light themes in storybook (#29848)

This commit is contained in:
Alex Khomenko
2020-12-15 17:40:24 +02:00
committed by GitHub
parent 555d3c275d
commit 8d9b4e4ac2
2 changed files with 93 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
import React from 'react';
import { Colors } from './Colors';
export default {
title: 'Docs Overview/Colors',
component: Colors,
decorators: [],
parameters: {
options: {
showPanel: false,
},
docs: {},
},
};
export const ColorsDemo = () => {
return <Colors />;
};

View File

@@ -0,0 +1,75 @@
import React from 'react';
import { css, cx } from 'emotion';
import darkTheme from '../../themes/dark';
import lightTheme from '../../themes/light';
import { useStyles } from '../../themes';
export const Colors = () => {
const styles = useStyles(getStyles);
const renderColors = (color: any) => {
return Object.entries(color)
.sort((a, b) => a[0].localeCompare(b[0]))
.map(([name, color]: [string, any]) => {
return (
<div key={name} className={styles.wrapper}>
<span className={styles.name}>
{name} ({color})
</span>
<span
className={cx(
styles.color,
css`
background: ${color};
`
)}
/>
</div>
);
});
};
return (
<div className={styles.container}>
<div>
<h2>Light theme</h2>
<h3 className={styles.subheader}>Palette</h3>
{renderColors(lightTheme.palette)}
<h3 className={styles.subheader}>Colors</h3>
{renderColors(lightTheme.colors)}
</div>
<div>
<h2>Dark theme</h2>
<h3 className={styles.subheader}>Palette</h3>
{renderColors(darkTheme.palette)}
<h3 className={styles.subheader}>Colors</h3>
{renderColors(darkTheme.colors)}
</div>
</div>
);
};
const getStyles = () => {
return {
subheader: css`
margin: 20px 0;
`,
container: css`
display: flex;
justify-content: space-around;
width: 100%;
`,
wrapper: css`
display: flex;
align-items: center;
`,
name: css`
width: 250px;
`,
color: css`
display: inline-block;
width: 50px;
height: 50px;
`,
};
};