mango-ui-v3/components/Checkbox.tsx

42 lines
1.0 KiB
TypeScript
Raw Normal View History

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;
`
const Checkbox = ({ checked, children, disabled = false, ...props }) => (
2021-09-26 06:20:51 -07:00
<label className="cursor-pointer flex items-center">
<HiddenCheckbox
checked={checked}
{...props}
disabled={disabled}
type="checkbox"
/>
2021-09-24 05:24:17 -07:00
<div
className={`${
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
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