-
Notifications
You must be signed in to change notification settings - Fork 40
/
Checkbox.tsx
40 lines (35 loc) · 1.06 KB
/
Checkbox.tsx
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
/**
* Copyright (c) 2020 BlockDev AG
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import styled from "styled-components"
import React from "react"
import { uniqueId } from "lodash"
const Container = styled.div`
height: 24px;
font-size: 14px;
display: flex;
`
const Input = styled.input`
margin-right: 8px;
border-radius: 2px;
height: 18px;
` as React.FC<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>>
const Label = styled.label`
display: inline;
line-height: 24px;
`
export type CheckboxProps = React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> & {
children: React.ReactNode
}
export const Checkbox: React.FC<CheckboxProps> = ({ children, ...rest }) => {
const inputId = uniqueId("checkbox")
return (
<Container>
<Input id={inputId} type="checkbox" {...rest} />
<Label htmlFor={inputId}>{children}</Label>
</Container>
)
}