-
Notifications
You must be signed in to change notification settings - Fork 0
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 #10 from Bland-UI/feat/radio-button
Feat/radio button
- Loading branch information
Showing
8 changed files
with
103 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,6 @@ | ||
--- | ||
"@blandui/blandui-react": patch | ||
"@blandui/blandui": patch | ||
--- | ||
|
||
RadioButton component added |
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,29 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { RadioButton } from '@blandui/blandui-react'; | ||
|
||
const meta: Meta<typeof RadioButton> = { | ||
title: 'Component/RadioButton', | ||
component: RadioButton, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof RadioButton>; | ||
|
||
export const Default: Story = { | ||
render: () => ( | ||
<div className="flex flex-col gap-lg items-start justify-center"> | ||
<div className="flex gap-md"> | ||
<RadioButton radioSize="sm" checked={false} /> | ||
<RadioButton radioSize="sm" checked={false} disabled /> | ||
<RadioButton radioSize="sm" checked /> | ||
<RadioButton radioSize="sm" checked disabled /> | ||
</div> | ||
<div className="flex gap-md"> | ||
<RadioButton radioSize="md" checked={false} /> | ||
<RadioButton radioSize="md" checked={false} disabled /> | ||
<RadioButton radioSize="md" checked /> | ||
<RadioButton radioSize="md" checked disabled /> | ||
</div> | ||
</div> | ||
), | ||
}; |
50 changes: 50 additions & 0 deletions
50
packages/blandui-react/src/components/RadioButton/RadioButton.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,50 @@ | ||
import { ComponentProps, forwardRef } from 'react'; | ||
import cn from '../../utils/cn'; | ||
|
||
export interface RadioButtonProps extends ComponentProps<'input'> { | ||
className?: string; | ||
radioSize?: 'sm' | 'md'; | ||
} | ||
|
||
export const RadioButton = forwardRef<HTMLInputElement, RadioButtonProps>(( | ||
{ | ||
className, | ||
radioSize = 'sm', | ||
...props | ||
}, | ||
ref, | ||
) => { | ||
const baseCn = ` | ||
not:checked:bg-radio-btn not:checked:border-radio-btn | ||
checked:text-radio-btn-checked | ||
focus:ring-2 | ||
focus:ring-offset-0 checked:focus:ring-offset-1 | ||
focus:ring-radio-btn-focused | ||
hover:ring-2 | ||
hover:ring-offset-0 checked:hover:ring-offset-1 | ||
hover:ring-radio-btn-hover | ||
disabled:hover:ring-0 | ||
disabled:border-radio-btn-disabled | ||
checked:disabled:border-transparent checked:disabled:text-radio-btn-checked-disabled | ||
`; | ||
|
||
const radioSizeClasses = { | ||
sm: 'w-4 h-4', | ||
md: 'w-5 h-5', | ||
}; | ||
|
||
const radioButtonCn = cn( | ||
baseCn, | ||
radioSizeClasses[radioSize], | ||
className, | ||
); | ||
|
||
return ( | ||
<input type="radio" className={radioButtonCn} ref={ref} {...props}/> | ||
); | ||
}); | ||
|
||
RadioButton.displayName = 'Button'; |
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,2 @@ | ||
export { RadioButton } from './RadioButton'; | ||
export type { RadioButtonProps } from './RadioButton'; |
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