2.2.0 • Published 6 months ago

@obosbbl/grunnmuren-tailwind v2.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@obosbbl/grunnmuren-tailwind

npm canary version

Grunnmuren Tailwind preset. See the Tailwind documentation for more information about how presets work.

Install

# npm
npm install -D @obosbbl/grunnmuren-tailwind@canary tailwindcss postcss autoprefixer

# pnpm
pnpm add -D @obosbbl/grunnmuren-tailwind@canary tailwindcss postcss autoprefixer

Usage

Configure Tailwind to use the preset

/* globals.css */

@import "@obosbbl/grunnmuren-tailwind";

/** Add any auto excluded sources (typically residing in node_modules) */
@source "../../node_modules/@obosbbl/grunnmuren-react/dist";
@source "../../node_modules/@code-obos/obos-layout/dist"

Fonts

Fonts are automatically loaded from OBOS' CDN, so you don't have to host the font files yourself.

If you use Content-Security-Policy, you have to allow https://www.obos.no as a font-src, otherwise the fonts will be blocked from loading.

The preset includes a (local) fallback font to prevent CLS while the fonts are loading. This is similar to the font optimization in Next. 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.

The fallback font metrics is generated with a script that can be run with pnpm font-fallback (requires Bun). If the fonts are changed, the script must be rerun and the resulting file commited.

Migrating from v1?

To ease the transition from v1 to v2 of Grunnmuren, it is possible to configure the preset to be (partially) compatible with v1. This allows you to use v2 of the Tailwind preset with v1 of the React components, and upgrade your application over time instead of a full migration.

To do that you need to configure the preset with legacyV1Compatibility option.

Options

// tailwind.config.js

/** @type {import('tailwindcss').Config} */
module.exports = {
  presets: [
    require('@obosbbl/grunnmuren-tailwind')({ includeFontFallback: false }),
  ],
  // content: [ ... ]
};

The preset supports the following options:

NameDefault valueDescription
includeFontFallbacktrueWhether the preset includes a font fallback
legacyV1CompatibilityfalseConfigures partial compatibility with Grunnmuren v1

Migrating from v2?

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.

The legacyV1Compatibility option is removed, so your project has to be fully upgraded to Grunnmuren v2.

The includeFontFallback option is also removed, and a font fallback will automatically be applied to the OBOS fonts by defaullt.

Migration

  1. Upgrade your project to Tailwind 4. You can try the migration guide from tailwind.
  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.
  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.
  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.

Here is an example of what your main CSS file might look like after migration:

@import "@obosbbl/grunnmuren-tailwind";

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

@theme {
  --animate-custom: custom-animation 1s ease-in-out infinite;
  @keyframes custom-animation {
    0%,
    100% {
      transform: rotate(-3deg);
    }
    50% {
      transform: rotate(3deg);
    }
  }
}

@utility my-custom-util {
  @apply flex flex-col min-h-screen;
}
2.0.0-canary.9

12 months ago

2.0.3

7 months ago

2.2.0

6 months ago

2.0.2

8 months ago

2.0.0-canary.11

9 months ago

2.0.0-canary.10

11 months ago

2.1.0

6 months ago

2.0.1

8 months ago

2.0.0-canary.12

9 months ago

2.0.0-canary.8

1 year ago

2.0.0-canary.7

1 year ago

2.0.0-canary.4

2 years ago

2.0.0-canary.3

2 years ago

2.0.0-canary.6

1 year ago

2.0.0-canary.5

1 year ago

2.0.0-canary.2

2 years ago

2.0.0-canary.1

2 years ago

2.0.0-canary.0

2 years ago

2.0.0

2 years ago

0.9.0

3 years ago

0.9.1

3 years ago

0.8.5

3 years ago

0.8.4

3 years ago

0.8.1

3 years ago

0.8.3

3 years ago

0.8.2

3 years ago

0.7.2

3 years ago

0.8.0

3 years ago

0.7.1

3 years ago

0.7.3

3 years ago

0.7.0

3 years ago

0.6.0

3 years ago

0.5.0

3 years ago

0.4.1

3 years ago

0.5.1

3 years ago

0.4.2

3 years ago

0.4.0

3 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago