Skip to content

Commit 2800a93

Browse files
committed
add overview about available css custom properties to the storybook
1 parent 88c45a7 commit 2800a93

1 file changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import React from "react";
2+
import { Meta, StoryFn } from "@storybook/react";
3+
4+
import CssCustomProperties from "../../common/utils/CssCustomProperties";
5+
import {
6+
Section,
7+
SectionHeader,
8+
Spacing,
9+
Table,
10+
TableBody,
11+
TableCell,
12+
TableContainer,
13+
TableHead,
14+
TableHeader,
15+
TableRow,
16+
TitleSubsection,
17+
} from "../../components";
18+
import { CLASSPREFIX as eccgui } from "../../index";
19+
20+
const groups: { title: string; filterName: (name: string) => boolean }[] = [
21+
{
22+
title: "Typography",
23+
filterName: (name) => name.startsWith(`--${eccgui}-size-typo`),
24+
},
25+
{
26+
title: "Font weights and spacing",
27+
filterName: (name) => name.startsWith(`--${eccgui}-font`),
28+
},
29+
{
30+
title: "Whitespace",
31+
filterName: (name) => name.startsWith(`--${eccgui}-size-block`) || name.startsWith(`--${eccgui}-size-inline`),
32+
},
33+
{
34+
title: "Color aliases",
35+
filterName: (name) => name.startsWith(`--${eccgui}-color`) && !name.startsWith(`--${eccgui}-color-palette`),
36+
},
37+
{
38+
title: "Opacity",
39+
filterName: (name) => name.startsWith(`--${eccgui}-opacity`),
40+
},
41+
{
42+
title: "Palette colors",
43+
filterName: (name) => name.startsWith(`--${eccgui}-color-palette`),
44+
},
45+
];
46+
47+
const CssCustomPropertiesOverview = () => {
48+
return (
49+
<>
50+
{groups.map(({ title, filterName }) => {
51+
const properties = new CssCustomProperties({
52+
selectorText: ":root",
53+
filterName,
54+
removeDashPrefix: false,
55+
returnObject: false,
56+
}).customProperties() as string[][];
57+
58+
return (
59+
<React.Fragment key={title}>
60+
<Section>
61+
<SectionHeader>
62+
<TitleSubsection>{title}</TitleSubsection>
63+
</SectionHeader>
64+
<Spacing size="tiny" />
65+
<TableContainer>
66+
<Table columnWidths={["60%", "40%"]}>
67+
<TableHead>
68+
<TableRow>
69+
<TableHeader>CSS custom property</TableHeader>
70+
<TableHeader>Current value</TableHeader>
71+
</TableRow>
72+
</TableHead>
73+
<TableBody>
74+
{properties.map(([name, value]) => (
75+
<TableRow key={name}>
76+
<TableCell>
77+
<code>{name}</code>
78+
</TableCell>
79+
<TableCell>
80+
{name.startsWith(`--${eccgui}-color`) && (
81+
<span
82+
style={{
83+
display: "inline-block",
84+
width: `var(--${eccgui}-size-block-whitespace)`,
85+
height: `var(--${eccgui}-size-block-whitespace)`,
86+
backgroundColor: value,
87+
verticalAlign: "middle",
88+
marginRight: `var(--${eccgui}-size-inline-whitespace)`,
89+
border: "1px solid currentColor",
90+
}}
91+
/>
92+
)}
93+
<code>{value}</code>
94+
</TableCell>
95+
</TableRow>
96+
))}
97+
</TableBody>
98+
</Table>
99+
</TableContainer>
100+
</Section>
101+
<Spacing size="large" />
102+
</React.Fragment>
103+
);
104+
})}
105+
</>
106+
);
107+
};
108+
109+
export default {
110+
title: "Configuration/CSS Custom Properties",
111+
component: CssCustomPropertiesOverview,
112+
} as Meta<typeof CssCustomPropertiesOverview>;
113+
114+
export const Default: StoryFn = () => <CssCustomPropertiesOverview />;

0 commit comments

Comments
 (0)