Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eighty-dryers-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zenml-io/react-component-library": minor
---

add checkbox component
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
},
"dependencies": {
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-collapsible": "^1.0.3",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
Expand Down
44 changes: 44 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions src/components/Checkbox/Checkbox.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Meta } from "@storybook/react";
import { Checkbox } from "./index";
import { StoryObj } from "@storybook/react";

const meta = {
title: "Elements/Checkbox",
component: Checkbox,
argTypes: {
disabled: {
control: "boolean",
defaultValue: false,
description: "if true, the input is disabled"
}
},
parameters: {
layout: "centered"
},

tags: ["autodocs"]
} satisfies Meta<typeof Checkbox>;

export default meta;

type Story = StoryObj<typeof meta>;

export const small: Story = {
name: "Checkbox",
args: {
checked: true,
disabled: false
}
};
46 changes: 46 additions & 0 deletions src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as React from "react";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { cn } from "../../utilities";

const CheckboxRoot = CheckboxPrimitive.Root;

const CheckboxIndicator = CheckboxPrimitive.Indicator;

const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
[
"flex h-4 w-4 shrink-0 items-center justify-center rounded-[4px] border border-theme-border-bold bg-theme-surface-primary",
"hover:ring-4 hover:ring-theme-surface-tertiary",
"focus:outline-none focus:ring-4 focus:ring-theme-surface-tertiary",
"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",
"active:bg-theme-surface-tertiary",
"disabled:pointer-events-none disabled:border-neutral-300 disabled:data-[state=checked]:border-neutral-300 disabled:data-[state=checked]:bg-neutral-300"
],
className
)}
{...props}
>
<CheckboxPrimitive.Indicator className={cn("flex items-center justify-center text-current")}>
<svg
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to hard embed the svg here, in case we need a more flexible usecase in the future, I also exported the base primitives CheckboxRoot and CheckboxIndicator

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for the moment it is enough embedding the svg but we have to find a way to "componentise" the icons. 🤔

className="w-2 h-2 fill-white"
viewBox="0 0 12 10"
fill="black"
xmlns="http://www.w3.org/2000/svg"
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M4.28267 6.34605L2.09696 4.09419L0.666677 5.55738L4.28267 9.28281L11.3333 2.01874L9.91314 0.555542L4.28267 6.34605Z"
/>
</svg>
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.displayName;

export { Checkbox, CheckboxRoot, CheckboxIndicator };
1 change: 1 addition & 0 deletions src/components/Checkbox/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Checkbox";
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export * from "./Spinner";
export * from "./Tabs";
export * from "./Collapsible";
export * from "./Tooltip";
export * from "./Checkbox";