镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Allow theme(…) options when using @import - #16514

Merged
RobinMalfait merged 4 commits into
mainfrom
feat/improve-theme-options-dx
Feb 20, 2025
Merged

RobinMalfait merged 4 commits into
mainfrom
feat/improve-theme-options-dx

Conversation

@RobinMalfait

@RobinMalfait RobinMalfait commented Feb 13, 2025 •

Copy link
Copy Markdown
Contributor

This PR improves the developer experience when trying to use theme(…) options on an import.

Today, if you want to use Tailwind CSS, you can import it as:

@import "tailwindcss";

But if you want to use any of the theme(…) options, like the static theme option, then you had to use this instead:

@layer theme, base, components, utilities;

@import 'tailwindcss/theme' layer(theme) theme(static);
@import 'tailwindcss/preflight' layer(base);
@import 'tailwindcss/utilities' layer(utilities);

In this scenario you have to be careful, because the layer(…) must be the first option after an import (according to the spec). So if you use @import 'tailwindcss/theme' theme(static) layer(theme); then that's not going to work either.

This PR solves that by allowing you to use the theme(…) options directly on the @import statement:

@import 'tailwindcss' theme(static);

The only edge case is when you want to use theme(reference). A typical use case is for projects with <style> blocks where you want to reference the CSS variables from the theme.

If you use @import 'tailwindcss' theme(reference);, then all @theme blocks will be references and you can reference theme values. This is good. The bad part is that @import 'tailwindcss'; also includes preflight CSS. This means that we will import the preflight CSS for every <style> block. This is probably not what you want.

The solution is to use @reference 'tailwindcss'; instead which strips all of that information and only gives you access to CSS variables.

This PR also makes sure that if you use theme(reference) on an import that we still throw an error and suggest you use @reference instead. This is not a breaking change because right now if you use @import with theme(…) options it will already throw an error.

Test plan:

  1. Added dedicated tests to make sure we don't throw anymore.
  2. Added test to make sure that we do throw when using theme(reference) on an import.

@RobinMalfait RobinMalfait changed the title Improve DX when importing with theme(…) options Allow theme(…) options when using @import Feb 13, 2025
@RobinMalfait
RobinMalfait marked this pull request as ready for review February 13, 2025 18:26
@RobinMalfait
RobinMalfait requested a review from a team as a code owner February 13, 2025 18:26

@philipp-spiess philipp-spiess left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants