forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckbox.tsx
More file actions
53 lines (48 loc) 路 1.67 KB
/
Copy pathCheckbox.tsx
File metadata and controls
53 lines (48 loc) 路 1.67 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use client';
import { InputHTMLAttributes } from 'react';
interface CheckboxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type' | 'size'> {
label?: string;
}
export function Checkbox({ label, id, disabled, className = '', ...props }: CheckboxProps) {
const inputId = id ?? label?.toLowerCase().replace(/\s+/g, '-');
return (
<label
htmlFor={inputId}
className={`inline-flex items-center gap-2 cursor-pointer select-none ${disabled ? 'opacity-50 cursor-not-allowed' : ''} ${className}`}
>
<input
id={inputId}
type="checkbox"
disabled={disabled}
className="h-4 w-4 rounded border-gray-300 text-brand accent-brand focus:ring-2 focus:ring-brand dark:border-gray-600"
{...props}
/>
{label && (
<span className="text-sm text-gray-700 dark:text-gray-300">{label}</span>
)}
</label>
);
}
interface RadioProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type'> {
label?: string;
}
export function Radio({ label, id, disabled, className = '', ...props }: RadioProps) {
const inputId = id ?? label?.toLowerCase().replace(/\s+/g, '-');
return (
<label
htmlFor={inputId}
className={`inline-flex items-center gap-2 cursor-pointer select-none ${disabled ? 'opacity-50 cursor-not-allowed' : ''} ${className}`}
>
<input
id={inputId}
type="radio"
disabled={disabled}
className="h-4 w-4 border-gray-300 text-brand accent-brand focus:ring-2 focus:ring-brand dark:border-gray-600"
{...props}
/>
{label && (
<span className="text-sm text-gray-700 dark:text-gray-300">{label}</span>
)}
</label>
);
}