forked from carbon-design-system/carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_toggle.scss
238 lines (197 loc) · 5.95 KB
/
_toggle.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
//
// Copyright IBM Corp. 2016, 2023
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//3
@use '../../config' as *;
@use '../../motion' as *;
@use '../../spacing' as *;
@use '../../theme' as *;
@use '../../type' as *;
@use '../button/tokens' as button;
@use '../../utilities/convert';
@use '../../utilities/high-contrast-mode' as *;
@use '../../utilities/visually-hidden' as *;
@use '../../utilities/skeleton' as *;
/// Toggle styles
/// @access public
/// @group toggle
@mixin toggle {
.#{$prefix}--toggle {
display: inline-block;
user-select: none;
}
.#{$prefix}--toggle__label-text {
@include type-style('label-01');
display: block;
color: $text-secondary;
margin-block-end: $spacing-05;
}
.#{$prefix}--toggle__button {
@include visually-hidden;
&:focus {
outline: none;
}
}
.#{$prefix}--toggle__appearance {
display: inline-grid;
align-items: center;
column-gap: $spacing-03;
cursor: pointer;
grid-template-columns: max-content max-content;
}
.#{$prefix}--toggle__switch {
position: relative;
border-radius: convert.to-rem(12px);
background-color: $toggle-off;
block-size: convert.to-rem(24px);
inline-size: convert.to-rem(48px);
transition: background-color $duration-fast-01 motion(exit, productive);
&::before {
position: absolute;
border-radius: 50%;
background-color: $icon-on-color;
block-size: convert.to-rem(18px);
content: '';
inline-size: convert.to-rem(18px);
inset-block-start: convert.to-rem(3px);
inset-inline-start: convert.to-rem(3px);
transition: transform $duration-fast-01 motion(exit, productive);
@media screen and (prefers-reduced-motion: reduce) {
transition: none;
}
}
}
.#{$prefix}--toggle__button:focus
+ .#{$prefix}--toggle__label
.#{$prefix}--toggle__switch,
.#{$prefix}--toggle:not(.#{$prefix}--toggle--disabled):active
.#{$prefix}--toggle__switch {
&::after {
display: block;
border: 2px solid $focus;
border-radius: convert.to-rem(16px);
block-size: calc(100% + convert.to-rem(6px));
content: '';
inline-size: calc(100% + convert.to-rem(6px));
margin-block-start: convert.to-rem(-3px);
margin-inline-start: convert.to-rem(-3px);
}
}
.#{$prefix}--toggle__switch--checked {
background-color: $support-success;
&::before {
transform: translateX(convert.to-rem(24px));
}
}
.#{$prefix}--toggle__text {
@include type-style('body-01');
color: $text-primary;
}
.#{$prefix}--toggle__appearance--sm .#{$prefix}--toggle__switch {
block-size: convert.to-rem(16px);
inline-size: convert.to-rem(32px);
&::before {
block-size: convert.to-rem(10px);
inline-size: convert.to-rem(10px);
}
}
.#{$prefix}--toggle__appearance--sm
.#{$prefix}--toggle__switch--checked::before {
transform: translateX(convert.to-rem(16px));
}
.#{$prefix}--toggle__check {
position: absolute;
block-size: convert.to-rem(5px);
fill: $support-success;
inline-size: convert.to-rem(6px);
inset-block-start: convert.to-rem(6px);
inset-inline-end: convert.to-rem(5px);
visibility: hidden;
}
.#{$prefix}--toggle__switch--checked .#{$prefix}--toggle__check {
visibility: visible;
}
// ----------------------------------------
// disabled
// ----------------------------------------
.#{$prefix}--toggle--disabled .#{$prefix}--toggle__appearance {
cursor: not-allowed;
}
.#{$prefix}--toggle--disabled .#{$prefix}--toggle__label-text,
.#{$prefix}--toggle--disabled .#{$prefix}--toggle__text {
color: $text-disabled;
}
.#{$prefix}--toggle--disabled .#{$prefix}--toggle__switch {
background-color: button.$button-disabled;
&::before {
background-color: $icon-on-color-disabled;
}
}
.#{$prefix}--toggle--disabled .#{$prefix}--toggle__check {
fill: button.$button-disabled;
}
// ----------------------------------------
// readonly
// ----------------------------------------
.#{$prefix}--toggle--readonly .#{$prefix}--toggle__appearance {
cursor: default;
}
.#{$prefix}--toggle--readonly .#{$prefix}--toggle__switch {
border: 1px solid $icon-disabled;
background-color: transparent;
&::before {
background-color: $text-primary;
inset-block-start: convert.to-rem(2px);
inset-inline-start: convert.to-rem(2px);
}
}
.#{$prefix}--toggle--readonly .#{$prefix}--toggle__check {
fill: $background;
inset-block-start: convert.to-rem(5px);
inset-inline-end: convert.to-rem(4px);
}
.#{$prefix}--toggle--readonly .#{$prefix}--toggle__text {
cursor: text;
user-select: text;
}
// HCM
.#{$prefix}--toggle__switch,
.#{$prefix}--toggle__switch::before {
@include high-contrast-mode('outline');
}
.#{$prefix}--toggle__button:focus
+ .#{$prefix}--toggle__label
.#{$prefix}--toggle__switch,
.#{$prefix}--toggle:not(.#{$prefix}--toggle--disabled):active
.#{$prefix}--toggle__switch {
@include high-contrast-mode('focus');
}
// Skeleton state
.#{$prefix}--toggle--skeleton {
display: flex;
align-items: center;
}
.#{$prefix}--toggle--skeleton .#{$prefix}--toggle__skeleton-circle {
@include circular-skeleton;
border-radius: 50%;
block-size: convert.to-rem(18px);
inline-size: convert.to-rem(18px);
}
.#{$prefix}--toggle--skeleton .#{$prefix}--toggle__skeleton-rectangle {
@include skeleton;
block-size: convert.to-rem(8px);
inline-size: convert.to-rem(24px);
margin-inline-start: convert.to-rem(8px);
}
// RTL overrides
[dir='rtl'] .#{$prefix}--toggle__switch--checked::before {
transform: translateX(convert.to-rem(-24px));
}
[dir='rtl']
.#{$prefix}--toggle__appearance--sm
.#{$prefix}--toggle__switch--checked::before {
transform: translateX(convert.to-rem(-16px));
}
}