Skip to content

Feat: CSSRuleWith type #236#237

Merged
github-actions[bot] merged 1 commit intomainfrom
css-rule-with
Sep 2, 2025
Merged

Feat: CSSRuleWith type #236#237
github-actions[bot] merged 1 commit intomainfrom
css-rule-with

Conversation

@black7375
Copy link
Contributor

@black7375 black7375 commented Sep 2, 2025

Description

CSSRuleWith type & VariantStyle update

Related Issue

Summary by CodeRabbit

  • New Features

    • Improved TypeScript typing for CSS rules, enhancing IntelliSense and type safety.
    • Introduced CSSRuleWith for composing CSS rules with stricter semantics.
    • Variant styles now automatically wrap CSSRule values for stronger typings.
  • Refactor

    • Updated cssWith callback typing (no runtime changes).
    • Streamlined exports: RecipeVariants remains available; direct RulesVariants export removed.

Additional context

Checklist

@changeset-bot
Copy link

changeset-bot bot commented Sep 2, 2025

⚠️ No Changeset found

Latest commit: 432b68d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Sep 2, 2025

Walkthrough

Introduces CSSRuleWith as a replacement for RestrictCSSRule across CSS type utilities, updates cssWith typing to use CSSRuleWith, wraps VariantStyle values when they are CSSRule with CSSRuleWith, adjusts public exports (including aliasing StyleRuleWith and RecipeVariants), and adds vitest-gated type tests.

Changes

Cohort / File(s) Summary
CSS types refactor
packages/css/src/css/types.ts
Replaces RestrictCSSRule with CSSRuleWith, updates mapped-type conditionals (true extends T[K], NonNullable lookups), retains Resolve/required-vs-optional shaping, and adds import.meta.vitest type tests.
CSS API typing update
packages/css/src/css/index.ts
Changes cssWith callback param and internal alias from RestrictCSSRule to CSSRuleWith; imports updated accordingly; no runtime logic changes.
Rules typing adjustments
packages/css/src/rules/types.ts
VariantStyle now wraps CSSRule values with CSSRuleWith; removes public alias RecipeVariants.
Public exports surface
packages/css/src/index.ts, packages/css/src/compat.ts
Adds export of CSSRuleWith; in compat, re-exports CSSRuleWith as StyleRuleWith and removes RecipeVariants from exports; in index, exports RulesVariants as RecipeVariants (alias), removing direct RulesVariants export.

Sequence Diagram(s)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

enhancement

Poem

I twitch my whiskers at types that grew,
From Restrict to With—a fresh, crisp view.
Variants wrapped, exports neat,
Little pawprints, compile-time sweet.
In burrows of CSS, I hop with delight—
Stronger shapes by day, safer styles by night. 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch css-rule-with

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 2, 2025

Triggered from #237 by @​black7375.

Checking if we can fast forward main (c268326) to css-rule-with (432b68d).

Target branch (main):

commit c268326ae498f7c2d1f0504d517fd4d340a1169f (HEAD -> main, origin/main)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Tue Jul 22 00:00:00 2025 +0900

    Feat: Rules - `rules.raw()` API supports #231

Pull request (css-rule-with):

commit 432b68d9b638c4f662ccaffdfba184a97d39f22f (pull_request/css-rule-with)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Thu Jul 24 00:00:00 2025 +0900

    Feat: `CSSRuleWith` type #236

It is possible to fast forward main (c268326) to css-rule-with (432b68d). If you have write access to the target repository, you can add a comment with /fast-forward to fast forward main to css-rule-with.

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 (3)
packages/css/src/css/types.ts (1)

10-10: Consider excluding keys when false appears in unions.

T[K] extends false ? never : K only excludes when the type is exactly false. If you intend “any presence of false means forbidden,” prefer false extends T[K] ? never : K.

Apply:

-  [K in keyof T as T[K] extends false ? never : K]: true extends T[K]
+  [K in keyof T as false extends T[K] ? never : K]: true extends T[K]
packages/css/src/index.ts (1)

33-33: Alias RulesVariantsRecipeVariants: confirm BC.

This preserves the commonly used RecipeVariants name. If any consumers also import RulesVariants directly from here, consider exporting both for a transition period.

packages/css/src/css/index.ts (1)

114-117: Type the fallback callback to avoid union widening.

Without annotation, cssFunction can widen to RestrictedCSSRule | ComplexCSSRule. Type the fallback for cleaner inference.

Apply:

-function cssWith<const T extends CSSRule>(
-  callback?: (style: CSSRuleWith<T>) => ComplexCSSRule
-) {
-  type RestrictedCSSRule = CSSRuleWith<T>;
-  const cssFunction = callback ?? ((style: RestrictedCSSRule) => style);
+function cssWith<const T extends CSSRule>(
+  callback?: (style: CSSRuleWith<T>) => ComplexCSSRule
+) {
+  type RestrictedCSSRule = CSSRuleWith<T>;
+  const cssFunction: (style: RestrictedCSSRule) => ComplexCSSRule =
+    callback ?? ((style) => style);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c268326 and 432b68d.

📒 Files selected for processing (5)
  • packages/css/src/compat.ts (1 hunks)
  • packages/css/src/css/index.ts (2 hunks)
  • packages/css/src/css/types.ts (2 hunks)
  • packages/css/src/index.ts (1 hunks)
  • packages/css/src/rules/types.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: black7375
PR: mincho-js/mincho#113
File: packages/css/src/index.ts:33-33
Timestamp: 2024-10-09T13:00:38.449Z
Learning: `recipe` is properly exported from './rules' in `packages/css/src/rules/index.ts`.
📚 Learning: 2024-10-09T13:00:38.449Z
Learnt from: black7375
PR: mincho-js/mincho#113
File: packages/css/src/index.ts:33-33
Timestamp: 2024-10-09T13:00:38.449Z
Learning: `recipe` is properly exported from './rules' in `packages/css/src/rules/index.ts`.

Applied to files:

  • packages/css/src/index.ts
  • packages/css/src/css/index.ts
  • packages/css/src/compat.ts
  • packages/css/src/rules/types.ts
🧬 Code graph analysis (4)
packages/css/src/css/index.ts (3)
packages/css/src/compat.ts (2)
  • CSSRuleWith (26-26)
  • ComplexCSSRule (46-46)
packages/css/src/css/types.ts (1)
  • CSSRuleWith (9-23)
packages/transform-to-vanilla/src/types/style-rule.ts (2)
  • ComplexCSSRule (26-26)
  • CSSRule (33-35)
packages/css/src/compat.ts (1)
packages/transform-to-vanilla/src/types/style-rule.ts (3)
  • CSSRule (33-35)
  • CSSPropertiesWithVars (49-52)
  • CSSPropertiesWithConditions (45-47)
packages/css/src/rules/types.ts (2)
packages/transform-to-vanilla/src/types/style-rule.ts (4)
  • CSSRule (33-35)
  • CSSPropertiesWithVars (49-52)
  • CSSPropertiesWithConditions (45-47)
  • CSSComplexProperties (54-56)
packages/css/src/css/types.ts (1)
  • CSSRuleWith (9-23)
packages/css/src/css/types.ts (3)
packages/css/src/compat.ts (2)
  • CSSRuleWith (26-26)
  • CSSRule (47-47)
packages/css/src/index.ts (2)
  • CSSRuleWith (29-29)
  • CSSRule (5-5)
packages/transform-to-vanilla/src/types/style-rule.ts (1)
  • CSSRule (33-35)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (8)
packages/css/src/css/types.ts (2)

9-15: Good rename and improved truthiness check.

Switching to true extends T[K] correctly handles unions containing true and fixes the prior narrow check. The NonNullable<CSSRule[K]> coercion is also a good guardrail.


25-33: ESM-only output (package.json type: "module"); no CommonJS build is emitted, so import.meta.vitest blocks are valid at runtime.

packages/css/src/compat.ts (2)

26-26: Alias looks right.

CSSRuleWith re-exported as StyleRuleWith maintains the compat surface.


28-41: No downstream imports of RecipeVariants found; safe to remove from compat exports.

packages/css/src/index.ts (1)

29-29: Expose CSSRuleWith at top-level.

Good addition; keeps the main entrypoint aligned with the new type.

packages/css/src/css/index.ts (1)

16-16: Updated import aligns with new type.

Switching to CSSRuleWith is consistent with the rest of the PR.

packages/css/src/rules/types.ts (2)

9-9: Correct import location for CSSRuleWith.

Pulling from ../css/types.js keeps the rules layer decoupled from transform internals.


37-40: Wrapping CSS-rule variants with CSSRuleWith is a solid safety net.

Only CSSRule-shaped variant values are constrained; string/classname and complex values remain untouched. This matches intended ergonomics.

@black7375
Copy link
Contributor Author

/fast-forward

@github-actions
Copy link
Contributor

github-actions bot commented Sep 2, 2025

Triggered from #237 (comment) by @​black7375.

Trying to fast forward main (c268326) to css-rule-with (432b68d).

Target branch (main):

commit c268326ae498f7c2d1f0504d517fd4d340a1169f (HEAD -> main, origin/main)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Tue Jul 22 00:00:00 2025 +0900

    Feat: Rules - `rules.raw()` API supports #231

Pull request (css-rule-with):

commit 432b68d9b638c4f662ccaffdfba184a97d39f22f (pull_request/css-rule-with)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Thu Jul 24 00:00:00 2025 +0900

    Feat: `CSSRuleWith` type #236

Fast forwarding main (c268326) to css-rule-with (432b68d).

$ git push origin 432b68d9b638c4f662ccaffdfba184a97d39f22f:main
To https://github.com/mincho-js/mincho.git
   c268326..432b68d  432b68d9b638c4f662ccaffdfba184a97d39f22f -> main

@github-actions github-actions bot merged commit 432b68d into main Sep 2, 2025
12 checks passed
@github-actions github-actions bot deleted the css-rule-with branch September 2, 2025 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant