Debian Codegraph @

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

raw
1 // PatternFly functions
2 // --------------------------------------------------
3 @use '../sass-utilities/scss-variables' as *;
4 @use '../sass-utilities/init' as *;
5 @use 'sass:math';
6 @use 'sass:meta';
7 @use 'sass:list';
8 @use 'sass:map';
9
10 // Transform px to rems
11 @function pf-strip-unit($num) {
12 @if meta.type-of($num) == 'number' and not math.is-unitless($num) {
13 @return math.div($num, ($num * 0 + 1));
14 }
15
16 @return $num;
17 }
18
19 @function pf-size-prem($pxval, $base: $pf-v6-global--space-size-root) {
20 @return math.div(pf-strip-unit($pxval), $base) * 1rem;
21 }
22
23 @function pf-font-prem($pxval, $base: $pf-v6-global--font-size-root) {
24 @return math.div(pf-strip-unit($pxval), $base) * 1rem;
25 }
26
27 // Return breakpoint for max-width
28 // Used in combination with min-width avoids 1px overlap
29 @function pf-v6-max-width-bp($breakpoint) {
30 @return calc($breakpoint - 1px);
31 }
32
33 // Return (width) breakpoint value if it exists
34 @function pf-breakpoint-value($breakpoint, $breakpoint-map: $pf-v6-global--breakpoint-name-map) {
35 @if map.has-key($breakpoint-map, #{$breakpoint}) {
36 @return #{map.get($breakpoint-map, #{$breakpoint})};
37 } @else {
38 @return false;
39 }
40 }
41
42 // Return height breakpoint value if it exists
43 @function pf-height-breakpoint-value($height-breakpoint, $height-breakpoint-map: $pf-v6-global--height-breakpoint-name-map) {
44 @if map.has-key($height-breakpoint-map, #{$height-breakpoint}) {
45 @return #{map.get($height-breakpoint-map, #{$height-breakpoint})};
46 } @else {
47 @return false;
48 }
49 }
50
51 // Build breakpoint map
52 // Based on $pf-v6-global--breakpoint-name-map
53 @function build-breakpoint-map($map-items...) {
54 $map: ();
55
56 @if list.length($map-items) == 0 {
57 $map: ("base": null);
58 $map: map.merge($map, $pf-v6-global--breakpoint-name-map);
59 } @else {
60 @each $breakpoint in $map-items {
61 @if not map.has-key($pf-v6-global--breakpoint-name-map, $breakpoint) and $breakpoint != "base" {
62 $map: map.merge($map, ("invalid breakpoint #{$breakpoint}": null));
63 } @else if $breakpoint == "base" {
64 $map: map.merge($map, ($breakpoint: null));
65 } @else {
66 $map: map.merge($map, ($breakpoint: map.get($pf-v6-global--breakpoint-name-map, #{$breakpoint})));
67 }
68 }
69 }
70
71 @return $map;
72 }
73
74 // Build height breakpoint map
75 // Based on $pf-v6-global--height-breakpoint-name-map
76 @function build-height-breakpoint-map($map-items...) {
77 $map: ();
78
79 @if list.length($map-items) == 0 {
80 $map: ("base": null);
81 $map: map.merge($map, $pf-v6-global--height-breakpoint-name-map);
82 } @else {
83 @each $breakpoint in $map-items {
84 @if not map.has-key($pf-v6-global--height-breakpoint-name-map, $breakpoint) and $breakpoint != "base" {
85 $map: map.merge($map, ("invalid breakpoint #{$breakpoint}": null));
86 } @else if $breakpoint == "base" {
87 $map: map.merge($map, ($breakpoint: null));
88 } @else {
89 $map: map.merge($map, ($breakpoint: map.get($pf-v6-global--height-breakpoint-name-map, #{$breakpoint})));
90 }
91 }
92 }
93
94 @return $map;
95 }
96
97
98 // Build spacer map
99 // Based on $pf-v6-global--spacer-map
100 @function build-spacer-map($map-items...) {
101 $map: ();
102
103 @if list.length($map-items) == 0 {
104 $map: ("none": 0);
105 $map: map.merge($map, $pf-v6-global--spacer-map);
106 $map: map.remove($map, "auto", "0");
107 }
108
109 @each $spacer in $map-items {
110 @if $spacer == "none" {
111 $map: map.merge($map, ($spacer: 0));
112 } @else {
113 $map: map.merge($map, ($spacer: map.get($pf-v6-global--spacer-map, #{$spacer})));
114 }
115 }
116
117 @return $map;
118 }
119
120 // Build variable map
121 // Based on custom map
122 @function build-variable-map($namespace, $map: ()) {
123 $new-map: ();
124
125 @each $size, $value in $map {
126 $new-map: map.merge($new-map, (map.get($map, $size): --#{$namespace}--#{$size}));
127 }
128
129 @return $new-map;
130 }
131
132 // Returns a calc() with the inverse of a value used for RTL. Most commonly used as the inverse/negative of a value in a transform function (eg, translate(), rotate(), scale(), etc)
133 // Shouldn't be used on an existing LTR style as adding a calc() in an existing style could be breaking. Should used within an RTL selector, which is basically an opt-in.
134 @function pf-v6-calc-inverse($val, $multiplier: var(--#{$pf-global}--inverse--multiplier)) {
135 @return calc(#{$val} * #{$multiplier});
136 }