Debian Codegraph @

node/@patternfly/patternfly/components/Switch/switch.scss

raw
1 @use '../../sass-utilities' as *;
2
3 @include pf-root($switch) {
4 // Switch - the vars for this file don't follow our normal order so that the IE11 script can convert the vars correctly
5 --#{$switch}--FontSize: var(--pf-t--global--font--size--sm);
6 --#{$switch}--ColumnGap: var(--pf-t--global--spacer--sm);
7
8 // Switch icon
9 --#{$switch}__toggle-icon--FontSize: calc(var(--#{$switch}--FontSize) * .625); // We don't use an icon font-size here because this value allows the icon to scale relative to the switch's font-size.
10 --#{$switch}__toggle-icon--Color: var(--pf-t--global--icon--color--on-brand--default);
11 --#{$switch}__toggle-icon--InsetInlineStart: calc(var(--#{$switch}--FontSize) * .4);
12 --#{$switch}__toggle-icon--Offset: #{pf-size-prem(2px)}; // this value is created to handle sizing of the toggle and therefore the width of the toggle and its transform value.
13 --#{$switch}__input--disabled__toggle-icon--Color: var(--pf-t--global--icon--color--disabled);
14
15 // Switch
16 --#{$switch}--LineHeight: var(--pf-t--global--font--line-height--body);
17 --#{$switch}--Height: auto;
18
19 // Switch input
20 --#{$switch}__input--checked__toggle--BackgroundColor: var(--pf-t--global--color--brand--default);
21 --#{$switch}__input--checked__toggle--before--TranslateX: calc(100% + var(--#{$switch}__toggle-icon--Offset));
22 --#{$switch}__input--checked__toggle--BorderColor: transparent;
23 --#{$switch}__input--checked__toggle--BorderWidth: var(--pf-t--global--border--width--high-contrast--regular);
24 --#{$switch}__input--checked__label--Color: var(--pf-t--global--text--color--regular);
25 --#{$switch}__input--not-checked__label--Color: var(--pf-t--global--text--color--subtle);
26 --#{$switch}__input--disabled__label--Color: var(--pf-t--global--text--color--disabled);
27 --#{$switch}__input--disabled__toggle--BackgroundColor: var(--pf-t--global--background--color--disabled--default);
28 --#{$switch}__input--disabled__toggle--BorderColor: var(--pf-t--global--border--color--high-contrast);
29 --#{$switch}__input--checked__toggle--before--BackgroundColor: var(--pf-t--global--icon--color--inverse);
30 --#{$switch}__input--not-checked__toggle--before--BackgroundColor: var(--pf-t--global--icon--color--subtle);
31 --#{$switch}__input--disabled__toggle--before--BackgroundColor: var(--pf-t--global--icon--color--on-disabled);
32 --#{$switch}__input--focus__toggle--OutlineWidth: var(--pf-t--global--border--width--strong);
33 --#{$switch}__input--focus__toggle--OutlineOffset: var(--pf-t--global--spacer--xs);
34 --#{$switch}__input--focus__toggle--OutlineColor: var(--pf-t--global--color--brand--default);
35
36 // Switch toggle
37 --#{$switch}__toggle--Height: calc(var(--#{$switch}--FontSize) * var(--#{$switch}--LineHeight));
38 --#{$switch}__toggle--BackgroundColor: var(--pf-t--global--background--color--control--default);
39 --#{$switch}__toggle--BorderColor: var(--pf-t--global--border--color--control--default);
40 --#{$switch}__toggle--BorderWidth: var(--pf-t--global--border--width--control--default);
41 --#{$switch}__toggle--BorderRadius: var(--pf-t--global--border--radius--pill);
42 --#{$switch}__toggle--before--Width: calc(var(--#{$switch}--FontSize) - var(--#{$switch}__toggle-icon--Offset));
43 --#{$switch}__toggle--before--Height: var(--#{$switch}__toggle--before--Width);
44 --#{$switch}__toggle--before--InsetInlineStart: calc((var(--#{$switch}__toggle--Height) - var(--#{$switch}__toggle--before--Height)) / 2);
45 --#{$switch}__toggle--before--BorderWidth: var(--pf-t--global--border--width--high-contrast--regular);
46 --#{$switch}__toggle--before--BorderRadius: var(--pf-t--global--border--radius--large);
47 --#{$switch}__toggle--before--TransitionTimingFunction: var(--pf-t--global--motion--timing-function--default);
48 --#{$switch}__toggle--before--TransitionDuration: var(--pf-t--global--motion--duration--md);
49 --#{$switch}__toggle--before--Transition: transform var(--#{$switch}__toggle--before--TransitionTimingFunction) var(--#{$switch}__toggle--before--TransitionDuration), background-color var(--#{$switch}__toggle--before--TransitionTimingFunction) var(--#{$switch}__toggle--before--TransitionDuration); // TODO remove in breaking change along with shorthand property
50 --#{$switch}__toggle--Width: calc(var(--#{$switch}__toggle--Height) + var(--#{$switch}__toggle-icon--Offset) + var(--#{$switch}__toggle--before--Width));
51 }
52
53 .#{$switch} {
54 position: relative;
55 display: inline-grid;
56 grid-template-columns: auto;
57 grid-auto-columns: 1fr;
58 column-gap: var(--#{$switch}--ColumnGap);
59 height: var(--#{$switch}--Height);
60 font-size: var(--#{$switch}--FontSize);
61 line-height: var(--#{$switch}--LineHeight);
62 vertical-align: middle;
63 cursor: pointer;
64
65 &.pf-m-reverse {
66 .#{$switch}__label,
67 .#{$switch}__toggle {
68 grid-row: 1;
69 }
70
71 .#{$switch}__label {
72 grid-column: 1;
73 }
74 }
75 }
76
77 .#{$switch}__input {
78 position: absolute;
79 cursor: pointer;
80 opacity: 0;
81
82 &:focus-visible ~ .#{$switch}__toggle {
83 outline: var(--#{$switch}__input--focus__toggle--OutlineWidth) solid var(--#{$switch}__input--focus__toggle--OutlineColor);
84 outline-offset: var(--#{$switch}__input--focus__toggle--OutlineOffset);
85 }
86
87 &:checked {
88 ~ .#{$switch}__label {
89 color: var(--#{$switch}__input--checked__label--Color);
90 }
91
92 ~ .#{$switch}__toggle {
93 --#{$switch}__toggle--BorderWidth: var(--#{$switch}__input--checked__toggle--BorderWidth);
94 --#{$switch}__toggle--BorderColor: var(--#{$switch}__input--checked__toggle--BorderColor);
95
96 background-color: var(--#{$switch}__input--checked__toggle--BackgroundColor);
97
98 &::before {
99 @include pf-v6-bidirectional-style(
100 $prop: transform,
101 $ltr-val: translate(var(--#{$switch}__input--checked__toggle--before--TranslateX), -50%),
102 $rtl-val: translate(#{pf-v6-calc-inverse(var(--#{$switch}__input--checked__toggle--before--TranslateX))}, -50%)
103 );
104
105 background-color: var(--#{$switch}__input--checked__toggle--before--BackgroundColor);
106 }
107 }
108 }
109
110 &:not(:checked) {
111 ~ .#{$switch}__label {
112 color: var(--#{$switch}__input--not-checked__label--Color);
113 }
114
115 ~ .#{$switch}__toggle {
116 .#{$switch}__toggle-icon {
117 display: none;
118 }
119 }
120 }
121
122 &:disabled {
123 cursor: not-allowed;
124
125 ~ .#{$switch}__label {
126 color: var(--#{$switch}__input--disabled__label--Color);
127 cursor: not-allowed;
128 }
129
130 ~ .#{$switch}__toggle {
131 --#{$switch}__toggle-icon--Color: var(--#{$switch}__input--disabled__toggle-icon--Color);
132 --#{$switch}__toggle--BorderColor: var(--#{$switch}__input--disabled__toggle--BorderColor);
133
134 cursor: not-allowed;
135 background-color: var(--#{$switch}__input--disabled__toggle--BackgroundColor);
136
137 &::before {
138 background-color: var(--#{$switch}__input--disabled__toggle--before--BackgroundColor);
139 }
140 }
141 }
142 }
143
144 .#{$switch}__toggle {
145 position: relative;
146 display: inline-block;
147 width: var(--#{$switch}__toggle--Width);
148 height: var(--#{$switch}__toggle--Height);
149 background-color: var(--#{$switch}__toggle--BackgroundColor);
150 border-radius: var(--#{$switch}__toggle--BorderRadius);
151
152 &::before {
153 position: absolute;
154 inset-block-start: 50%;
155 inset-inline-start: var(--#{$switch}__toggle--before--InsetInlineStart);
156 display: block;
157 width: var(--#{$switch}__toggle--before--Width);
158 height: var(--#{$switch}__toggle--before--Height);
159 content: "";
160 background-color: var(--#{$switch}__input--not-checked__toggle--before--BackgroundColor);
161 border: var(--#{$switch}__toggle--before--BorderWidth) solid transparent; // for forced color mode
162 border-radius: var(--#{$switch}__toggle--before--BorderRadius);
163 transform: translateY(-50%);
164 transition: var(--#{$switch}__toggle--before--Transition); // TODO remove shorthand in breaking change
165 }
166
167 &::after {
168 position: absolute;
169 inset: 0;
170 content: "";
171 border: var(--#{$switch}__toggle--BorderWidth) solid var(--#{$switch}__toggle--BorderColor);
172 border-radius: var(--#{$switch}__toggle--BorderRadius);
173 }
174 }
175
176 .#{$switch}__toggle-icon {
177 position: absolute;
178 inset-block-start: 0;
179 inset-block-end: 0;
180 inset-inline-start: var(--#{$switch}__toggle-icon--InsetInlineStart);
181 display: flex;
182 align-items: center;
183 font-size: var(--#{$switch}__toggle-icon--FontSize);
184 color: var(--#{$switch}__toggle-icon--Color);
185 }
186
187 .#{$switch}__label {
188 display: inline-block;
189 grid-column: 2;
190 vertical-align: top;
191 }