@timmo001/groundwork-ui 0.5.0 → 0.7.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.
@@ -81,6 +81,13 @@ let lastList = 0;
81
81
  * @attr {boolean} search - Shows a search field above the list.
82
82
  * @attr {string} placeholder - The search placeholder. Defaults to `Search`.
83
83
  *
84
+ * @csspart search - The search field's row.
85
+ * @csspart listbox - The scrolling list.
86
+ * @csspart option - Each option.
87
+ * @csspart group - Each group heading.
88
+ * @csspart description - An option's second line.
89
+ * @csspart none - The no matches line.
90
+ *
84
91
  * @cssprop --gw-option-list-height - The list's maximum height. Defaults to `20rem`.
85
92
  *
86
93
  * @fires {CustomEvent<{ value: string }>} pick - When an option is picked, with its `value` in `detail`.
@@ -273,11 +280,15 @@ export class GwOptionList extends GwElement {
273
280
 
274
281
  readonly #listbox = h(
275
282
  "div",
276
- { role: "listbox", tabindex: "-1" },
283
+ { role: "listbox", part: "listbox", tabindex: "-1" },
277
284
  this.#spacer,
278
285
  );
279
286
 
280
- readonly #none = h("div", { class: "none", hidden: true }, "No matches");
287
+ readonly #none = h(
288
+ "div",
289
+ { class: "none", part: "none", hidden: true },
290
+ "No matches",
291
+ );
281
292
 
282
293
  #query = "";
283
294
 
@@ -433,7 +444,12 @@ export class GwOptionList extends GwElement {
433
444
  });
434
445
 
435
446
  root.append(
436
- h("div", { class: "search" }, createIcon(searchIcon), this.#input),
447
+ h(
448
+ "div",
449
+ { class: "search", part: "search" },
450
+ createIcon(searchIcon),
451
+ this.#input,
452
+ ),
437
453
  this.#listbox,
438
454
  this.#none,
439
455
  );
@@ -585,7 +601,7 @@ export class GwOptionList extends GwElement {
585
601
  if (row.kind === "group") {
586
602
  const element = h(
587
603
  "div",
588
- { class: "row group", role: "presentation" },
604
+ { class: "row group", part: "group", role: "presentation" },
589
605
  row.label,
590
606
  );
591
607
 
@@ -602,6 +618,7 @@ export class GwOptionList extends GwElement {
602
618
  "div",
603
619
  {
604
620
  class: "row",
621
+ part: "option",
605
622
  role: "option",
606
623
  id: `${this.#id}-${index}`,
607
624
  "data-index": index,
@@ -618,7 +635,11 @@ export class GwOptionList extends GwElement {
618
635
  h("span", {}, option.label),
619
636
  option.description === undefined
620
637
  ? null
621
- : h("span", { class: "description" }, option.description),
638
+ : h(
639
+ "span",
640
+ { class: "description", part: "description" },
641
+ option.description,
642
+ ),
622
643
  ),
623
644
  option.swatches === undefined
624
645
  ? null
@@ -19,6 +19,10 @@ import { base, createIcon, setIconPath } from "./styles.js";
19
19
  * @attr {string} icon - SVG path data for the icon tile.
20
20
  *
21
21
  * @slot actions - The page's controls.
22
+ *
23
+ * @csspart tile - The icon tile.
24
+ * @csspart heading - The title.
25
+ * @csspart description - The line under the title.
22
26
  */
23
27
  export class GwPageHeader extends GwElement {
24
28
  static override properties = {
@@ -86,11 +90,11 @@ export class GwPageHeader extends GwElement {
86
90
 
87
91
  readonly #icon = createIcon("");
88
92
 
89
- readonly #tile = h("span", { class: "tile" }, this.#icon);
93
+ readonly #tile = h("span", { class: "tile", part: "tile" }, this.#icon);
90
94
 
91
- readonly #heading = h("h1");
95
+ readonly #heading = h("h1", { part: "heading" });
92
96
 
93
- readonly #description = h("p");
97
+ readonly #description = h("p", { part: "description" });
94
98
 
95
99
  constructor() {
96
100
  super();
package/src/gw-popover.ts CHANGED
@@ -38,6 +38,11 @@ const sheetBelow = 600;
38
38
  * @slot - The content.
39
39
  * @slot actions - Buttons; one with a `value` closes it with that value.
40
40
  *
41
+ * @csspart surface - The popover's surface.
42
+ * @csspart heading - The heading.
43
+ * @csspart body - The content.
44
+ * @csspart footer - The actions row.
45
+ *
41
46
  * @cssprop --gw-popover-width - Its width beside a button. Defaults to `20rem`.
42
47
  *
43
48
  * @fires {Event} close - When it closes; `returnValue` holds the button's value.
@@ -187,7 +192,7 @@ export class GwPopover extends GwElement {
187
192
  /** The value of the action that closed it, or "" for Esc or a click outside. */
188
193
  returnValue = "";
189
194
 
190
- readonly #heading = h("h2", { id: "heading" });
195
+ readonly #heading = h("h2", { id: "heading", part: "heading" });
191
196
 
192
197
  readonly #closeButton = h(
193
198
  "gw-button",
@@ -204,7 +209,12 @@ export class GwPopover extends GwElement {
204
209
 
205
210
  readonly #popover = h(
206
211
  "div",
207
- { popover: "manual", tabindex: "-1", "data-placement": "center" },
212
+ {
213
+ popover: "manual",
214
+ tabindex: "-1",
215
+ "data-placement": "center",
216
+ part: "surface",
217
+ },
208
218
  h(
209
219
  "header",
210
220
  {},
@@ -212,11 +222,11 @@ export class GwPopover extends GwElement {
212
222
  "div",
213
223
  { class: "content" },
214
224
  this.#heading,
215
- h("div", { class: "body", id: "body" }, h("slot")),
225
+ h("div", { class: "body", id: "body", part: "body" }, h("slot")),
216
226
  ),
217
227
  this.#closeButton,
218
228
  ),
219
- h("footer", {}, h("slot", { name: "actions" })),
229
+ h("footer", { part: "footer" }, h("slot", { name: "actions" })),
220
230
  );
221
231
 
222
232
  readonly #dismissal = new Dismissal(
@@ -17,6 +17,8 @@ import { base } from "./styles.js";
17
17
  *
18
18
  * @slot - The heading text.
19
19
  * @slot actions - Buttons at the end of the row.
20
+ *
21
+ * @csspart heading - The heading.
20
22
  */
21
23
  export class GwSectionTitle extends GwElement {
22
24
  static override properties = {
@@ -46,7 +48,7 @@ export class GwSectionTitle extends GwElement {
46
48
 
47
49
  declare level: number;
48
50
 
49
- readonly #heading = h("div", { role: "heading" }, h("slot"));
51
+ readonly #heading = h("div", { role: "heading", part: "heading" }, h("slot"));
50
52
 
51
53
  constructor() {
52
54
  super();
@@ -5,7 +5,7 @@
5
5
  * @module
6
6
  */
7
7
  import { GwElement, css, h, setAttribute } from "./element.js";
8
- import { base, createIcon } from "./styles.js";
8
+ import { base, controlSizes, createIcon } from "./styles.js";
9
9
 
10
10
  export interface Segment {
11
11
  readonly value: string;
@@ -31,9 +31,14 @@ export interface Segment {
31
31
  * @attr {string} value - The chosen option's value.
32
32
  * @attr {"show"|"hide"|"auto"} labels - Whether option text shows beside icons. Defaults to `show`.
33
33
  * @attr {Segment[]} options - The options, as JSON.
34
+ * @attr {"xs"|"small"|"medium"|"large"|"xl"} size - The size, 40px tall at medium. Defaults to `medium`.
34
35
  *
36
+ * @csspart option - Each option.
35
37
  * @csspart indicator - The pill that slides to the chosen option.
36
38
  *
39
+ * @cssprop --gw-segmented-scale - Scales the control, around 1 for medium.
40
+ * @cssprop --gw-control-scale - Scales its height and icons with the theme's density. The theme sets it.
41
+ *
37
42
  * @fires {Event} change - When the chosen option changes.
38
43
  */
39
44
  export class GwSegmented extends GwElement {
@@ -43,12 +48,17 @@ export class GwSegmented extends GwElement {
43
48
  value: { reflect: true },
44
49
  labels: { reflect: true },
45
50
  options: { type: "json" },
51
+ size: { reflect: true },
46
52
  } as const;
47
53
 
48
54
  static override styles = [
49
55
  base,
56
+ controlSizes("segmented"),
50
57
  css`
51
58
  :host {
59
+ --gw-size: var(--gw-segmented-scale, 1);
60
+ --gw-scale: calc(var(--gw-size) * var(--gw-control-scale, 1));
61
+
52
62
  display: inline-block;
53
63
  }
54
64
 
@@ -77,20 +87,21 @@ export class GwSegmented extends GwElement {
77
87
  label {
78
88
  position: relative;
79
89
  display: inline-flex;
80
- gap: var(--gw-space-2);
90
+ gap: calc(var(--gw-space-2) * var(--gw-size));
81
91
  align-items: center;
82
92
  box-sizing: border-box;
83
- /* 32px options in a 40px track, matching fields and buttons */
84
- height: 2rem;
85
- padding: 0 var(--gw-space-3);
86
- font-size: var(--gw-font-size-s);
93
+ /* 32px options in a 40px track at medium, matching fields and
94
+ buttons */
95
+ height: calc(2rem * var(--gw-scale));
96
+ padding: 0 calc(var(--gw-space-3) * var(--gw-size));
97
+ font-size: calc(var(--gw-font-size-s) * var(--gw-size));
87
98
  color: var(--gw-color-text-primary);
88
99
  cursor: pointer;
89
100
  background: transparent;
90
101
  border-radius: var(--gw-radius-pill);
91
102
  transition: background-color var(--gw-motion-fast)
92
103
  var(--gw-motion-easing);
93
- --gw-icon-size: 1.125rem;
104
+ --gw-icon-size: calc(1.125rem * var(--gw-scale));
94
105
  }
95
106
 
96
107
  :host([labels="hide"]) label.has-icon {
@@ -187,6 +198,7 @@ export class GwSegmented extends GwElement {
187
198
  declare value: string;
188
199
  declare labels: "show" | "hide" | "auto";
189
200
  declare options: readonly Segment[];
201
+ declare size: "xs" | "small" | "medium" | "large" | "xl";
190
202
 
191
203
  constructor() {
192
204
  super();
@@ -195,6 +207,7 @@ export class GwSegmented extends GwElement {
195
207
  this.value = "";
196
208
  this.labels = "show";
197
209
  this.options = [];
210
+ this.size = "medium";
198
211
  }
199
212
 
200
213
  readonly #legend = h("legend");
@@ -267,7 +280,7 @@ export class GwSegmented extends GwElement {
267
280
 
268
281
  const label = h(
269
282
  "label",
270
- { class: option.icon ? "has-icon" : null },
283
+ { class: option.icon ? "has-icon" : null, part: "option" },
271
284
  input,
272
285
  option.icon ? createIcon(option.icon) : null,
273
286
  h("span", { class: "text" }, option.label),
package/src/gw-select.ts CHANGED
@@ -62,6 +62,10 @@ const chevronIcon =
62
62
  * @attr {OptionItem[]} options - The options, as JSON.
63
63
  * @attr {boolean} label-hidden - Hides the label but keeps it for assistive technology.
64
64
  * @attr {boolean} inline-label - Shows the label inside the trigger, before the value, for toolbars and filters.
65
+ * @attr {"xs"|"small"|"medium"|"large"|"xl"} size - The field's size, 40px tall at medium. Defaults to `medium`.
66
+ *
67
+ * @cssprop --gw-field-scale - Scales the field, around 1 for medium.
68
+ * @cssprop --gw-control-scale - Scales its height with the theme's density. The theme sets it.
65
69
  *
66
70
  * @fires {Event} change - When the value, or `values` with `multiple`, changes.
67
71
  */
@@ -81,6 +85,7 @@ export class GwSelect extends LightElement {
81
85
  options: { type: "json" },
82
86
  labelHidden: { type: "boolean", attribute: "label-hidden" },
83
87
  inlineLabel: { type: "boolean", attribute: "inline-label", reflect: true },
88
+ size: { reflect: true },
84
89
  } as const;
85
90
 
86
91
  declare label: string;
@@ -99,6 +104,7 @@ export class GwSelect extends LightElement {
99
104
  declare options: readonly OptionItem[];
100
105
  declare labelHidden: boolean;
101
106
  declare inlineLabel: boolean;
107
+ declare size: "xs" | "small" | "medium" | "large" | "xl";
102
108
 
103
109
  readonly #id = fieldId();
104
110
 
@@ -172,6 +178,7 @@ export class GwSelect extends LightElement {
172
178
  this.options = [];
173
179
  this.labelHidden = false;
174
180
  this.inlineLabel = false;
181
+ this.size = "medium";
175
182
  }
176
183
 
177
184
  /** Opens the list, such as from a keyboard shortcut. */
@@ -7,7 +7,7 @@
7
7
  import { GwElement, css, h, setAttribute } from "./element.js";
8
8
  import "./gw-skeleton.js";
9
9
  import { fadeIn } from "./motion.js";
10
- import { base } from "./styles.js";
10
+ import { base, controlSizes } from "./styles.js";
11
11
 
12
12
  /**
13
13
  * A setting: its name and description on one side, its control on the
@@ -21,34 +21,42 @@ import { base } from "./styles.js";
21
21
  * @attr {string} heading - The setting's name.
22
22
  * @attr {string} description - What it does.
23
23
  * @attr {boolean} loading - Shows skeletons for the control and any unknown text.
24
+ * @attr {"xs"|"small"|"medium"|"large"|"xl"} size - The text and spacing size. Defaults to `medium`.
24
25
  *
25
26
  * @slot - The control.
26
27
  *
27
28
  * @csspart row - The row.
28
29
  *
29
30
  * @cssprop --gw-row-padding - The padding above and below. Defaults to `--gw-space-2`.
31
+ * @cssprop --gw-setting-row-scale - Scales the text and spacing, around 1 for medium.
30
32
  */
31
33
  export class GwSettingRow extends GwElement {
32
34
  static override properties = {
33
35
  heading: {},
34
36
  description: {},
35
37
  loading: { type: "boolean", reflect: true },
38
+ size: { reflect: true },
36
39
  } as const;
37
40
 
38
41
  static override styles = [
39
42
  base,
43
+ controlSizes("setting-row"),
40
44
  css`
41
45
  :host {
46
+ --gw-size: var(--gw-setting-row-scale, 1);
47
+
42
48
  display: block;
43
49
  }
44
50
 
45
51
  .row {
46
52
  display: flex;
47
53
  flex-wrap: wrap;
48
- gap: var(--gw-space-1) var(--gw-space-3);
54
+ gap: calc(var(--gw-space-1) * var(--gw-size))
55
+ calc(var(--gw-space-3) * var(--gw-size));
49
56
  align-items: center;
50
57
  justify-content: space-between;
51
- padding: var(--gw-row-padding, var(--gw-space-2)) 0;
58
+ padding: var(--gw-row-padding, calc(var(--gw-space-2) * var(--gw-size)))
59
+ 0;
52
60
  }
53
61
 
54
62
  /* A full line even in themes without borders, since it separates rows */
@@ -63,13 +71,19 @@ export class GwSettingRow extends GwElement {
63
71
  }
64
72
 
65
73
  .heading {
66
- font-size: var(--gw-font-size-s);
74
+ font-size: max(
75
+ var(--gw-font-size-xs),
76
+ calc(var(--gw-font-size-s) * var(--gw-size))
77
+ );
67
78
  font-weight: var(--gw-font-weight-strong);
68
79
  color: var(--gw-color-text-strong);
69
80
  }
70
81
 
71
82
  .description {
72
- font-size: var(--gw-font-size-xs);
83
+ font-size: max(
84
+ var(--gw-font-size-2xs),
85
+ calc(var(--gw-font-size-xs) * var(--gw-size))
86
+ );
73
87
  color: var(--gw-color-text-secondary);
74
88
  }
75
89
 
@@ -89,6 +103,7 @@ export class GwSettingRow extends GwElement {
89
103
  declare heading: string;
90
104
  declare description: string;
91
105
  declare loading: boolean;
106
+ declare size: "xs" | "small" | "medium" | "large" | "xl";
92
107
 
93
108
  readonly #row = h("div", { class: "row", part: "row" });
94
109
 
@@ -124,6 +139,7 @@ export class GwSettingRow extends GwElement {
124
139
  this.heading = "";
125
140
  this.description = "";
126
141
  this.loading = false;
142
+ this.size = "medium";
127
143
  }
128
144
 
129
145
  protected override create(root: ShadowRoot) {
@@ -89,6 +89,8 @@ export class GwSkeletonText extends GwSkeleton {
89
89
  * @summary A placeholder for a paragraph.
90
90
  *
91
91
  * @attr {number} lines - How many lines. Defaults to 3.
92
+ *
93
+ * @csspart line - Each line.
92
94
  */
93
95
  export class GwSkeletonLines extends GwElement {
94
96
  static override properties = {
@@ -129,7 +131,7 @@ export class GwSkeletonLines extends GwElement {
129
131
  protected override update() {
130
132
  this.renderRoot.replaceChildren(
131
133
  ...Array.from({ length: Math.max(1, this.lines || 1) }, () =>
132
- h("gw-skeleton-text"),
134
+ h("gw-skeleton-text", { part: "line" }),
133
135
  ),
134
136
  );
135
137
  }
package/src/gw-spinner.ts CHANGED
@@ -15,6 +15,8 @@ import { base } from "./styles.js";
15
15
  *
16
16
  * @attr {string} label - What's loading, for assistive technology. Defaults to `Loading`.
17
17
  *
18
+ * @csspart ring - The spinning ring.
19
+ *
18
20
  * @cssprop --gw-spinner-size - The ring's size. Defaults to `1.25rem`.
19
21
  */
20
22
  export class GwSpinner extends GwElement {
@@ -67,7 +69,9 @@ export class GwSpinner extends GwElement {
67
69
  }
68
70
 
69
71
  protected override create(root: ShadowRoot) {
70
- root.append(h("span", { class: "ring", role: "status" }, this.#label));
72
+ root.append(
73
+ h("span", { class: "ring", part: "ring", role: "status" }, this.#label),
74
+ );
71
75
  }
72
76
 
73
77
  protected override update() {