-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, { useState } from "react"; | ||
|
||
export interface CheckBoxButtonProps { | ||
name: string; | ||
onClick: () => void; | ||
} | ||
|
||
export const CheckBoxButton = ( | ||
props: React.InputHTMLAttributes<HTMLButtonElement> & CheckBoxButtonProps | ||
) => { | ||
const { name, onClick } = props; | ||
const [checked, setChecked] = useState(false); | ||
|
||
const handleClick = () => { | ||
setChecked(!checked); | ||
onClick(); | ||
}; | ||
|
||
return ( | ||
<div className="flex items-center pb-0.5 "> | ||
<button | ||
className="flex items-center justify-center w-3.5 h-3.5 rounded border-2 border-c_accent focus:outline-none" | ||
onClick={handleClick} | ||
> | ||
<span | ||
className={`block w-2 h-2 rounded ${ | ||
checked ? "bg-c_accent" : "bg-transparent" | ||
} transform transition-transform duration-200 ease-in-out`} | ||
> | ||
{checked && ( | ||
<span className="absolute block w-full h-full rounded-sm bg-c_accent"></span> | ||
)} | ||
</span> | ||
</button> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { | ||
CheckBoxButton, | ||
CheckBoxButtonProps, | ||
} from "../components/button/checkBoxButton"; | ||
import React from "react"; | ||
import { StoryFn as Story, Meta } from "@storybook/react"; | ||
|
||
export default { | ||
title: "Components/CheckBoxButton", | ||
component: CheckBoxButton, | ||
parameters: { | ||
layout: "centered", | ||
}, | ||
} as Meta; | ||
|
||
const Template: Story<CheckBoxButtonProps> = (args) => ( | ||
<CheckBoxButton {...args} /> | ||
); | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { | ||
name: "checkbox", | ||
}; | ||
const Templatee: Story<CheckBoxButtonProps> = (args) => ( | ||
<div> | ||
<CheckBoxButton {...args} /> | ||
<CheckBoxButton {...args} /> | ||
</div> | ||
); | ||
|
||
export const Pair = Templatee.bind({}); | ||
Pair.args = { | ||
name: "checkbox", | ||
}; |