Skip to content

Feat: selector() API implement #236#246

Merged
github-actions[bot] merged 1 commit intomainfrom
selector-util
Oct 1, 2025
Merged

Feat: selector() API implement #236#246
github-actions[bot] merged 1 commit intomainfrom
selector-util

Conversation

@black7375
Copy link
Contributor

@black7375 black7375 commented Oct 1, 2025

Description

Type inference doesn't work well for computed property names in TypeScript.
This type utility makes it easier to handle this.

css({
  [selector(`.otherClass &`)]: {
    color: "red"
  }
});

Related Issue

Summary by CodeRabbit

  • New Features

    • Added a selector utility in the CSS package to create computed selectors with improved type safety, exposed via the public API.
  • Documentation

    • Added documentation describing the new selector utility under the CSS section.
  • Chores

    • Updated release metadata and bumped the CSS package version to a minor release.

Additional context

Checklist

@changeset-bot
Copy link

changeset-bot bot commented Oct 1, 2025

🦋 Changeset detected

Latest commit: d9445d5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@mincho-js/css Minor
@mincho-js/react Patch
@mincho-js/vite Patch
react-babel Patch

Not sure what this means? Click here to learn what changesets are.

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

@github-actions
Copy link
Contributor

github-actions bot commented Oct 1, 2025

Triggered from #246 by @​black7375.

Checking if we can fast forward main (aafcd1c) to selector-util (d9445d5).

Target branch (main):

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

    Feat: `rules.with()` API implement #234

Pull request (selector-util):

commit d9445d541aae580053755bfc3a5f9e07620241d0 (pull_request/selector-util)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Thu Jul 31 00:00:00 2025 +0900

    Feat: `selector()` API implement #236

It is possible to fast forward main (aafcd1c) to selector-util (d9445d5). If you have write access to the target repository, you can add a comment with /fast-forward to fast forward main to selector-util.

@black7375 black7375 requested a review from Copilot October 1, 2025 17:25
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a new selector() utility function to improve TypeScript type inference for computed property names in CSS objects, addressing issue #236.

  • Added a selector() utility function that accepts a string and returns it typed as &
  • Exported the new function from main package entry points
  • Updated changeset to reflect the new feature addition

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/css/src/css/index.ts Implements the core selector() utility function
packages/css/src/index.ts Exports the new selector function from main entry point
packages/css/src/compat.ts Exports selector for compatibility
.changeset/strong-cases-grin.md Updates version bump from patch to minor
.changeset/great-buckets-clean.md Adds changeset documenting the new feature

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +241 to +242

export function selector(selector: string): `&` {
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

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

The function returns a template literal type & but accepts any string. This could lead to runtime issues if the selector doesn't actually contain &. Consider adding validation or documenting that the input should contain & for proper functionality.

Suggested change
export function selector(selector: string): `&` {
/**
* Accepts a selector string that must contain '&' and returns it as a template literal type.
* Throws an error if the selector does not contain '&'.
*/
export function selector(selector: string): `&` {
if (!selector.includes('&')) {
throw new Error("Selector must contain '&'. Received: " + selector);
}

Copilot uses AI. Check for mistakes.
export function mincho$<T>(block: () => T) {
return block();
}

Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

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

The selector function lacks JSDoc documentation. Consider adding documentation to explain its purpose, expected input format, and usage example as shown in the PR description.

Suggested change
/**
* Marks a string as a selector reference for use in style definitions.
*
* @param selector - The selector string to be marked as a reference (e.g., "&:hover").
* @returns The selector string, typed as `&`, for use in style rules.
*
* @example
* ```ts
* const style = {
* [selector("&:hover")]: { color: "red" }
* };
* ```
*/

Copilot uses AI. Check for mistakes.
@black7375
Copy link
Contributor Author

@coderabbitai fullreview

@coderabbitai
Copy link

coderabbitai bot commented Oct 1, 2025

@black7375: I'll conduct a full review of the PR changes now.

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link

coderabbitai bot commented Oct 1, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds a new public API utility selector to packages/css, updates re-exports in index.ts and compat.ts, and records the change via new/updated changeset entries. No other runtime logic changes.

Changes

Cohort / File(s) Summary
Changesets (metadata/docs)
\.changeset/great-buckets-clean.md, \.changeset/strong-cases-grin.md
Add/update changeset entries for @mincho-js/css documenting a minor version bump and the new selector() utility; changes are metadata/documentation only.
CSS public API: new selector + re-exports
packages/css/src/css/index.ts, packages/css/src/index.ts, packages/css/src/compat.ts
Add exported function selector(selector: string): '&' in packages/css/src/css/index.ts; re-export selector from ./css/index.js in packages/css/src/index.ts and packages/css/src/compat.ts alongside existing exports.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Consumer as Consumer Code
  participant Pkg as @mincho-js/css (re-exports)
  participant Impl as css/index.ts (implementation)

  Consumer->>Pkg: import { selector }
  Pkg->>Impl: resolve re-export -> selector
  Consumer->>Impl: selector(":hover &")
  note over Impl: Treat input as typed selector (returns '&' literal-typed string)
  Impl-->>Consumer: typed selector string
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

A rabbit hops through code and leaves a mark,
I carve an ampersand where selectors spark.
Re-exports neat, a tiny tidy feat,
A minor bump, yet tidy and sweet. 🥕🫧

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly identifies the primary enhancement—adding the selector() API—directly tying it to the associated issue, so it accurately summarizes the main change without unrelated details.
Description Check ✅ Passed The description includes a concise explanation of the change in the “## Description” section, references the related issue (#236) under “## Related Issue,” and retains the required headings from the repository template.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aafcd1c and d9445d5.

📒 Files selected for processing (5)
  • .changeset/great-buckets-clean.md (1 hunks)
  • .changeset/strong-cases-grin.md (1 hunks)
  • packages/css/src/compat.ts (1 hunks)
  • packages/css/src/css/index.ts (1 hunks)
  • packages/css/src/index.ts (1 hunks)

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@black7375
Copy link
Contributor Author

@coderabbitai summary

@coderabbitai
Copy link

coderabbitai bot commented Oct 1, 2025

✅ Actions performed

Summary regeneration triggered.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.changeset/strong-cases-grin.md (1)

1-8: Changeset describes unrelated feature.

This changeset documents rules.multiple() API, but the PR implements selector() utility. The content does not match the changes in this PR.

Please ensure this changeset either:

  1. Documents the selector() feature (if this is the intended changeset for this PR), or
  2. Is removed from this PR if it belongs to a different feature branch
🧹 Nitpick comments (2)
.changeset/great-buckets-clean.md (1)

1-9: LGTM! Changeset correctly documents the new feature.

The changeset properly documents the selector() utility addition with appropriate version bump (minor) and clear description.

Note: There's a minor markdown linting issue on line 5 (emphasis instead of heading), but this is a pedantic style concern and can be addressed optionally.

If you want to address the linting issue, change line 5 from:

-**css**
+## css
packages/css/src/css/index.ts (1)

242-244: Consider adding tests for the new function.

The file includes comprehensive tests for other functions, but the new selector() utility has no test coverage.

Add test coverage to verify:

  1. The function returns the input string unchanged
  2. TypeScript correctly infers the & literal type
  3. Integration with css() for computed property names (as shown in PR example)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aafcd1c and d9445d5.

📒 Files selected for processing (5)
  • .changeset/great-buckets-clean.md (1 hunks)
  • .changeset/strong-cases-grin.md (1 hunks)
  • packages/css/src/compat.ts (1 hunks)
  • packages/css/src/css/index.ts (1 hunks)
  • packages/css/src/index.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 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
🪛 markdownlint-cli2 (0.18.1)
.changeset/great-buckets-clean.md

5-5: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

🔇 Additional comments (3)
packages/css/src/css/index.ts (1)

242-244: Consider whether runtime validation is needed.

A past review comment suggested validating that the selector contains &. However, since this appears to be a type-level utility for improving TypeScript inference (not runtime behavior), validation may not be necessary.

Please clarify:

  1. Is this function intended purely for type inference, or does it affect runtime behavior?
  2. Should invalid selectors fail at compile-time, runtime, or is flexibility preferred?

The current implementation (simple type cast) is appropriate for a type utility, but if runtime validation is desired, add the check suggested in the past review.

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

28-28: LGTM! Export correctly added.

The selector export is properly added alongside related CSS utilities, maintaining consistency with the existing export pattern.

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

24-26: LGTM! Compat export correctly added.

The selector export is properly added to the compat entry point. Unlike other exports that provide aliased names (globalCssglobalStyle, cssstyle), selector is exported with its original name, which is appropriate for a new API.

Comment on lines +242 to +244
export function selector(selector: string): `&` {
return selector as `&`;
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Add JSDoc documentation for public API.

The selector() function is part of the public API but lacks documentation explaining its purpose, usage, and expected input format.

Add documentation like:

+/**
+ * Type utility that marks a selector string for use as a computed property name.
+ * Enables proper TypeScript inference when using selectors as object keys.
+ *
+ * @param selector - A CSS selector string (e.g., ".otherClass &", "&:hover")
+ * @returns The selector string, typed as `&` for TypeScript inference
+ *
+ * @example
+ * ```ts
+ * css({
+ *   [selector(".otherClass &")]: {
+ *     color: "red"
+ *   }
+ * });
+ * ```
+ */
 export function selector(selector: string): `&` {
   return selector as `&`;
 }
🤖 Prompt for AI Agents
In packages/css/src/css/index.ts around lines 242 to 244, the public API
function selector lacks JSDoc; add a concise JSDoc block immediately above the
function that explains its purpose (marks a string as a nested selector
reference `&` for use in css() objects), describes the expected input format (a
selector string that contains `&`, e.g. ".otherClass &"), documents the
parameter and return type, and includes a short usage example showing css({
[selector(".otherClass &")]: { color: "red" } }); so consumers understand how to
use it.

@black7375
Copy link
Contributor Author

/fast-forward

@github-actions
Copy link
Contributor

github-actions bot commented Oct 1, 2025

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

Trying to fast forward main (aafcd1c) to selector-util (d9445d5).

Target branch (main):

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

    Feat: `rules.with()` API implement #234

Pull request (selector-util):

commit d9445d541aae580053755bfc3a5f9e07620241d0 (pull_request/selector-util)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Thu Jul 31 00:00:00 2025 +0900

    Feat: `selector()` API implement #236

Fast forwarding main (aafcd1c) to selector-util (d9445d5).

$ git push origin d9445d541aae580053755bfc3a5f9e07620241d0:main
To https://github.com/mincho-js/mincho.git
   aafcd1c..d9445d5  d9445d541aae580053755bfc3a5f9e07620241d0 -> main

@github-actions github-actions bot merged commit d9445d5 into main Oct 1, 2025
12 checks passed
@github-actions github-actions bot deleted the selector-util branch October 1, 2025 17:32
@github-actions github-actions bot mentioned this pull request Sep 28, 2025
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.

2 participants