Skip to content

Commit 6f6619f

Browse files
authored
feat(tokens): include fonts in package (#1405)
* feat(tokens): include fonts in package * chore: update readme
1 parent 5b0cea4 commit 6f6619f

File tree

10 files changed

+73
-19
lines changed

10 files changed

+73
-19
lines changed

.changeset/empty-ears-arrive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@launchpad-ui/tokens": patch
3+
---
4+
5+
Include fonts in package

.storybook/preview.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { BrowserRouter, useNavigate } from 'react-router-dom';
1111
import { allModes } from './modes';
1212

1313
import '../packages/components/src/styles/themes.css';
14+
import '../packages/tokens/dist/fonts.css';
1415
import '../packages/tokens/dist/index.css';
1516
import '../packages/tokens/dist/media-queries.css';
1617
import '../packages/tokens/dist/themes.css';

.storybook/styles.css

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
@font-face {
2-
font-family: inter;
3-
font-style: normal;
4-
font-weight: 300 800;
5-
font-display: swap;
6-
src: url('https://fonts.gstatic.com/s/inter/v7/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa1ZL7.woff2')
7-
format('woff2');
8-
}
9-
10-
@font-face {
11-
font-family: 'Audimat 3000 Regulier';
12-
font-style: normal;
13-
font-weight: 400;
14-
font-display: swap;
15-
src: url('Audimat3000-Regulier.var-subset.woff2') format('woff2');
16-
}
17-
181
.sb-main-padded.sb-show-main {
192
padding: 0;
203
margin: 0;

packages/tokens/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ $ npm install @launchpad-ui/tokens
1818
### CSS Custom Properties
1919

2020
```css
21+
@import '@launchpad-ui/tokens/dist/fonts.css';
2122
@import '@launchpad-ui/tokens/dist/index.css';
2223
@import '@launchpad-ui/tokens/dist/media-queries.css';
2324
@import '@launchpad-ui/tokens/dist/themes.css';
File renamed without changes.
97.8 KB
Binary file not shown.

packages/tokens/build.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const sd = new StyleDictionary({
88
css: {
99
prefix: 'lp',
1010
transformGroup: 'css',
11-
transforms: ['name/kebab', 'time/seconds', 'size/rem', 'color/rgb'],
11+
transforms: ['name/kebab', 'time/seconds', 'size/rem', 'color/rgb', 'attribute/font'],
1212
buildPath: 'dist/',
1313
options: {
1414
outputReferences: true,
@@ -30,7 +30,13 @@ const sd = new StyleDictionary({
3030
format: 'custom/media-query',
3131
filter: (token) => token.filePath === 'src/viewport.json',
3232
},
33+
{
34+
destination: 'fonts.css',
35+
format: 'custom/font-face',
36+
filter: (token) => token.$type === 'file',
37+
},
3338
],
39+
actions: ['copy_assets'],
3440
},
3541
js: {
3642
transformGroup: 'js',
@@ -105,6 +111,26 @@ sd.registerFormat({
105111
},
106112
});
107113

114+
sd.registerFormat({
115+
name: 'custom/font-face',
116+
format: async ({ dictionary }) => {
117+
return dictionary.allTokens
118+
.map((token) => {
119+
const {
120+
// @ts-expect-error attr
121+
attributes: { family, weight, style },
122+
formats,
123+
$value,
124+
} = token;
125+
const urls = formats.map(
126+
(extension: string) => `url("./assets/${$value}.${extension}") format("${extension}")`,
127+
);
128+
return `@font-face {\n\tfont-family: "${family}";\n\tfont-style: ${style};\n\tfont-weight: ${weight};\n\tsrc: ${urls.join(',\n\t\t\t ')};\n\tfont-display: swap;\n}\n`;
129+
})
130+
.join('\n');
131+
},
132+
});
133+
108134
sd.registerFormat({
109135
name: 'custom/json',
110136
format: async ({ dictionary, options }) => {
@@ -167,4 +193,17 @@ sd.registerTransform({
167193
},
168194
});
169195

196+
sd.registerTransform({
197+
name: 'attribute/font',
198+
type: 'attribute',
199+
filter: (token) => token.$type === 'file',
200+
transform: (token) => ({
201+
category: token.path[0],
202+
type: token.path[1],
203+
family: token.path[2],
204+
weight: token.path[3],
205+
style: token.path[4],
206+
}),
207+
});
208+
170209
await sd.buildAllPlatforms();

packages/tokens/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
"./themes.css": "./dist/themes.css",
3030
"./index.css": "./dist/index.css",
3131
"./media-queries.css": "./dist/media-queries.css",
32+
"./fonts.css": "./dist/fonts.css",
3233
"./dist/themes.css": "./dist/themes.css",
3334
"./dist/index.css": "./dist/index.css",
3435
"./dist/media-queries.css": "./dist/media-queries.css",
36+
"./dist/fonts.css": "./dist/fonts.css",
3537
"./dist/contract.json": "./dist/contract.json"
3638
},
3739
"scripts": {

packages/tokens/src/asset.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"asset": {
3+
"$type": "file",
4+
"font": {
5+
"Audimat 3000 Regulier": {
6+
"400": {
7+
"normal": {
8+
"$value": "Audimat3000-Regulier.var-subset",
9+
"formats": ["woff2"]
10+
}
11+
}
12+
},
13+
"Inter": {
14+
"300 800": {
15+
"normal": {
16+
"$value": "Inter.var-subset",
17+
"formats": ["woff2"]
18+
}
19+
}
20+
}
21+
}
22+
}
23+
}

packages/tokens/src/font.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"fontFamily": {
33
"$type": "fontFamily",
44
"base": {
5-
"$value": "inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, Helvetica, Arial, sans-serif"
5+
"$value": "Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, Helvetica, Arial, sans-serif"
66
},
77
"monospace": {
88
"$value": "SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace"

0 commit comments

Comments
 (0)