@kenlo/sds-design-system 0.9.9 → 1.0.2

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.
Files changed (45) hide show
  1. package/README.md +58 -7
  2. package/components/Avatar/Avatar.css +22 -0
  3. package/components/Button/Button.css +95 -8
  4. package/components/Card/Card.css +16 -6
  5. package/components/Card/card-variants.js +18 -0
  6. package/components/Card/card.marko +12 -2
  7. package/components/Checkbox/Checkbox.css +56 -0
  8. package/components/ColorPicker/ColorPicker.css +25 -2
  9. package/components/ColorPicker/color-picker.marko +25 -4
  10. package/components/DatePicker/DatePicker.css +22 -0
  11. package/components/Floating/focus-when-ready.js +59 -0
  12. package/components/Incrementer/Incrementer.css +22 -0
  13. package/components/Input/Input.css +25 -2
  14. package/components/Menu/Menu.css +21 -11
  15. package/components/Menu/menu-variants.js +12 -0
  16. package/components/Menu/menu.marko +11 -7
  17. package/components/Pill/Pill.css +46 -0
  18. package/components/Radio/Radio.css +75 -0
  19. package/components/Select/Select.css +21 -1
  20. package/components/Select/select-options.js +10 -1
  21. package/components/Select/select.marko +112 -5
  22. package/components/Table/Table.css +73 -2
  23. package/components/Table/table-column-picker.marko +161 -0
  24. package/components/Table/table-logic.js +56 -0
  25. package/components/Table/table.marko +50 -12
  26. package/components/TextEditor/TextEditor.css +2 -2
  27. package/components/Toggle/Toggle.css +40 -0
  28. package/components/Tooltip/Tooltip.css +2 -2
  29. package/components/Uploader/Uploader.css +23 -0
  30. package/foundations/custom-scheme.js +128 -10
  31. package/foundations/fonts/OFL.txt +114 -0
  32. package/foundations/fonts/fonts.json +152 -0
  33. package/foundations/fonts/manrope-cyrillic-ext.woff2 +0 -0
  34. package/foundations/fonts/manrope-cyrillic.woff2 +0 -0
  35. package/foundations/fonts/manrope-greek.woff2 +0 -0
  36. package/foundations/fonts/manrope-latin-ext.woff2 +0 -0
  37. package/foundations/fonts/manrope-latin.woff2 +0 -0
  38. package/foundations/fonts/manrope-vietnamese.woff2 +0 -0
  39. package/foundations/tokens.css +1095 -15
  40. package/icons/generated/fluent-chevron-down-filled.marko +3 -0
  41. package/icons/generated/fluent-chevron-up-filled.marko +3 -0
  42. package/icons/generated/fluent-column-triple-regular.marko +3 -0
  43. package/icons/manifest.json +3 -0
  44. package/marko.json +3 -0
  45. package/package.json +8 -3
@@ -24,6 +24,21 @@
24
24
  import { pickLabelColour, FALLBACK_TOKENS } from './contrast.js';
25
25
 
26
26
  const STYLE_ID = 'sds-custom-scheme';
27
+ /**
28
+ * What the document wears while the primary slot holds a gradient.
29
+ *
30
+ * `border-color` and `color` reject a gradient, so a stroke reads the `-solid` companion —
31
+ * the first stop, flat. Painting a gradient ON a stroke needs a different shape of rule
32
+ * altogether: a two-layer background over a transparent border. A stylesheet cannot ask
33
+ * what a custom property contains, so the JavaScript that fills the slot says it here.
34
+ *
35
+ * KDLS wrote those rules under `[data-color-scheme="lya"]`, its own brand gradient. This
36
+ * says the thing that is actually true — the slot holds a gradient — rather than which
37
+ * brand is in use, so it works for any site's gradient.
38
+ */
39
+ const GRADIENT_MARK = 'data-primary-gradient';
40
+ /** The complement's own element — see applyComplementColor for why it is not the same one. */
41
+ const COMPLEMENT_STYLE_ID = 'sds-custom-complement';
27
42
  const TONES = [10, 20, 30, 40, 50, 60, 70, 80, 90];
28
43
  /** The tones a component uses as a surface, and therefore needs a label colour for. */
29
44
  const SURFACE_TONES = [10, 20, 30, 40, 50];
@@ -125,23 +140,67 @@ export function generateGradientPalette(hexes) {
125
140
  }, {});
126
141
  }
127
142
 
128
- /** WCAG relative luminance, deciding whether text on the colour is white or black. */
129
- /** The token for the contrast pick, so a literal never reaches the stylesheet. */
130
- export function onPrimaryToken(hex) {
131
- return FALLBACK_TOKENS[onPrimaryColor(hex)];
132
- }
133
-
134
- export function onPrimaryColor(hex) {
143
+ /** WCAG relative luminance. */
144
+ function luminance(hex) {
135
145
  const clean = assertHex(hex).replace(/^#/, '').slice(0, 6);
136
146
  const n = parseInt(clean, 16);
137
147
  const toLinear = (c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
138
148
  const r = toLinear(((n >> 16) & 255) / 255);
139
149
  const g = toLinear(((n >> 8) & 255) / 255);
140
150
  const b = toLinear((n & 255) / 255);
141
- const lum = 0.2126 * r + 0.7152 * g + 0.0722 * b;
142
- return 1.05 / (lum + 0.05) >= (lum + 0.05) / 0.05 ? '#FFFFFF' : '#000000';
151
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
152
+ }
153
+
154
+ /** WCAG contrast between a surface and white or black. */
155
+ const contrastWithWhite = (hex) => 1.05 / (luminance(hex) + 0.05);
156
+ const contrastWithBlack = (hex) => (luminance(hex) + 0.05) / 0.05;
157
+
158
+ /** The ratio below which WCAG stops calling normal text readable. */
159
+ const AA = 4.5;
160
+
161
+ /** The token for the contrast pick, so a literal never reaches the stylesheet. */
162
+ export function onPrimaryToken(hex) {
163
+ return FALLBACK_TOKENS[onPrimaryColor(hex)];
164
+ }
165
+
166
+ export function onPrimaryColor(hex) {
167
+ return contrastWithWhite(hex) >= contrastWithBlack(hex) ? '#FFFFFF' : '#000000';
143
168
  }
144
169
 
170
+ /**
171
+ * The label for a surface made of several stops, judged by the WORST of them.
172
+ *
173
+ * A label is as readable as its least readable part, and a gradient draws the text across
174
+ * every stop. Choosing against the first one — which is what this did — picked white for
175
+ * `#2E7D32 → #BF71E5`, the portal's own default pair: 5.13:1 on the green end and 3.13:1
176
+ * on the purple, under AA, on the half of the control nobody looks at.
177
+ *
178
+ * It warns rather than throws when neither choice clears AA, because that is a fact about
179
+ * the two colours somebody chose, not a bug: no label clears 4.5:1 over that pair. The
180
+ * system picks the better of the two and says so, so a CMS can tell the estate agency
181
+ * before the site is published. Silently shipping 3.13:1 is how a design system becomes
182
+ * the reason a site cannot be read.
183
+ */
184
+ export function onGradientColor(hexes) {
185
+ const worst = (against) => Math.min(...hexes.map(against));
186
+ const best = worst(contrastWithWhite) >= worst(contrastWithBlack) ? '#FFFFFF' : '#000000';
187
+ const ratio = best === '#FFFFFF' ? worst(contrastWithWhite) : worst(contrastWithBlack);
188
+
189
+ if (ratio < AA) {
190
+ const weakest = hexes
191
+ .map((hex) => [hex, best === '#FFFFFF' ? contrastWithWhite(hex) : contrastWithBlack(hex)])
192
+ .sort((a, b) => a[1] - b[1])[0];
193
+ console.warn(
194
+ `[sds] no label colour reaches ${AA}:1 across this gradient — `
195
+ + `the best available is ${best} at ${ratio.toFixed(2)}:1, weakest on ${weakest[0]}. `
196
+ + 'Choose a pair with less distance in lightness.',
197
+ );
198
+ }
199
+ return best;
200
+ }
201
+
202
+ export const onGradientToken = (hexes) => FALLBACK_TOKENS[onGradientColor(hexes)];
203
+
145
204
  function invertPalette(light) {
146
205
  return {
147
206
  10: light[90], 20: light[80], 30: light[70], 40: light[60], 50: light[50],
@@ -206,6 +265,7 @@ function inject(light, onColor, solidOf) {
206
265
  /** Fills the primary slot with a solid ramp generated from one hex. */
207
266
  export function applyCustomColor(hex) {
208
267
  inject(generatePalette(hex), onPrimaryToken(hex), (value) => value);
268
+ document.documentElement.removeAttribute(GRADIENT_MARK);
209
269
  }
210
270
 
211
271
  /**
@@ -214,9 +274,67 @@ export function applyCustomColor(hex) {
214
274
  * where a label starts.
215
275
  */
216
276
  export function applyCustomGradient(hexes) {
217
- inject(generateGradientPalette(hexes), onPrimaryToken(hexes[0]), firstStopOf);
277
+ inject(generateGradientPalette(hexes), onGradientToken(hexes), firstStopOf);
278
+ document.documentElement.setAttribute(GRADIENT_MARK, '');
218
279
  }
219
280
 
281
+ /**
282
+ * The complementary colour — the second of the two a site's brand actually has.
283
+ *
284
+ * A brand has a highlight and a complement. The highlight fills the primary slot and
285
+ * paints everything; the complement paints one thing, the ghost button, which is the
286
+ * outlined control. SDS could only receive the first of the two, so a product that
287
+ * modelled both had to drop one at the border.
288
+ *
289
+ * It is a LAYER rather than a third mode, and that is the whole design:
290
+ *
291
+ * applyCustomColor(highlight) one solid
292
+ * applyCustomColor(highlight) + this two solids
293
+ * applyCustomGradient([start, end]) gradient — this is not used
294
+ *
295
+ * So "two solids" is "one solid" with one more call, and no component needs to be told
296
+ * which of the three is in effect. `Button.css` reads `var(--color-complement-50,
297
+ * var(--color-primary-50-solid))`: with no complement set the fallback fires and the ghost
298
+ * button is byte for byte what it has always been, in every consumer that never uses this.
299
+ *
300
+ * Its own <style> element, not the primary's. One replacing the other would mean that
301
+ * re-picking the highlight silently dropped the complement — two answers, not one.
302
+ *
303
+ * No `-solid` twins. That suffix exists because the primary slot may hold a gradient and
304
+ * `color` / `box-shadow` reject one; this slot is solid by definition, so the twin would
305
+ * be the same value under a longer name. No `-on` labels either: the ghost button paints
306
+ * the complement ON the complement's own pale tones, which is the contrast the primary
307
+ * ramp already answers for.
308
+ */
309
+ export function applyComplementColor(hex) {
310
+ const light = generatePalette(hex);
311
+ const dark = invertPalette(light);
312
+ const vars = (palette) => TONES
313
+ .map((tone) => `--color-complement-${tone}:${palette[tone]};`)
314
+ .join('');
315
+
316
+ let el = document.getElementById(COMPLEMENT_STYLE_ID);
317
+ if (!el) {
318
+ el = document.createElement('style');
319
+ el.id = COMPLEMENT_STYLE_ID;
320
+ document.head.appendChild(el);
321
+ }
322
+ el.textContent = `:root{${vars(light)}}[data-theme="dark"]{${vars(dark)}}`;
323
+ }
324
+
325
+ export function clearComplementColor() {
326
+ document.getElementById(COMPLEMENT_STYLE_ID)?.remove();
327
+ }
328
+
329
+ /**
330
+ * Drops both layers.
331
+ *
332
+ * Both, because this is what runs when the reader picks an installed scheme — `leaf`,
333
+ * `sea` — and at that moment the site is not on custom colours at all. Leaving the
334
+ * complement behind would paint the ghost button a colour nothing else on screen explains.
335
+ */
220
336
  export function clearCustomScheme() {
221
337
  document.getElementById(STYLE_ID)?.remove();
338
+ document.documentElement.removeAttribute(GRADIENT_MARK);
339
+ clearComplementColor();
222
340
  }
@@ -0,0 +1,114 @@
1
+ Manrope
2
+ Designed by Mikhail Sharanda.
3
+ Licensed under the SIL Open Font License, Version 1.1.
4
+
5
+ Obtained from Google Fonts (https://fonts.google.com/specimen/Manrope), which reports the
6
+ licence as "ofl". The .woff2 files in this directory are Google's own subsets, downloaded
7
+ unmodified by scripts/gen-font.mjs — run `npm run gen:font` to refresh them.
8
+
9
+ Manrope is the only typeface this package REDISTRIBUTES, which is why it is the only one
10
+ this file has to cover. The four opt-in families the picker offers — Inter, Montserrat,
11
+ Nunito and Source Sans 3 — are also SIL OFL 1.1, and are equally covered where they are
12
+ actually served from: Kenlo's bucket, published by the kdls-design-system pipeline.
13
+ Referencing a file by URL is not redistribution; carrying it in a package is.
14
+
15
+ The full licence text follows, as published by SIL at https://openfontlicense.org.
16
+
17
+ -------------------------------------------------------------------------------
18
+ Copyright (c) <dates>, <Copyright Holder> (<URL|email>),
19
+ with Reserved Font Name <Reserved Font Name>.
20
+ Copyright (c) <dates>, <additional Copyright Holder> (<URL|email>),
21
+ with Reserved Font Name <additional Reserved Font Name>.
22
+ Copyright (c) <dates>, <additional Copyright Holder> (<URL|email>).
23
+
24
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
25
+ This license is copied below, and is also available with a FAQ at:
26
+ https://openfontlicense.org
27
+
28
+
29
+ -----------------------------------------------------------
30
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
31
+ -----------------------------------------------------------
32
+
33
+ PREAMBLE
34
+ The goals of the Open Font License (OFL) are to stimulate worldwide
35
+ development of collaborative font projects, to support the font creation
36
+ efforts of academic and linguistic communities, and to provide a free and
37
+ open framework in which fonts may be shared and improved in partnership
38
+ with others.
39
+
40
+ The OFL allows the licensed fonts to be used, studied, modified and
41
+ redistributed freely as long as they are not sold by themselves. The
42
+ fonts, including any derivative works, can be bundled, embedded,
43
+ redistributed and/or sold with any software provided that any reserved
44
+ names are not used by derivative works. The fonts and derivatives,
45
+ however, cannot be released under any other type of license. The
46
+ requirement for fonts to remain under this license does not apply
47
+ to any document created using the fonts or their derivatives.
48
+
49
+ DEFINITIONS
50
+ "Font Software" refers to the set of files released by the Copyright
51
+ Holder(s) under this license and clearly marked as such. This may
52
+ include source files, build scripts and documentation.
53
+
54
+ "Reserved Font Name" refers to any names specified as such after the
55
+ copyright statement(s).
56
+
57
+ "Original Version" refers to the collection of Font Software components as
58
+ distributed by the Copyright Holder(s).
59
+
60
+ "Modified Version" refers to any derivative made by adding to, deleting,
61
+ or substituting -- in part or in whole -- any of the components of the
62
+ Original Version, by changing formats or by porting the Font Software to a
63
+ new environment.
64
+
65
+ "Author" refers to any designer, engineer, programmer, technical
66
+ writer or other person who contributed to the Font Software.
67
+
68
+ PERMISSION & CONDITIONS
69
+ Permission is hereby granted, free of charge, to any person obtaining
70
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
71
+ redistribute, and sell modified and unmodified copies of the Font
72
+ Software, subject to the following conditions:
73
+
74
+ 1) Neither the Font Software nor any of its individual components,
75
+ in Original or Modified Versions, may be sold by itself.
76
+
77
+ 2) Original or Modified Versions of the Font Software may be bundled,
78
+ redistributed and/or sold with any software, provided that each copy
79
+ contains the above copyright notice and this license. These can be
80
+ included either as stand-alone text files, human-readable headers or
81
+ in the appropriate machine-readable metadata fields within text or
82
+ binary files as long as those fields can be easily viewed by the user.
83
+
84
+ 3) No Modified Version of the Font Software may use the Reserved Font
85
+ Name(s) unless explicit written permission is granted by the corresponding
86
+ Copyright Holder. This restriction only applies to the primary font name as
87
+ presented to the users.
88
+
89
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
90
+ Software shall not be used to promote, endorse or advertise any
91
+ Modified Version, except to acknowledge the contribution(s) of the
92
+ Copyright Holder(s) and the Author(s) or with their explicit written
93
+ permission.
94
+
95
+ 5) The Font Software, modified or unmodified, in part or in whole,
96
+ must be distributed entirely under this license, and must not be
97
+ distributed under any other license. The requirement for fonts to
98
+ remain under this license does not apply to any document created
99
+ using the Font Software.
100
+
101
+ TERMINATION
102
+ This license becomes null and void if any of the above conditions are
103
+ not met.
104
+
105
+ DISCLAIMER
106
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
107
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
108
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
109
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
110
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
111
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
112
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
113
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
114
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,152 @@
1
+ {
2
+ "bucket": "https://storage.googleapis.com/kenlo-open-docs/kdls-design-system/assets/fonts",
3
+ "families": [
4
+ {
5
+ "id": "manrope",
6
+ "scheme": "manrope",
7
+ "label": "Manrope",
8
+ "mode": "local",
9
+ "subsets": [
10
+ "cyrillic-ext",
11
+ "cyrillic",
12
+ "greek",
13
+ "vietnamese",
14
+ "latin-ext",
15
+ "latin"
16
+ ],
17
+ "bytes": 74804
18
+ },
19
+ {
20
+ "id": "inter",
21
+ "scheme": "inter",
22
+ "label": "Inter",
23
+ "mode": "bucket",
24
+ "subsets": [
25
+ "cyrillic-ext",
26
+ "cyrillic",
27
+ "greek-ext",
28
+ "greek",
29
+ "vietnamese",
30
+ "latin-ext",
31
+ "latin",
32
+ "cyrillic-ext",
33
+ "cyrillic",
34
+ "greek-ext",
35
+ "greek",
36
+ "vietnamese",
37
+ "latin-ext",
38
+ "latin",
39
+ "cyrillic-ext",
40
+ "cyrillic",
41
+ "greek-ext",
42
+ "greek",
43
+ "vietnamese",
44
+ "latin-ext",
45
+ "latin",
46
+ "cyrillic-ext",
47
+ "cyrillic",
48
+ "greek-ext",
49
+ "greek",
50
+ "vietnamese",
51
+ "latin-ext",
52
+ "latin"
53
+ ],
54
+ "bytes": 875552
55
+ },
56
+ {
57
+ "id": "montserrat",
58
+ "scheme": "montserrat",
59
+ "label": "Montserrat",
60
+ "mode": "bucket",
61
+ "subsets": [
62
+ "cyrillic-ext",
63
+ "cyrillic",
64
+ "vietnamese",
65
+ "latin-ext",
66
+ "latin",
67
+ "cyrillic-ext",
68
+ "cyrillic",
69
+ "vietnamese",
70
+ "latin-ext",
71
+ "latin",
72
+ "cyrillic-ext",
73
+ "cyrillic",
74
+ "vietnamese",
75
+ "latin-ext",
76
+ "latin",
77
+ "cyrillic-ext",
78
+ "cyrillic",
79
+ "vietnamese",
80
+ "latin-ext",
81
+ "latin"
82
+ ],
83
+ "bytes": 639664
84
+ },
85
+ {
86
+ "id": "nunito",
87
+ "scheme": "nunito",
88
+ "label": "Nunito",
89
+ "mode": "bucket",
90
+ "subsets": [
91
+ "cyrillic-ext",
92
+ "cyrillic",
93
+ "vietnamese",
94
+ "latin-ext",
95
+ "latin",
96
+ "cyrillic-ext",
97
+ "cyrillic",
98
+ "vietnamese",
99
+ "latin-ext",
100
+ "latin",
101
+ "cyrillic-ext",
102
+ "cyrillic",
103
+ "vietnamese",
104
+ "latin-ext",
105
+ "latin",
106
+ "cyrillic-ext",
107
+ "cyrillic",
108
+ "vietnamese",
109
+ "latin-ext",
110
+ "latin"
111
+ ],
112
+ "bytes": 549376
113
+ },
114
+ {
115
+ "id": "source-sans-3",
116
+ "scheme": "source-sans",
117
+ "label": "Source Sans 3",
118
+ "mode": "bucket",
119
+ "subsets": [
120
+ "cyrillic-ext",
121
+ "cyrillic",
122
+ "greek-ext",
123
+ "greek",
124
+ "vietnamese",
125
+ "latin-ext",
126
+ "latin",
127
+ "cyrillic-ext",
128
+ "cyrillic",
129
+ "greek-ext",
130
+ "greek",
131
+ "vietnamese",
132
+ "latin-ext",
133
+ "latin",
134
+ "cyrillic-ext",
135
+ "cyrillic",
136
+ "greek-ext",
137
+ "greek",
138
+ "vietnamese",
139
+ "latin-ext",
140
+ "latin",
141
+ "cyrillic-ext",
142
+ "cyrillic",
143
+ "greek-ext",
144
+ "greek",
145
+ "vietnamese",
146
+ "latin-ext",
147
+ "latin"
148
+ ],
149
+ "bytes": 610544
150
+ }
151
+ ]
152
+ }