@swisspost/design-system-styles 5.3.2 → 5.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/basics.css +1 -1
- package/components/alert.scss +2 -1
- package/components/floating-label.scss +10 -5
- package/components/toast.scss +2 -2
- package/components/utilities.scss +2 -1
- package/functions/_color.scss +0 -20
- package/functions/_contrast.scss +70 -0
- package/functions/_index.scss +1 -0
- package/index.css +5 -3
- package/intranet.css +5 -3
- package/layouts/portal/_type.scss +4 -2
- package/mixins/_button.scss +12 -3
- package/package.json +13 -8
- package/placeholders/_notifications.scss +2 -2
- package/variables/_color.scss +2 -2
package/components/alert.scss
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
@use './../variables/components/alert';
|
|
15
15
|
@use './../variables/options';
|
|
16
16
|
@use './../functions/color' as color-fn;
|
|
17
|
+
@use './../functions/contrast' as contrast-fn;
|
|
17
18
|
@use './../placeholders/color' as color-ph;
|
|
18
19
|
@use './../placeholders/notifications';
|
|
19
20
|
|
|
@@ -71,7 +72,7 @@
|
|
|
71
72
|
--post-bg-rgb: #{color-fn.rgb-values($color)};
|
|
72
73
|
@extend %notification-#{$name};
|
|
73
74
|
|
|
74
|
-
@if (
|
|
75
|
+
@if (contrast-fn.light-or-dark($color) == 'dark') {
|
|
75
76
|
@extend %color-background-dark-variables;
|
|
76
77
|
} @else {
|
|
77
78
|
@extend %color-background-light-variables;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
@use 'sass:color';
|
|
2
|
+
@use 'sass:math';
|
|
2
3
|
|
|
3
4
|
@forward './../variables/options';
|
|
4
5
|
|
|
@@ -7,17 +8,21 @@
|
|
|
7
8
|
@use './../mixins/forms' as forms-mx;
|
|
8
9
|
@use './../mixins/utilities' as utilities-mx;
|
|
9
10
|
|
|
11
|
+
@use './../variables/type';
|
|
10
12
|
@use './../variables/components/forms';
|
|
11
13
|
@use './../variables/components/form-feedback';
|
|
12
14
|
|
|
13
15
|
.form-floating {
|
|
14
16
|
> label {
|
|
15
|
-
display:
|
|
16
|
-
align-items: center;
|
|
17
|
+
display: block;
|
|
17
18
|
top: forms.$input-border-width;
|
|
18
19
|
left: forms.$input-border-width;
|
|
19
20
|
margin: 0;
|
|
20
|
-
padding: forms.$form-floating-padding-
|
|
21
|
+
padding-inline: forms.$form-floating-padding-x;
|
|
22
|
+
padding-block: calc(
|
|
23
|
+
#{forms.$input-border-width} + #{forms.$form-floating-label-height * 0.5} - #{forms.$form-floating-label-font-size *
|
|
24
|
+
type.$line-height-base * 0.5}
|
|
25
|
+
);
|
|
21
26
|
height: forms.$form-floating-label-height;
|
|
22
27
|
border: 0;
|
|
23
28
|
color: forms.$form-floating-label-color;
|
|
@@ -50,7 +55,7 @@
|
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
~ label {
|
|
53
|
-
padding-top: 0;
|
|
58
|
+
padding-top: 0.7rem;
|
|
54
59
|
max-width: calc(
|
|
55
60
|
(100% * forms.$form-floating-label-upscale) -
|
|
56
61
|
(forms.$form-floating-label-translate-x * forms.$form-floating-label-upscale * 2) -
|
|
@@ -69,7 +74,7 @@
|
|
|
69
74
|
padding-bottom: forms.$form-floating-input-padding-b;
|
|
70
75
|
|
|
71
76
|
~ label {
|
|
72
|
-
padding-top: 0;
|
|
77
|
+
padding-top: 0.7rem;
|
|
73
78
|
max-width: calc(
|
|
74
79
|
(100% * forms.$form-floating-label-upscale) -
|
|
75
80
|
(forms.$form-floating-label-translate-x * forms.$form-floating-label-upscale * 2) -
|
package/components/toast.scss
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
@use './../variables/components/alert';
|
|
8
8
|
@use './../components/close';
|
|
9
9
|
@use './../functions/color' as color-fn;
|
|
10
|
+
@use './../functions/contrast' as contrast-fn;
|
|
10
11
|
@use './../placeholders/color' as color-ph;
|
|
11
12
|
@use './../placeholders/notifications';
|
|
12
13
|
|
|
@@ -147,7 +148,6 @@
|
|
|
147
148
|
}
|
|
148
149
|
/* stylelint-enable */
|
|
149
150
|
|
|
150
|
-
|
|
151
151
|
// Variants
|
|
152
152
|
|
|
153
153
|
@each $name, $color, $icon in alert.$alert-list {
|
|
@@ -155,7 +155,7 @@
|
|
|
155
155
|
--post-bg-rgb: #{color-fn.rgb-values($color)};
|
|
156
156
|
@extend %notification-#{$name};
|
|
157
157
|
|
|
158
|
-
@if (
|
|
158
|
+
@if (contrast-fn.light-or-dark($color) == 'dark') {
|
|
159
159
|
@extend %color-background-dark-variables;
|
|
160
160
|
} @else {
|
|
161
161
|
@extend %color-background-light-variables;
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
@use './../variables/spacing';
|
|
11
11
|
@use './../variables/grid';
|
|
12
12
|
@use './../functions/color' as color-fn;
|
|
13
|
+
@use './../functions/contrast' as contrast-fn;
|
|
13
14
|
@use './../placeholders/color' as color-ph;
|
|
14
15
|
|
|
15
16
|
.bold {
|
|
@@ -67,7 +68,7 @@ span.spacer {
|
|
|
67
68
|
--post-bg-rgb: #{color-fn.rgb-values($color)};
|
|
68
69
|
@extend %color-background-rgba;
|
|
69
70
|
|
|
70
|
-
@if (
|
|
71
|
+
@if (contrast-fn.light-or-dark($color) == 'dark') {
|
|
71
72
|
@extend %color-background-dark-variables;
|
|
72
73
|
} @else {
|
|
73
74
|
@extend %color-background-light-variables;
|
package/functions/_color.scss
CHANGED
|
@@ -33,23 +33,3 @@
|
|
|
33
33
|
|
|
34
34
|
@return string.unquote('\##{string.to-lower-case($hex)}');
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
// Color contrast funtion adopted from:
|
|
38
|
-
// https://medium.com/@MikeKellyWeb/calculating-color-contrast-with-sass-eff39ef23f96
|
|
39
|
-
@function get-contrast-color($color, $dark-color: #000, $light-color: #fff, $threshold: 128) {
|
|
40
|
-
@if (meta.type-of($color) != color) {
|
|
41
|
-
@error "Please provide a color for this function. Supplied: '#{$color}'.";
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
$r: color.red($color);
|
|
45
|
-
$g: color.green($color);
|
|
46
|
-
$b: color.blue($color);
|
|
47
|
-
|
|
48
|
-
$yiq: math.div(($r * 299) + ($g * 587) + ($b * 114), 1000);
|
|
49
|
-
|
|
50
|
-
@if ($yiq >= $threshold) {
|
|
51
|
-
@return $dark-color;
|
|
52
|
-
} @else {
|
|
53
|
-
@return $light-color;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
@use 'sass:math';
|
|
2
|
+
|
|
3
|
+
// From https://codetuts.dev/text-contrast-sass/
|
|
4
|
+
// with updated math.pow and math.div
|
|
5
|
+
|
|
6
|
+
@function luminance($color) {
|
|
7
|
+
$rgb: (
|
|
8
|
+
'red': red($color),
|
|
9
|
+
'green': green($color),
|
|
10
|
+
'blue': blue($color),
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
@each $color, $value in $rgb {
|
|
14
|
+
$value: math.div($value, 255);
|
|
15
|
+
|
|
16
|
+
@if ($value <= 0.03928) {
|
|
17
|
+
$value: math.div($value, 12.92);
|
|
18
|
+
} @else {
|
|
19
|
+
$value: math.div($value + 0.055, 1.055);
|
|
20
|
+
$value: math.pow($value, 2.4);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
$rgb: map-merge(
|
|
24
|
+
$rgb,
|
|
25
|
+
(
|
|
26
|
+
$color: $value,
|
|
27
|
+
)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
$result-luminance: (map-get($rgb, 'red') * 0.2126) + (map-get($rgb, 'green') * 0.7152) +
|
|
32
|
+
(map-get($rgb, 'blue') * 0.0722);
|
|
33
|
+
|
|
34
|
+
@return $result-luminance;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@function contrast-ratio($background-color, $text-color) {
|
|
38
|
+
$l-background: luminance($background-color);
|
|
39
|
+
$l-text: luminance($text-color);
|
|
40
|
+
|
|
41
|
+
@if ($l-background > $l-text) {
|
|
42
|
+
@return math.div($l-background + 0.05, $l-text + 0.05);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@return math.div($l-text + 0.05, $l-background + 0.05);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@function light-or-dark($background, $light-color: #fff, $dark-color: #000) {
|
|
49
|
+
// Contrast ratio with a light color
|
|
50
|
+
$contrast-light: contrast-ratio($background, $light-color);
|
|
51
|
+
|
|
52
|
+
// Contrast ratio with a dark color
|
|
53
|
+
$contrast-dark: contrast-ratio($background, $dark-color);
|
|
54
|
+
|
|
55
|
+
@if $contrast-light < $contrast-dark {
|
|
56
|
+
// Dark color has better contrast on light backgrounds, so background is light
|
|
57
|
+
@return 'light';
|
|
58
|
+
} @else {
|
|
59
|
+
// Light color has better contrast on dark backgrounds, so background is dark
|
|
60
|
+
@return 'dark';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@function get-best-contrast-text($background, $light-text: #fff, $dark-text: #000) {
|
|
65
|
+
@if light-or-dark($background, $light-text, $dark-text) == 'light' {
|
|
66
|
+
@return $dark-text;
|
|
67
|
+
} @else {
|
|
68
|
+
@return $light-text;
|
|
69
|
+
}
|
|
70
|
+
}
|
package/functions/_index.scss
CHANGED