Created
August 2, 2025 12:01
-
-
Save czak/2016895f2b856c23acf13b2a3b7c1880 to your computer and use it in GitHub Desktop.
Generate Radix color scales from command line
This file contains hidden or 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
| #!/bin/bash | |
| tsx generate.ts light "#3C5F3E" "#FBFBF7" "#F6F5F4" "primary" > primary.css | |
| tsx generate.ts dark "#3C5F3E" "#FBFBF7" "#F6F5F4" "primary" > primary-dark.css | |
| tsx generate.ts light "#A8BB97" "#FBFBF7" "#F6F5F4" "secondary" > secondary.css | |
| tsx generate.ts dark "#A8BB97" "#FBFBF7" "#F6F5F4" "secondary" > secondary-dark.css | |
| tsx generate.ts light "#3C5F3E" "#FBFBF7" "#F6F5F4" "neutral" gray > neutral.css | |
| tsx generate.ts dark "#3C5F3E" "#FBFBF7" "#F6F5F4" "neutral" gray > neutral-dark.css |
This file contains hidden or 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
| /* Run this with tsx from checked out https://github.com/radix-ui/website */ | |
| import { generateRadixColors } from "./components/generateRadixColors"; | |
| const [appearance, accent, gray, background, name, mode] = process.argv.slice(2); | |
| const result = generateRadixColors({ | |
| appearance: appearance as "light" | "dark", | |
| accent, | |
| gray, | |
| background, | |
| }); | |
| const selector = appearance === "light" ? ":root, .light, .light-theme" : ".dark, .dark-theme"; | |
| const isGrayMode = mode === "gray"; | |
| const scale = isGrayMode ? result.grayScale : result.accentScale; | |
| const scaleWideGamut = isGrayMode ? result.grayScaleWideGamut : result.accentScaleWideGamut; | |
| const scaleAlpha = isGrayMode ? result.grayScaleAlpha : result.accentScaleAlpha; | |
| const scaleAlphaWideGamut = isGrayMode ? result.grayScaleAlphaWideGamut : result.accentScaleAlphaWideGamut; | |
| const colorVars = scale.map((color: string, index: number) => | |
| ` --${name}-${index + 1}: ${color};` | |
| ).join('\n'); | |
| const colorWideGamutVars = scaleWideGamut.map((color: string, index: number) => | |
| ` --${name}-${index + 1}: ${color};` | |
| ).join('\n'); | |
| const colorAlphaVars = scaleAlpha.map((color: string, index: number) => | |
| ` --${name}-a${index + 1}: ${color};` | |
| ).join('\n'); | |
| const colorAlphaWideGamutVars = scaleAlphaWideGamut.map((color: string, index: number) => | |
| ` --${name}-a${index + 1}: ${color};` | |
| ).join('\n'); | |
| const css = `/* Generated with: tsx generate.ts ${process.argv.slice(2).join(' ')} */ | |
| ${selector} { | |
| ${colorVars} | |
| } | |
| @supports (color: color(display-p3 1 1 1)) { | |
| @media (color-gamut: p3) { | |
| ${selector} { | |
| ${colorWideGamutVars} | |
| } | |
| } | |
| } | |
| ${selector} { | |
| ${colorAlphaVars} | |
| } | |
| @supports (color: color(display-p3 1 1 1)) { | |
| @media (color-gamut: p3) { | |
| ${selector} { | |
| ${colorAlphaWideGamutVars} | |
| } | |
| } | |
| }`; | |
| console.log(css); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment