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

Improve Tailwind docs #136

Merged
merged 1 commit into from
Oct 23, 2023
Merged
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
23 changes: 21 additions & 2 deletions docs/src/pages/docs/integrations/tailwind.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ layout: ../../../layouts/docs.astro

# Tailwind

Cobalt integrates fully with TailwindCSS. To start, install the Tailwind plugin and CLI:
Cobalt’s Tailwind plugin lets you use your W3C Design Token Community Group tokens seamlessly in any Tailwind project by building your own custom [preset](https://tailwindcss.com/docs/presets). To start, install the Tailwind plugin and CLI:

```bash
npm install -D @cobalut-ui/plugin-tailwind @cobalt-ui/cli
```

_Note: this assumes you already have Tailwind [installed and configured](https://tailwindcss.com/docs/installation) in your project_

Then set up your `tokens.config.mjs` file, adding the Tailwind plugin, and mapping token IDs to the Tailwind [theme config](https://tailwindcss.com/docs/configuration#theme) inside the `tailwind` option:

```js
Expand Down Expand Up @@ -58,14 +60,31 @@ export default {
Then, when you run `co build` in your project, it will generate a `./tokens/tailwind-tokens.js` file. Now add it to your Tailwind config under `presets` ([docs](https://tailwindcss.com/docs/configuration#presets)):

```diff
// tailwind.config.js

/** @type {import('tailwindcss').Config} */
export default {
+ presets: ['./tokens/tailwind-tokens.js'],
};
```

_Note: if using CommonJS, use the `outputFormat: 'cjs'` plugin option._
_Note: if using CommonJS, use the `format: 'cjs'` plugin option._

And you’re up and running! You’ll now have all your design tokens available in Tailwind.

_✨ **Tip**: be sure to rerun `co build` to rebuild your Tailwind preset, or run `co build --watch` to rebuild your tokens every time they change!_

## Publishing to npm

You can publish your preset to npm, and keep it versioned like any of your other dependencies. You can then just consume the preset by passing the npm package name to Tailwind’s `presets` option:

```js
// tailwind.config.js

/** @type {import('tailwindcss').Config} */
export default {
presets: ['@my-scope/my-tokens-package'],
};
```

_✨ **Tip**: if publishing to npm, either name your Tailwind preset `./index.js`, or set the `package.json` [main field](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#main) to point directly to `./tailwind-tokens.js`._