@gitlab/ui 72.1.0 → 72.3.0

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,6 +1,12 @@
1
1
  {
2
2
  "theme": {
3
3
  "indigo": {
4
+ "10": {
5
+ "$value": "#f8f8ff",
6
+ "$type": "color",
7
+ "themeable": true,
8
+ "prefix": false
9
+ },
4
10
  "50": {
5
11
  "$value": "#f1f1ff",
6
12
  "$type": "color",
@@ -69,6 +75,12 @@
69
75
  }
70
76
  },
71
77
  "blue": {
78
+ "10": {
79
+ "$value": "#e6ecf0",
80
+ "$type": "color",
81
+ "themeable": true,
82
+ "prefix": false
83
+ },
72
84
  "50": {
73
85
  "$value": "#cdd8e3",
74
86
  "$type": "color",
@@ -137,6 +149,12 @@
137
149
  }
138
150
  },
139
151
  "light-blue": {
152
+ "10": {
153
+ "$value": "#eef3f7",
154
+ "$type": "color",
155
+ "themeable": true,
156
+ "prefix": false
157
+ },
140
158
  "50": {
141
159
  "$value": "#dde6ee",
142
160
  "$type": "color",
@@ -205,6 +223,12 @@
205
223
  }
206
224
  },
207
225
  "green": {
226
+ "10": {
227
+ "$value": "#eef4ef",
228
+ "$type": "color",
229
+ "themeable": true,
230
+ "prefix": false
231
+ },
208
232
  "50": {
209
233
  "$value": "#dde9de",
210
234
  "$type": "color",
@@ -273,6 +297,12 @@
273
297
  }
274
298
  },
275
299
  "red": {
300
+ "10": {
301
+ "$value": "#faf4f3",
302
+ "$type": "color",
303
+ "themeable": true,
304
+ "prefix": false
305
+ },
276
306
  "50": {
277
307
  "$value": "#f4e9e7",
278
308
  "$type": "color",
@@ -341,6 +371,12 @@
341
371
  }
342
372
  },
343
373
  "light-red": {
374
+ "10": {
375
+ "$value": "#fdf9f8",
376
+ "$type": "color",
377
+ "themeable": true,
378
+ "prefix": false
379
+ },
344
380
  "50": {
345
381
  "$value": "#faf2f1",
346
382
  "$type": "color",
@@ -1,17 +1,76 @@
1
- import { colorFromBackground } from '../utils/utils';
1
+ import { colorFromBackground, relativeLuminance, rgbFromHex } from '../utils/utils';
2
+ import { WHITE, GRAY_950 } from '../../dist/tokens/js/tokens';
3
+
4
+ const CONTRAST_LEVELS = [
5
+ {
6
+ grade: 'F',
7
+ min: 0,
8
+ max: 3,
9
+ },
10
+ {
11
+ grade: 'AA+',
12
+ min: 3,
13
+ max: 4.5,
14
+ },
15
+ {
16
+ grade: 'AA',
17
+ min: 4.5,
18
+ max: 7,
19
+ },
20
+ {
21
+ grade: 'AAA',
22
+ min: 7,
23
+ max: 22,
24
+ },
25
+ ];
2
26
 
3
27
  export const methods = {
28
+ isAlpha(value) {
29
+ return value.startsWith('rgba(');
30
+ },
4
31
  getTokenName(name, key) {
5
32
  return [name, key].filter(Boolean).join('.');
6
33
  },
7
34
  getTextColorClass(value) {
8
- if (value.startsWith('rgba(')) return '';
35
+ if (this.isAlpha(value)) return '';
9
36
  const textColorVariant = colorFromBackground(value, 4.5);
10
37
  return {
11
38
  'gl-text-gray-950': textColorVariant === 'dark',
12
39
  'gl-text-white': textColorVariant === 'light',
13
40
  };
14
41
  },
42
+ getColorContrast(foreground = 'light', background) {
43
+ const foregroundColor = {
44
+ light: WHITE,
45
+ dark: GRAY_950,
46
+ };
47
+ // Formula: http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef
48
+ const foregroundLuminance = relativeLuminance(rgbFromHex(foregroundColor[foreground])) + 0.05;
49
+ const backgroundLuminance = relativeLuminance(rgbFromHex(background)) + 0.05;
50
+
51
+ let score = foregroundLuminance / backgroundLuminance;
52
+ if (backgroundLuminance > foregroundLuminance) {
53
+ score = 1 / score;
54
+ }
55
+
56
+ const level = CONTRAST_LEVELS.find(({ min, max }) => {
57
+ return score >= min && score < max;
58
+ });
59
+
60
+ return {
61
+ score: (Math.round(score * 10) / 10).toFixed(1),
62
+ level,
63
+ };
64
+ },
65
+ getColorContrastClass(foreground, background) {
66
+ const { grade } = this.getColorContrast(foreground, background).level;
67
+ const isFail = grade === 'F';
68
+ const classes = {
69
+ light: isFail ? 'gl-inset-border-1-red-500 gl-text-red-500' : 'gl-text-gray-950',
70
+ dark: isFail ? 'gl-inset-border-1-red-300 gl-text-red-300' : 'gl-text-white',
71
+ };
72
+ return classes[foreground];
73
+ },
15
74
  };
16
75
 
17
76
  export const template = `
@@ -21,12 +80,30 @@ export const template = `
21
80
  <li
22
81
  v-for="(token, key) in tokens"
23
82
  :key="key"
24
- class="gl-display-flex gl-justify-content-space-between gl-gap-3 gl-p-3"
83
+ class="gl-display-flex gl-flex-wrap gl-align-items-center gl-justify-content-space-between gl-gap-3 gl-p-3"
25
84
  :class="getTextColorClass(token.$value)"
26
85
  :style="{ backgroundColor: token.$value }"
27
86
  >
28
87
  <code class="gl-reset-color">{{ getTokenName(name, key) }}</code>
29
- <code class="gl-reset-color">{{ token.$value }}</code>
88
+ <div class="gl-display-flex gl-align-items-center gl-gap-3">
89
+ <code class="gl-reset-color">{{ token.$value }}</code>
90
+ <code
91
+ v-if="!isAlpha(token.$value)"
92
+ class="gl-w-10 gl-text-center gl-rounded-base gl-font-xs gl-p-2 gl-bg-gray-900"
93
+ :class="getColorContrastClass('dark', token.$value)"
94
+ >
95
+ {{ getColorContrast('dark', token.$value).level.grade }}
96
+ {{ getColorContrast('dark', token.$value).score }}
97
+ </code>
98
+ <code
99
+ v-if="!isAlpha(token.$value)"
100
+ class="gl-w-10 gl-text-center gl-rounded-base gl-font-xs gl-p-2 gl-bg-white"
101
+ :class="getColorContrastClass('light', token.$value)"
102
+ >
103
+ {{ getColorContrast('light', token.$value).level.grade }}
104
+ {{ getColorContrast('light', token.$value).score }}
105
+ </code>
106
+ </div>
30
107
  </li>
31
108
  </ul>
32
109
  `;