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

Fix: Limit rules's prop expression #14

Merged
merged 1 commit into from
Nov 26, 2024
Merged

Fix: Limit rules's prop expression #14

merged 1 commit into from
Nov 26, 2024

Conversation

black7375
Copy link
Contributor

@black7375 black7375 commented Nov 26, 2024

Type inference is difficult because I currently have so many object types.
I have proven that it is possible, but since autocompletion rarely works, we need to change it to as concise a form as possible.
It may be reintroduced in the future through performance improvements and updates to TypeScript.

// == Maintained Syntax =======================================================
// 1. Property with Array
rules({
  props: ["color", "background"]
});

// 2. Property with targets
rules({
  props: {
    size: {
      targets: ["padding", "margin"]
    }
  }
});

// == Disappearing Syntax ======================================================
// 1. Property with base value
rules({
  props: {
    background: {
      base: "red"
    }
  }
});

// The targets should bd specified.
rules({
  props: {
    background: {
      base: "red",
      targets: ["background"]
    }
  }
});

// 2. Property with aliased
rules({
  props: {
    size: ["padding", "margin"]
  }
})

// Should be created as an Object structure.
rules({
  props: {
    size: {
      targets: ["padding", "margin"]
    }
  }
});

Summary by CodeRabbit

  • New Features

    • Introduced a new rules() API for dynamic and declarative style definitions.
    • Added support for variants, toggles, and compound variants for conditional styling.
    • Enhanced property grouping with a new props feature for better state management.
    • Improved syntax for nested property definitions to enhance clarity.
  • Documentation

    • Updated documentation with examples demonstrating the use of the new rules() API and its features.
    • Ensured backward compatibility with existing styling implementations.

Copy link

changeset-bot bot commented Nov 26, 2024

⚠️ No Changeset found

Latest commit: cf98bb8

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.

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

Copy link

graphite-app bot commented Nov 26, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “merge-queue” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

Copy link

coderabbitai bot commented Nov 26, 2024

Walkthrough

The pull request introduces a new API called rules() for defining styles in a dynamic and declarative manner within the CSS management system. It enhances the existing capabilities by allowing the creation of styles that utilize both static and dynamic properties, supporting variants, toggles, and compound variants. The changes include an updated syntax for defining properties, improved handling of boolean variants, and a focus on backward compatibility with existing implementations. Examples are provided to illustrate the new API's usage, ensuring clarity and usability for developers.

Changes

File Change Summary
text/002-css-rules.md - Added methods: const myRule = rules({...}), const button = rules({...}), const contents = rulesVariants({...})
- Updated method signatures for rules() to include props and variants.
- Enhanced syntax for defining props to support nested structures and boolean variants.

Possibly related PRs

🐇 In the meadow, styles bloom bright,
With rules() to guide, oh what a sight!
Dynamic and clear, they dance in the air,
Props and variants, with love and care.
A hop and a skip, let’s style with glee,
In our code garden, so wild and free! 🌼✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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

Triggered from #14 by @​black7375.

Checking if we can fast forward main (55ab16a) to props-change (cf98bb8).

Target branch (main):

commit 55ab16a3f934c059b4b4d7dd3953ebca290bb93c (HEAD -> main, origin/main, origin/HEAD)
Author: alstjr7375 <[email protected]>
Date:   Wed Oct 2 17:44:44 2024 +0900

    Fix: Typescript syntax, typos

Pull request (props-change):

commit cf98bb8ae7f0126345562918987d7f0d5a9429e5 (pull_request/props-change)
Author: alstjr7375 <[email protected]>
Date:   Tue Nov 26 21:39:24 2024 +0900

    Fix: Limit `rules`'s prop expression

It is possible to fast forward main (55ab16a) to props-change (cf98bb8). If you have write access to the target repository, you can add a comment with /fast-forward to fast forward main to props-change.

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

🧹 Outside diff range and nitpick comments (3)
text/002-css-rules.md (3)

447-447: Consider simplifying the props target syntax.

The current array syntax for defining prop targets could be error-prone. Consider a more explicit object-based approach:

- props: ["color", "background", { size: { targets: ["padding", "margin"] }}]
+ props: {
+   color: "color",
+   background: "background",
+   size: {
+     targets: ["padding", "margin"]
+   }
+ }

Line range hint 447-471: Consider specificity implications in compiled output.

The current compilation strategy might lead to specificity issues when combining multiple variants. Consider implementing a more robust specificity management system.

Suggestions:

  1. Add a specificity calculation system
  2. Document the specificity hierarchy
  3. Consider implementing a specificity normalization step during compilation

Line range hint 1-1000: Consider enhancing type safety and runtime performance.

The current API design could benefit from additional type safety measures and runtime optimizations.

Recommendations:

  1. Add strict type checking for variant combinations
  2. Implement runtime caching for frequently used style combinations
  3. Consider adding compile-time validation for prop types

Example type enhancement:

type VariantProps<T> = {
  [K in keyof T]: T[K] extends Record<string, unknown> ? keyof T[K] : never;
};

const button = rules<VariantProps<typeof variants>>({
  // ... implementation
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 55ab16a and cf98bb8.

📒 Files selected for processing (1)
  • text/002-css-rules.md (2 hunks)
🔇 Additional comments (1)
text/002-css-rules.md (1)

471-471: Verify CSS variable collision handling.

The base value implementation needs to ensure it doesn't conflict with CSS variable declarations.

@black7375
Copy link
Contributor Author

/fast-forward

Copy link

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

Trying to fast forward main (55ab16a) to props-change (cf98bb8).

Target branch (main):

commit 55ab16a3f934c059b4b4d7dd3953ebca290bb93c (HEAD -> main, origin/main, origin/HEAD)
Author: alstjr7375 <[email protected]>
Date:   Wed Oct 2 17:44:44 2024 +0900

    Fix: Typescript syntax, typos

Pull request (props-change):

commit cf98bb8ae7f0126345562918987d7f0d5a9429e5 (pull_request/props-change)
Author: alstjr7375 <[email protected]>
Date:   Tue Nov 26 21:39:24 2024 +0900

    Fix: Limit `rules`'s prop expression

Fast forwarding main (55ab16a) to props-change (cf98bb8).

$ git push origin cf98bb8ae7f0126345562918987d7f0d5a9429e5:main
To https://github.com/mincho-js/working-group.git
   55ab16a..cf98bb8  cf98bb8ae7f0126345562918987d7f0d5a9429e5 -> main

@github-actions github-actions bot merged commit cf98bb8 into main Nov 26, 2024
1 check passed
@github-actions github-actions bot deleted the props-change branch November 26, 2024 12:56
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.

1 participant