Skip to content

Conversation

@platosha
Copy link
Contributor

Summary

Adds support for Tailwind CSS's @theme directive by allowing users to create an optional frontend/tailwind-custom.css file that gets automatically imported into the generated tailwind.css.

Motivation

Fixes #22914

Users want to use Tailwind's @theme directive to define custom theme values, but the current Tailwind integration doesn't provide a way to add custom directives without modifying generated files.

Implementation

When a frontend/tailwind-custom.css file exists, it is automatically imported into the generated tailwind.css file via @import statement. This allows users to:

  • Add custom @theme blocks for defining theme values
  • Include additional @import statements
  • Add any other Tailwind CSS directives

Example Usage

Create frontend/tailwind-custom.css:

@theme {
  --color-my-theme: red;
  --spacing-custom: 2.5rem;
}

Use in Java components:

div.addClassName("text-my-theme");

Changes

  • Add #customImport# placeholder in tailwind.css template
  • Detect and import frontend/tailwind-custom.css if it exists in TaskGenerateTailwindCss
  • Add comprehensive unit tests (7 test cases)
  • Add integration tests with real @theme directive example in test-tailwindcss module

Benefits

  • ✅ Fully backward compatible - no changes needed for existing projects
  • ✅ HMR (Hot Module Reload) works automatically for custom file changes
  • ✅ Low barrier to entry - just create one file
  • ✅ Framework ensures correct file structure and imports
  • ✅ Standard CSS import approach

Testing

  • All existing tests pass
  • 7 new unit tests covering custom import functionality
  • Integration tests verify @theme directive works in browser
  • Path calculation handles cross-platform file separators

🤖 Generated with Claude Code

platosha and others added 3 commits December 11, 2025 13:45
Users can now create an optional `frontend/tailwind-custom.css` file
to add custom Tailwind CSS directives such as @theme blocks for
defining custom theme values.

When the custom file exists, it is automatically imported into the
generated tailwind.css, allowing users to extend the default Tailwind
theme without modifying generated files.

Example usage:
```css
@theme {
  --color-my-theme: red;
  --spacing-custom: 2.5rem;
}
```

Changes:
- Add #customImport# placeholder in tailwind.css template
- Detect and import frontend/tailwind-custom.css if it exists
- Add comprehensive unit tests for custom import functionality
- Add integration tests with @theme directive example
- Fully backward compatible - no changes needed for existing projects

Fixes #22914

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Reuse File object in path calculation instead of reconstructing path
- Make @source assertion more specific by checking for quoted pattern
- Improves code clarity without changing functionality

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Verify that @source directive contains the specific path "../.."
instead of just checking for the presence of quotes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@github-actions
Copy link

github-actions bot commented Dec 11, 2025

Test Results

1 255 files   -  20  1 255 suites   - 20   1h 15m 46s ⏱️ + 5m 39s
8 771 tests  - 371  8 697 ✅  - 378  67 💤 +1  7 ❌ +7 
9 198 runs   - 367  9 116 ✅  - 374  75 💤 +1  7 ❌ +7 

For more details on these failures, see this check.

Results for commit dcc8c9f. ± Comparison against base commit 0d1677c.

This pull request removes 451 and adds 80 tests. Note that renamed tests count towards both.
com.vaadin.flow.component.littemplate.BundleLitParserTest ‑ parseTemplate
com.vaadin.flow.component.littemplate.BundleLitParserTest ‑ parseTemplateWithComments_commentsProperlyIgnored
com.vaadin.flow.component.littemplate.BundleLitParserTest ‑ parseTemplate_codeInRenderBeforeHtml_templateProperlyParsed
com.vaadin.flow.component.littemplate.BundleLitParserTest ‑ parseTemplate_codeWithHtmlAfterRender_templateProperlyParsed
com.vaadin.flow.component.littemplate.BundleLitParserTest ‑ parseTemplate_codeWithHtmlBeforeRender_templateProperlyParsed
com.vaadin.flow.component.littemplate.InjectableLitElementInitializerTest ‑ initializeElement_disabled_exceptionIsThrown
com.vaadin.flow.component.littemplate.InjectableLitElementInitializerTest ‑ initializeElement_setAttributeBinding_attributeIsIgnored
com.vaadin.flow.component.littemplate.InjectableLitElementInitializerTest ‑ initializeElement_setClass_classIsSetAsAttribute
com.vaadin.flow.component.littemplate.InjectableLitElementInitializerTest ‑ initializeElement_setDynamicValue_attributeIsIgnored
com.vaadin.flow.component.littemplate.InjectableLitElementInitializerTest ‑ initializeElement_setHref_hrefIsSetAsAttribute
…
com.vaadin.flow.AddQueryParamIT ‑ validateReactInUse[any_Chrome_]
com.vaadin.flow.NavigationIT ‑ testReactNavigationBrowserHistoryBack_serverNavigation[any_Chrome_]
com.vaadin.flow.NavigationIT ‑ testReactNavigation_flowContentCleaned[any_Chrome_]
com.vaadin.flow.NavigationIT ‑ testreactNavigationBrowserHistoryBack_anchor[any_Chrome_]
com.vaadin.flow.StateIT ‑ validateReactInUse[any_Chrome_]
com.vaadin.flow.ccdmtest.AppThemeTestIT ‑ should_apply_AppTheme_on_clientSideView[any_Chrome_]
com.vaadin.flow.ccdmtest.AppThemeTestIT ‑ should_apply_AppTheme_on_serverSideView[any_Chrome_]
com.vaadin.flow.ccdmtest.CCDMTest ‑ Unknown test
com.vaadin.flow.ccdmtest.IndexHtmlRequestHandlerIT ‑ indexHtmlRequestHandler_importDynamically_shouldLoadBundleCorrectly[any_Chrome_]
com.vaadin.flow.ccdmtest.IndexHtmlRequestHandlerIT ‑ indexHtmlRequestHandler_openRandomRoute_shouldResponseIndexHtml[any_Chrome_]
…
This pull request removes 1 skipped test and adds 2 skipped tests. Note that renamed tests count towards both.
com.vaadin.flow.spring.springnative.ClientCallableAotProcessorTest ‑ processAheadOfTime_clientCallableOnInterface_typesDetected
com.vaadin.flow.ccdmtest.CCDMTest ‑ Unknown test
com.vaadin.flow.mixedtest.ui.IdTestIT(production) ‑ Unknown test

♻️ This comment has been updated with latest results.

@platosha platosha changed the title Add support for Tailwind CSS @theme directive customization feat(TailwindCSS): Add support for Tailwind CSS @theme directive customization Dec 12, 2025
@sonarqubecloud
Copy link

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tailwind integration does not support Tailwind's @theme customization

2 participants