Skip to content

Commit

Permalink
feat(box, vars): add typography tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Niznikr committed Nov 21, 2023
1 parent b2c20a0 commit 56c8387
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"@vanilla-extract/css": "^1.14.0",
"@vanilla-extract/vite-plugin": "^3.9.0",
"@vanilla-extract/vite-plugin": "^3.9.2",
"@vitejs/plugin-react-swc": "^3.5.0",
"@vitest/coverage-v8": "^1.0.0-beta.4",
"@vitest/ui": "^1.0.0-beta.4",
Expand Down
12 changes: 12 additions & 0 deletions packages/box/src/styles/rainbow-sprinkles.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import { flatten } from 'flat';
import { defineProperties, createRainbowSprinkles } from 'rainbow-sprinkles';

const { bg, border, fill, shadow, text, gradient, ...global } = vars.color;
const { body, heading, small, label, code, display } = vars;
const typography = {
body,
heading,
small,
label,
code,
display,
};

type FlattenObjectKeys<T extends Record<string, unknown>, Key = keyof T> = Key extends string
? T[Key] extends Record<string, unknown>
Expand All @@ -16,13 +25,15 @@ type BackgroundKeys = FlattenObjectKeys<typeof bg>;
type BorderKeys = FlattenObjectKeys<typeof border>;
type FillKeys = FlattenObjectKeys<typeof fill>;
type TextKeys = FlattenObjectKeys<typeof text>;
type TypographyKeys = FlattenObjectKeys<typeof typography>;

const colors = flatten<typeof global, Record<GlobalKeys, string>>(global);
const gradients = flatten<typeof gradient, Record<GradientKeys, string>>(gradient);
const backgrounds = flatten<typeof bg, Record<BackgroundKeys, string>>(bg);
const borders = flatten<typeof border, Record<BorderKeys, string>>(border);
const fills = flatten<typeof fill, Record<FillKeys, string>>(fill);
const texts = flatten<typeof text, Record<TextKeys, string>>(text);
const typographies = flatten<typeof typography, Record<TypographyKeys, string>>(typography);

const responsiveProperties = defineProperties({
conditions: {
Expand Down Expand Up @@ -53,6 +64,7 @@ const responsiveProperties = defineProperties({
marginBottom: vars.spacing,
borderRadius: vars.border.radius,
borderWidth: vars.border.width,
font: typographies,
fontFamily: vars.font.family,
fontSize: vars.font.size,
fontWeight: vars.font.weight,
Expand Down
2 changes: 1 addition & 1 deletion packages/tokens/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const myStyleDictionary = StyleDictionary.extend({
},
json: {
buildPath: 'dist/',
transforms: ['attribute/cti', 'name/cti/kebab', 'value/path'],
transforms: ['attribute/cti', 'name/cti/kebab', 'font/css', 'value/path'],
files: [
{
format: 'json/nested',
Expand Down
41 changes: 34 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 56c8387

Please sign in to comment.