nextui/packages/components/checkbox/stories/checkbox.stories.tsx
Junior Garcia d794225cb7
Pr/1224 (#1301)
* chore: storybook migration

* chore: storybook migration

* chore: storybook migration

* fix: moved options in arg types out of control

* fix: fixed type issues

* fix: renamed sb:start script to start

* chore: migrate csf 2 to csf 3

* fix: removed storybook build from root build script

* chore: kick

* chore(root): pnpm lock updated

* chore(root): new changeset

---------

Co-authored-by: Jakob Guddas <github@jguddas.de>
2023-08-06 15:04:26 -03:00

136 lines
2.5 KiB
TypeScript

import React from "react";
import {Meta} from "@storybook/react";
import {checkbox} from "@nextui-org/theme";
import {CloseIcon} from "@nextui-org/shared-icons";
import {Checkbox, CheckboxIconProps, CheckboxProps} from "../src";
export default {
title: "Components/Checkbox",
component: Checkbox,
argTypes: {
color: {
control: {
type: "select",
},
options: ["default", "primary", "secondary", "success", "warning", "danger"],
},
radius: {
control: {
type: "select",
},
options: ["none", "sm", "md", "lg", "full"],
},
size: {
control: {
type: "select",
},
options: ["sm", "md", "lg"],
},
lineThrough: {
control: {
type: "boolean",
},
},
isDisabled: {
control: {
type: "boolean",
},
},
},
} as Meta<typeof Checkbox>;
const defaultProps: CheckboxProps = {
...checkbox.defaultVariants,
children: "Option",
};
const ControlledTemplate = (args: CheckboxProps) => {
const [selected, setSelected] = React.useState<boolean>(true);
React.useEffect(() => {
// eslint-disable-next-line no-console
console.log("Checkbox ", selected);
}, [selected]);
return (
<div className="flex flex-col gap-2">
<Checkbox isSelected={selected} onValueChange={setSelected} {...args}>
Subscribe (controlled)
</Checkbox>
<p className="text-default-500">Selected: {selected ? "true" : "false"}</p>
</div>
);
};
export const Default = {
args: {
...defaultProps,
},
};
export const IsDisabled = {
args: {
...defaultProps,
isDisabled: true,
},
};
export const DefaultSelected = {
args: {
...defaultProps,
defaultSelected: true,
},
};
export const CustomIconNode = {
args: {
...defaultProps,
icon: <CloseIcon />,
},
};
export const CustomIconFunction = {
args: {
...defaultProps,
// eslint-disable-next-line react/display-name
icon: (props: CheckboxIconProps) => <CloseIcon {...props} />,
},
};
export const AlwaysSelected = {
args: {
...defaultProps,
isSelected: true,
},
};
export const IsIndeterminate = {
args: {
...defaultProps,
isIndeterminate: true,
},
};
export const LineThrough = {
args: {
...defaultProps,
lineThrough: true,
},
};
export const DisableAnimation = {
args: {
...defaultProps,
disableAnimation: true,
},
};
export const Controlled = {
render: ControlledTemplate,
args: {
...defaultProps,
},
};