-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckbox.tsx
More file actions
38 lines (33 loc) · 1.13 KB
/
checkbox.tsx
File metadata and controls
38 lines (33 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use client'
import { useState } from 'react'
import toast from 'react-hot-toast'
import type { FormColumn } from '@/types'
interface CheckboxProps {
column: FormColumn
}
export const Checkbox = ({ column }: CheckboxProps): JSX.Element => {
const [isValid, setIsValid] = useState(true)
return (
<div className='flex w-full flex-col items-start justify-start'>
<label className='relative flex w-full cursor-pointer select-none flex-row-reverse items-center justify-end'>
<p className='ml-2 text-body-1 text-black'>{column.name}</p>
<input
type='checkbox'
name={column.name}
required={column.required}
className='size-4 rounded-md'
onInvalid={(e) => {
e.preventDefault()
setIsValid(false)
toast.error('กรุณายอมรับข้อตกลง', { id: 'invalid' })
}}
/>
{!isValid ? (
<p className='absolute -bottom-10 my-2 w-full text-body-2 italic text-red-600'>
จำเป็นต้องยอมรับ
</p>
) : null}
</label>
</div>
)
}