2021-09-24 05:24:17 -07:00
|
|
|
import React from 'react'
|
|
|
|
import styled from '@emotion/styled'
|
|
|
|
import { CheckIcon } from '@heroicons/react/solid'
|
|
|
|
|
|
|
|
const HiddenCheckbox = styled.input`
|
|
|
|
border: 0;
|
|
|
|
clip: rect(0 0 0 0);
|
|
|
|
clippath: inset(50%);
|
|
|
|
height: 1px;
|
|
|
|
margin: -1px;
|
|
|
|
overflow: hidden;
|
|
|
|
padding: 0;
|
|
|
|
position: absolute;
|
|
|
|
white-space: nowrap;
|
|
|
|
width: 1px;
|
|
|
|
`
|
|
|
|
|
2021-10-11 11:02:20 -07:00
|
|
|
const Checkbox = ({ checked, children, disabled = false, ...props }) => (
|
2021-09-26 06:20:51 -07:00
|
|
|
<label className="cursor-pointer flex items-center">
|
2021-10-11 11:02:20 -07:00
|
|
|
<HiddenCheckbox
|
|
|
|
checked={checked}
|
|
|
|
{...props}
|
|
|
|
disabled={disabled}
|
|
|
|
type="checkbox"
|
|
|
|
/>
|
2021-09-24 05:24:17 -07:00
|
|
|
<div
|
|
|
|
className={`${
|
2021-10-11 11:02:20 -07:00
|
|
|
checked && !disabled ? 'border-th-primary' : 'border-th-fgd-4'
|
2021-09-25 05:41:04 -07:00
|
|
|
} border cursor-pointer default-transition flex items-center justify-center rounded h-4 w-4`}
|
2021-09-24 05:24:17 -07:00
|
|
|
>
|
|
|
|
<CheckIcon
|
2021-10-11 11:02:20 -07:00
|
|
|
className={`${checked ? 'block' : 'hidden'} h-4 w-4 ${
|
|
|
|
disabled ? 'text-th-fgd-4' : 'text-th-primary'
|
|
|
|
}`}
|
2021-09-24 05:24:17 -07:00
|
|
|
/>
|
|
|
|
</div>
|
2021-09-26 06:20:51 -07:00
|
|
|
<span className="ml-2 text-xs text-th-fgd-3">{children}</span>
|
|
|
|
</label>
|
2021-09-24 05:24:17 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
export default Checkbox
|