Skip to content

Commit 63baf62

Browse files
feat: add checkbox component (#63)
1 parent 87d623c commit 63baf62

File tree

7 files changed

+130
-0
lines changed

7 files changed

+130
-0
lines changed

.changeset/eighty-dryers-notice.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@zenml-io/react-component-library": minor
3+
---
4+
5+
add checkbox component

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
},
8686
"dependencies": {
8787
"@radix-ui/react-avatar": "^1.0.4",
88+
"@radix-ui/react-checkbox": "^1.0.4",
8889
"@radix-ui/react-collapsible": "^1.0.3",
8990
"@radix-ui/react-dialog": "^1.0.5",
9091
"@radix-ui/react-dropdown-menu": "^2.0.6",

pnpm-lock.yaml

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Meta } from "@storybook/react";
2+
import { Checkbox } from "./index";
3+
import { StoryObj } from "@storybook/react";
4+
5+
const meta = {
6+
title: "Elements/Checkbox",
7+
component: Checkbox,
8+
argTypes: {
9+
disabled: {
10+
control: "boolean",
11+
defaultValue: false,
12+
description: "if true, the input is disabled"
13+
}
14+
},
15+
parameters: {
16+
layout: "centered"
17+
},
18+
19+
tags: ["autodocs"]
20+
} satisfies Meta<typeof Checkbox>;
21+
22+
export default meta;
23+
24+
type Story = StoryObj<typeof meta>;
25+
26+
export const small: Story = {
27+
name: "Checkbox",
28+
args: {
29+
checked: true,
30+
disabled: false
31+
}
32+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import * as React from "react";
2+
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
3+
import { cn } from "../../utilities";
4+
5+
const CheckboxRoot = CheckboxPrimitive.Root;
6+
7+
const CheckboxIndicator = CheckboxPrimitive.Indicator;
8+
9+
const Checkbox = React.forwardRef<
10+
React.ElementRef<typeof CheckboxPrimitive.Root>,
11+
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
12+
>(({ className, ...props }, ref) => (
13+
<CheckboxPrimitive.Root
14+
ref={ref}
15+
className={cn(
16+
[
17+
"flex h-4 w-4 shrink-0 items-center justify-center rounded-[4px] border border-theme-border-bold bg-theme-surface-primary",
18+
"hover:ring-4 hover:ring-theme-surface-tertiary",
19+
"focus:outline-none focus:ring-4 focus:ring-theme-surface-tertiary",
20+
"data-[state=checked]:border-theme-surface-strong data-[state=checked]:bg-theme-surface-strong data-[state=checked]:active:border-primary-200 data-[state=checked]:active:bg-primary-200",
21+
"active:bg-theme-surface-tertiary",
22+
"disabled:pointer-events-none disabled:border-neutral-300 disabled:data-[state=checked]:border-neutral-300 disabled:data-[state=checked]:bg-neutral-300"
23+
],
24+
className
25+
)}
26+
{...props}
27+
>
28+
<CheckboxPrimitive.Indicator className={cn("flex items-center justify-center text-current")}>
29+
<svg
30+
className="w-2 h-2 fill-white"
31+
viewBox="0 0 12 10"
32+
fill="black"
33+
xmlns="http://www.w3.org/2000/svg"
34+
>
35+
<path
36+
fillRule="evenodd"
37+
clipRule="evenodd"
38+
d="M4.28267 6.34605L2.09696 4.09419L0.666677 5.55738L4.28267 9.28281L11.3333 2.01874L9.91314 0.555542L4.28267 6.34605Z"
39+
/>
40+
</svg>
41+
</CheckboxPrimitive.Indicator>
42+
</CheckboxPrimitive.Root>
43+
));
44+
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
45+
46+
export { Checkbox, CheckboxRoot, CheckboxIndicator };

src/components/Checkbox/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./Checkbox";

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export * from "./Spinner";
1313
export * from "./Tabs";
1414
export * from "./Collapsible";
1515
export * from "./Tooltip";
16+
export * from "./Checkbox";

0 commit comments

Comments
 (0)