@eui/styles 21.0.0-next.48 → 21.0.0-next.49

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.
@@ -1,28 +1,29 @@
1
1
  @use "sass:math";
2
+ @use "sass:color";
2
3
 
3
4
  @function toRGB($color) {
4
- @return red($color) + ", " + green($color) + ", " + blue($color);
5
+ @return red($color)+", "+green($color)+", "+blue($color);
5
6
  }
7
+
6
8
  @function getContrastOld($color) {
7
- $color-brightness: round(
8
- (red($color) * 299) + (green($color) * 587) +
9
- math.div((blue($color) * 114), 1000)
10
- );
11
- $light-color: round(
12
- (red(#fff) * 299) + (green(#fff) * 587) +
13
- math.div((blue(#fff) * 114), 1000)
14
- );
9
+ $color-brightness: round((red($color) * 299) + (green($color) * 587) + math.div((blue($color) * 114), 1000));
10
+ $light-color: round((red(#fff) * 299) + (green(#fff) * 587) + math.div((blue(#fff) * 114), 1000));
11
+
15
12
  @if abs($color-brightness) < math.div($light-color, 1.7) {
16
13
  @return #ffffff;
17
- } @else {
14
+ }
15
+
16
+ @else {
18
17
  @return #000000;
19
18
  }
20
19
  }
21
20
 
22
21
  @function col_r($color) {
23
- @if $color <= 0.03928 {
22
+ @if $color <=0.03928 {
24
23
  @return math.div($color, 12.92);
25
- } @else {
24
+ }
25
+
26
+ @else {
26
27
  @return math.pow(math.div(($color + 0.055), 1.055), (2.4));
27
28
  }
28
29
  }
@@ -39,12 +40,17 @@
39
40
  $ui_g_c: col_r($ui_g);
40
41
  $ui_b_c: col_r($ui_b);
41
42
 
42
- $L: (0.2126 * $ui_r_c) + (0.7152 * $ui_g_c) + (0.0722 * $ui_b_c);
43
- @if ($L > 0.179) {
44
- @return $darkColor;
45
- } @else {
46
- @return $lightColor;
47
- }
43
+ $L: (
44
+ 0.2126 * $ui_r_c) + (0.7152 * $ui_g_c) + (0.0722 * $ui_b_c
45
+ );
46
+
47
+ @if ($L > 0.179) {
48
+ @return $darkColor;
49
+ }
50
+
51
+ @else {
52
+ @return $lightColor;
53
+ }
48
54
  }
49
55
 
50
56
 
@@ -55,131 +61,47 @@
55
61
  // Adapted from: https://github.com/LeaVerou/contrast-ratio/blob/gh-pages/color.js
56
62
  // Formula: http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
57
63
  $rgba: red($color), green($color), blue($color);
58
- $rgba2: ();
64
+ $rgba2: (
65
+ );
59
66
 
60
- @for $i from 1 through 3 {
61
- $rgb: nth($rgba, $i);
62
- $rgb: calc($rgb / 255);
67
+ @for $i from 1 through 3 {
68
+ $rgb: nth($rgba, $i);
69
+ $rgb: calc($rgb / 255);
63
70
 
64
- $rgb: if($rgb < .03928, calc($rgb / 12.92), math.pow(math.div($rgb + .055, 1.055), 2.4));
71
+ $rgb: if($rgb < .03928, calc($rgb / 12.92), math.pow(math.div($rgb + .055, 1.055), 2.4));
65
72
 
66
- $rgba2: append($rgba2, $rgb);
67
- }
73
+ $rgba2: append($rgba2, $rgb);
74
+ }
68
75
 
69
- @return .2126 * nth($rgba2, 1) + .7152 * nth($rgba2, 2) + 0.0722 * nth($rgba2, 3);
70
- }
76
+ @return .2126 * nth($rgba2, 1)+.7152 * nth($rgba2, 2)+0.0722 * nth($rgba2, 3);
77
+ }
71
78
 
72
- @function calculate-contrast($color1, $color2) {
79
+ @function calculate-contrast($color1, $color2) {
73
80
  // Adapted from: https://github.com/LeaVerou/contrast-ratio/blob/gh-pages/color.js
74
81
  // Formula: http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef
75
82
  $luminance1: color_luminance($color1) + .05;
76
83
  $luminance2: color_luminance($color2) + .05;
77
84
  $ratio: math.div($luminance1, $luminance2);
78
85
 
79
- @if $luminance2 > $luminance1 {
80
- $ratio: calc(1 / $ratio);
86
+ @if $luminance2 >$luminance1 {
87
+ $ratio: calc(1 / $ratio);
81
88
  }
82
89
 
83
90
  $ratio: calc(round($ratio * 10) / 10);
84
91
 
85
92
  @return $ratio;
86
- }
87
-
88
-
89
- // https://www.jasongaylord.com/blog/2023/05/30/calculate-contrast-in-sass
90
-
91
- // NOT used as not accurate compared to chrome extension tool
92
-
93
- // @function sRGBToLinear($colorValue) {
94
- // $colorValue: calc($colorValue / 255);
95
- // @if $colorValue <= 0.04045 {
96
- // @return calc($colorValue / 12.92);
97
- // } @else {
98
- // @return calc(math.pow($colorValue + 0.055, 2.4));
99
- // }
100
- // }
101
-
102
- // @function calculate-contrast($value1, $value2) {
103
- // $luminance1: (0.2126 * sRGBToLinear(red($value1))) +
104
- // (0.7152 * sRGBToLinear(green($value1))) +
105
- // (0.0722 * sRGBToLinear(blue($value1)));
106
- // $luminance2: (0.2126 * sRGBToLinear(red($value2))) +
107
- // (0.7152 * sRGBToLinear(green($value2))) +
108
- // (0.0722 * sRGBToLinear(blue($value2)));
109
-
110
- // @return calc(
111
- // (max($luminance1, $luminance2) + 0.05) /
112
- // (min($luminance1, $luminance2) + 0.05)
113
- // );
114
- // }
115
-
116
-
117
-
118
- // TO BE TESTED to auto-calculated based on a certain ratio, creating high-contrast maps, etc...
119
-
120
- @function find-safe-color($color, $ratio: 4.5) {
121
- $lightness: lightness($color);
122
- $value: $color;
123
- $contrast: 0;
124
- $i: 0;
125
-
126
- @if $lightness < 50 {
127
- $value: lighten($value, 5%);
128
- $contrast: calculate-contrast($color, $value);
129
- $i: $i + 1;
130
-
131
- @while $contrast < $ratio and $i < 20 {
132
- $value: lighten($value, 5%);
133
- $contrast: calculate-contrast($color, $value);
134
- $i: $i + 1;
135
- }
136
- } @else {
137
- $value: darken($value, 5%);
138
- $contrast: calculate-contrast($color, $value);
139
- $i: $i + 1;
140
-
141
- @while $contrast < $ratio and $i < 20 {
142
- $value: darken($value, 5%);
143
- $contrast: calculate-contrast($color, $value);
144
- $i: $i + 1;
145
- }
146
- }
147
-
148
- @if $i >= 20 {
149
- @debug "Color not safe";
150
- }
93
+ }
151
94
 
152
- @return ($value, $contrast);
95
+ @function tint-color($color, $weight) {
96
+ @return color.mix(white, $color, $weight);
153
97
  }
154
98
 
155
- // interesting to generate maps of same colors and corresponding to some defaults for some
156
- // categories of html elements where the colors are used : to be checked later
157
-
158
- @function wcag-safe-colors($base-color) {
159
- $colors: ();
160
-
161
- $wcag30: find-safe-color($base-color, 3);
162
- $wcag45: find-safe-color($base-color);
163
- $wcag70: find-safe-color($base-color, 7);
164
-
165
- // Generate shades
166
- $colors: map-merge(
167
- $colors,
168
- (
169
- "base-color": $base-color,
170
- "wcag20-aa-normal-color": nth($wcag45, 1),
171
- "wcag20-aa-normal-ratio": nth($wcag45, 2),
172
- "wcag20-aa-large-color": nth($wcag30, 1),
173
- "wcag20-aa-large-ratio": nth($wcag30, 2),
174
- "wcag21-aa-input-color": nth($wcag30, 1),
175
- "wcag21-aa-input-ratio": nth($wcag30, 1),
176
- "wcag21-aaa-normal-color": nth($wcag70, 1),
177
- "wcag21-aaa-normal-ratio": nth($wcag70, 2),
178
- "wcag21-aaa-large-color": nth($wcag45, 1),
179
- "wcag21-aaa-large-ratio": nth($wcag45, 2),
180
- )
181
- );
99
+ // Shade a color: mix a color with black
100
+ @function shade-color($color, $weight) {
101
+ @return color.mix(black, $color, $weight);
102
+ }
182
103
 
183
- @return $colors;
104
+ @function shift-color($color, $weight) {
105
+ @return if($weight > 0, shade-color($color, $weight), tint-color($color, -$weight));
184
106
  }
185
107
 
@@ -0,0 +1,232 @@
1
+ @use 'sass:map';
2
+ @use 'sass:color';
3
+ @use '../01-base/' as base;
4
+ @use './colors-default' as defaultColors;
5
+
6
+ $color-map: (
7
+ br: base.mapReverseValues(map.get(defaultColors.$color-map, 'br')),
8
+ pr: base.mapReverseValues(map.get(defaultColors.$color-map, 'pr')),
9
+ gr: base.mapReverseValues(map.get(defaultColors.$color-map, 'gr')),
10
+ grn: base.mapReverseValues(map.get(defaultColors.$color-map, 'grn')),
11
+ cta: base.mapReverseValues(map.get(defaultColors.$color-map, 'cta')),
12
+ in: base.mapReverseValues(map.get(defaultColors.$color-map, 'in')),
13
+ su: base.mapReverseValues(map.get(defaultColors.$color-map, 'su')),
14
+ wa: base.mapReverseValues(map.get(defaultColors.$color-map, 'wa')),
15
+ da: base.mapReverseValues(map.get(defaultColors.$color-map, 'da'))
16
+ );
17
+
18
+ $color-state-map: (
19
+ branding: (
20
+ base: map.get(map.get($color-map, br), 900),
21
+ default: map.get(map.get($color-map, br), 900),
22
+ lighter: map.get(map.get($color-map, br), 700),
23
+ light: map.get(map.get($color-map, br), 800),
24
+ dark: map.get(map.get($color-map, br), 950),
25
+ surface: map.get(map.get($color-map, br), 900),
26
+ on-surface: base.getContrast(map.get(map.get($color-map, br), 900)),
27
+ surface-light: map.get(map.get($color-map, br), 800),
28
+ on-surface-light: base.getContrast(map.get(map.get($color-map, br), 800)),
29
+ surface-dark: map.get(map.get($color-map, br), 950),
30
+ on-surface-dark: base.getContrast(map.get(map.get($color-map, br), 950)),
31
+ ),
32
+ primary: (
33
+ base: map.get(map.get($color-map, pr), 600),
34
+ default: map.get(map.get($color-map, pr), 700),
35
+ lighter: map.get(map.get($color-map, pr), 500),
36
+ light: map.get(map.get($color-map, pr), 600),
37
+ dark: map.get(map.get($color-map, pr), 900),
38
+ darker: map.get(map.get($color-map, pr), 950),
39
+ surface-light: map.get(map.get($color-map, pr), 75),
40
+ on-surface-light: map.get(map.get($color-map, pr), 900),
41
+ surface-light-hover: map.get(map.get($color-map, pr), 100),
42
+ on-surface-light-hover: map.get(map.get($color-map, pr), 950),
43
+ surface-medium: map.get(map.get($color-map, pr), 200),
44
+ on-surface-medium: base.getContrast(map.get(map.get($color-map, pr), 200)),
45
+ surface-medium-hover: map.get(map.get($color-map, pr), 300),
46
+ on-surface-medium-hover: base.getContrast(map.get(map.get($color-map, pr), 300)),
47
+ surface: map.get(map.get($color-map, pr), 600),
48
+ on-surface: base.getContrast(map.get(map.get($color-map, pr), 600)),
49
+ surface-hover: map.get(map.get($color-map, pr), 700),
50
+ on-surface-hover: base.getContrast(map.get(map.get($color-map, pr), 700)),
51
+ surface-dark: map.get(map.get($color-map, pr), 900),
52
+ on-surface-dark: base.getContrast(map.get(map.get($color-map, pr), 900)),
53
+ border: map.get(map.get($color-map, pr), 500),
54
+ border-light: map.get(map.get($color-map, pr), 300),
55
+ border-lighter: map.get(map.get($color-map, pr), 200),
56
+ ),
57
+ secondary: (
58
+ base: map.get(map.get($color-map, gr), 500),
59
+ default: map.get(map.get($color-map, gr), 800),
60
+ lighter: map.get(map.get($color-map, gr), 600),
61
+ light: map.get(map.get($color-map, gr), 700),
62
+ dark: map.get(map.get($color-map, gr), 900),
63
+ darker: map.get(map.get($color-map, gr), 950),
64
+ surface-light: map.get(map.get($color-map, gr), 50),
65
+ on-surface-light: map.get(map.get($color-map, gr), 900),
66
+ surface-light-hover: map.get(map.get($color-map, gr), 75),
67
+ on-surface-light-hover: map.get(map.get($color-map, gr), 950),
68
+ surface-medium: map.get(map.get($color-map, gr), 75),
69
+ on-surface-medium: map.get(map.get($color-map, gr), 900),
70
+ surface-medium-hover: map.get(map.get($color-map, gr), 100),
71
+ on-surface-medium-hover: map.get(map.get($color-map, gr), 950),
72
+ surface: map.get(map.get($color-map, gr), 600),
73
+ on-surface: base.getContrast(map.get(map.get($color-map, gr), 600)),
74
+ surface-hover: map.get(map.get($color-map, gr), 700),
75
+ on-surface-hover: base.getContrast(map.get(map.get($color-map, gr), 700)),
76
+ surface-dark: map.get(map.get($color-map, gr), 900),
77
+ on-surface-dark: base.getContrast(map.get(map.get($color-map, gr), 900)),
78
+ border: map.get(map.get($color-map, gr), 500),
79
+ border-light: map.get(map.get($color-map, gr), 300),
80
+ border-lighter: map.get(map.get($color-map, gr), 200),
81
+ ),
82
+ neutral: (
83
+ base: map.get(map.get($color-map, grn), 500),
84
+ default: map.get(map.get($color-map, grn), 500),
85
+ lighter: map.get(map.get($color-map, grn), 600),
86
+ light: map.get(map.get($color-map, grn), 700),
87
+ dark: map.get(map.get($color-map, grn), 900),
88
+ darker: map.get(map.get($color-map, grn), 950),
89
+ surface-light: map.get(map.get($color-map, grn), 50),
90
+ on-surface-light: map.get(map.get($color-map, grn), 900),
91
+ surface-light-hover: map.get(map.get($color-map, grn), 75),
92
+ on-surface-light-hover: map.get(map.get($color-map, grn), 950),
93
+ surface-medium: map.get(map.get($color-map, grn), 75),
94
+ on-surface-medium: map.get(map.get($color-map, grn), 900),
95
+ surface-medium-hover: map.get(map.get($color-map, grn), 100),
96
+ on-surface-medium-hover: map.get(map.get($color-map, grn), 950),
97
+ surface: map.get(map.get($color-map, grn), 400),
98
+ on-surface: base.getContrast(map.get(map.get($color-map, grn), 400)),
99
+ surface-hover: map.get(map.get($color-map, grn), 300),
100
+ on-surface-hover: base.getContrast(map.get(map.get($color-map, grn), 300)),
101
+ surface-dark: map.get(map.get($color-map, grn), 900),
102
+ on-surface-dark: base.getContrast(map.get(map.get($color-map, grn), 900)),
103
+ border: map.get(map.get($color-map, grn), 500),
104
+ border-light: map.get(map.get($color-map, grn), 400),
105
+ border-lighter: map.get(map.get($color-map, grn), 300),
106
+ ),
107
+ cta: (
108
+ base: map.get(map.get($color-map, cta), 400),
109
+ default: map.get(map.get($color-map, cta), 900),
110
+ lighter: map.get(map.get($color-map, cta), 400),
111
+ light: map.get(map.get($color-map, cta), 500),
112
+ dark: map.get(map.get($color-map, cta), 800),
113
+ darker: map.get(map.get($color-map, cta), 900),
114
+ surface-light: map.get(map.get($color-map, cta), 25),
115
+ on-surface-light: map.get(map.get($color-map, cta), 800),
116
+ surface-light-hover: map.get(map.get($color-map, cta), 50),
117
+ on-surface-light-hover: map.get(map.get($color-map, cta), 950),
118
+ surface-medium: map.get(map.get($color-map, cta), 75),
119
+ on-surface-medium: map.get(map.get($color-map, cta), 900),
120
+ surface-medium-hover: map.get(map.get($color-map, cta), 100),
121
+ on-surface-medium-hover: map.get(map.get($color-map, cta), 950),
122
+ surface: map.get(map.get($color-map, cta), 400),
123
+ on-surface: base.getContrast(map.get(map.get($color-map, cta), 400)),
124
+ surface-hover: map.get(map.get($color-map, cta), 500),
125
+ on-surface-hover: base.getContrast(map.get(map.get($color-map, cta), 500)),
126
+ surface-dark: map.get(map.get($color-map, cta), 600),
127
+ on-surface-dark: base.getContrast(map.get(map.get($color-map, cta), 600)),
128
+ border: map.get(map.get($color-map, cta), 300),
129
+ border-light: map.get(map.get($color-map, cta), 100),
130
+ border-lighter: map.get(map.get($color-map, cta), 75),
131
+ ),
132
+ info: (
133
+ base: map.get(map.get($color-map, in), 500),
134
+ default: map.get(map.get($color-map, in), 600),
135
+ lighter: map.get(map.get($color-map, in), 400),
136
+ light: map.get(map.get($color-map, in), 500),
137
+ dark: map.get(map.get($color-map, in), 800),
138
+ darker: map.get(map.get($color-map, in), 900),
139
+ surface-light: map.get(map.get($color-map, in), 75),
140
+ on-surface-light: map.get(map.get($color-map, in), 600),
141
+ surface-light-hover: map.get(map.get($color-map, in), 100),
142
+ on-surface-light-hover: map.get(map.get($color-map, in), 800),
143
+ surface-medium: map.get(map.get($color-map, in), 200),
144
+ on-surface-medium: map.get(map.get($color-map, in), 950),
145
+ surface-medium-hover: map.get(map.get($color-map, in), 300),
146
+ on-surface-medium-hover: base.getContrast(map.get(map.get($color-map, in), 300)),
147
+ surface: map.get(map.get($color-map, in), 600),
148
+ on-surface: base.getContrast(map.get(map.get($color-map, in), 600)),
149
+ surface-hover: map.get(map.get($color-map, in), 800),
150
+ on-surface-hover: base.getContrast(map.get(map.get($color-map, in), 800)),
151
+ surface-dark: map.get(map.get($color-map, in), 800),
152
+ on-surface-dark: base.getContrast(map.get(map.get($color-map, in), 800)),
153
+ border: map.get(map.get($color-map, in), 400),
154
+ border-light: map.get(map.get($color-map, in), 300),
155
+ border-lighter: map.get(map.get($color-map, in), 200),
156
+ ),
157
+ success: (
158
+ base: map.get(map.get($color-map, su), 700),
159
+ default: map.get(map.get($color-map, su), 900),
160
+ lighter: map.get(map.get($color-map, su), 700),
161
+ light: map.get(map.get($color-map, su), 800),
162
+ dark: map.get(map.get($color-map, su), 900),
163
+ darker: map.get(map.get($color-map, su), 950),
164
+ surface-light: map.get(map.get($color-map, su), 100),
165
+ on-surface-light: map.get(map.get($color-map, su), 950),
166
+ surface-light-hover: map.get(map.get($color-map, su), 200),
167
+ on-surface-light-hover: map.get(map.get($color-map, su), 950),
168
+ surface-medium: map.get(map.get($color-map, su), 300),
169
+ on-surface-medium: base.getContrast(map.get(map.get($color-map, su), 300)),
170
+ surface-medium-hover: map.get(map.get($color-map, su), 400),
171
+ on-surface-medium-hover: base.getContrast(map.get(map.get($color-map, su), 400)),
172
+ surface: map.get(map.get($color-map, su), 900),
173
+ on-surface: base.getContrast(map.get(map.get($color-map, su), 900)),
174
+ surface-hover: map.get(map.get($color-map, su), 950),
175
+ on-surface-hover: base.getContrast(map.get(map.get($color-map, su), 950)),
176
+ surface-dark: map.get(map.get($color-map, su), 950),
177
+ on-surface-dark: base.getContrast(map.get(map.get($color-map, su), 950)),
178
+ border: map.get(map.get($color-map, su), 600),
179
+ border-light: map.get(map.get($color-map, su), 400),
180
+ border-lighter: map.get(map.get($color-map, su), 300),
181
+ ),
182
+ warning: (
183
+ base: map.get(map.get($color-map, wa), 500),
184
+ default: map.get(map.get($color-map, wa), 900),
185
+ lighter: map.get(map.get($color-map, wa), 700),
186
+ light: map.get(map.get($color-map, wa), 800),
187
+ dark: map.get(map.get($color-map, wa), 950),
188
+ darker: map.get(map.get($color-map, wa), 950),
189
+ surface-light: map.get(map.get($color-map, wa), 50),
190
+ on-surface-light: map.get(map.get($color-map, wa), 900),
191
+ surface-light-hover: map.get(map.get($color-map, wa), 75),
192
+ on-surface-light-hover: map.get(map.get($color-map, wa), 950),
193
+ surface-medium: map.get(map.get($color-map, wa), 100),
194
+ on-surface-medium: map.get(map.get($color-map, wa), 900),
195
+ surface-medium-hover: map.get(map.get($color-map, wa), 200),
196
+ on-surface-medium-hover: map.get(map.get($color-map, wa), 950),
197
+ surface: map.get(map.get($color-map, wa), 500),
198
+ on-surface: base.getContrast(map.get(map.get($color-map, wa), 500)),
199
+ surface-hover: map.get(map.get($color-map, wa), 600),
200
+ on-surface-hover: base.getContrast(map.get(map.get($color-map, wa), 600)),
201
+ surface-dark: map.get(map.get($color-map, wa), 900),
202
+ on-surface-dark: base.getContrast(map.get(map.get($color-map, wa), 900)),
203
+ border: map.get(map.get($color-map, wa), 400),
204
+ border-light: map.get(map.get($color-map, wa), 200),
205
+ border-lighter: map.get(map.get($color-map, wa), 100),
206
+ ),
207
+ danger: (
208
+ base: map.get(map.get($color-map, da), 500),
209
+ default: map.get(map.get($color-map, da), 600),
210
+ lighter: map.get(map.get($color-map, da), 400),
211
+ light: map.get(map.get($color-map, da), 500),
212
+ dark: map.get(map.get($color-map, da), 700),
213
+ darker: map.get(map.get($color-map, da), 800),
214
+ surface-light: map.get(map.get($color-map, da), 75),
215
+ on-surface-light: map.get(map.get($color-map, da), 700),
216
+ surface-light-hover: map.get(map.get($color-map, da), 100),
217
+ on-surface-light-hover: map.get(map.get($color-map, da), 900),
218
+ surface-medium: map.get(map.get($color-map, da), 200),
219
+ on-surface-medium: map.get(map.get($color-map, da), 900),
220
+ surface-medium-hover: map.get(map.get($color-map, da), 300),
221
+ on-surface-medium-hover: map.get(map.get($color-map, da), 950),
222
+ surface: map.get(map.get($color-map, da), 600),
223
+ on-surface: base.getContrast(map.get(map.get($color-map, da), 600)),
224
+ surface-hover: map.get(map.get($color-map, da), 600),
225
+ on-surface-hover: base.getContrast(map.get(map.get($color-map, da), 700)),
226
+ surface-dark: map.get(map.get($color-map, da), 800),
227
+ on-surface-dark: base.getContrast(map.get(map.get($color-map, da), 800)),
228
+ border: map.get(map.get($color-map, da), 500),
229
+ border-light: map.get(map.get($color-map, da), 300),
230
+ border-lighter: map.get(map.get($color-map, da), 200),
231
+ ),
232
+ );