Skip to content

Commit f6346c8

Browse files
feat: ability to copy colors in v4 docs (#1945)
- Enables the ability to copy colors in the v4 `/docs/colors` page. - Converts `oklch` to hex as it's more recognizable from a DX perspective. This should be okay because the color palette doesn't utilize values. Gif: ![click-to-copy](https://github.com/user-attachments/assets/4f0ce530-dfe7-40c7-9a0b-947afc558ba0) --------- Co-authored-by: Philipp Spiess <[email protected]>
1 parent 794640d commit f6346c8

File tree

2 files changed

+384
-9
lines changed

2 files changed

+384
-9
lines changed

src/components/color-palette.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ import path from "node:path";
33

44
import { fileURLToPath } from "node:url";
55
import React from "react";
6+
import { Color } from "./color";
67

78
const __filename = fileURLToPath(import.meta.url);
89
const __dirname = path.dirname(__filename);
910

10-
const styles = await fs.readFile(path.join(__dirname, "../../node_modules/tailwindcss/theme.css"), "utf-8");
11+
let styles = await fs.readFile(path.join(__dirname, "../../node_modules/tailwindcss/theme.css"), "utf-8");
1112

1213
let colors: Record<string, Record<string, string>> = {};
1314
for (let line of styles.split("\n")) {
1415
if (line.startsWith(" --color-")) {
15-
const [key, value] = line.split(":").map((part) => part.trim().replace(";", ""));
16-
const match = key.match(/^--color-([a-z]+)-(\d+)$/);
16+
let [key, value] = line.split(":").map((part) => part.trim().replace(";", ""));
17+
let match = key.match(/^--color-([a-z]+)-(\d+)$/);
1718

1819
if (match) {
19-
const [, group, shade] = match;
20+
let [, group, shade] = match;
2021

2122
if (!colors[group]) {
2223
colors[group] = {};
@@ -49,11 +50,7 @@ export function ColorPalette() {
4950
<p className="font-medium text-gray-950 capitalize sm:pr-12 dark:text-white">{key}</p>
5051
<div className="grid grid-cols-11 gap-1.5 sm:gap-4">
5152
{Object.keys(shades).map((shade, i) => (
52-
<div
53-
key={i}
54-
style={{ backgroundColor: `var(--color-${key}-${shade})` }}
55-
className="aspect-1/1 rounded-sm outline -outline-offset-1 outline-black/10 sm:rounded-md dark:outline-white/10"
56-
/>
53+
<Color key={i} name={key} shade={shade} value={shades[shade]} />
5754
))}
5855
</div>
5956
</React.Fragment>

0 commit comments

Comments
 (0)