-
Notifications
You must be signed in to change notification settings - Fork 13.5k
/
Copy pathcheckbox.scss
365 lines (282 loc) · 8.54 KB
/
checkbox.scss
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
@import "../../themes/ionic.globals";
@import "./checkbox.vars.scss";
// Checkbox
// --------------------------------------------------
:host {
/**
* @prop --size: Size of the checkbox icon
*
* @prop --checkbox-background: Background of the checkbox icon
* @prop --checkbox-background-checked: Background of the checkbox icon when checked
*
* @prop --border-color: Border color of the checkbox icon
* @prop --border-radius: Border radius of the checkbox icon
* @prop --border-width: Border width of the checkbox icon
* @prop --border-style: Border style of the checkbox icon
* @prop --border-color-checked: Border color of the checkbox icon when checked
*
* @prop --transition: Transition of the checkbox icon
*
* @prop --checkmark-color: Color of the checkbox checkmark when checked
* @prop --checkmark-width: Stroke width of the checkbox checkmark
*/
--checkbox-background-checked: #{ion-color(primary, base)};
--border-color-checked: #{ion-color(primary, base)};
--checkmark-color: #{ion-color(primary, contrast)};
--transition: none;
display: inline-block;
position: relative;
cursor: pointer;
user-select: none;
z-index: $z-index-item-input;
}
:host(.in-item) {
flex: 1 1 0;
width: 100%;
height: 100%;
}
/**
* Checkbox can be slotted
* in components such as item and
* toolbar which is why we do not
* limit the below behavior to just ion-item.
*/
:host([slot="start"]),
:host([slot="end"]) {
// Reset the flex property when the checkbox
// is slotted to avoid growing the element larger
// than its content.
flex: initial;
width: auto;
}
:host(.ion-color) {
--checkbox-background-checked: #{current-color(base)};
--border-color-checked: #{current-color(base)};
--checkmark-color: #{current-color(contrast)};
}
.checkbox-wrapper {
display: flex;
flex-grow: 1;
align-items: center;
justify-content: space-between;
height: inherit;
cursor: inherit;
}
.label-text-wrapper {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
// Checkboxes that are not slotted inside an item and are not used with a
// stacked label should have margins equal to those of the label.
:host(.in-item) .label-text-wrapper,
:host(.in-item:not(.checkbox-label-placement-stacked):not([slot])) .native-wrapper {
@include margin($checkbox-item-label-margin-top, null, $checkbox-item-label-margin-bottom, null);
}
:host(.in-item.checkbox-label-placement-stacked) .label-text-wrapper {
@include margin($checkbox-item-label-margin-top, null, $form-control-label-margin, null);
}
:host(.in-item.checkbox-label-placement-stacked) .native-wrapper {
@include margin(null, null, $checkbox-item-label-margin-bottom, null);
}
/**
* If no label text is placed into the slot
* then the element should be hidden otherwise
* there will be additional margins added.
*/
.label-text-wrapper-hidden {
display: none;
}
/**
* The native input must be hidden with display instead of visibility or
* aria-hidden to avoid accessibility issues with nested interactive elements.
*/
input {
display: none;
}
.native-wrapper {
display: flex;
align-items: center;
}
.checkbox-icon {
@include border-radius(var(--border-radius));
position: relative;
width: var(--size);
height: var(--size);
transition: var(--transition);
border-width: var(--border-width);
border-style: var(--border-style);
border-color: var(--border-color);
background: var(--checkbox-background);
box-sizing: border-box;
}
.checkbox-icon path {
fill: none;
stroke: var(--checkmark-color);
stroke-width: var(--checkmark-width);
opacity: 0;
}
// Checkbox Bottom Content
// ----------------------------------------------------------------
.checkbox-bottom {
@include padding(4px, null, null, null);
display: flex;
justify-content: space-between;
font-size: dynamic-font(12px);
white-space: normal;
}
:host(.checkbox-label-placement-stacked) .checkbox-bottom {
font-size: dynamic-font(16px);
}
// Checkbox Hint Text
// ----------------------------------------------------------------
/**
* Error text should only be shown when .ion-invalid is
* present on the checkbox. Otherwise the helper text should
* be shown.
*/
.checkbox-bottom .error-text {
display: none;
color: ion-color(danger, base);
}
.checkbox-bottom .helper-text {
display: block;
color: $text-color-step-300;
}
:host(.ion-touched.ion-invalid) .checkbox-bottom .error-text {
display: block;
}
:host(.ion-touched.ion-invalid) .checkbox-bottom .helper-text {
display: none;
}
// Label Placement - Start
// ----------------------------------------------------------------
/**
* Label is on the left of the checkbox in LTR and
* on the right in RTL.
*/
:host(.checkbox-label-placement-start) .checkbox-wrapper {
flex-direction: row;
}
:host(.checkbox-label-placement-start) .label-text-wrapper {
/**
* The margin between the label and
* the checkbox should be on the end
* when the label sits at the start.
*/
@include margin(null, $form-control-label-margin, null, 0);
}
// Label Placement - End
// ----------------------------------------------------------------
/**
* Label is on the right of the checkbox in LTR and
* on the left in RTL.
*/
:host(.checkbox-label-placement-end) .checkbox-wrapper {
flex-direction: row-reverse;
justify-content: start;
}
/**
* The margin between the label and
* the checkbox should be on the start
* when the label sits at the end.
*/
:host(.checkbox-label-placement-end) .label-text-wrapper {
@include margin(null, 0, null, $form-control-label-margin);
}
// Label Placement - Fixed
// ----------------------------------------------------------------
:host(.checkbox-label-placement-fixed) .label-text-wrapper {
/**
* The margin between the label and
* the checkbox should be on the end
* when the label sits at the start.
*/
@include margin(null, $form-control-label-margin, null, 0);
}
/**
* Label is on the left of the checkbox in LTR and
* on the right in RTL. Label also has a fixed width.
*/
:host(.checkbox-label-placement-fixed) .label-text-wrapper {
flex: 0 0 100px;
width: 100px;
min-width: 100px;
max-width: 200px;
}
// Label Placement - Stacked
// ----------------------------------------------------------------
/**
* Label is on top of the checkbox.
*/
:host(.checkbox-label-placement-stacked) .checkbox-wrapper {
flex-direction: column;
text-align: center;
}
:host(.checkbox-label-placement-stacked) .label-text-wrapper {
@include transform(scale(#{$form-control-label-stacked-scale}));
/**
* The margin between the label and
* the checkbox should be on the bottom
* when the label sits at the top.
*/
@include margin(null, 0, $form-control-label-margin, 0);
/**
* Label text should not extend
* beyond the bounds of the checkbox.
*/
max-width: calc(100% / #{$form-control-label-stacked-scale});
}
:host(.checkbox-label-placement-stacked.checkbox-alignment-start) .label-text-wrapper {
@include transform-origin(start, top);
}
:host(.checkbox-label-placement-stacked.checkbox-alignment-center) .label-text-wrapper {
@include transform-origin(center, top);
}
// Justify Content
// ---------------------------------------------
:host(.checkbox-justify-space-between) .checkbox-wrapper {
justify-content: space-between;
}
:host(.checkbox-justify-start) .checkbox-wrapper {
justify-content: start;
}
:host(.checkbox-justify-end) .checkbox-wrapper {
justify-content: end;
}
// Align Items
// ---------------------------------------------
:host(.checkbox-alignment-start) .checkbox-wrapper {
align-items: start;
}
:host(.checkbox-alignment-center) .checkbox-wrapper {
align-items: center;
}
// Justify Content & Align Items
// ---------------------------------------------
// The checkbox should be displayed as block when either justify
// or alignment is set; otherwise, these properties will have no
// visible effect.
:host(.checkbox-justify-space-between),
:host(.checkbox-justify-start),
:host(.checkbox-justify-end),
:host(.checkbox-alignment-start),
:host(.checkbox-alignment-center) {
display: block;
}
// Checked / Indeterminate Checkbox
// ---------------------------------------------
:host(.checkbox-checked) .checkbox-icon,
:host(.checkbox-indeterminate) .checkbox-icon {
border-color: var(--border-color-checked);
background: var(--checkbox-background-checked);
}
:host(.checkbox-checked) .checkbox-icon path,
:host(.checkbox-indeterminate) .checkbox-icon path {
opacity: 1;
}
// Disabled Checkbox
// ---------------------------------------------
:host(.checkbox-disabled) {
pointer-events: none;
}