Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix responsive issues, typography tokens #387

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/healthy-icons-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@terrazzo/cli": patch
"@terrazzo/parser": patch
"@terrazzo/token-tools": patch
---

Fix incorrect parsing of typography tokens’ lineHeight when it’s a dimension value.
7 changes: 7 additions & 0 deletions .changeset/quiet-files-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@terrazzo/parser": patch
"@terrazzo/cli": patch
"@terrazzo/token-tools": patch
---

Fix warning on parsing dimension tokens in typography tokens
1 change: 1 addition & 0 deletions packages/cli/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.turbo
biome.json
src/**
test/**
Expand Down
1 change: 1 addition & 0 deletions packages/icons/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.turbo
biome.json
src/**
rollup.*
Expand Down
1 change: 1 addition & 0 deletions packages/parser/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.turbo
biome.json
test/
tsconfig.*
Expand Down
1 change: 1 addition & 0 deletions packages/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"license": "MIT",
"scripts": {
"build": "tsc -p tsconfig.build.json",
"dev": "pnpm run build --watch",
"lint": "biome check .",
"test": "vitest run"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/parser/src/parse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ async function parseSingle(
const $typeInheritance: Record<string, Token['$type']> = {};
traverse(document, {
enter(node, parent, path) {
if (node.type === 'Member' && node.value.type === 'Object' && node.value.members) {
if (node.type === 'Member' && node.value.type === 'Object' && node.value.members && !path.includes('$value')) {
const members = getObjMembers(node.value);

// keep track of $types
Expand Down Expand Up @@ -370,7 +370,7 @@ async function parseSingle(
}

tokens[id] = token;
} else if (!id.includes('.$value') && members.value) {
} else if (!path.includes('.$value') && members.value) {
logger.warn({ message: `Group ${id} has "value". Did you mean "$value"?`, filename, node, src });
}
}
Expand Down
10 changes: 9 additions & 1 deletion packages/parser/src/parse/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,18 @@ export default function normalizeValue<T extends Token>(token: T): T['$value'] {
const output: TypographyValueNormalized = {};
for (const k in token.$value) {
switch (k) {
case 'letterSpacing':
case 'fontSize':
case 'letterSpacing': {
output[k] = normalizeValue({ $type: 'dimension', $value: token.$value[k] as DimensionValue });
break;
}
case 'lineHeight': {
output[k] = normalizeValue({
$type: typeof token.$value === 'number' ? 'number' : 'dimension',
$value: token.$value[k] as any,
});
break;
}
default:
output[k] = token.$value[k];
}
Expand Down
52 changes: 50 additions & 2 deletions packages/parser/test/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2219,7 +2219,7 @@ font:
fontVariant: 'small-caps',
fontWeight: 400,
letterSpacing: { value: 0.125, unit: 'em' },
lineHeight: 1.5,
lineHeight: { value: 24, unit: 'px' },
textDecoration: 'underline',
textTransform: 'uppercase',
},
Expand All @@ -2236,14 +2236,62 @@ font:
fontVariant: 'small-caps',
fontWeight: 400,
letterSpacing: { value: 0.125, unit: 'em' },
lineHeight: 1.5,
lineHeight: { value: 24, unit: 'px' },
textDecoration: 'underline',
textTransform: 'uppercase',
},
},
},
},
],
[
'lineHeight: number',
{
given: [
{
filename: DEFAULT_FILENAME,
src: {
typography: {
$type: 'typography',
$value: {
lineHeight: 1.5,
},
},
},
},
],
want: { tokens: { typography: { lineHeight: 1.5 } } },
},
],
[
'dimension (legacy format)',
{
given: [
{
filename: DEFAULT_FILENAME,
src: {
typography: {
$type: 'typography',
$value: {
fontSize: '16px',
letterSpacing: '0.001em',
lineHeight: '24px',
},
},
},
},
],
want: {
tokens: {
typography: {
fontSize: { value: 16, unit: 'px' },
letterSpacing: { value: 0.001, unit: 'em' },
lineHeight: { value: 24, unit: 'px' },
},
},
},
},
],
];

it.each(tests)('%s', (_, testCase) => runTest(testCase));
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-css/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.turbo
biome.json
src/**
test/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"fontSize": { "value": 18, "unit": "px" },
"fontVariationSettings": "\"wght\" 130, \"opsz\" 100, \"wdth\" 50",
"fontWeight": 500,
"lineHeight": 1.375,
"lineHeight": { "value": 24, "unit": "px" },
"letterSpacing": { "value": 0.25, "unit": "em" },
"textTransform": "uppercase"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-css/test/fixtures/type-typography/want.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
--ds-typography-subheading-font-size: 18px;
--ds-typography-subheading-font-variation-settings: "wght" 130, "opsz" 100, "wdth" 50;
--ds-typography-subheading-font-weight: 500;
--ds-typography-subheading-line-height: 1.375;
--ds-typography-subheading-line-height: 24px;
--ds-typography-subheading-letter-spacing: 0.25em;
--ds-typography-subheading-text-transform: uppercase;
--ds-typography-callout-font-family: var(--ds-typography-family-body);
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-js/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.turbo
biome.json
src/**
test/**
Expand Down
80 changes: 64 additions & 16 deletions packages/plugin-js/test/typography/want.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,56 +25,80 @@ export const tokens = {
"unit": "px"
},
"fontWeight": 400,
"lineHeight": "41px"
"lineHeight": {
"value": 41,
"unit": "px"
}
},
"xs": {
"fontSize": {
"value": 31,
"unit": "px"
},
"lineHeight": "38px"
"lineHeight": {
"value": 38,
"unit": "px"
}
},
"s": {
"fontSize": {
"value": 32,
"unit": "px"
},
"lineHeight": "39px"
"lineHeight": {
"value": 39,
"unit": "px"
}
},
"m": {
"fontSize": {
"value": 33,
"unit": "px"
},
"lineHeight": "40px"
"lineHeight": {
"value": 40,
"unit": "px"
}
},
"l": {
"fontSize": {
"value": 34,
"unit": "px"
},
"lineHeight": "41px"
"lineHeight": {
"value": 41,
"unit": "px"
}
},
"xl": {
"fontSize": {
"value": 36,
"unit": "px"
},
"lineHeight": "43px"
"lineHeight": {
"value": 43,
"unit": "px"
}
},
"2xl": {
"fontSize": {
"value": 38,
"unit": "px"
},
"lineHeight": "46px"
"lineHeight": {
"value": 46,
"unit": "px"
}
},
"3xl": {
"fontSize": {
"value": 40,
"unit": "px"
},
"lineHeight": "48px"
"lineHeight": {
"value": 48,
"unit": "px"
}
},
},
"typography.body": {
Expand All @@ -87,56 +111,80 @@ export const tokens = {
"unit": "px"
},
"fontWeight": 400,
"lineHeight": "22px"
"lineHeight": {
"value": 22,
"unit": "px"
}
},
"xs": {
"fontSize": {
"value": 14,
"unit": "px"
},
"lineHeight": "19px"
"lineHeight": {
"value": 19,
"unit": "px"
}
},
"s": {
"fontSize": {
"value": 15,
"unit": "px"
},
"lineHeight": "20px"
"lineHeight": {
"value": 20,
"unit": "px"
}
},
"m": {
"fontSize": {
"value": 16,
"unit": "px"
},
"lineHeight": "21px"
"lineHeight": {
"value": 21,
"unit": "px"
}
},
"l": {
"fontSize": {
"value": 17,
"unit": "px"
},
"lineHeight": "22px"
"lineHeight": {
"value": 22,
"unit": "px"
}
},
"xl": {
"fontSize": {
"value": 19,
"unit": "px"
},
"lineHeight": "24px"
"lineHeight": {
"value": 24,
"unit": "px"
}
},
"2xl": {
"fontSize": {
"value": 21,
"unit": "px"
},
"lineHeight": "26px"
"lineHeight": {
"value": 26,
"unit": "px"
}
},
"3xl": {
"fontSize": {
"value": 23,
"unit": "px"
},
"lineHeight": "29px"
"lineHeight": {
"value": 29,
"unit": "px"
}
},
},
};
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-sass/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.turbo
biome.json
src/**
test/**
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-swift/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.turbo
biome.json
src/**
test/**
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-tailwind/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.turbo
biome.json
src/**
test/**
Expand Down
1 change: 1 addition & 0 deletions packages/react-color-picker/.npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.test.*
.size-limit.js
.turbo
biome.*
rollup.*
src/**
Expand Down
6 changes: 3 additions & 3 deletions packages/react-color-picker/src/components/ColorPicker.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
border-radius: var(--tz-radius-300);
color: var(--tz-color-picker-input);
flex: 1 0 auto;
font-family: var(--tz-typography-family-mono);
font-size: var(--tz-typography-100-regular-font-size);
font-family: var(--tz-font-mono);
font-size: var(--tz-font-label-small-font-size);
font-variant-ligatures: none;
font-weight: var(--tz-typography-100-regular-font-weight);
font-weight: var(--tz-font-label-small-font-weight);
height: var(--tz-space-control-m);
letter-spacing: 0;
line-height: var(--tz-space-control-m);
Expand Down
Loading
Loading