mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-15 13:43:39 +01:00
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import classNames from 'classnames';
|
|
import { Icon } from './Icon';
|
|
import { HStack } from './Stacks';
|
|
|
|
interface Props {
|
|
checked: boolean;
|
|
title: string;
|
|
onChange: (checked: boolean) => void;
|
|
disabled?: boolean;
|
|
className?: string;
|
|
inputWrapperClassName?: string;
|
|
indeterminate?: boolean;
|
|
hideLabel?: boolean;
|
|
}
|
|
|
|
export function Checkbox({
|
|
checked,
|
|
indeterminate,
|
|
onChange,
|
|
className,
|
|
inputWrapperClassName,
|
|
disabled,
|
|
title,
|
|
hideLabel,
|
|
}: Props) {
|
|
return (
|
|
<HStack
|
|
as="label"
|
|
space={2}
|
|
className={classNames(className, 'text-fg', disabled && 'opacity-disabled')}
|
|
>
|
|
<div className={classNames(inputWrapperClassName, 'x-theme-input', 'relative flex')}>
|
|
<input
|
|
aria-hidden
|
|
className={classNames(
|
|
'appearance-none w-4 h-4 flex-shrink-0 border border-background-highlight',
|
|
'rounded hocus:border-border-focus hocus:bg-focus/[5%] outline-none ring-0',
|
|
)}
|
|
type="checkbox"
|
|
disabled={disabled}
|
|
onChange={() => onChange(!checked)}
|
|
/>
|
|
<div className="absolute inset-0 flex items-center justify-center">
|
|
<Icon size="sm" icon={indeterminate ? 'minus' : checked ? 'check' : 'empty'} />
|
|
</div>
|
|
</div>
|
|
{!hideLabel && title}
|
|
</HStack>
|
|
);
|
|
}
|