Debian Codegraph @

node/@patternfly/patternfly/sass-utilities/mixins.scss

raw
1 @use '../sass-utilities/functions' as *;
2 @use '../sass-utilities/init' as *;
3 @use '../sass-utilities/scss-variables' as *;
4 @use '../sass-utilities/namespaces-components' as *;
5 @use 'sass:list';
6 @use 'sass:meta';
7
8 // Media query used to create responsive classes
9 @mixin pf-v6-media-query($point) {
10 @if $point == "" or not $point or $point == "base" {
11 @content;
12 } @else if $point == "sm" {
13 @media screen and (min-width: $pf-v6-global--breakpoint--sm) {
14 @content;
15 }
16 } @else if $point == "md" {
17 @media screen and (min-width: $pf-v6-global--breakpoint--md) {
18 @content;
19 }
20 } @else if $point == "lg" {
21 @media screen and (min-width: $pf-v6-global--breakpoint--lg) {
22 @content;
23 }
24 } @else if $point == "xl" {
25 @media screen and (min-width: $pf-v6-global--breakpoint--xl) {
26 @content;
27 }
28 } @else if $point == "2xl" {
29 @media screen and (min-width: $pf-v6-global--breakpoint--2xl) {
30 @content;
31 }
32 }
33 }
34
35 // Media query used to create responsive classes
36 @mixin pf-v6-height-media-query($point) {
37 @if $point == "" or not $point or $point == "base" {
38 @content;
39 } @else if $point == "sm" {
40 @media screen and (min-height: $pf-v6-global--height-breakpoint--sm) {
41 @content;
42 }
43 } @else if $point == "md" {
44 @media screen and (min-height: $pf-v6-global--height-breakpoint--md) {
45 @content;
46 }
47 } @else if $point == "lg" {
48 @media screen and (min-height: $pf-v6-global--height-breakpoint--lg) {
49 @content;
50 }
51 } @else if $point == "xl" {
52 @media screen and (min-height: $pf-v6-global--height-breakpoint--xl) {
53 @content;
54 }
55 } @else if $point == "2xl" {
56 @media screen and (min-height: $pf-v6-global--height-breakpoint--2xl) {
57 @content;
58 }
59 }
60 }
61
62 // Create single prop / value classes, optionally add responsive suffix
63 // @group mixins
64 // @moduleType mixin
65 // @parameter: [Suffix] xs, sm, md, lg, xl, base or null
66 // @usage: @include pf-v6-utility-builder(class-name, base sm md lg xl);
67 // ===============================================================================================
68
69 // ## Example sass map:
70 // this must be used when order matters or a cluster of similar utilties need to overwrite each other
71
72 // Justify content options
73 // $pf-v6-u-flex-options: (
74 // flex-none: (flex none),
75 // flex-1: (flex 1)
76 // );
77
78 // non-responsive, base only @include pf-v6-utility-builder($sass-map)
79 // responsive, including all breakpoints @include pf-v6-utility-builder($sass-map, $pf-v6-global--breakpoint-list)
80 // responsive height breakpoints @include pf-v6-utility-builder($sass-map, $pf-v6-global--height-breakpoint-list, 'height')
81
82 // ## Passing individual utilities values
83 // ===============================================================================================
84 // Example individual utility:
85 // @include pf-v6-utility-builder(flex-fill flex "1 1 auto", $pf-v6-global--breakpoint-list);
86 @mixin pf-v6-utility-builder($props, $breakpoints: null, $direction: 'width') {
87 // if $class-name is a map
88
89 // stylelint-disable
90 @if meta.type-of($props) == map {
91 @each $class, $val in $props {
92 $property: list.nth($val, 1);
93 $value: #{list.nth($val, 2)} !important;
94
95 .#{$pf-prefix}u-#{$class} {
96 #{$property}: #{$value};
97 }
98 }
99
100 // if breakpoints are requested
101 @if $breakpoints != null {
102 @each $breakpoint in $breakpoints {
103 $suffix: -on-#{$breakpoint};
104
105 @if $direction == 'height' {
106 @include pf-v6-height-media-query($breakpoint) {
107 @each $class, $val in $props {
108 $property: list.nth($val, 1);
109 $value: #{list.nth($val, 2)} !important;
110
111 .#{$pf-prefix}u-#{$class}#{$suffix}-height {
112 #{$property}: #{$value};
113 }
114 }
115 }
116 }
117 @else if ($direction == 'width') {
118 @include pf-v6-media-query($breakpoint) {
119 @each $class, $val in $props {
120 $property: list.nth($val, 1);
121 $value: #{list.nth($val, 2)} !important;
122
123 .#{$pf-prefix}u-#{$class}#{$suffix} {
124 #{$property}: #{$value};
125 }
126 }
127 }
128 }
129 }
130 }
131 }
132 @else if meta.type-of($props) == list {
133 $class: list.nth($props, 1);
134 $property: list.nth($props, 2);
135 $value: list.nth($props, 3) !important;
136
137 .#{$pf-prefix}u-#{$class} {
138 #{$property}: #{$value};
139 }
140
141 @if $breakpoints != null {
142 @each $breakpoint in $breakpoints {
143 $suffix: -on-#{$breakpoint};
144
145 .#{$pf-prefix}u-#{$class}#{$suffix} {
146 @include pf-v6-media-query($breakpoint) {
147 #{$property}: #{$value};
148 }
149 }
150 }
151 }
152 }
153 }
154
155 // stylelint-enable
156
157 @mixin pf-v6-u-screen-reader {
158 position: fixed;
159 inset-block-start: 0;
160 inset-inline-start: 0;
161 overflow: hidden;
162 white-space: nowrap;
163 border: 0;
164 clip-path: inset(50%);
165 }
166
167 @mixin pf-v6-u-visible {
168 position: static;
169 overflow: visible;
170 white-space: normal;
171 border: inherit;
172 clip-path: revert;
173 }
174
175 @mixin pf-v6-text-overflow {
176 overflow: hidden;
177 text-overflow: ellipsis;
178 white-space: nowrap;
179 }
180
181 @mixin pf-v6-line-clamp($line-clamp-val: 1) {
182 // stylelint-disable
183 display: -webkit-box;
184 overflow: hidden;
185 -webkit-box-orient: vertical;
186 -webkit-line-clamp: #{$line-clamp-val};
187 // stylelint-enable
188 }
189
190 @mixin pf-v6-overflow-hide-scroll {
191 &::-webkit-scrollbar {
192 display: none;
193 } // hides scrollbars in Chrome
194
195 scrollbar-width: none; // hides scrollbars in Firefox 64 and up
196 -ms-overflow-style: -ms-autohiding-scrollbar; // auto hides scrollbars in Edge
197 }
198
199 @mixin pf-v6-hidden-visible($val: "block", $ifIncludeHeight: false) {
200 // stylelint-disable-next-line
201 --#{$pf-prefix}hidden-visible--visible--Display: #{$val};
202
203 // base value for visible display property is set to 'block' by default and passed in to
204 // placeholder via `pf-v6-hidden-visible` mixin
205
206 // set hidden var values
207 // stylelint-disable custom-property-pattern
208 --#{$pf-prefix}hidden-visible--hidden--Display: none;
209
210 // set visibile var values
211 --#{$pf-prefix}hidden-visible--Display: var(--#{$pf-prefix}hidden-visible--visible--Display);
212
213 // set default state to visible
214 display: var(--#{$pf-prefix}hidden-visible--Display);
215
216 // toggle values based on state
217 &.pf-m-hidden {
218 --#{$pf-prefix}hidden-visible--Display: var(--#{$pf-prefix}hidden-visible--hidden--Display);
219 }
220
221 // only apply height breakpoints if $ifIncludeHeight is true
222 @if $ifIncludeHeight {
223 @each $size, $bp in $pf-v6-global--height-breakpoint-name-map {
224 @media screen and (min-height: $bp) {
225 &.pf-m-hidden-on-#{$size}-height {
226 --#{$pf-prefix}hidden-visible--Display: var(--#{$pf-prefix}hidden-visible--hidden--Display);
227 }
228
229 &.pf-m-visible-on-#{$size}-height {
230 --#{$pf-prefix}hidden-visible--Display: var(--#{$pf-prefix}hidden-visible--visible--Display);
231 }
232 }
233 }
234 }
235
236 @each $size, $bp in $pf-v6-global--breakpoint-name-map {
237 @media screen and (min-width: $bp) {
238 &.pf-m-hidden-on-#{$size} {
239 --#{$pf-prefix}hidden-visible--Display: var(--#{$pf-prefix}hidden-visible--hidden--Display);
240 }
241
242 &.pf-m-visible-on-#{$size} {
243 --#{$pf-prefix}hidden-visible--Display: var(--#{$pf-prefix}hidden-visible--visible--Display);
244 }
245 }
246 }
247 // stylelint-enable
248 }
249
250 // Apply media query if value is passed
251 @mixin pf-v6-apply-breakpoint($breakpoint) {
252 @if $breakpoint == "null" or $breakpoint == "base" or $breakpoint == "" {
253 @content;
254 } @else {
255 $breakpoint: pf-breakpoint-value($breakpoint);
256
257 @media (min-width: $breakpoint) {
258 @content;
259 }
260 }
261 }
262
263 // Apply height media query if value is passed
264 @mixin pf-v6-apply-height-breakpoint($breakpoint) {
265 @if $breakpoint == "null" or $breakpoint == "base" or $breakpoint == "" {
266 @content;
267 } @else {
268 $breakpoint: pf-height-breakpoint-value($breakpoint);
269
270 @media (min-height: $breakpoint) {
271 @content;
272 }
273 }
274 }
275
276 @mixin pf-v6-emit-properties($map) {
277 @each $prop, $value in $map {
278 #{$value}: #{$prop};
279 }
280 }
281
282 // Animate tab focus removal
283 @mixin pf-v6-animate-remove-tab-focus($element, $delay: $pf-v6-global--TransitionDuration) {
284 @keyframes pf-remove-tab-focus {
285 to {
286 visibility: hidden;
287 }
288 }
289
290 #{$element}[hidden] {
291 animation-name: pf-remove-tab-focus;
292 animation-delay: #{$delay};
293 animation-fill-mode: forwards;
294 }
295 }
296
297 // Animate error state on form elements
298 @mixin pf-v6-animate-danger-jiggle {
299 translate: var(--#{$pf-global}--danger-jiggle--TranslateX, 0);
300 animation-name: #{$pf-global}-danger-jiggle-motion;
301 animation-duration: var(--#{$pf-global}--danger-jiggle--AnimationDuration--Transform);
302 animation-timing-function: var(--#{$pf-global}--danger-jiggle--AnimationTimingFunction--Transform);
303 animation-fill-mode: both;
304 }
305
306 // Animate default fade in/out
307 @mixin pf-v6-fade-default($element) {
308 --#{$element}--TransitionDuration--Opacity: var(--pf-t--global--motion--duration--fade--default);
309 --#{$element}--TransitionTimingFunction--Opacity: var(--pf-t--global--motion--timing-function--default);
310
311 animation-name: #{$pf-global}-fade-in;
312 animation-duration: var(--#{$element}--TransitionDuration--Opacity);
313 animation-timing-function: var(--#{$element}--TransitionTimingFunction--Opacity);
314 }
315
316 // Build variable stack
317 @mixin pf-v6-build-css-variable-stack($prop, $css-var, $breakpoint-map: $pf-v6-global--breakpoint-map, $important: false) {
318 $list: ();
319
320 @each $breakpoint, $breakpoint-value in $breakpoint-map {
321 $variable-list: ();
322
323 // Build variable list
324 @if $breakpoint != "base" {
325 $list: list.append($list, $css-var + "-on-" + $breakpoint);
326 } @else {
327 $list: list.append($list, $css-var);
328 }
329
330 // Construct variable stack
331 @each $list-item in $list {
332 @if list.length($variable-list) == 0 {
333 $variable-list: var(#{$list-item});
334 } @else {
335 $variable-list: var(#{$list-item}, $variable-list);
336 }
337 }
338
339 // Assign variable stack to $prop
340 @include pf-v6-apply-breakpoint($breakpoint) {
341 @if $important == true {
342 // stylelint-disable declaration-no-important
343 #{$prop}: #{$variable-list} !important;
344 // stylelint-enable
345 } @else {
346 #{$prop}: #{$variable-list};
347 }
348 }
349 }
350 }
351
352 // Build variable stack
353 @mixin pf-v6-output-root-variables($css-var, $breakpoint-map: $pf-v6-global--breakpoint-map) {
354 $list: ();
355
356 @each $breakpoint, $breakpoint-value in $breakpoint-map {
357 // Build variable list
358 // stylelint-disable scss/at-if-no-null
359 @if $breakpoint-value {
360 $list: list.append($list, $css-var + "-on-" + $breakpoint);
361 }
362 // stylelint-enable
363 }
364
365 @each $item in $list {
366 #{$item}: inherit;
367 }
368 }
369
370 // Dark theme style block
371 @mixin pf-v6-theme-dark($theme-dark-class: $pf-v6--theme-dark--class, $theme-dark-target: $pf-v6--theme-dark--target) {
372 #{$theme-dark-target}:where(#{$theme-dark-class}) {
373 @content;
374 }
375 }
376
377 @mixin pf-v6-construct-global-vars($prefix: $pf-prefix--version, $maps...) {
378 @each $map in $maps {
379 @each $name, $val in $map {
380 #{$prefix}#{$name}: #{$val};
381 }
382 }
383 }
384
385 @mixin pf-v6-remove-num-arrows {
386 appearance: textfield;
387
388 // stylelint-disable
389 &::-webkit-inner-spin-button,
390 &::-webkit-outer-spin-button {
391 // stylelint-enable
392 margin: 0;
393 appearance: none;
394 }
395 }
396
397 // RTL helpers
398
399 // Used to create the RTL selector for RTL specific styles
400
401 // @include pf-v6-rtl {
402 // background: red;
403 // }
404
405 // renders as
406
407 // [dir="rtl"] {
408 // background: red;
409 // }
410 @mixin pf-v6-rtl($hasWhere: true) {
411 $sel: ':is';
412
413 @if $hasWhere {
414 $sel: ':where';
415 }
416
417 @at-root #{$sel}(.#{$pf-prefix}m-dir-rtl, [dir="rtl"]) #{&} {
418 @content;
419 }
420 }
421
422 // Used to create the LTR selector for LTR specific styles
423 @mixin pf-v6-ltr($hasWhere: true) {
424 $sel: ':is';
425
426 @if $hasWhere {
427 $sel: ':where';
428 }
429
430 @at-root #{$sel}(.#{$pf-prefix}m-dir-ltr, [dir="ltr"]) #{&} {
431 @content;
432 }
433 }
434
435 // Creates a default/LTR declaration, and an RTL declaration.
436
437 // @include pf-v6-bidirectional-style(background, blue, red)
438
439 // renders as
440
441 // background: blue;
442 // [dir="rtl"] {
443 // background: red;
444 // }
445 @mixin pf-v6-bidirectional-style($prop, $ltr-val, $rtl-val) {
446 #{$prop}: #{$ltr-val};
447
448 @include pf-v6-rtl {
449 #{$prop}: #{$rtl-val};
450 }
451 }
452
453 // Mirrors/flips something horizontally/inline. Relies upon scale/scale() not already being used for the element. Can be extended to take arguments to use different methods other than scale().
454 @mixin pf-v6-mirror-inline {
455 scale: -1 1;
456 }
457
458
459 @mixin pf-v6-mirror-inline-on-rtl {
460 @include pf-v6-rtl {
461 @include pf-v6-mirror-inline;
462 }
463 }
464
465 // Declares a global inverse multiplier var used for returning the inverse of a number. Defined within blocks that reference the global var in calc() functions to conditionally return the default or inverse value of a number.
466 @mixin pf-v6-set-inverse($val: true) {
467 @if $val {
468 --#{$pf-global}--inverse--multiplier: -1;
469 } @else {
470 --#{$pf-global}--inverse--multiplier: 1;
471 }
472 }
473
474 @mixin pf-root($selector, $isClass: true) {
475 @if $isClass {
476 $selector: "." + $selector;
477 }
478 #{$selector} {
479 @content
480 }
481 }
482
483 // Sets hamburger styles. Defaults to expand styles (right arrow)
484 // $collapse - if true, changes to left arrow
485 // $reset - will reset the bars to the default (no arrow)
486 @mixin pf-v6-hamburger($collapse: false, $reset: false) {
487 @if $reset {
488 --#{$button}--hamburger-icon--top--path: var(--#{$button}--hamburger-icon--top--path--base);
489 --#{$button}--hamburger-icon--arrow--path: var(--#{$button}--hamburger-icon--arrow--path--base);
490 --#{$button}--hamburger-icon--bottom--path: var(--#{$button}--hamburger-icon--bottom--path--base);
491 --#{$button}__icon--TransitionDelay: var(--#{$button}--hamburger-icon--TransitionDuration);
492 --#{$button}--hover__icon--TransitionDelay: var(--#{$button}--hamburger-icon--TransitionDuration);
493 } @else {
494 // set direction vars
495 --#{$button}--hamburger-icon--top--path: var(--#{$button}--hamburger-icon--top--collapse--path);
496 --#{$button}--hamburger-icon--arrow--path: var(--#{$button}--hamburger-icon--arrow--collapse--path);
497 --#{$button}--hamburger-icon--bottom--path: var(--#{$button}--hamburger-icon--bottom--collapse--path);
498
499 // collapse
500 @if $collapse {
501 --#{$button}__icon--TransitionDelay: 0s;
502 --#{$button}__icon--ScaleX: var(--#{$button}--m-hamburger__icon--m-collapse--ScaleX);
503 --#{$button}--hover__icon--TransitionDelay: 0s;
504 --#{$button}--hover__icon--ScaleX: var(--#{$button}--m-hamburger__icon--m-collapse--ScaleX);
505
506 // expand
507 } @else {
508 --#{$button}__icon--TransitionDelay: 0s;
509 --#{$button}__icon--ScaleX: var(--#{$button}--m-hamburger__icon--m-expand--ScaleX);
510 --#{$button}--hover__icon--TransitionDelay: 0s;
511 --#{$button}--hover__icon--ScaleX: var(--#{$button}--m-hamburger__icon--m-expand--ScaleX);
512 }
513 }
514 }