Skip to content

Conversation

@ariflogs
Copy link
Member

@ariflogs ariflogs commented Feb 20, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a new radio button component with three selectable options.
    • Added multiple radio button examples showcasing different styles, sizes, and variants.
    • Enhanced the navigation menu with a dedicated "Radio" section.
  • Documentation

    • Provided comprehensive documentation with installation instructions, code snippets, and usage examples for the radio component.
  • Style

    • Updated the checkbox styling for a refreshed visual appearance when checked.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 20, 2025

Walkthrough

The changes introduce a new radio button component implemented using Radix UI. A new RadioGroup is added to a demo page, and supporting preview components demonstrate various styles, sizes, and variants. Configuration files have been updated to include type definitions and new entries for the radio component, and navigation as well as documentation now reflect this addition. A new dependency is added and a minor visual tweak was made to the Checkbox styling.

Changes

File(s) Summary
packages/ui/Form/Radio.tsx
packages/ui/Form/index.tsx
Introduced a new radio button component using Radix UI primitives by creating RadioGroupRoot and RadioItem with style variants, and exported it as RadioGroup via the index file.
preview/components/radio-style-default.tsx
preview/components/radio-style-sizes.tsx
preview/components/radio-style-variants.tsx
Added new preview components to demonstrate radio examples: one for the default setup, one showcasing different sizes (small, medium, large), and one displaying style variants (default, outline, solid).
app/(sink)/demo/components/page.tsx Integrated the new RadioGroup component within a page, rendering three radio options ("Option 1", "Option 2", "Option 3") inside a styled container.
config/components.ts
config/navigation.ts
Enhanced the componentConfig by adding type definitions and new entries for the radio component in both the core and examples sections. Updated the navigation configuration to include a new sidebar entry for the Radio component.
content/docs/components/radio.mdx Created new documentation for the Radio component including metadata, installation instructions, API reference, and usage examples.
package.json
packages/ui/Form/Checkbox.tsx
Added the dependency "@radix-ui/react-radio-group": "^1.2.3" and updated the Checkbox styling by changing the checked state background color from bg-primary-400 to bg-primary-500.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Page as Page Component
    participant RadioGroup as RadioGroup Component
    participant RadioItem as Radio Option

    User->>Page: Navigates to demo page
    Page->>RadioGroup: Renders RadioGroup with options
    RadioGroup->>RadioItem: Displays "Option 1", "Option 2", "Option 3"
    User->>RadioItem: Selects an option
    RadioItem-->>RadioGroup: Updates selection state
Loading

Poem

I'm a bunny in a tech field hop,
New radio buttons make my heart go pop!
Options lined up like a carrot row,
With variants and sizes stealing the show.
Docs and configs join my joyful dance,
Leaping through code in a happy, breezy prance!
🐇💻🌟

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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
Contributor

@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: 5

🧹 Nitpick comments (2)
packages/ui/Form/Radio.tsx (1)

8-10: Consider adding distinct styles for variants.

The variant styles are currently empty strings, which means they don't provide any visual differentiation. Consider adding distinct styles for each variant to match the indicator styles.

-      default: "",
-      outline: "",
-      solid: "",
+      default: "data-[state=checked]:bg-primary-500",
+      outline: "bg-white",
+      solid: "data-[state=checked]:bg-black"
app/(sink)/demo/components/page.tsx (1)

45-51: Consider showcasing variants and sizes.

While the basic implementation is good, consider adding examples of different variants and sizes like the Checkbox demo above. This would help demonstrate the component's flexibility.

       <div className="space-x-4">
         <RadioGroup>
           <RadioGroup.Item value="1">Option 1</RadioGroup.Item>
           <RadioGroup.Item value="2">Option 2</RadioGroup.Item>
           <RadioGroup.Item value="3">Option 3</RadioGroup.Item>
         </RadioGroup>
+        <RadioGroup className="space-x-4">
+          <RadioGroup.Item value="outline1" variant="outline">Outline</RadioGroup.Item>
+          <RadioGroup.Item value="solid1" variant="solid">Solid</RadioGroup.Item>
+        </RadioGroup>
+        <RadioGroup className="space-x-4">
+          <RadioGroup.Item value="size1" size="sm">Small</RadioGroup.Item>
+          <RadioGroup.Item value="size2" size="lg">Large</RadioGroup.Item>
+        </RadioGroup>
       </div>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 540ce8a and de0b627.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (11)
  • app/(sink)/demo/components/page.tsx (2 hunks)
  • config/components.ts (4 hunks)
  • config/navigation.ts (1 hunks)
  • content/docs/components/radio.mdx (1 hunks)
  • package.json (1 hunks)
  • packages/ui/Form/Checkbox.tsx (1 hunks)
  • packages/ui/Form/Radio.tsx (1 hunks)
  • packages/ui/Form/index.tsx (1 hunks)
  • preview/components/radio-style-default.tsx (1 hunks)
  • preview/components/radio-style-sizes.tsx (1 hunks)
  • preview/components/radio-style-variants.tsx (1 hunks)
🔇 Additional comments (11)
packages/ui/Form/index.tsx (1)

4-4: LGTM!

The new export follows the established pattern and maintains consistency with other component exports.

packages/ui/Form/Checkbox.tsx (1)

9-9: LGTM! Visual enhancement for checked state.

The darker background color (bg-primary-500) provides better contrast for the checked state.

config/navigation.ts (1)

30-30: LGTM! Navigation entry properly added.

The Radio component entry is correctly placed in alphabetical order with appropriate href and "New" tag.

packages/ui/Form/Radio.tsx (2)

71-73: LGTM! Clean implementation of the radio indicator.

The indicator implementation is well-structured with proper centering and variant application.


78-82: LGTM! Excellent use of compound component pattern.

The Object.assign pattern for creating a compound component is a clean and maintainable approach.

config/components.ts (4)

3-18: LGTM! Type definitions enhance code maintainability.

The added TypeScript type definitions for componentConfig improve type safety and make the code more maintainable.


56-59: LGTM! Radio component configuration follows established patterns.

The radio component entry follows the same structure as other components and is correctly placed in the Form directory.


200-214: LGTM! Radio examples are well-structured.

The radio examples follow the established pattern with default, variants, and sizes, maintaining consistency with other components.


185-189:

✅ Verification successful

Verify if dropdown-style-default should be removed.

The dropdown-style-default component is commented out. Please verify if this was intentional or if it should be completely removed.


🏁 Script executed:

#!/bin/bash
# Check if the dropdown-style-default component is used elsewhere
rg -l "dropdown-style-default"

Length of output: 51


Action: Remove the Unused Dropdown Component Reference

The shell script confirms that the only mention of "dropdown-style-default" is in the commented section of config/components.ts and it isn’t actively used elsewhere in the codebase. Please verify against the product requirements, but if there are no plans to re-enable or use this component in the near future, the commented-out code can be completely removed to clean up the file.

  • File: config/components.ts (lines 185-189)
content/docs/components/radio.mdx (1)

1-8: LGTM! Documentation metadata is complete and well-structured.

The metadata section includes all necessary information: title, description, last updated date, and relevant links.

package.json (1)

18-18: LGTM! Radix UI Radio Group dependency added.

The @radix-ui/react-radio-group dependency is added with version ^1.2.3, consistent with other Radix UI dependencies.

@@ -0,0 +1,20 @@
import { RadioGroup } from "@/packages/ui";

export default function RadioStyleSizes() {
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Rename component to match its purpose.

The component name RadioStyleSizes is misleading as it demonstrates default radio button usage, not size variations.

-export default function RadioStyleSizes() {
+export default function RadioStyleDefault() {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export default function RadioStyleSizes() {
export default function RadioStyleDefault() {

Comment on lines +5 to +18
<RadioGroup>
<div className="flex items-center space-x-2">
<RadioGroup.Item value="1" />
<label htmlFor="1"> Option 1</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroup.Item value="2" />
<label htmlFor="2"> Option 2</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroup.Item value="3" />
<label htmlFor="3"> Option 3</label>
</div>
</RadioGroup>
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance accessibility and add controlled state management.

The radio group implementation needs improvements:

  1. Missing aria-label on the radio group for screen readers
  2. Missing proper label association using id attributes
  3. Missing controlled state management
  4. Missing default selected value
+import { useState } from "react";
+
 export default function RadioStyleDefault() {
+  const [value, setValue] = useState("1");
+
   return (
-    <RadioGroup>
+    <RadioGroup
+      value={value}
+      onValueChange={setValue}
+      aria-label="Default radio options"
+    >
       <div className="flex items-center space-x-2">
-        <RadioGroup.Item value="1" />
-        <label htmlFor="1"> Option 1</label>
+        <RadioGroup.Item id="option1" value="1" />
+        <label htmlFor="option1">Option 1</label>
       </div>
       <div className="flex items-center space-x-2">
-        <RadioGroup.Item value="2" />
-        <label htmlFor="2"> Option 2</label>
+        <RadioGroup.Item id="option2" value="2" />
+        <label htmlFor="option2">Option 2</label>
       </div>
       <div className="flex items-center space-x-2">
-        <RadioGroup.Item value="3" />
-        <label htmlFor="3"> Option 3</label>
+        <RadioGroup.Item id="option3" value="3" />
+        <label htmlFor="option3">Option 3</label>
       </div>
     </RadioGroup>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<RadioGroup>
<div className="flex items-center space-x-2">
<RadioGroup.Item value="1" />
<label htmlFor="1"> Option 1</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroup.Item value="2" />
<label htmlFor="2"> Option 2</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroup.Item value="3" />
<label htmlFor="3"> Option 3</label>
</div>
</RadioGroup>
import { useState } from "react";
export default function RadioStyleDefault() {
const [value, setValue] = useState("1");
return (
<RadioGroup
value={value}
onValueChange={setValue}
aria-label="Default radio options"
>
<div className="flex items-center space-x-2">
<RadioGroup.Item id="option1" value="1" />
<label htmlFor="option1">Option 1</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroup.Item id="option2" value="2" />
<label htmlFor="option2">Option 2</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroup.Item id="option3" value="3" />
<label htmlFor="option3">Option 3</label>
</div>
</RadioGroup>
);
}

Comment on lines +5 to +19
<div className="flex gap-4">
<RadioGroup>
<div className="flex items-center space-x-2">
<RadioGroup.Item value="default" variant="default" />
<label htmlFor="default">Default Style</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroup.Item value="outline" variant="outline" />
<label htmlFor="outline">Outline Style</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroup.Item value="solid" variant="solid" />
<label htmlFor="solid">Solid Style</label>
</div>
</RadioGroup>
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance accessibility and add controlled state management.

The radio group implementation needs improvements:

  1. Missing aria-label on the radio group for screen readers
  2. Missing proper label association using id attributes
  3. Missing controlled state management
  4. Missing default selected value
+import { useState } from "react";
+
 export default function RadioStyleVariants() {
+  const [value, setValue] = useState("default");
+
   return (
     <div className="flex gap-4">
-      <RadioGroup>
+      <RadioGroup
+        value={value}
+        onValueChange={setValue}
+        aria-label="Radio style variants"
+      >
         <div className="flex items-center space-x-2">
-          <RadioGroup.Item value="default" variant="default" />
-          <label htmlFor="default">Default Style</label>
+          <RadioGroup.Item id="style-default" value="default" variant="default" />
+          <label htmlFor="style-default">Default Style</label>
         </div>
         <div className="flex items-center space-x-2">
-          <RadioGroup.Item value="outline" variant="outline" />
-          <label htmlFor="outline">Outline Style</label>
+          <RadioGroup.Item id="style-outline" value="outline" variant="outline" />
+          <label htmlFor="style-outline">Outline Style</label>
         </div>
         <div className="flex items-center space-x-2">
-          <RadioGroup.Item value="solid" variant="solid" />
-          <label htmlFor="solid">Solid Style</label>
+          <RadioGroup.Item id="style-solid" value="solid" variant="solid" />
+          <label htmlFor="style-solid">Solid Style</label>
         </div>
       </RadioGroup>
     </div>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<div className="flex gap-4">
<RadioGroup>
<div className="flex items-center space-x-2">
<RadioGroup.Item value="default" variant="default" />
<label htmlFor="default">Default Style</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroup.Item value="outline" variant="outline" />
<label htmlFor="outline">Outline Style</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroup.Item value="solid" variant="solid" />
<label htmlFor="solid">Solid Style</label>
</div>
</RadioGroup>
import { useState } from "react";
export default function RadioStyleVariants() {
const [value, setValue] = useState("default");
return (
<div className="flex gap-4">
<RadioGroup
value={value}
onValueChange={setValue}
aria-label="Radio style variants"
>
<div className="flex items-center space-x-2">
<RadioGroup.Item id="style-default" value="default" variant="default" />
<label htmlFor="style-default">Default Style</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroup.Item id="style-outline" value="outline" variant="outline" />
<label htmlFor="style-outline">Outline Style</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroup.Item id="style-solid" value="solid" variant="solid" />
<label htmlFor="style-solid">Solid Style</label>
</div>
</RadioGroup>
</div>
);
}

Comment on lines +5 to +23
<div className="flex gap-4">
<RadioGroup>
<div className="flex items-center space-x-2">
<RadioGroup.Item value="sm" size="sm" />
<label htmlFor="sm" className="text-sm">
Small
</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroup.Item value="md" size="md" />
<label htmlFor="md">Medium</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroup.Item value="lg" size="lg" />
<label htmlFor="lg" className="text-lg">
Large Size
</label>
</div>
</RadioGroup>
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance accessibility, add controlled state management, and fix label sizes.

The radio group implementation needs improvements:

  1. Missing aria-label on the radio group for screen readers
  2. Missing proper label association using id attributes
  3. Missing controlled state management
  4. Missing default selected value
  5. Inconsistent label text sizes don't match the radio button sizes
+import { useState } from "react";
+
 export default function RadioStyleSizes() {
+  const [value, setValue] = useState("md");
+
   return (
     <div className="flex gap-4">
-      <RadioGroup>
+      <RadioGroup
+        value={value}
+        onValueChange={setValue}
+        aria-label="Radio size options"
+      >
         <div className="flex items-center space-x-2">
-          <RadioGroup.Item value="sm" size="sm" />
-          <label htmlFor="sm" className="text-sm">
+          <RadioGroup.Item id="size-sm" value="sm" size="sm" />
+          <label htmlFor="size-sm">
             Small
           </label>
         </div>
         <div className="flex items-center space-x-2">
-          <RadioGroup.Item value="md" size="md" />
-          <label htmlFor="md">Medium</label>
+          <RadioGroup.Item id="size-md" value="md" size="md" />
+          <label htmlFor="size-md">Medium</label>
         </div>
         <div className="flex items-center space-x-2">
-          <RadioGroup.Item value="lg" size="lg" />
-          <label htmlFor="lg" className="text-lg">
+          <RadioGroup.Item id="size-lg" value="lg" size="lg" />
+          <label htmlFor="size-lg">
             Large Size
           </label>
         </div>
       </RadioGroup>
     </div>

Note: Removed text size classes from labels as they don't need to match the radio button sizes. The visual hierarchy should be maintained through the radio buttons themselves.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<div className="flex gap-4">
<RadioGroup>
<div className="flex items-center space-x-2">
<RadioGroup.Item value="sm" size="sm" />
<label htmlFor="sm" className="text-sm">
Small
</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroup.Item value="md" size="md" />
<label htmlFor="md">Medium</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroup.Item value="lg" size="lg" />
<label htmlFor="lg" className="text-lg">
Large Size
</label>
</div>
</RadioGroup>
import { useState } from "react";
export default function RadioStyleSizes() {
const [value, setValue] = useState("md");
return (
<div className="flex gap-4">
<RadioGroup
value={value}
onValueChange={setValue}
aria-label="Radio size options"
>
<div className="flex items-center space-x-2">
<RadioGroup.Item id="size-sm" value="sm" size="sm" />
<label htmlFor="size-sm">
Small
</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroup.Item id="size-md" value="md" size="md" />
<label htmlFor="size-md">Medium</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroup.Item id="size-lg" value="lg" size="lg" />
<label htmlFor="size-lg">
Large Size
</label>
</div>
</RadioGroup>
</div>
);
}

Comment on lines +18 to +20
```sh
npm install @radix-ui/react-radio-group class-variance-authority
```
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify dependency versions in installation instructions.

Please ensure that the dependency versions in the installation instructions match those in package.json.


🏁 Script executed:

#!/bin/bash
# Extract versions from package.json
echo "Versions in package.json:"
jq -r '.dependencies["@radix-ui/react-radio-group"], .dependencies["class-variance-authority"]' package.json

Length of output: 185


Update installation instructions to include explicit dependency versions

The installation snippet in content/docs/components/radio.mdx (lines 18-20) currently lacks explicit versions. Our verification shows that the dependencies in package.json are:

  • @radix-ui/react-radio-group: ^1.2.3
  • class-variance-authority: ^0.7.0

For consistency and clarity, please update the snippet to:

npm install @radix-ui/react-radio-group@^1.2.3 class-variance-authority@^0.7.0

@ariflogs ariflogs merged commit b1bef6d into main Feb 20, 2025
1 check passed
This was referenced Mar 1, 2025
@coderabbitai coderabbitai bot mentioned this pull request Mar 16, 2025
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