Skip to content

Add Opt-in to exported CSS Vars and clean generated CSS code #200

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

llanesluis
Copy link
Contributor

@llanesluis llanesluis commented Jul 29, 2025

Additions:

  • User can now choose if they wanna export the Font Variables in the generated CSS code.
  • Cleaned up the generated CSS code for the selectors. Some properties do not need to be overriden (e.g. font vars and radius)
2025-07-28.17-40-41.mp4

These are the diffs in code for :root, .dark and @theme inline.
Same theme, but with vars cleaned up.

image image image

Summary by CodeRabbit

  • New Features

    • Added a user preference to include or exclude font-related CSS variables in generated theme code.
    • Introduced a "Preferences" button in the code panel with a toggle for font variables, making this setting easily accessible.
    • Added automatic tab switching in the code panel based on the selected Tailwind version.
  • UI Improvements

    • Updated layout of the code panel for clearer grouping of options and improved accessibility.
    • Enhanced responsive sizing and spacing for buttons and selectors.
    • Improved tab control with consistent state management and conditional display of Tailwind config tab.

Copy link

vercel bot commented Jul 29, 2025

@llanesluis is attempting to deploy a commit to the tweakcn OSS program Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented Jul 29, 2025

Walkthrough

A new boolean preference, includeFontVariables, was introduced to control whether font-related CSS variables are included in generated theme code. This preference is managed in the store, surfaced in the UI via a toggleable switch within a popover, and passed through utility functions to conditionally include or exclude font variables in the generated CSS. The code panel UI was enhanced with controlled tabs and automatic tab switching based on Tailwind version.

Changes

Cohort / File(s) Change Summary
Editor UI and Preferences Popover
components/editor/code-panel.tsx
Refactored imports for consistency, added controlled tab state with constants, introduced a popover containing a toggle switch for includeFontVariables, restructured layout for Tailwind version and color format selectors, and added automatic tab switching when Tailwind version changes. Adjusted classNames for responsive sizing and spacing. Passed font variable preference to code generation calls.
Preferences Store
store/preferences-store.ts
Added includeFontVariables boolean state and setter method to the preferences store interface and implementation, with default value true. Reordered imports for clarity.
Theme Code Generation Utilities
utils/theme-style-generator.ts
Added exported type GenerateVarsPreferences with optional includeFontVariables. Updated multiple functions (generateThemeVariables, generateTailwindV4ThemeInline, generateTailwindV3ConfigFile, generateThemeCode, generateTailwindConfigFileCode) to accept preferences and conditionally include font variables. Refined logic to separate light and dark mode variables and replaced tracking variable generation with a new helper.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CodePanel
    participant PreferencesStore
    participant ThemeStyleGenerator

    User->>CodePanel: Open Preferences popover
    User->>CodePanel: Toggle "Include font variables" switch
    CodePanel->>PreferencesStore: setIncludeFontVariables(value)
    CodePanel->>ThemeStyleGenerator: generateThemeCode(..., { includeFontVariables })
    ThemeStyleGenerator-->>CodePanel: Return generated CSS with/without font variables
    CodePanel-->>User: Display updated generated code
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

Poem

A toggle for fonts, a switch in the sky,
Now code panels twinkle as themes flutter by.
Preferences pop—popover delight!
Font vars included, or hidden from sight.
With stores and utilities hopping in tune,
The rabbit reviews, beneath the CSS moon.
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
components/editor/code-panel.tsx (1)

218-221: Consider improving the explanatory text.

The current text "If you handle fonts separately, turn this OFF" could be more specific about what "handling fonts separately" means.

-                <span className="text-muted-foreground text-xs text-pretty">
-                  If you handle fonts separately, turn this OFF.
-                </span>
+                <span className="text-muted-foreground text-xs text-pretty">
+                  Disable if you manage font definitions outside of this theme (e.g., in a separate CSS file or via @import).
+                </span>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a02f9f6 and ae52f8c.

📒 Files selected for processing (3)
  • components/editor/code-panel.tsx (6 hunks)
  • store/preferences-store.ts (4 hunks)
  • utils/theme-style-generator.ts (5 hunks)
🔇 Additional comments (10)
store/preferences-store.ts (1)

16-16: LGTM! Clean implementation of the new preference.

The new includeFontVariables preference follows the established patterns in the store, with proper TypeScript typing, sensible default value, and consistent setter implementation.

Also applies to: 22-22, 34-34, 52-54

components/editor/code-panel.tsx (3)

37-37: LGTM! Proper integration with the preferences store.

The component correctly reads the includeFontVariables state and passes it to the theme code generator. The integration follows React and Zustand best practices.

Also applies to: 41-41, 50-52


174-231: Well-structured UI enhancement with good UX.

The restructured layout effectively groups related controls and the new preferences popover provides clear context for the font variables option. The explanatory text helps users understand when to disable this feature.


138-138: Good responsive design improvements.

The className changes improve button sizing consistency and add proper responsive width handling.

Also applies to: 248-248

utils/theme-style-generator.ts (6)

71-73: Well-defined type for preferences.

The GenerateVarsPreferences type is appropriately named and uses optional properties, allowing for future extensibility.


75-82: Proper implementation of conditional font variables.

The function correctly destructures the preferences with a sensible default and conditionally generates font variables based on the user preference.

Also applies to: 85-85


119-129: Good refactoring of tracking variables generation.

The new generateInlineTrackingVariables function properly handles the conditional generation based on whether letter-spacing is "0em", avoiding unnecessary CSS when not needed.


131-201: Consistent implementation of preferences in Tailwind v4 theme.

The function properly handles the includeFontVariables preference and maintains consistency with the main theme generation logic.


203-208: Clean function signature extension.

The main generateThemeCode function properly accepts the new preferences parameter with appropriate defaults and passes it through to the generation functions consistently.

Also applies to: 220-223


100-116: All Clear: No Dark-Mode Dependencies Found

A repository-wide search in CSS/SCSS/TS/TSX for --font-*, --radius-*, --tracking-*, and --spacing-* under a .dark context returned zero matches. Removing these overrides in dark mode will not impact any existing themes.

@jnsahaj
Copy link
Owner

jnsahaj commented Jul 29, 2025

Superb change!
I just merged a change that added generated tailwind.config.ts for tailwind v3. I believe you'll have to modify the code to suppor that as well

@llanesluis
Copy link
Contributor Author

Sure I'll merge main and check for conflicts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
utils/theme-style-generator.ts (1)

203-290: Functional implementation with room for improvement.

The conditional font family inclusion works correctly. The string-based approach for building the config is functional, though consider using object composition for better maintainability in the future.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ae52f8c and 42ecc3b.

📒 Files selected for processing (2)
  • components/editor/code-panel.tsx (8 hunks)
  • utils/theme-style-generator.ts (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/editor/code-panel.tsx
🧰 Additional context used
🧬 Code Graph Analysis (1)
utils/theme-style-generator.ts (4)
types/theme.ts (1)
  • ThemeStyles (72-72)
types/editor.ts (1)
  • ThemeEditorState (18-27)
types/index.ts (1)
  • ColorFormat (53-53)
utils/color-converter.ts (1)
  • colorFormatter (14-46)
🔇 Additional comments (7)
utils/theme-style-generator.ts (7)

2-6: Import statements look good.

The added imports are appropriate for the new functionality and type safety requirements.


71-73: Well-structured preferences type.

The GenerateVarsPreferences type provides a clean interface for controlling theme generation options.


75-117: Clean implementation of conditional font variables.

The function correctly implements the opt-in behavior for font variables while maintaining backward compatibility with the default value of true. The separation of variables between light and dark modes is appropriate.


119-130: Smart optimization for tracking variables.

The function efficiently avoids generating tracking variables when letter-spacing is zero, reducing unnecessary CSS output.


131-201: Well-implemented Tailwind V4 inline theme generator.

The function correctly handles the conditional inclusion of font variables and properly generates the @theme inline block for Tailwind V4.


292-320: Correct propagation of preferences parameter.

The function properly passes the preferences through to all relevant sub-functions while maintaining backward compatibility.


322-336: Preferences parameter correctly integrated.

The function properly accepts and forwards the preferences parameter to the Tailwind V3 config generator.

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