Skip to content

Commit e003751

Browse files
authored
docs: add ui kit tokens section (#4862)
* docs: add ui kit tokens section
1 parent 0ff2c62 commit e003751

File tree

10 files changed

+315
-13
lines changed

10 files changed

+315
-13
lines changed

apps/docs/src/components/ThemeSwitcher.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const allowedPaths = [
1616
"/charts",
1717
"/examples",
1818
"/docs/color-tokens",
19+
"/docs/theme-tokens",
1920
];
2021

2122
export const ThemeSwitcher = () => {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"use client";
2+
3+
import { HvTypography, useTheme } from "@hitachivantara/uikit-react-core";
4+
import { HvBreakpoints } from "@hitachivantara/uikit-styles";
5+
6+
import { DocsProvider } from "../code/DocsProvider";
7+
8+
export const BreakpointTokens = () => {
9+
return (
10+
<DocsProvider className="bg-transparent space-y-10">
11+
<BreakpointTokensInternal />
12+
</DocsProvider>
13+
);
14+
};
15+
export const BreakpointTokensInternal = () => {
16+
const { activeTheme } = useTheme();
17+
if (!activeTheme) return null;
18+
19+
return (
20+
<section className="flex flex-col gap-sm w-100% mt-sm">
21+
{Object.entries(activeTheme.breakpoints.values).map(([categoryKey]) => {
22+
if (categoryKey === "circle") return null;
23+
24+
const breakpointValue =
25+
activeTheme.breakpoints.values[categoryKey as HvBreakpoints];
26+
27+
const barWidth =
28+
categoryKey === "xs" ? 3 : (breakpointValue * 80) / 1920;
29+
30+
return (
31+
<div
32+
className="flex w-100% flex items-center gap-xs"
33+
key={categoryKey}
34+
>
35+
<div
36+
className="h-20px border-1 border-dashed border-borderStrong bg-bgContainer"
37+
style={{ width: `${barWidth}%` }}
38+
>
39+
<HvTypography component="code">{categoryKey}</HvTypography>
40+
</div>
41+
42+
<HvTypography variant="caption1">{breakpointValue}px</HvTypography>
43+
</div>
44+
);
45+
})}
46+
</section>
47+
);
48+
};

apps/docs/src/components/color/ColorTokens.tsx renamed to apps/docs/src/components/tokens/ColorTokens.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import { HvTypography, useTheme } from "@hitachivantara/uikit-react-core";
44

55
import { DocsProvider } from "../code/DocsProvider";
6-
import { descriptions } from "./descriptions";
6+
import { descriptions } from "../color/descriptions";
77
import {
88
colorTokensSpec,
99
compatMap,
1010
groupColorTokensByCategory,
11-
} from "./utils";
11+
} from "../color/utils";
1212

1313
export const ColorTokens = () => {
1414
return (
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"use client";
2+
3+
import { HvTypography, useTheme } from "@hitachivantara/uikit-react-core";
4+
5+
import { DocsProvider } from "../code/DocsProvider";
6+
7+
export const RadiiTokens = () => {
8+
return (
9+
<DocsProvider className="bg-transparent space-y-10">
10+
<RadiiTokensInternal />
11+
</DocsProvider>
12+
);
13+
};
14+
15+
export const RadiiTokensInternal = () => {
16+
const { activeTheme } = useTheme();
17+
if (!activeTheme) return null;
18+
19+
return (
20+
<section className="flex gap-sm w-100% justify-center mt-sm">
21+
{Object.entries(activeTheme.radii).map(([categoryKey]) => {
22+
if (categoryKey === "circle") return null;
23+
24+
return (
25+
<div className="flex flex-col items-center" key={categoryKey}>
26+
<div
27+
style={{ borderRadius: activeTheme.radii[categoryKey] }}
28+
className="p-md border-dashed border-1 border-borderStrong bg-bgContainer w-100px h-100px"
29+
/>
30+
<HvTypography component="code">{categoryKey}</HvTypography>
31+
<HvTypography variant="caption1">
32+
{activeTheme.radii[categoryKey]}
33+
</HvTypography>
34+
</div>
35+
);
36+
})}
37+
</section>
38+
);
39+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"use client";
2+
3+
import { HvTypography, useTheme } from "@hitachivantara/uikit-react-core";
4+
5+
import { DocsProvider } from "../code/DocsProvider";
6+
7+
export const SpaceTokens = () => {
8+
return (
9+
<DocsProvider className="bg-transparent space-y-10">
10+
<SpaceTokensInternal />
11+
</DocsProvider>
12+
);
13+
};
14+
15+
export const SpaceTokensInternal = () => {
16+
const { activeTheme } = useTheme();
17+
if (!activeTheme) return null;
18+
19+
return (
20+
<section className="flex flex-wrap gap-xl gap-row-sm w-100% justify-center mt-sm">
21+
{Object.entries(activeTheme.space).map(([categoryKey]) => {
22+
return (
23+
<div className="flex flex-col items-center" key={categoryKey}>
24+
<div
25+
className="flex"
26+
style={{ gap: activeTheme.space[categoryKey] }}
27+
>
28+
<div className="p-md border-dashed border-1 border-borderStrong bg-bgContainer w-50px h-50px" />
29+
<div className="p-md border-dashed border-1 border-borderStrong bg-bgContainer w-50px h-50px" />
30+
</div>
31+
<HvTypography component="code">{categoryKey}</HvTypography>
32+
<HvTypography variant="caption1">
33+
{activeTheme.space[categoryKey]}
34+
</HvTypography>
35+
</div>
36+
);
37+
})}
38+
</section>
39+
);
40+
};
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"use client";
2+
3+
import { HvTypography, useTheme } from "@hitachivantara/uikit-react-core";
4+
5+
import { DocsProvider } from "../code/DocsProvider";
6+
7+
export const TypographyTokens = () => {
8+
return (
9+
<DocsProvider className="bg-transparent space-y-10">
10+
<TypographyTokensInternal />
11+
</DocsProvider>
12+
);
13+
};
14+
15+
const sections = {
16+
fontFamily: "fontFamily",
17+
fontSizes: "fontSize",
18+
fontWeights: "fontWeight",
19+
lineHeights: "lineHeight",
20+
} as const;
21+
22+
export const TypographyTokensInternal = () => {
23+
const { activeTheme } = useTheme();
24+
if (!activeTheme) return null;
25+
26+
return (
27+
<section className="flex flex-col gap-sm w-100% justify-center mt-sm">
28+
{(Object.keys(sections) as Array<keyof typeof sections>).map(
29+
(section) => (
30+
<section
31+
key={section}
32+
className="flex flex-col gap-sm w-100% justify-center mt-sm"
33+
>
34+
<HvTypography variant="title4" className="font-semibold">
35+
{section}
36+
</HvTypography>
37+
<div className="flex gap-lg justify-center w-100% flex-wrap">
38+
{Object.entries(activeTheme[section]).map(([categoryKey]) => {
39+
const sectionKey = sections[section];
40+
return (
41+
<div className="flex gap-md" key={categoryKey}>
42+
<div className="flex flex-col text-align-center">
43+
<span
44+
style={{
45+
[sectionKey]: activeTheme[section][categoryKey],
46+
}}
47+
>
48+
UI Kit
49+
</span>
50+
<code>{categoryKey}</code>
51+
<HvTypography variant="caption1">
52+
{activeTheme[section][categoryKey]}
53+
</HvTypography>
54+
</div>
55+
</div>
56+
);
57+
})}
58+
</div>
59+
</section>
60+
),
61+
)}
62+
</section>
63+
);
64+
};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"use client";
2+
3+
import { HvTypography, useTheme } from "@hitachivantara/uikit-react-core";
4+
5+
import { DocsProvider } from "../code/DocsProvider";
6+
7+
export const ZIndexTokens = () => {
8+
return (
9+
<DocsProvider className="bg-transparent space-y-10">
10+
<ZIndexTokensInternal />
11+
</DocsProvider>
12+
);
13+
};
14+
15+
export const ZIndexTokensInternal = () => {
16+
const { activeTheme } = useTheme();
17+
if (!activeTheme) return null;
18+
19+
let left = 0;
20+
let top = 0;
21+
22+
return (
23+
<section className="flex gap-sm w-100% justify-center mt-sm relative h-420px">
24+
{Object.entries(activeTheme.zIndices).map(([categoryKey]) => {
25+
left += 10;
26+
top += 30;
27+
28+
return (
29+
<div
30+
className="absolute border-1 border-dashed border-borderStrong bg-bgContainer w-300px h-50px "
31+
style={{ left, top }}
32+
key={categoryKey}
33+
>
34+
<div className="absolute flex top-5px w-100% h-[100%] gap-md justify-center color-text">
35+
<HvTypography component="code">{categoryKey}</HvTypography>
36+
<HvTypography variant="caption1">
37+
{activeTheme.zIndices[categoryKey]}
38+
</HvTypography>
39+
</div>
40+
</div>
41+
);
42+
})}
43+
</section>
44+
);
45+
};

apps/docs/src/content/docs/_meta.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ export default {
1919
type: "separator",
2020
title: "Foundation",
2121
},
22-
theming: "Theming",
22+
"theme-tokens": {
23+
title: "Theme Tokens",
24+
theme: { layout: "full", toc: false },
25+
},
2326
"color-tokens": {
2427
title: "Color Tokens",
2528
theme: { layout: "full", toc: false },
2629
},
30+
theming: "Theming",
2731
"color-palette": {
2832
title: "Color Palette",
2933
theme: { layout: "full", toc: false },

apps/docs/src/content/docs/color-tokens.mdx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1-
import { ColorTokens } from "../../components/color/ColorTokens";
1+
import { ColorTokens } from "../../components/tokens/ColorTokens";
22

33
# Color Tokens
44

5-
Color tokens are the **semantic layer** of the **UI Kit** color system, providing **consistent**, and **themeable** values for UI development.
6-
They ensure design integrity, maintainability, and seamless alignment between design and implementation.
7-
8-
> [!NOTE]
9-
>
10-
> Think of color tokens as the handshake between design and development. They
11-
> keep everyone on the same page — so always use them to ensure things stay
12-
> consistent and clean.
13-
145
Color tokens can be accessed through the `theme.colors` object:
156

167
```tsx
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { BreakpointTokens } from "../../components/tokens/BreakpointTokens";
2+
import { RadiiTokens } from "../../components/tokens/RadiiTokens";
3+
import { SpaceTokens } from "../../components/tokens/SpaceTokens";
4+
import { TypographyTokens } from "../../components/tokens/TypographyTokens";
5+
import { ZIndexTokens } from "../../components/tokens/ZIndexTokens";
6+
7+
# UI Kit tokens
8+
9+
UI Kit tokens are the **semantic layer** of the **UI Kit** system, providing **consistent**, and **themeable** values for UI development.
10+
They ensure design integrity, maintainability, and seamless alignment between design and implementation.
11+
12+
> [!NOTE]
13+
>
14+
> Think of UI Kit tokens as the handshake between design and development. They
15+
> keep everyone on the same page - so always use them to ensure things stay
16+
> consistent and clean.
17+
18+
UI Kit tokens can be accessed through the `theme` object:
19+
20+
```tsx
21+
import { theme } from "@hitachivantara/uikit-react-core";
22+
23+
const MyComponent = () => (
24+
<div style={{ color: theme.colors.primary }}>
25+
This text uses the semantic primary color.
26+
</div>
27+
);
28+
```
29+
30+
These tokens are categorized into several groups, each serving a specific purpose in the UI Kit design system and can be
31+
accessed through the `theme` object.
32+
33+
When creating a new theme, you can extend any of the supported themes by overriding these tokens (or adding new ones).
34+
This allows you to customize the UI Kit to fit your brand or application needs while maintaining the core design principles.
35+
36+
> [!NOTE]
37+
>
38+
> Check the [Color tokens page](/docs/color-tokens) for more information on how to use color tokens in your components.
39+
40+
Below is a summary of the available token categories:
41+
42+
## Radii
43+
44+
Accessible through the `theme.radii` object, these tokens define the border radius values used across the UI Kit components.
45+
46+
<RadiiTokens />
47+
48+
## Spacing
49+
50+
Accessible through the `theme.spacing` object, these tokens define the spacing values used for margins, paddings, and gaps in the UI Kit components.
51+
52+
<SpaceTokens />
53+
54+
## ZIndex
55+
56+
Accessible through the `theme.zIndex` object, these tokens define the stacking order of UI Kit components.
57+
58+
<ZIndexTokens />
59+
60+
## Typography
61+
62+
These tokens define the typography styles used in the UI Kit components.
63+
64+
<TypographyTokens />
65+
66+
## Breakpoints
67+
68+
Accessible through the `theme.breakpoints` object, these tokens define the responsive breakpoints used in the UI Kit components.
69+
70+
<BreakpointTokens />

0 commit comments

Comments
 (0)