Skip to content

Commit d744e97

Browse files
feat(typography, tokens): DLT-2856 DLT-2857 next typography system (#994)
1 parent b6c6456 commit d744e97

23 files changed

Lines changed: 802 additions & 364 deletions

File tree

apps/dialtone-documentation/docs/.vuepress/baseComponents/ThemeColorTable.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
'background-color': `var(--dt-shell-mention-color-background)`,
6060
}"
6161
>
62-
Aa
62+
Ag
6363
</dt-stack>
6464
</dt-stack>
6565
<dt-stack
@@ -78,7 +78,7 @@
7878
:style="{ color: `var(${color.variable})` }"
7979
class="d-fs-300 d-p6 d-ta-center d-fw-medium"
8080
>
81-
Aa
81+
Ag
8282
</div>
8383
<div
8484
v-else-if="color.property === 'border-color'"

apps/dialtone-documentation/docs/.vuepress/baseComponents/tokens/TokenExample.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
:style="getColorStyle"
99
>
1010
<div v-if="isForeground || isLink" :class="['d-headline--lg', { 'link-example': isLink }]">
11-
Aa
11+
Ag
1212
</div>
1313
</dt-stack>
1414
<dt-stack
15-
v-if="category === 'typography'"
15+
v-if="category === 'typography' || category === 'text'"
1616
direction="row"
1717
justify="center"
1818
align="center"
1919
class="d-h32"
2020
>
2121
<div :style="getTypographyStyle">
22-
Aa
22+
Ag
2323
</div>
2424
</dt-stack>
2525
<div
@@ -65,6 +65,7 @@ const TYPOGRAPHY_KEY_MAP = {
6565
const SHADOW_COMPOSITION_TOKENS = ['small', 'medium', 'large', 'extra-large', 'card', 'focus', 'focus-inset'];
6666
6767
const isTypography = (name, key) => name.includes('--dt-typography') && name.includes(key);
68+
const isText = (name, key) => name.includes('--dt-text') && name.includes(key);
6869
const isFont = (name, key) => name.includes(`--dt-font-${key}`);
6970
const getRectSizeStyle = (value) => {
7071
if (value.endsWith('%')) return { 'inline-size': value };
@@ -142,11 +143,11 @@ const foregroundBackgroundColor = computed(() => {
142143
143144
const getTypographyStyle = computed(() => {
144145
for (const key in TYPOGRAPHY_KEY_MAP) {
145-
if (isFont(props.name, key) || isTypography(props.name, key)) {
146+
if (isFont(props.name, key) || isTypography(props.name, key) || isText(props.name, key)) {
146147
return { [TYPOGRAPHY_KEY_MAP[key]]: props.value };
147148
}
148149
}
149-
if (props.name.startsWith('var(--dt-typography')) {
150+
if (props.name.startsWith('var(--dt-typography') || props.name.startsWith('var(--dt-text')) {
150151
return `font: ${props.value}`;
151152
}
152153
return null;

apps/dialtone-documentation/docs/.vuepress/baseComponents/tokens/TokenTable.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</thead>
4343
<tbody>
4444
<tr
45-
v-for="({ exampleValue, exampleName, name, tokenValue, description }) in shownTokens"
45+
v-for="({ exampleValue, exampleName, name, tokenValue, description, deprecated }) in shownTokens"
4646
:key="name"
4747
tabindex="0"
4848
@mouseenter="onEnterRow(name)"
@@ -59,6 +59,7 @@
5959
/>
6060
</td>
6161
<th scope="row">
62+
<dt-badge v-if="deprecated" type="critical" kind="label" text="Deprecated" />
6263
<dt-stack
6364
direction="row"
6465
gap="300"
@@ -86,7 +87,7 @@
8687
:tokens="tokens"
8788
/>
8889
</th>
89-
<td v-if="!isSmallDevice && showValue" class="d-code--sm d-fc-blue-500 d-ta-right d-wmx164">
90+
<td v-if="!isSmallDevice && showValue" class="d-code--sm d-fc-blue-500 d-ta-right d-wmx164">
9091
<token-value :token-value="valueToString(tokenValue)" :tokens="tokens" />
9192
</td>
9293
<td

apps/dialtone-documentation/docs/.vuepress/baseComponents/tokens/TokenValue.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<template>
2-
<div class="d-code--sm d-docsite-code d-wmx164">
2+
<div class="d-code--sm d-docsite-code">
33
<div v-if="isCompositionToken(tokenValue)">
44
<span v-for="value in tokenValue" :key="value">
5-
<span v-dt-tooltip="getTooltipValue(value)" :class="{ 'h:d-fc-secondary': getTooltipValue(value) }">
5+
<span
6+
v-dt-tooltip="getTooltipValue(value)"
7+
:class="{ 'd-d-block h:d-fc-secondary d-c-default': getTooltipValue(value) }"
8+
>
69
{{ value }}&nbsp;
710
</span>
811
</span>

apps/dialtone-documentation/docs/.vuepress/baseComponents/tokens/constants.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const THEMES = [
2626

2727
export const CATEGORY_MAP = {
2828
color: ['color', 'opacity', 'shell'],
29-
typography: ['typography', 'font'],
29+
typography: ['typography', 'font', 'text'],
3030
size: ['size'],
3131
space: ['space'],
3232
shadow: ['shadow'],
@@ -39,6 +39,14 @@ export const SUBCATEGORY_MAP = {
3939
size: ['radius', 'border'],
4040
};
4141

42+
export const DEPRECATED_PATTERNS = [
43+
'typography-headline-',
44+
'typography-body-',
45+
'typography-label-',
46+
'typography-helper-',
47+
'typography-code-',
48+
];
49+
4250
export const getTokensStructure = () => ({
4351
color: {
4452
foreground: {
@@ -73,7 +81,7 @@ export const getTokensStructure = () => ({
7381
},
7482
},
7583
typography: {
76-
'font style': {
84+
'text style': {
7785
_children: [],
7886
},
7987
'font family': {

apps/dialtone-documentation/docs/.vuepress/baseComponents/tokens/utilities.js

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import tokensJson from '@dialpad/dialtone-tokens/dist/doc.json';
2-
import { CATEGORY_MAP, SUBCATEGORY_MAP, FORMAT_MAP, MODES, THEMES, getTokensStructure } from './constants';
2+
import { CATEGORY_MAP, SUBCATEGORY_MAP, FORMAT_MAP, MODES, THEMES, DEPRECATED_PATTERNS, getTokensStructure } from './constants';
33

44
/**
55
Process the file tokensJson and fill processedTokens with the data we want to show.
@@ -24,6 +24,9 @@ export const addTokensToStructure = (structure) => {
2424
Object.entries(combined).forEach((token) => {
2525
addTokensToCategories(token, format, structure[format][themeKey]);
2626
});
27+
28+
// Sort text style tokens: text first, then typography, each by type then size
29+
structure[format][themeKey].typography['text style']._children.sort(sortFontStyleTokens);
2730
}
2831
}
2932
});
@@ -41,14 +44,42 @@ const splitCompositionTokenIntoArray = (value) => {
4144
return value;
4245
};
4346

47+
/**
48+
* Sort text style tokens: text tokens first, then typography tokens,
49+
* each sorted by type (headline, body, label, code, etc.) then by size (xxxl -> xs)
50+
*/
51+
const TYPE_ORDER = ['headline', 'body', 'label', 'code', 'helper', 'button', 'inputs'];
52+
const SIZE_ORDER = ['xxxl', 'xxl', 'xl', 'lg', 'md', 'sm', 'xs'];
53+
54+
const sortFontStyleTokens = (a, b) => {
55+
const aName = a.name || a.exampleName || '';
56+
const bName = b.name || b.exampleName || '';
57+
58+
// Text tokens before typography tokens
59+
const aIsText = aName.includes('--dt-text');
60+
const bIsText = bName.includes('--dt-text');
61+
if (aIsText !== bIsText) return aIsText ? -1 : 1;
62+
63+
// Sort by type
64+
const aType = TYPE_ORDER.findIndex(t => aName.includes(t));
65+
const bType = TYPE_ORDER.findIndex(t => bName.includes(t));
66+
if (aType !== bType) return aType - bType;
67+
68+
// Sort by size
69+
const aSize = SIZE_ORDER.findIndex(s => aName.includes(`-${s})`));
70+
const bSize = SIZE_ORDER.findIndex(s => bName.includes(`-${s})`));
71+
return aSize - bSize;
72+
};
73+
4474
// eslint-disable-next-line complexity
4575
const addTokensToCategories = (token, format, structure) => {
4676
const [key, value] = token;
4777
if (!value[FORMAT_MAP[format]] || !value[FORMAT_MAP.CSS] || isBaseToken(key)) return;
4878

4979
const { name, value: tokenValue, description, keywords, isCompositionToken } = value[FORMAT_MAP[format]];
5080
const { value: exampleValue, name: exampleName } = value[FORMAT_MAP.CSS];
51-
const displayToken = { exampleValue, exampleName, name, tokenValue, description, keywords };
81+
const deprecated = isDeprecatedToken(exampleName);
82+
const displayToken = { exampleValue, exampleName, name, tokenValue, description, keywords, deprecated };
5283

5384
if (isCompositionToken) {
5485
displayToken.tokenValue = splitCompositionTokenIntoArray(tokenValue);
@@ -90,7 +121,7 @@ const addTokensToCategories = (token, format, structure) => {
90121

91122
// TYPOGRAPHY
92123
if (key.startsWith('typography')) {
93-
structure.typography['font style']._children.push({ ...displayToken, hidden: !isCompositionToken });
124+
structure.typography['text style']._children.push({ ...displayToken, hidden: !isCompositionToken });
94125
return;
95126
}
96127

@@ -116,6 +147,12 @@ const addTokensToCategories = (token, format, structure) => {
116147
return;
117148
}
118149

150+
// TEXT (display alongside typography in Font Style)
151+
if (key.startsWith('text')) {
152+
structure.typography['text style']._children.push({ ...displayToken, hidden: !isCompositionToken });
153+
return;
154+
}
155+
119156
// SHADOW
120157
if (key.startsWith('shadow')) {
121158
structure.shadow._children.push({ ...displayToken, hidden: !isCompositionToken });
@@ -183,3 +220,7 @@ const addTokenToSubcategory = (token, category, subcategory, structure) => {
183220
};
184221

185222
const isBaseToken = (name) => name.endsWith('base') || name.endsWith('root');
223+
224+
const isDeprecatedToken = (name) => {
225+
return DEPRECATED_PATTERNS.some(pattern => name.includes(pattern));
226+
};
Lines changed: 7 additions & 0 deletions
Loading
Lines changed: 7 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)