mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
184 lines
4.9 KiB
TypeScript
184 lines
4.9 KiB
TypeScript
import React from "react";
|
|
import {ComponentStory, ComponentMeta} from "@storybook/react";
|
|
import {checkbox} from "@nextui-org/theme";
|
|
|
|
import {CheckboxGroup, Checkbox, CheckboxGroupProps} from "../src";
|
|
|
|
import {
|
|
CustomWithStyles as CheckboxItemWithStyles,
|
|
CustomWithHooks as CheckboxItemWithHooks,
|
|
} from "./checkbox.stories";
|
|
|
|
export default {
|
|
title: "Inputs/CheckboxGroup",
|
|
component: CheckboxGroup,
|
|
argTypes: {
|
|
color: {
|
|
control: {
|
|
type: "select",
|
|
options: ["neutral", "primary", "secondary", "success", "warning", "danger"],
|
|
},
|
|
},
|
|
radius: {
|
|
control: {
|
|
type: "select",
|
|
options: ["none", "base", "sm", "md", "lg", "xl", "full"],
|
|
},
|
|
},
|
|
size: {
|
|
control: {
|
|
type: "select",
|
|
options: ["xs", "sm", "md", "lg", "xl"],
|
|
},
|
|
},
|
|
lineThrough: {
|
|
control: {
|
|
type: "boolean",
|
|
},
|
|
},
|
|
isDisabled: {
|
|
control: {
|
|
type: "boolean",
|
|
},
|
|
},
|
|
},
|
|
} as ComponentMeta<typeof Checkbox>;
|
|
|
|
const defaultProps = {
|
|
...checkbox.defaultVariants,
|
|
};
|
|
|
|
const Template: ComponentStory<typeof CheckboxGroup> = (args: CheckboxGroupProps) => (
|
|
<CheckboxGroup {...args}>
|
|
<Checkbox value="buenos-aires">Buenos Aires</Checkbox>
|
|
<Checkbox value="sydney">Sydney</Checkbox>
|
|
<Checkbox value="san-francisco">San Francisco</Checkbox>
|
|
<Checkbox value="london">London</Checkbox>
|
|
<Checkbox value="tokyo">Tokyo</Checkbox>
|
|
</CheckboxGroup>
|
|
);
|
|
|
|
export const Default = Template.bind({});
|
|
Default.args = {
|
|
...defaultProps,
|
|
};
|
|
|
|
export const WithLabel = Template.bind({});
|
|
WithLabel.args = {
|
|
label: "Select cities",
|
|
};
|
|
|
|
export const DefaultValue = Template.bind({});
|
|
DefaultValue.args = {
|
|
...defaultProps,
|
|
label: "Select cities",
|
|
defaultValue: ["buenos-aires", "london"],
|
|
};
|
|
|
|
export const Horizontal = Template.bind({});
|
|
Horizontal.args = {
|
|
label: "Select cities",
|
|
orientation: "horizontal",
|
|
};
|
|
|
|
export const IsDisabled = Template.bind({});
|
|
IsDisabled.args = {
|
|
label: "Select cities",
|
|
isDisabled: true,
|
|
};
|
|
|
|
export const LineThrough = Template.bind({});
|
|
LineThrough.args = {
|
|
label: "Select cities",
|
|
lineThrough: true,
|
|
};
|
|
|
|
export const DisableAnimation = Template.bind({});
|
|
DisableAnimation.args = {
|
|
label: "Select cities",
|
|
disableAnimation: true,
|
|
};
|
|
|
|
export const Controlled = () => {
|
|
const [groupSelected, setGroupSelected] = React.useState<string[]>(["buenos-aires", "sydney"]);
|
|
|
|
React.useEffect(() => {
|
|
// eslint-disable-next-line no-console
|
|
console.log("CheckboxGroup ", groupSelected);
|
|
}, [groupSelected]);
|
|
|
|
return (
|
|
<div className="flex flex-row gap-2">
|
|
<CheckboxGroup
|
|
color="warning"
|
|
label="Select cities"
|
|
value={groupSelected}
|
|
onChange={setGroupSelected}
|
|
>
|
|
<Checkbox color="primary" value="buenos-aires">
|
|
Buenos Aires
|
|
</Checkbox>
|
|
<Checkbox value="sydney">Sydney</Checkbox>
|
|
<Checkbox value="london">London</Checkbox>
|
|
<Checkbox value="tokyo">Tokyo</Checkbox>
|
|
</CheckboxGroup>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export const CustomWithStyles = () => {
|
|
const [groupSelected, setGroupSelected] = React.useState<string[]>([]);
|
|
|
|
return (
|
|
<>
|
|
<CheckboxGroup label="Select employees" value={groupSelected} onChange={setGroupSelected}>
|
|
<CheckboxItemWithStyles value="junior" />
|
|
<CheckboxItemWithStyles
|
|
userName="John Doe"
|
|
userProfile={{
|
|
avatar: "https://i.pravatar.cc/300?u=a042581f4e29026707d",
|
|
username: "johndoe",
|
|
url: "#",
|
|
}}
|
|
userRole="Product Designer"
|
|
value="johndoe"
|
|
/>
|
|
<CheckboxItemWithStyles
|
|
userName="Zoey Lang"
|
|
userProfile={{
|
|
avatar: "https://i.pravatar.cc/150?u=a042581f4e29026704d",
|
|
username: "zoeylang",
|
|
url: "#",
|
|
}}
|
|
userRole="Technical Writer"
|
|
value="zoeylang"
|
|
/>
|
|
<CheckboxItemWithStyles
|
|
userName="William Howard"
|
|
userProfile={{
|
|
avatar: "https://i.pravatar.cc/150?u=a048581f4e29026701d",
|
|
username: "william",
|
|
url: "#",
|
|
}}
|
|
userRole="Sales Manager"
|
|
value="william"
|
|
/>
|
|
</CheckboxGroup>
|
|
<p className="mt-4 ml-1 text-neutral-500">Selected: {groupSelected.join(", ")}</p>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export const CustomWithHooks = () => {
|
|
return (
|
|
<CheckboxGroup className="gap-1" label="Select ammenities" orientation="horizontal">
|
|
<CheckboxItemWithHooks value="wifi">Wifi</CheckboxItemWithHooks>
|
|
<CheckboxItemWithHooks value="tv">TV</CheckboxItemWithHooks>
|
|
<CheckboxItemWithHooks value="kitchen">Kitchen</CheckboxItemWithHooks>
|
|
<CheckboxItemWithHooks value="parking">Parking</CheckboxItemWithHooks>
|
|
<CheckboxItemWithHooks value="pool">Pool</CheckboxItemWithHooks>
|
|
<CheckboxItemWithHooks value="gym">Gym</CheckboxItemWithHooks>
|
|
</CheckboxGroup>
|
|
);
|
|
};
|