-
Notifications
You must be signed in to change notification settings - Fork 342
/
CheckboxNotInput.tsx
219 lines (201 loc) · 6.69 KB
/
CheckboxNotInput.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import * as React from 'react'
import styled, { ThemeProps, css } from 'styled-components'
import Icon from '@worldbrain/memex-common/lib/common-ui/components/icon'
import * as icons from 'src/common-ui/components/design-library/icons'
import LoadingIndicator from '@worldbrain/memex-common/lib/common-ui/components/loading-indicator'
import { ColorThemeKeys } from '@worldbrain/memex-common/lib/common-ui/styles/types'
export type CheckboxToggle = (event: React.MouseEvent<HTMLInputElement>) => void
export interface Props {
id?: string
onClick: React.MouseEventHandler
name?: string
isChecked: boolean
isDisabled?: boolean
containerClass?: string
textClass?: string
inputClass?: string
labelClass?: string
mode?: 'radio' | 'multiSelect'
size?: number
label?: string
subLabel?: string
zIndex?: number
isLoading?: boolean
fontSize?: number
checkBoxColor?: ColorThemeKeys
borderColor?: ColorThemeKeys
width?: string
}
export default class CheckboxNotInput extends React.PureComponent<Props> {
render() {
return (
<LabelContainer
width={this.props.width}
zIndex={this.props.zIndex}
htmlFor={this.props.id}
onClick={this.props.onClick}
>
<LabelText>
{/* <InputContainer
type="checkbox"
checked={this.props.isChecked}
onChange={this.props.handleChange}
id={this.props.id}
disabled={this.props.isDisabled}
name={this.props.name}
/> */}
{this.props.isLoading ? (
<LoadingIndicator size={16} />
) : (
<LabelCheck
size={this.props.size}
mode={this.props.mode}
isChecked={this.props.isChecked}
checkBoxColor={this.props.checkBoxColor}
borderColor={this.props.borderColor}
>
{this.props.isChecked && (
<Icon
filePath={icons.check}
color="black"
heightAndWidth={'14px'}
hoverOff
/>
)}
</LabelCheck>
)}
{this.props.label && (
<LabelContentBox>
<LabelTitle fontSize={this.props.fontSize}>
{this.props.label}
</LabelTitle>
<SubLabel>{this.props.subLabel}</SubLabel>
</LabelContentBox>
)}
{this.props.children && (
<ChildrenBox mode={this.props.mode}>
{this.props.children}
</ChildrenBox>
)}
</LabelText>
</LabelContainer>
)
}
}
const Container = styled.div`
cursor: pointer;
`
const LabelContentBox = styled.div`
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: center;
margin-left: 8px;
`
const LabelTitle = styled.div<{ fontSize: number }>`
color: ${(props) => props.theme.colors.greyScale6};
font-weight: 300;
font-size: ${(props) => (props.fontSize ? props.fontSize + 'px' : '16px')};
white-space: nowrap;
`
const SubLabel = styled.div<{ fontSize?: number }>`
color: ${(props) => props.theme.colors.greyScale5};
font-weight: 300;
font-size: ${(props) => (props.fontSize ? props.fontSize + 'px' : '14px')};
white-space: nowrap;
`
const ChildrenBox = styled.span<{ mode }>`
color: ${(props) => props.theme.colors.greyScale1};
border-radius: ${(props) => (props.mode === 'radio' ? '20px' : '3px')};
display: flex;
justify-content: space-between;
align-items: center;
cursor: pointer;
flex: 1;
& * {
cursor: pointer;
}
`
const LabelContainer = styled.label<{ zIndex?: number; width: string }>`
display: flex;
align-items: center;
width: ${(props) => (props.width ? props.width : '100%')};
cursor: pointer;
z-index: ${(props) => props.zIndex};
user-select: none; // Prevent text selection
`
const InputContainer = styled.input`
display: none;
padding: 2px;
border: 2px solid ${(props) => props.theme.colors.black};
cursor: pointer;
`
const LabelText = styled.span<{ fontSize? }>`
font-size: ${(props) => (props.fontSize ? props.fontSize + 'px' : '0.9em')};
display: flex;
align-items: center;
width: inherit;
cursor: pointer;
width: fill-available;
height: fill-available;
justify-content: center;
&:hover {
color: ${(props) => props.theme.colors.black};
}
`
const LabelCheck = styled.span<{
isChecked
mode
size
checkBoxColor
borderColor
}>`
border-radius: ${(props) => (props.mode === 'radio' ? '20px' : '5px')};
border: 2px solid
${(props) =>
props.isChecked
? props.theme.colors.white
: props.theme.colors.greyScale3};
background: ${(props) =>
props.isChecked
? props.theme.colors.white
: props.theme.colors[props.checkBoxColor] ?? 'greyScale2'};
vertical-align: middle;
width: ${(props) => (props.size ? props.size + 'px' : '24px')};
height: ${(props) => (props.size ? props.size + 'px' : '24px')};
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
& * {
cursor: pointer !important;
}
&:hover {
outline: none;
}
&:focus {
outline: none;
}
${(props) =>
props.theme.variant === 'light' &&
css<any>`
background-color: ${(props) =>
props.isChecked
? props.theme.colors.greyScale5
: props.theme.colors.greyScale4};
border-color: ${(props) =>
props.isChecked
? props.theme.colors.greyScale5
: props.theme.colors.greyScale4};
`};
${(props) =>
props.borderColor &&
css<any>`
outline: 1px solid
${(props) => props.theme.colors[props.borderColor]};
border: none;
&:hover {
outline: 1px solid ${(props) => props.theme.colors.greyScale4};
}
`};
`