-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
Checkbox
component & story (#1487)
* feat: `Checkbox` component & story * fix: fine-tune styling & use blue color for now
- Loading branch information
1 parent
4c9a241
commit a1fa61d
Showing
4 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
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,33 @@ | ||
import { Meta, StoryObj } from "@storybook/react" | ||
import { Checkbox, CheckboxProps } from "./Checkbox" | ||
import { Label } from "./Label" | ||
|
||
const CheckboxExample = (props: CheckboxProps) => { | ||
return ( | ||
<div className="flex items-center space-x-2"> | ||
<Checkbox id="terms" {...props} /> | ||
<Label htmlFor="terms">Accept terms and conditions</Label> | ||
</div> | ||
) | ||
} | ||
|
||
const meta: Meta<typeof CheckboxExample> = { | ||
title: "Design system/Checkbox", | ||
component: CheckboxExample, | ||
} | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof CheckboxExample> | ||
|
||
export const Default: Story = { | ||
args: { | ||
disabled: false, | ||
}, | ||
argTypes: { | ||
disabled: { | ||
type: "boolean", | ||
control: "boolean", | ||
}, | ||
}, | ||
} |
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,30 @@ | ||
"use client" | ||
|
||
import * as CheckboxPrimitive from "@radix-ui/react-checkbox" | ||
|
||
import { cn } from "@/lib/utils" | ||
import { Check } from "@phosphor-icons/react/dist/ssr" | ||
import { ComponentPropsWithoutRef, ElementRef, forwardRef } from "react" | ||
|
||
export type CheckboxProps = ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root> | ||
|
||
const Checkbox = forwardRef< | ||
ElementRef<typeof CheckboxPrimitive.Root>, | ||
CheckboxProps | ||
>(({ className, ...props }, ref) => ( | ||
<CheckboxPrimitive.Root | ||
ref={ref} | ||
className={cn( | ||
"relative size-4 shrink-0 rounded-sm border-2 border-border focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:border-0 data-[state=checked]:bg-info data-[state=checked]:text-info-foreground [&~label]:cursor-pointer [&~label]:disabled:cursor-not-allowed [&~label]:disabled:opacity-50", | ||
className | ||
)} | ||
{...props} | ||
> | ||
<CheckboxPrimitive.Indicator className="absolute inset-0 flex items-center justify-center rounded-full bg-info"> | ||
<Check className="size-[75%]" weight="bold" /> | ||
</CheckboxPrimitive.Indicator> | ||
</CheckboxPrimitive.Root> | ||
)) | ||
Checkbox.displayName = CheckboxPrimitive.Root.displayName | ||
|
||
export { Checkbox } |