-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #973 from tszhong0411/pack-32-add-radio-group
Add Radio Group
- Loading branch information
Showing
8 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@tszhong0411/ui': patch | ||
--- | ||
|
||
Add Radio Group |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
title: Radio Group | ||
description: A set of checkable buttons—known as radio buttons—where no more than one of the buttons can be checked at a time. | ||
--- | ||
|
||
<ComponentPreview name='radio-group/radio-group' /> | ||
|
||
## Usage | ||
|
||
```tsx | ||
import { Label, RadioGroup, RadioGroupItem } from '@tszhong0411/ui' | ||
``` | ||
|
||
```tsx | ||
<RadioGroup defaultValue='option-one'> | ||
<div className='flex items-center space-x-2'> | ||
<RadioGroupItem value='option-one' id='option-one' /> | ||
<Label htmlFor='option-one'>Option One</Label> | ||
</div> | ||
<div className='flex items-center space-x-2'> | ||
<RadioGroupItem value='option-two' id='option-two' /> | ||
<Label htmlFor='option-two'>Option Two</Label> | ||
</div> | ||
</RadioGroup> | ||
``` |
22 changes: 22 additions & 0 deletions
22
apps/docs/src/components/demos/radio-group/radio-group.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Label, RadioGroup, RadioGroupItem } from '@tszhong0411/ui' | ||
|
||
const RadioGroupDemo = () => { | ||
return ( | ||
<RadioGroup defaultValue='comfortable'> | ||
<div className='flex items-center space-x-2'> | ||
<RadioGroupItem value='default' id='r1' /> | ||
<Label htmlFor='r1'>Default</Label> | ||
</div> | ||
<div className='flex items-center space-x-2'> | ||
<RadioGroupItem value='comfortable' id='r2' /> | ||
<Label htmlFor='r2'>Comfortable</Label> | ||
</div> | ||
<div className='flex items-center space-x-2'> | ||
<RadioGroupItem value='compact' id='r3' /> | ||
<Label htmlFor='r3'>Compact</Label> | ||
</div> | ||
</RadioGroup> | ||
) | ||
} | ||
|
||
export default RadioGroupDemo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use client' | ||
|
||
import * as RadioGroupPrimitive from '@radix-ui/react-radio-group' | ||
import { cn } from '@tszhong0411/utils' | ||
import { CircleIcon } from 'lucide-react' | ||
|
||
type RadioGroupProps = React.ComponentProps<typeof RadioGroupPrimitive.Root> | ||
|
||
export const RadioGroup = (props: RadioGroupProps) => { | ||
const { className, ...rest } = props | ||
|
||
return <RadioGroupPrimitive.Root className={cn('grid gap-2', className)} {...rest} /> | ||
} | ||
|
||
type RadioGroupItemProps = React.ComponentProps<typeof RadioGroupPrimitive.Item> | ||
|
||
export const RadioGroupItem = (props: RadioGroupItemProps) => { | ||
const { className, ...rest } = props | ||
|
||
return ( | ||
<RadioGroupPrimitive.Item | ||
className={cn( | ||
'border-primary text-primary ring-offset-background aspect-square size-4 rounded-full border', | ||
'focus:outline-none', | ||
'focus-visible:ring-ring focus-visible:ring-2 focus-visible:ring-offset-2', | ||
'disabled:cursor-not-allowed disabled:opacity-50', | ||
className | ||
)} | ||
{...rest} | ||
> | ||
<RadioGroupPrimitive.Indicator className='flex items-center justify-center'> | ||
<CircleIcon className='size-2.5 fill-current text-current' /> | ||
</RadioGroupPrimitive.Indicator> | ||
</RadioGroupPrimitive.Item> | ||
) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.