Skip to content

Commit

Permalink
Update: CheckboxGroup & RadioGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
tuzkituan committed Oct 25, 2023
1 parent a2e0c8f commit 070d411
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 32 deletions.
16 changes: 1 addition & 15 deletions lib/components/checkbox/Checkbox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Meta, StoryObj } from "@storybook/react";
import { Checkbox } from "./Checkbox";

const meta = {
title: "ATOMS/Checkbox",
title: "ATOMS/Checkbox/Checkbox",
component: Checkbox,
tags: ["autodocs"],
argTypes: {
Expand Down Expand Up @@ -60,17 +60,3 @@ export const Disabled: Story = {
isDisabled: true,
},
};

export const CheckboxGroup = () => {
return (
<Checkbox.Group
value={["1"]}
layout="horizontal"
onChange={(val) => console.log("checked: ", val)}
>
<Checkbox value="1">Option A</Checkbox>
<Checkbox value="2">Option B</Checkbox>
<Checkbox value="3">Option C</Checkbox>
</Checkbox.Group>
);
};
5 changes: 1 addition & 4 deletions lib/components/checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const Checkbox = (props: ICheckbox) => {
);
};

const CheckboxGroup = ({
export const CheckboxGroup = ({
children,
defaultValue,
value,
Expand Down Expand Up @@ -158,6 +158,3 @@ const CheckboxGroup = ({
</div>
);
};

Checkbox.Group = CheckboxGroup;
export default Checkbox;
50 changes: 50 additions & 0 deletions lib/components/checkbox/CheckboxGroup.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type { Meta, StoryObj } from "@storybook/react";

import { ICheckboxGroup } from "./Checkbox.types";
import { Checkbox, CheckboxGroup } from "./Checkbox";

const meta = {
title: "ATOMS/Checkbox/CheckboxGroup",
component: CheckboxGroup,
tags: ["autodocs"],
argTypes: {
layout: {
options: ["horizontal", "vertical"],
control: { type: "radio" },
},
defaultValue: {
control: { type: "text" },
},
spacing: {
control: { type: "number" },
},
value: {
control: { type: "text" },
},
onChange: {
action: "onChange",
},
},
} satisfies Meta<typeof CheckboxGroup>;

export default meta;
type Story = StoryObj<ICheckboxGroup>;

const radioGroupArgs: ICheckboxGroup = {
value: ["1"],
layout: "horizontal",
onChange: (val) => console.log("checked: ", val),
};

export const Primary: Story = (props: ICheckboxGroup) => {
const all = { ...radioGroupArgs, ...props };
return (
<CheckboxGroup {...all}>
<Checkbox value="1">Option A</Checkbox>
<Checkbox value="2">Option B</Checkbox>
<Checkbox value="3">Option C</Checkbox>
</CheckboxGroup>
);
};

Primary.args = radioGroupArgs;
20 changes: 13 additions & 7 deletions lib/components/radio/Radio.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { Meta, StoryObj } from "@storybook/react";

import { Radio } from "./Radio";
import { IRadioGroup } from "./Radio.types";

const meta = {
title: "ATOMS/Radio",
title: "ATOMS/Radio/Radio",
component: Radio,
tags: ["autodocs"],
argTypes: {
Expand Down Expand Up @@ -60,16 +61,21 @@ export const Disabled: Story = {
},
};

export const RadioGroup = () => {
const radioGroupArgs: IRadioGroup = {
value: "1",
layout: "horizontal",
onChange: (val) => console.log("checked: ", val),
};

export const RadioGroup = (props: IRadioGroup) => {
const all = { ...radioGroupArgs, ...props };
return (
<Radio.Group
value="1"
layout="horizontal"
onChange={(val) => console.log("checked: ", val)}
>
<Radio.Group {...all}>
<Radio value="1">Option A</Radio>
<Radio value="2">Option B</Radio>
<Radio value="3">Option C</Radio>
</Radio.Group>
);
};

RadioGroup.args = radioGroupArgs;
5 changes: 1 addition & 4 deletions lib/components/radio/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const Radio = (props: IRadio) => {
);
};

const RadioGroup = ({
export const RadioGroup = ({
children,
defaultValue,
value,
Expand Down Expand Up @@ -142,6 +142,3 @@ const RadioGroup = ({
</div>
);
};

Radio.Group = RadioGroup;
export default Radio;
50 changes: 50 additions & 0 deletions lib/components/radio/RadioGroup.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type { Meta, StoryObj } from "@storybook/react";

import { IRadioGroup } from "./Radio.types";
import { Radio, RadioGroup } from "./Radio";

const meta = {
title: "ATOMS/Radio/RadioGroup",
component: RadioGroup,
tags: ["autodocs"],
argTypes: {
layout: {
options: ["horizontal", "vertical"],
control: { type: "radio" },
},
defaultValue: {
control: { type: "text" },
},
spacing: {
control: { type: "number" },
},
value: {
control: { type: "text" },
},
onChange: {
action: "onChange",
},
},
} satisfies Meta<typeof RadioGroup>;

export default meta;
type Story = StoryObj<IRadioGroup>;

const radioGroupArgs: IRadioGroup = {
value: "1",
layout: "horizontal",
onChange: (val) => console.log("checked: ", val),
};

export const Primary: Story = (props: IRadioGroup) => {
const all = { ...radioGroupArgs, ...props };
return (
<RadioGroup {...all}>
<Radio value="1">Option A</Radio>
<Radio value="2">Option B</Radio>
<Radio value="3">Option C</Radio>
</RadioGroup>
);
};

Primary.args = radioGroupArgs;
2 changes: 1 addition & 1 deletion lib/customization/styles/components/Checkbox.styles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cva } from "class-variance-authority";

const container = cva(["flex", "items-center", "w-fit", "gap-3"]);
const container = cva(["flex", "items-center", "w-fit", "gap-2"]);
const input = cva(
[
"bg-primary-background",
Expand Down
2 changes: 1 addition & 1 deletion lib/customization/styles/components/Radio.styles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cva } from "class-variance-authority";

const container = cva(["flex", "items-center", "w-fit", "gap-3"]);
const container = cva(["flex", "items-center", "w-fit", "gap-2"]);
const input = cva(
[
"bg-primary-background",
Expand Down

0 comments on commit 070d411

Please sign in to comment.