-
-
Notifications
You must be signed in to change notification settings - Fork 45
✅ Radio #39
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
Conversation
WalkthroughThe changes introduce a new radio button component implemented using Radix UI. A new Changes
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
Poem
✨ Finishing Touches
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis 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
componentConfigimprove 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.tsand 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-groupdependency 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() { | |||
There was a problem hiding this comment.
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.
| export default function RadioStyleSizes() { | |
| export default function RadioStyleDefault() { |
| <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> |
There was a problem hiding this comment.
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:
- Missing
aria-labelon the radio group for screen readers - Missing proper label association using
idattributes - Missing controlled state management
- 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.
| <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> | |
| ); | |
| } |
| <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> |
There was a problem hiding this comment.
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:
- Missing
aria-labelon the radio group for screen readers - Missing proper label association using
idattributes - Missing controlled state management
- 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.
| <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> | |
| ); | |
| } |
| <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> |
There was a problem hiding this comment.
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:
- Missing
aria-labelon the radio group for screen readers - Missing proper label association using
idattributes - Missing controlled state management
- Missing default selected value
- 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.
| <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> | |
| ); | |
| } |
| ```sh | ||
| npm install @radix-ui/react-radio-group class-variance-authority | ||
| ``` |
There was a problem hiding this comment.
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.jsonLength 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.3class-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
Summary by CodeRabbit
New Features
Documentation
Style