-
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.
- Loading branch information
Showing
11 changed files
with
153 additions
and
4 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 @@ | ||
--- | ||
"@utima/ui": minor | ||
--- | ||
|
||
Added `Checkbox` component |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,29 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { Checkbox } from './Checkbox'; | ||
import { Label } from '../label/Label'; | ||
|
||
const meta: Meta<typeof Checkbox> = { | ||
component: Checkbox, | ||
tags: ['autodocs'], | ||
title: 'Components/Checkbox', | ||
args: { | ||
id: 'checkbox-id', | ||
disabled: false, | ||
required: false, | ||
}, | ||
decorators: [ | ||
Story => ( | ||
<div className='flex items-center gap-2'> | ||
<Story /> | ||
<Label htmlFor='checkbox-id'>Checkbox</Label> | ||
</div> | ||
), | ||
], | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Checkbox>; | ||
|
||
export const Basic: Story = {}; |
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,46 @@ | ||
import { cva } from 'class-variance-authority'; | ||
|
||
import { twOverrides } from '@/overrides'; | ||
|
||
export const checkboxDef = twOverrides( | ||
{ | ||
checkbox: | ||
'peer transition-all shrink-0 rounded-sm border border-input-border focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 hover:bg-input-border/25', | ||
indicator: 'flex items-center justify-center text-current', | ||
icon: '', | ||
iconSize: { | ||
xs: 'h-2 w-2', | ||
sm: 'h-3 w-3', | ||
md: 'h-4 w-4', | ||
lg: 'h-5 w-5', | ||
}, | ||
variants: { | ||
variant: { | ||
primary: | ||
'hover:data-[state=checked]:bg-primary/80 active:data-[state=checked]:bg-primary/90 data-[state=checked]:bg-primary data-[state=checked]:text-primary-fg data-[state=checked]:border-primary', | ||
secondary: | ||
'hover:data-[state=checked]:bg-secondary/80 active:data-[state=checked]:bg-secondary/90 data-[state=checked]:bg-secondary data-[state=checked]:text-secondary-fg data-[state=checked]:border-secondary', | ||
muted: | ||
'hover:data-[state=checked]:bg-muted/80 active:data-[state=checked]:bg-muted/90 data-[state=checked]:bg-muted data-[state=checked]:text-muted-fg data-[state=checked]border:text-muted', | ||
success: | ||
'hover:data-[state=checked]:bg-success/80 active:data-[state=checked]:bg-success/90 data-[state=checked]:bg-success data-[state=checked]:text-success-fg data-[state=checked]:border-success', | ||
danger: | ||
'hover:data-[state=checked]:bg-danger/80 active:data-[state=checked]:bg-danger/90 data-[state=checked]:bg-danger data-[state=checked]:text-danger-fg data-[state=checked]:border-danger', | ||
warning: | ||
'hover:data-[state=checked]:bg-warning/80 active:data-[state=checked]:bg-warning/90 data-[state=checked]:bg-warning data-[state=checked]:text-warning-fg data-[state=checked]:border-warning', | ||
info: 'hover:data-[state=checked]:bg-info/80 active:data-[state=checked]:bg-info/90 data-[state=checked]:bg-info data-[state=checked]:text-info-fg data-[state=border]:text-info', | ||
}, | ||
size: { | ||
xs: 'h-3 w-3', | ||
sm: 'h-4 w-4', | ||
md: 'h-5 w-5', | ||
lg: 'h-6 w-6', | ||
}, | ||
}, | ||
}, | ||
'checkbox', | ||
); | ||
|
||
export const checkboxStyles = cva(checkboxDef.checkbox, { | ||
variants: checkboxDef.variants, | ||
}); |
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,32 @@ | ||
import { Root, Indicator } from '@radix-ui/react-checkbox'; | ||
import type { VariantProps } from 'class-variance-authority'; | ||
import { CheckIcon } from 'lucide-react'; | ||
import { | ||
forwardRef, | ||
type ElementRef, | ||
type ComponentPropsWithoutRef, | ||
} from 'react'; | ||
|
||
import { cn } from '@/utils'; | ||
|
||
import { checkboxDef, checkboxStyles } from './Checkbox.styles'; | ||
|
||
type CheckboxProps = ComponentPropsWithoutRef<typeof Root> & | ||
Omit<VariantProps<typeof checkboxStyles>, 'thumbSize'>; | ||
|
||
export const Checkbox = forwardRef<ElementRef<typeof Root>, CheckboxProps>( | ||
({ className, variant = 'primary', size = 'md', ...props }, ref) => ( | ||
<Root | ||
ref={ref} | ||
className={cn(checkboxStyles({ variant, size }), className)} | ||
{...props} | ||
> | ||
<Indicator className={cn(checkboxDef.indicator)}> | ||
<CheckIcon | ||
className={cn(checkboxDef.icon, size && checkboxDef.iconSize[size])} | ||
strokeWidth={3} | ||
/> | ||
</Indicator> | ||
</Root> | ||
), | ||
); |
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
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