From e82c7116bc92698431803487a447d11883ca03f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CSalar?= <“salar.sali97@gmail.com”> Date: Thu, 4 Aug 2022 17:03:11 +0300 Subject: [PATCH] Checkbox component with its stories --- src/components/Checkbox.tsx | 103 ++++++++++++------------------- src/stories/Checkbox.stories.tsx | 14 ----- 2 files changed, 40 insertions(+), 77 deletions(-) diff --git a/src/components/Checkbox.tsx b/src/components/Checkbox.tsx index 96ec6e0..fe69bb0 100644 --- a/src/components/Checkbox.tsx +++ b/src/components/Checkbox.tsx @@ -1,71 +1,48 @@ +import classNames from "classnames"; import React from "react"; +import { ReactComponent as Checkmark } from "assets/svg/check.svg"; -/** - * [*] A Checkbox Component - * - * [*] when the label is clicked => The checkbox will be checked - * - * [*] for each item(row) you have to put the following in App.tsx: - * const [isCheckedA, setIsCheckedA] = useState(true); - const handleChangeA = (e: React.ChangeEvent) => { - setIsCheckedA(e.target.checked); - }; - * - * [*] to create this component, you have to provide the following: - * [1] label - * [2] if the item is checked or not. - * - * [*] A good example will be: -const App: React.FC = () => -{ - const [isCheckedA, setIsCheckedA] = useState(true); - const handleChangeA = (e: React.ChangeEvent) => { - setIsCheckedA(e.target.checked); - }; - - const [isCheckedB, setIsCheckedB] = useState(true); - const handleChangeB = (e: React.ChangeEvent) => { - setIsCheckedB(e.target.checked); - }; - - return ( -
- - - - - -
- ); -}; - -*/ - -interface Props { +export type Props = { + /** + * Control the state of checkbox + */ isChecked: boolean; - handleChange: (event: React.ChangeEvent) => void; - label: string; -} + /** + * An Element next to the checkbox + */ + children?: React.ReactNode; +} & Omit, "type">; -const Checkbox = (props: Props) => { +const Checkbox = ({ children, className, isChecked, ...props }: Props) => { return ( -
- - -
+ ); }; export default Checkbox; diff --git a/src/stories/Checkbox.stories.tsx b/src/stories/Checkbox.stories.tsx index 7faf1bd..054bf99 100644 --- a/src/stories/Checkbox.stories.tsx +++ b/src/stories/Checkbox.stories.tsx @@ -20,14 +20,6 @@ export default { type: "boolean", defaultValue: "false", }, - id: { - type: "string", - defaultValue: "uniqueID", - }, - name: { - type: "string", - defaultValue: "checkbox name", - }, }, } as ComponentMeta; @@ -50,9 +42,3 @@ export const Disabled = Template.bind({}); Disabled.args = { disabled: true, }; - -export const Hovered = bindTemplate({}); -Hovered.args = { - className: "hover:true", - isChecked: false, -};