From a72da8ca6bcd4bb035128414d2fad338b1deaf97 Mon Sep 17 00:00:00 2001 From: rina Date: Sun, 22 Sep 2024 12:59:30 +0300 Subject: [PATCH] checkbox component --- src/app/new-project/page.tsx | 5 ++ src/components/checkbox/checkbox.tsx | 72 ++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 src/components/checkbox/checkbox.tsx diff --git a/src/app/new-project/page.tsx b/src/app/new-project/page.tsx index 56ba922..8c06d51 100644 --- a/src/app/new-project/page.tsx +++ b/src/app/new-project/page.tsx @@ -5,6 +5,7 @@ import { Input } from '@/components/input/input'; import { SitePage } from '@/components/site/site-page'; import { classnames } from '@/utils/classnames'; import { useState } from 'react'; +import Checkbox from '@/components/checkbox/checkbox'; const form = classnames(['flex w-[100%] flex-col items-center justify-between gap-[40px]']); @@ -13,6 +14,7 @@ const forms = classnames(['flex w-[50%] flex-col items-center justify-between ga const NewProject = () => { const [value, setValue] = useState('אהרון'); const [value2, setValue2] = useState('וויינרוב'); + const [value3, setValue3] = useState(false); return (
@@ -26,6 +28,9 @@ const NewProject = () => { error="שדה חובה" /> + + + diff --git a/src/components/checkbox/checkbox.tsx b/src/components/checkbox/checkbox.tsx new file mode 100644 index 0000000..50cc8e5 --- /dev/null +++ b/src/components/checkbox/checkbox.tsx @@ -0,0 +1,72 @@ +import { classnames } from '@/utils/classnames'; +import React, { useState } from 'react'; + +export const checkboxContainerClasses = classnames([ + 'flex', + 'justify-end', + 'items-center', + 'flex-row-reverse', + 'w-full' +]); + +export const checkboxClasses = (props: { size?: 'small' | 'medium' | 'large' }) => + classnames([ + props.size === 'small' && 'h-[10px] text-[1.4rem]', + props.size === 'medium' && 'h-[20px] text-[1.5rem]', + props.size === 'large' && 'h-[30px] text-[1.7rem]', + 'bg-white text-primary', + 'transition', + 'focus-visible:border-primary', + 'mr-[4px]' + ]); + +export const labelClasses = classnames([ + 'ml-[8px]', + 'bg-white text-primary', + 'cursor-pointer', + 'hover:text-primary500', + 'transition-all duration-200 ease-in-out' +]); + +export interface CheckboxProps { + clear?: boolean; + size?: 'small' | 'medium' | 'large'; + className?: string; + label: string; + checked?: boolean; + onChange?: (checked: boolean) => void; +} + +const Checkbox: React.FC = ({ + size, + label, + checked = false, + onChange, + className +}) => { + const [isChecked, setIsChecked] = useState(checked); + + const handleCheckboxChange = (event: React.ChangeEvent) => { + const newChecked = event.target.checked; + setIsChecked(newChecked); + if (onChange) { + onChange(newChecked); + } + }; + + return ( + + ); +}; + +export default Checkbox;