Skip to content

Commit 64f2f2f

Browse files
Remove font-fallback as an option (#1275)
1 parent 436ea29 commit 64f2f2f

File tree

8 files changed

+23
-49
lines changed

8 files changed

+23
-49
lines changed

.changeset/odd-yaks-switch.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,21 @@
77

88
Tailwind is upgraded to v4. The `grunnmuren-tailwind` package is now CSS-first configured. And the previously exposed JS config file is now replaced by a CSS config file.
99

10-
The `legacyV1Compatibility` option is now removed, so your project has to be fully upgraded to Grunnmuren v2.
10+
The `legacyV1Compatibility` option is removed, so your project has to be fully upgraded to Grunnmuren v2.
11+
12+
The `includeFontFallback` option is also removed, and a font fallback will automatically be applied to the OBOS fonts by defaullt.
1113

1214
## Migration
1315
1. Upgrade your project to Tailwind 4. You can try the [migration guide](https://tailwindcss.com/docs/upgrade-guide)
1416
from tailwind.
1517
2. Add `@import "@obosbbl/grunnmuren-tailwind";` to the top of the main CSS file of your project. This is the new CSS configuration file for Grunnmuren.
1618
3. If you have a JS/TS `tailwind.config` in your project and would like to keep it. You can include it in the main CSS file (mentioned in step 2), by using the `@config` directive, e.g: `@config '../tailwind.config.ts';`. Read more [here](https://tailwindcss.com/docs/functions-and-directives#compatibility).
17-
4. If you would like to get rid of the old `tailwind.config`. You can move all your configuration to the main CSS file of your project. Tailwind 4 has automatic content detection, but if you need to include some excluded source you can use the `@source` directive, e.g: `@source "./node_modules/@obosbbl/grunnmuren-react/dist";`. You can also extend the `@obosbbl/grunnmuren-tailwind` config by using various directives such as `@base` or `@theme`.
18-
5. Finally, if you want to use the font fallback option: add `@import "@obosbbl/grunnmuren-tailwind/font-fallback";` **below** `@import "@obosbbl/grunnmuren-tailwind";`:
19-
20-
``` CSS
21-
@import "@obosbbl/grunnmuren-tailwind";
22-
@import "@obosbbl/grunnmuren-tailwind/font-fallback";
23-
```
24-
25-
The order matters here, since the `@obosbbl/grunnmuren-tailwind/font-fallback` config overrides the font definitions of `"@obosbbl/grunnmuren-tailwind"`.
19+
4. Finally, if you would like to get rid of the old `tailwind.config`. You can move all your configuration to the main CSS file of your project. Tailwind 4 has automatic content detection, but if you need to include some excluded source you can use the `@source` directive, e.g: `@source "./node_modules/@obosbbl/grunnmuren-react/dist";`. You can also extend the `@obosbbl/grunnmuren-tailwind` config by using various directives such as `@base` or `@theme`.
2620

2721
Here is an example of what your main CSS file __might__ look like after migration:
2822

2923
``` CSS
3024
@import "@obosbbl/grunnmuren-tailwind";
31-
@import "@obosbbl/grunnmuren-tailwind/font-fallback";
3225

3326
@source "../../node_modules/@obosbbl/grunnmuren-react/dist";
3427
@source "../../node_modules/@code-obos/obos-layout/dist"

apps/docs/app/styles/app.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
@import "@obosbbl/grunnmuren-tailwind";
2-
@import "@obosbbl/grunnmuren-tailwind/font-fallback";
32

43
@source "../../node_modules/@obosbbl/grunnmuren-react/dist";

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"packages/icons-react/src",
1212
"apps/docs/component-props.ts",
1313
"apps/docs/sanity.types.ts",
14-
"packages/tailwind/font-fallback.css"
14+
"packages/tailwind/font.css"
1515
]
1616
},
1717
"linter": {

packages/tailwind/README.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ Configure Tailwind to use the preset
2222
/* globals.css */
2323

2424
@import "@obosbbl/grunnmuren-tailwind";
25-
/** Add this if you want to use a fallback font for the OBOS fonts */
26-
@import "@obosbbl/grunnmuren-tailwind/font-fallback";
2725

2826
/** Add any auto excluded sources (typically residing in node_modules) */
2927
@source "../../node_modules/@obosbbl/grunnmuren-react/dist";
@@ -36,7 +34,7 @@ Fonts are automatically loaded from OBOS' CDN, so you don't have to host the fon
3634

3735
If you use [Content-Security-Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP), you have to allow `https://www.obos.no` as a [font-src](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/font-src), otherwise the fonts will be blocked from loading.
3836

39-
The preset includes a (local) fallback font to prevent [CLS](https://web.dev/articles/cls) while the fonts are loading. This is similar to the [font optimization in Next](https://nextjs.org/docs/app/building-your-application/optimizing/fonts). This is enabled by default, but can be disabled with the `includeFontFallback` option.
37+
The preset includes a (local) fallback font to prevent [CLS](https://web.dev/articles/cls) while the fonts are loading. This is similar to the [font optimization in Next](https://nextjs.org/docs/app/building-your-application/optimizing/fonts). This is enabled by default, and can only be disabled by a @theme override of the font variables in your own main tailwind CSS file.
4038

4139
The fallback font metrics is generated with a script that can be run with `pnpm font-fallback` (requires [Bun](https://bun.sh/)). If the fonts are changed, the script must be rerun and the resulting file commited.
4240

@@ -68,25 +66,23 @@ The preset supports the following options:
6866
| legacyV1Compatibility | `false` | Configures partial compatibility with Grunnmuren v1 |
6967

7068
## Migrating from v2?
69+
Tailwind is upgraded to v4. The `grunnmuren-tailwind` package is now CSS-first configured. And the previously exposed JS config file is now replaced by a CSS config file.
70+
71+
The `legacyV1Compatibility` option is removed, so your project has to be fully upgraded to Grunnmuren v2.
72+
73+
The `includeFontFallback` option is also removed, and a font fallback will automatically be applied to the OBOS fonts by defaullt.
74+
75+
## Migration
7176
1. Upgrade your project to Tailwind 4. You can try the [migration guide](https://tailwindcss.com/docs/upgrade-guide)
7277
from tailwind.
7378
2. Add `@import "@obosbbl/grunnmuren-tailwind";` to the top of the main CSS file of your project. This is the new CSS configuration file for Grunnmuren.
7479
3. If you have a JS/TS `tailwind.config` in your project and would like to keep it. You can include it in the main CSS file (mentioned in step 2), by using the `@config` directive, e.g: `@config '../tailwind.config.ts';`. Read more [here](https://tailwindcss.com/docs/functions-and-directives#compatibility).
75-
4. If you would like to get rid of the old `tailwind.config`. You can move all your configuration to the main CSS file of your project. Tailwind 4 has automatic content detection, but if you need to include some excluded source you can use the `@source` directive, e.g: `@source "./node_modules/@obosbbl/grunnmuren-react/dist";`. You can also extend the `@obosbbl/grunnmuren-tailwind` config by using various directives such as `@base` or `@theme`.
76-
5. Finally, if you want to use the font fallback option: add `@import "@obosbbl/grunnmuren-tailwind/font-fallback";` **below** `@import "@obosbbl/grunnmuren-tailwind";`:
77-
78-
``` CSS
79-
@import "@obosbbl/grunnmuren-tailwind";
80-
@import "@obosbbl/grunnmuren-tailwind/font-fallback";
81-
```
82-
83-
The order matters here, since the `@obosbbl/grunnmuren-tailwind/font-fallback` config overrides the font definitions of `"@obosbbl/grunnmuren-tailwind"`.
80+
4. Finally, if you would like to get rid of the old `tailwind.config`. You can move all your configuration to the main CSS file of your project. Tailwind 4 has automatic content detection, but if you need to include some excluded source you can use the `@source` directive, e.g: `@source "./node_modules/@obosbbl/grunnmuren-react/dist";`. You can also extend the `@obosbbl/grunnmuren-tailwind` config by using various directives such as `@base` or `@theme`.
8481

8582
Here is an example of what your main CSS file __might__ look like after migration:
8683

8784
``` CSS
8885
@import "@obosbbl/grunnmuren-tailwind";
89-
@import "@obosbbl/grunnmuren-tailwind/font-fallback";
9086

9187
@source "../../node_modules/@obosbbl/grunnmuren-react/dist";
9288
@source "../../node_modules/@code-obos/obos-layout/dist"
@@ -107,4 +103,4 @@ Here is an example of what your main CSS file __might__ look like after migratio
107103
@utility my-custom-util {
108104
@apply flex flex-col min-h-screen;
109105
}
110-
```
106+
```

packages/tailwind/font-fallback.css renamed to packages/tailwind/font.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,3 @@
1919

2020
}
2121

22-
@theme {
23-
--font-text: OBOSText, __OBOSText_Fallback, sans-serif;
24-
--font-display: OBOSDisplay, __OBOSDisplay_Fallback, sans-serif;
25-
}

packages/tailwind/fonts/generate-font-fallback.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,7 @@ for (const [_, fallback] of Object.entries(fontFallbacks)) {
8686
cssContent += ' }\n\n';
8787
}
8888

89-
cssContent += '}\n\n@theme {\n';
89+
cssContent += '}\n\n';
9090

91-
// Add theme variables for each font family
92-
for (const fontFamily of Object.keys(fontFallbacks)) {
93-
// Define the CSS variable for each font family
94-
// and remove the OBOS prefix and _Fallback suffix in the variable name
95-
cssContent += ` --font-${fontFamily.replace(/(OBOS|_Fallback)/gi, '').toLowerCase()}: ${fontFamily}, __${fontFamily}_Fallback, sans-serif;\n`;
96-
}
97-
98-
cssContent += '}\n';
99-
100-
// Write to ../font-fallback.css
101-
await Bun.write('../font-fallback.css', cssContent);
91+
// Write to ../font.css
92+
await Bun.write('../font.css', cssContent);

packages/tailwind/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
"license": "MIT",
99
"type": "commonjs",
1010
"exports": {
11-
".": "./tailwind-base.css",
12-
"./font-fallback": "./font-fallback.css"
11+
".": "./tailwind-base.css"
1312
},
1413
"files": [
15-
"tailwind-base.css",
16-
"fonts/font-fallback.js"
14+
"tailwind-base.css"
1715
],
1816
"scripts": {
1917
"font-fallback": "bun --cwd=./fonts ./generate-font-fallback.ts"

packages/tailwind/tailwind-base.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
@import "tailwindcss";
22
@import "./tailwind-typography";
3+
@import "./font";
34

45
@theme {
56
/*** Font stacks ***/
6-
--font-display: OBOSDisplay, sans-serif;
7-
--font-text: OBOSText, sans-serif;
7+
--font-text: OBOSText, __OBOSText_Fallback, sans-serif;
8+
--font-display: OBOSDisplay, __OBOSDisplay_Fallback, sans-serif;
89

910
/*** Widths ***/
1011
--container-width: 92rem;

0 commit comments

Comments
 (0)