@getflip/swirl-components 0.88.1 → 0.90.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.
Files changed (59) hide show
  1. package/components.json +146 -3
  2. package/dist/cjs/index-506fe4ea.js +4 -0
  3. package/dist/cjs/loader.cjs.js +1 -1
  4. package/dist/cjs/swirl-checkbox.cjs.entry.js +4 -3
  5. package/dist/cjs/swirl-chip.cjs.entry.js +6 -4
  6. package/dist/cjs/swirl-components.cjs.js +1 -1
  7. package/dist/cjs/swirl-description-list-item.cjs.entry.js +2 -1
  8. package/dist/cjs/swirl-radio.cjs.entry.js +4 -3
  9. package/dist/cjs/swirl-toolbar.cjs.entry.js +83 -0
  10. package/dist/collection/assets/pdfjs/pdf.worker.min.js +22 -0
  11. package/dist/collection/collection-manifest.json +1 -0
  12. package/dist/collection/components/swirl-checkbox/swirl-checkbox.css +33 -0
  13. package/dist/collection/components/swirl-checkbox/swirl-checkbox.js +26 -2
  14. package/dist/collection/components/swirl-checkbox/swirl-checkbox.spec.js +1 -1
  15. package/dist/collection/components/swirl-chip/swirl-chip.css +34 -0
  16. package/dist/collection/components/swirl-chip/swirl-chip.js +23 -4
  17. package/dist/collection/components/swirl-chip/swirl-chip.spec.js +30 -21
  18. package/dist/collection/components/swirl-description-list-item/swirl-description-list-item.js +19 -1
  19. package/dist/collection/components/swirl-radio/swirl-radio.css +33 -0
  20. package/dist/collection/components/swirl-radio/swirl-radio.js +26 -2
  21. package/dist/collection/components/swirl-radio/swirl-radio.spec.js +1 -1
  22. package/dist/collection/components/swirl-toolbar/swirl-toolbar.css +7 -0
  23. package/dist/collection/components/swirl-toolbar/swirl-toolbar.js +128 -0
  24. package/dist/collection/components/swirl-toolbar/swirl-toolbar.spec.js +26 -0
  25. package/dist/collection/components/swirl-toolbar/swirl-toolbar.stories.js +24 -0
  26. package/dist/components/assets/pdfjs/pdf.worker.min.js +22 -0
  27. package/dist/components/swirl-checkbox.js +6 -4
  28. package/dist/components/swirl-chip.js +8 -6
  29. package/dist/components/swirl-description-list-item.js +3 -1
  30. package/dist/components/swirl-radio.js +6 -4
  31. package/dist/components/swirl-toolbar.d.ts +11 -0
  32. package/dist/components/swirl-toolbar.js +107 -0
  33. package/dist/esm/index-99d0060d.js +4 -0
  34. package/dist/esm/loader.js +1 -1
  35. package/dist/esm/swirl-checkbox.entry.js +4 -3
  36. package/dist/esm/swirl-chip.entry.js +6 -4
  37. package/dist/esm/swirl-components.js +1 -1
  38. package/dist/esm/swirl-description-list-item.entry.js +2 -1
  39. package/dist/esm/swirl-radio.entry.js +4 -3
  40. package/dist/esm/swirl-toolbar.entry.js +79 -0
  41. package/dist/swirl-components/p-240552ca.entry.js +1 -0
  42. package/dist/swirl-components/p-7c70d4b2.entry.js +1 -0
  43. package/dist/swirl-components/p-ae31163c.entry.js +1 -0
  44. package/dist/swirl-components/p-ea08c219.entry.js +1 -0
  45. package/dist/swirl-components/p-f75a91a5.entry.js +1 -0
  46. package/dist/swirl-components/swirl-components.esm.js +1 -1
  47. package/dist/types/components/swirl-checkbox/swirl-checkbox.d.ts +2 -0
  48. package/dist/types/components/swirl-chip/swirl-chip.d.ts +1 -0
  49. package/dist/types/components/swirl-description-list-item/swirl-description-list-item.d.ts +1 -0
  50. package/dist/types/components/swirl-radio/swirl-radio.d.ts +2 -0
  51. package/dist/types/components/swirl-toolbar/swirl-toolbar.d.ts +15 -0
  52. package/dist/types/components/swirl-toolbar/swirl-toolbar.stories.d.ts +14 -0
  53. package/dist/types/components.d.ts +31 -4
  54. package/package.json +13 -13
  55. package/vscode-data.json +57 -0
  56. package/dist/swirl-components/p-2c44a1cb.entry.js +0 -1
  57. package/dist/swirl-components/p-31eb71e2.entry.js +0 -1
  58. package/dist/swirl-components/p-62f1aaae.entry.js +0 -1
  59. package/dist/swirl-components/p-d6034b86.entry.js +0 -1
@@ -48,6 +48,7 @@
48
48
  "./components/swirl-thumbnail/swirl-thumbnail.js",
49
49
  "./components/swirl-toast/swirl-toast.js",
50
50
  "./components/swirl-toast-provider/swirl-toast-provider.js",
51
+ "./components/swirl-toolbar/swirl-toolbar.js",
51
52
  "./components/swirl-tooltip/swirl-tooltip.js",
52
53
  "./components/swirl-action-list/swirl-action-list.js",
53
54
  "./components/swirl-action-list-section/swirl-action-list-section.js",
@@ -17,6 +17,39 @@
17
17
  0 0 0 0.1875rem var(--s-focus-default);
18
18
  }
19
19
 
20
+ .checkbox--variant-card {
21
+ width: 100%;
22
+ padding: var(--s-space-16);
23
+ border: 0.0625rem solid var(--s-border-default);
24
+ border-radius: var(--s-border-radius-sm);
25
+ background-color: var(--s-surface);
26
+ }
27
+
28
+ .checkbox--variant-card:focus-within {
29
+ box-shadow: 0 0 0 0.125rem var(--s-background-default),
30
+ 0 0 0 0.25rem var(--s-focus-default);
31
+ }
32
+
33
+ .checkbox--variant-card:focus-within .checkbox__box {
34
+ box-shadow: none;
35
+ }
36
+
37
+ .checkbox--variant-card:hover:not(.checkbox--disabled) {
38
+ background-color: var(--s-surface-hovered);
39
+ }
40
+
41
+ .checkbox--variant-card:active:not(.checkbox--disabled) {
42
+ background-color: var(--s-surface-pressed);
43
+ }
44
+
45
+ .checkbox--variant-card.checkbox--checked:not(.checkbox--disabled) {
46
+ border-color: var(--s-border-highlight);
47
+ }
48
+
49
+ .checkbox--variant-card.checkbox--invalid:not(.checkbox--disabled) {
50
+ border-color: var(--s-border-critical);
51
+ }
52
+
20
53
  .checkbox--checked .checkbox__control:hover .checkbox__box, .checkbox--indeterminate .checkbox__control:hover .checkbox__box {
21
54
  border-color: var(--s-interactive-primary-hovered);
22
55
  background-color: var(--s-interactive-primary-hovered);
@@ -18,6 +18,7 @@ export class SwirlCheckbox {
18
18
  this.label = undefined;
19
19
  this.labelWeight = "medium";
20
20
  this.value = undefined;
21
+ this.variant = "default";
21
22
  }
22
23
  getAriaCheckedLabel(checked, unchecked) {
23
24
  if (checked) {
@@ -37,14 +38,14 @@ export class SwirlCheckbox {
37
38
  const ariaInvalid = this.invalid === true || this.invalid === false
38
39
  ? String(this.invalid)
39
40
  : undefined;
40
- const className = classnames("checkbox", `checkbox--label-weight-${this.labelWeight}`, {
41
+ const className = classnames("checkbox", `checkbox--label-weight-${this.labelWeight}`, `checkbox--variant-${this.variant}`, {
41
42
  "checkbox--checked": checked,
42
43
  "checkbox--disabled": this.disabled,
43
44
  "checkbox--indeterminate": indeterminate,
44
45
  "checkbox--invalid": this.invalid,
45
46
  "checkbox--unchecked": unchecked,
46
47
  });
47
- return (h(Host, null, h("label", { class: className, htmlFor: this.inputId }, h("span", { class: "checkbox__control" }, h("swirl-visually-hidden", null, h("input", { "aria-checked": ariaCheckedLabel, "aria-describedby": this.swirlAriaDescribedby, "aria-invalid": ariaInvalid, "aria-label": this.swirlAriaLabel, checked: checked, class: "checkbox__input", disabled: this.disabled, id: this.inputId, indeterminate: indeterminate, name: this.inputName, onChange: this.onChange, type: "checkbox", value: this.value })), h("span", { "aria-hidden": "true", class: "checkbox__box" }, h("span", { class: "checkbox__icon" }, checked && h("swirl-icon-check-strong", null), indeterminate && (h("span", { class: "checkbox__indeterminate-icon" }))))), showLabelContainer && (h("span", { class: "checkbox__label-container" }, this.label && h("span", { class: "checkbox__label" }, this.label), this.description && (h("span", { class: "checkbox__description" }, this.description)))))));
48
+ return (h(Host, { style: { width: this.variant === "card" ? "100%" : undefined } }, h("label", { class: className, htmlFor: this.inputId }, h("span", { class: "checkbox__control" }, h("swirl-visually-hidden", null, h("input", { "aria-checked": ariaCheckedLabel, "aria-describedby": this.swirlAriaDescribedby, "aria-invalid": ariaInvalid, "aria-label": this.swirlAriaLabel, checked: checked, class: "checkbox__input", disabled: this.disabled, id: this.inputId, indeterminate: indeterminate, name: this.inputName, onChange: this.onChange, type: "checkbox", value: this.value })), h("span", { "aria-hidden": "true", class: "checkbox__box" }, h("span", { class: "checkbox__icon" }, checked && h("swirl-icon-check-strong", null), indeterminate && (h("span", { class: "checkbox__indeterminate-icon" }))))), showLabelContainer && (h("span", { class: "checkbox__label-container" }, this.label && h("span", { class: "checkbox__label" }, this.label), this.description && (h("span", { class: "checkbox__description" }, this.description)))))));
48
49
  }
49
50
  static get is() { return "swirl-checkbox"; }
50
51
  static get encapsulation() { return "scoped"; }
@@ -259,6 +260,29 @@ export class SwirlCheckbox {
259
260
  },
260
261
  "attribute": "value",
261
262
  "reflect": false
263
+ },
264
+ "variant": {
265
+ "type": "string",
266
+ "mutable": false,
267
+ "complexType": {
268
+ "original": "SwirlCheckboxVariant",
269
+ "resolved": "\"card\" | \"default\"",
270
+ "references": {
271
+ "SwirlCheckboxVariant": {
272
+ "location": "local",
273
+ "path": "/home/runner/work/swirl/swirl/packages/swirl-components/src/components/swirl-checkbox/swirl-checkbox.tsx"
274
+ }
275
+ }
276
+ },
277
+ "required": false,
278
+ "optional": true,
279
+ "docs": {
280
+ "tags": [],
281
+ "text": ""
282
+ },
283
+ "attribute": "variant",
284
+ "reflect": false,
285
+ "defaultValue": "\"default\""
262
286
  }
263
287
  };
264
288
  }
@@ -8,7 +8,7 @@ describe("swirl-checkbox", () => {
8
8
  });
9
9
  expect(page.root).toMatchInlineSnapshot(`
10
10
  <swirl-checkbox checked="true" description="Description" disabled="true" input-id="checkbox" input-name="checkbox" label="Label" value="Value">
11
- <label class="checkbox checkbox--checked checkbox--disabled checkbox--label-weight-medium" htmlfor="checkbox">
11
+ <label class="checkbox checkbox--checked checkbox--disabled checkbox--label-weight-medium checkbox--variant-default" htmlfor="checkbox">
12
12
  <span class="checkbox__control">
13
13
  <swirl-visually-hidden>
14
14
  <input aria-checked="true" checked="" class="checkbox__input" disabled="" id="checkbox" name="checkbox" type="checkbox" value="Value">
@@ -110,6 +110,40 @@
110
110
  color: var(--s-icon-success);
111
111
  }
112
112
 
113
+ .chip--variant-outline.chip--pressed {
114
+ background-color: var(--s-action-primary-default);
115
+ color: var(--s-text-on-action-primary);
116
+ }
117
+
118
+ .chip--variant-outline.chip--pressed:hover {
119
+ background-color: var(--s-action-primary-hovered);
120
+ }
121
+
122
+ .chip--variant-outline.chip--pressed:hover + .chip__remove-button {
123
+ background-color: var(--s-action-primary-hovered);
124
+ }
125
+
126
+ .chip--variant-outline.chip--pressed:active {
127
+ background-color: var(--s-action-primary-pressed);
128
+ }
129
+
130
+ .chip--variant-outline.chip--pressed:active + .chip__remove-button {
131
+ background-color: var(--s-action-primary-pressed);
132
+ }
133
+
134
+ .chip--variant-outline.chip--pressed + .chip__remove-button {
135
+ background-color: var(--s-action-primary-default);
136
+ color: var(--s-text-on-action-primary);
137
+ }
138
+
139
+ .chip--variant-outline.chip--pressed + .chip__remove-button:hover {
140
+ background-color: var(--s-action-primary-hovered);
141
+ }
142
+
143
+ .chip--variant-outline.chip--pressed + .chip__remove-button:active {
144
+ background-color: var(--s-action-primary-pressed);
145
+ }
146
+
113
147
  .chip--variant-plain {
114
148
  height: auto;
115
149
  border: none;
@@ -17,6 +17,7 @@ export class SwirlChip {
17
17
  this.interactive = false;
18
18
  this.label = undefined;
19
19
  this.progress = undefined;
20
+ this.pressed = undefined;
20
21
  this.progressBarLabel = "Loading progress";
21
22
  this.removable = undefined;
22
23
  this.removeButtonLabel = "Remove";
@@ -39,18 +40,19 @@ export class SwirlChip {
39
40
  icon?.setAttribute("size", iconSize);
40
41
  }
41
42
  render() {
42
- const Tag = this.interactive ? "button" : "span";
43
+ const Tag = this.interactive || this.pressed !== undefined ? "button" : "span";
43
44
  const showAvatar = Boolean(this.el.querySelector('[slot="avatar"]'));
44
45
  const showIcon = !showAvatar && Boolean(this.icon);
45
46
  const className = classnames("chip", `chip--border-radius-${this.borderRadius}`, `chip--icon-color-${this.iconColor}`, `chip--intent-${this.intent}`, `chip--size-${this.size}`, `chip--variant-${this.variant}`, {
47
+ "chip--pressed": this.pressed,
46
48
  "chip--has-progress": this.progress !== undefined,
47
- "chip--interactive": this.interactive,
49
+ "chip--interactive": this.interactive || this.pressed !== undefined,
48
50
  "chip--removable": this.removable,
49
51
  });
50
- return (h(Host, null, h(Tag, { class: className, type: this.interactive ? "button" : undefined }, h("span", { class: "chip__inner" }, showAvatar && (h("span", { class: "chip__avatar" }, h("slot", { name: "avatar" }))), showIcon && (h("span", { class: "chip__icon", innerHTML: this.icon, ref: (el) => (this.iconEl = el) })), h("span", { class: "chip__label" }, this.label)), this.progress !== undefined && (h("span", { class: "chip__progress-indicator" }, h("swirl-progress-indicator", { label: this.progressBarLabel, value: this.progress })))), this.removable && (h("button", { "aria-label": this.removeButtonLabel, class: "chip__remove-button", onClick: this.remove.emit }, h("swirl-icon-close", { size: 20 })))));
52
+ return (h(Host, null, h(Tag, { class: className, type: this.interactive ? "button" : undefined, "aria-pressed": this.pressed !== undefined ? String(this.pressed) : undefined }, h("span", { class: "chip__inner" }, showAvatar && (h("span", { class: "chip__avatar" }, h("slot", { name: "avatar" }))), showIcon && (h("span", { class: "chip__icon", innerHTML: this.icon, ref: (el) => (this.iconEl = el) })), h("span", { class: "chip__label" }, this.label)), this.progress !== undefined && (h("span", { class: "chip__progress-indicator" }, h("swirl-progress-indicator", { label: this.progressBarLabel, value: this.progress })))), this.removable && (h("button", { "aria-label": this.removeButtonLabel, class: "chip__remove-button", onClick: this.remove.emit }, h("swirl-icon-close", { size: 20 })))));
51
53
  }
52
54
  static get is() { return "swirl-chip"; }
53
- static get encapsulation() { return "shadow"; }
55
+ static get encapsulation() { return "scoped"; }
54
56
  static get originalStyleUrls() {
55
57
  return {
56
58
  "$": ["swirl-chip.css"]
@@ -201,6 +203,23 @@ export class SwirlChip {
201
203
  "attribute": "progress",
202
204
  "reflect": false
203
205
  },
206
+ "pressed": {
207
+ "type": "boolean",
208
+ "mutable": false,
209
+ "complexType": {
210
+ "original": "boolean",
211
+ "resolved": "boolean",
212
+ "references": {}
213
+ },
214
+ "required": false,
215
+ "optional": true,
216
+ "docs": {
217
+ "tags": [],
218
+ "text": ""
219
+ },
220
+ "attribute": "pressed",
221
+ "reflect": false
222
+ },
204
223
  "progressBarLabel": {
205
224
  "type": "string",
206
225
  "mutable": false,
@@ -8,13 +8,11 @@ describe("swirl-chip", () => {
8
8
  });
9
9
  expect(page.root).toEqualHtml(`
10
10
  <swirl-chip intent="critical" label="Label">
11
- <mock:shadow-root>
12
- <span class="chip chip--border-radius-pill chip--icon-color-default chip--intent-critical chip--size-m chip--variant-outline">
13
- <span class="chip__inner">
14
- <span class="chip__label">Label</span>
15
- </span>
11
+ <span class="chip chip--border-radius-pill chip--icon-color-default chip--intent-critical chip--size-m chip--variant-outline">
12
+ <span class="chip__inner">
13
+ <span class="chip__label">Label</span>
16
14
  </span>
17
- </mock:shadow-root>
15
+ </span>
18
16
  </swirl-chip>
19
17
  `);
20
18
  });
@@ -25,13 +23,11 @@ describe("swirl-chip", () => {
25
23
  });
26
24
  expect(page.root).toEqualHtml(`
27
25
  <swirl-chip interactive="true" label="Label">
28
- <mock:shadow-root>
29
- <button class="chip chip--border-radius-pill chip--icon-color-default chip--intent-default chip--size-m chip--interactive chip--variant-outline" type="button">
30
- <span class="chip__inner">
31
- <span class="chip__label">Label</span>
32
- </span>
33
- </button>
34
- </mock:shadow-root>
26
+ <button class="chip chip--border-radius-pill chip--icon-color-default chip--intent-default chip--size-m chip--interactive chip--variant-outline" type="button">
27
+ <span class="chip__inner">
28
+ <span class="chip__label">Label</span>
29
+ </span>
30
+ </button>
35
31
  </swirl-chip>
36
32
  `);
37
33
  });
@@ -42,14 +38,27 @@ describe("swirl-chip", () => {
42
38
  });
43
39
  expect(page.root).toEqualHtml(`
44
40
  <swirl-chip label="Label">
45
- <mock:shadow-root>
46
- <span class="chip chip--border-radius-pill chip--icon-color-default chip--intent-default chip--size-m chip--variant-outline">
47
- <span class="chip__inner">
48
- <span class="chip__label">Label</span>
49
- </span>
50
- </span>
51
- </mock:shadow-root>
52
41
  <swirl-avatar initials="JD" size="xs"></swirl-avatar>
42
+ <span class="chip chip--border-radius-pill chip--icon-color-default chip--intent-default chip--size-m chip--variant-outline">
43
+ <span class="chip__inner">
44
+ <span class="chip__label">Label</span>
45
+ </span>
46
+ </span>
47
+ </swirl-chip>
48
+ `);
49
+ });
50
+ it("renders pressed", async () => {
51
+ const page = await newSpecPage({
52
+ components: [SwirlChip],
53
+ html: `<swirl-chip pressed="true" label="Label"></swirl-chip>`,
54
+ });
55
+ expect(page.root).toEqualHtml(`
56
+ <swirl-chip pressed="true" label="Label">
57
+ <button aria-pressed="true" class="chip chip--border-radius-pill chip--icon-color-default chip--intent-default chip--size-m chip--variant-outline chip--interactive chip--pressed">
58
+ <span class="chip__inner">
59
+ <span class="chip__label">Label</span>
60
+ </span>
61
+ </button>
53
62
  </swirl-chip>
54
63
  `);
55
64
  });
@@ -58,7 +67,7 @@ describe("swirl-chip", () => {
58
67
  components: [SwirlChip],
59
68
  html: `<swirl-chip label="Label" icon="<swirl-icon-person size=&quot;16&quot;></swirl-icon-person>"></swirl-chip>`,
60
69
  });
61
- const icon = page.root.shadowRoot.querySelector(".chip__icon > *");
70
+ const icon = page.root.querySelector(".chip__icon > *");
62
71
  await page.waitForChanges();
63
72
  expect(icon).toBeTruthy();
64
73
  expect(icon.getAttribute("size")).toBe("24");
@@ -6,12 +6,13 @@ import classNames from "classnames";
6
6
  export class SwirlDescriptionListItem {
7
7
  constructor() {
8
8
  this.bordered = true;
9
+ this.maxWidth = undefined;
9
10
  this.orientation = "horizontal";
10
11
  this.term = undefined;
11
12
  }
12
13
  render() {
13
14
  const className = classNames("description-list-item", `description-list-item--orientation-${this.orientation}`, { "description-list-item--bordered": this.bordered });
14
- return (h(Host, { role: "listitem" }, h("div", { class: className, part: "description-list-item", role: "group" }, h("div", { class: "description-list-item__term", part: "description-list-item__term", role: "term" }, this.term), h("div", { class: "description-list-item__description", role: "definition" }, h("slot", null)))));
15
+ return (h(Host, { role: "listitem" }, h("div", { class: className, part: "description-list-item", role: "group" }, h("div", { class: "description-list-item__term", part: "description-list-item__term", role: "term" }, this.term), h("div", { style: { maxWidth: this.maxWidth }, class: "description-list-item__description", role: "definition" }, h("slot", null)))));
15
16
  }
16
17
  static get is() { return "swirl-description-list-item"; }
17
18
  static get encapsulation() { return "shadow"; }
@@ -45,6 +46,23 @@ export class SwirlDescriptionListItem {
45
46
  "reflect": false,
46
47
  "defaultValue": "true"
47
48
  },
49
+ "maxWidth": {
50
+ "type": "string",
51
+ "mutable": false,
52
+ "complexType": {
53
+ "original": "string",
54
+ "resolved": "string",
55
+ "references": {}
56
+ },
57
+ "required": false,
58
+ "optional": true,
59
+ "docs": {
60
+ "tags": [],
61
+ "text": ""
62
+ },
63
+ "attribute": "max-width",
64
+ "reflect": false
65
+ },
48
66
  "orientation": {
49
67
  "type": "string",
50
68
  "mutable": false,
@@ -17,6 +17,39 @@
17
17
  0 0 0 0.1875rem var(--s-focus-default);
18
18
  }
19
19
 
20
+ .radio--variant-card {
21
+ width: 100%;
22
+ padding: var(--s-space-16);
23
+ border: 0.0625rem solid var(--s-border-default);
24
+ border-radius: var(--s-border-radius-sm);
25
+ background-color: var(--s-surface);
26
+ }
27
+
28
+ .radio--variant-card:focus-within {
29
+ box-shadow: 0 0 0 0.125rem var(--s-background-default),
30
+ 0 0 0 0.25rem var(--s-focus-default);
31
+ }
32
+
33
+ .radio--variant-card:focus-within .radio__box {
34
+ box-shadow: none;
35
+ }
36
+
37
+ .radio--variant-card:hover:not(.radio--disabled) {
38
+ background-color: var(--s-surface-hovered);
39
+ }
40
+
41
+ .radio--variant-card:active:not(.radio--disabled) {
42
+ background-color: var(--s-surface-pressed);
43
+ }
44
+
45
+ .radio--variant-card.radio--checked:not(.radio--disabled) {
46
+ border-color: var(--s-border-highlight);
47
+ }
48
+
49
+ .radio--variant-card.radio--invalid:not(.radio--disabled) {
50
+ border-color: var(--s-border-critical);
51
+ }
52
+
20
53
  .radio--checked .radio__control:hover .radio__box {
21
54
  border-color: var(--s-interactive-primary-hovered);
22
55
  background-color: var(--s-interactive-primary-hovered);
@@ -14,6 +14,7 @@ export class SwirlRadio {
14
14
  this.invalid = undefined;
15
15
  this.label = undefined;
16
16
  this.value = undefined;
17
+ this.variant = "default";
17
18
  }
18
19
  getAriaCheckedLabel(checked, unchecked) {
19
20
  if (checked) {
@@ -29,13 +30,13 @@ export class SwirlRadio {
29
30
  const checked = this.checked === true || this.checked === "true";
30
31
  const ariaCheckedLabel = this.getAriaCheckedLabel(checked, unchecked);
31
32
  const ariaInvalid = this.invalid;
32
- const className = classnames("radio", {
33
+ const className = classnames("radio", `radio--variant-${this.variant}`, {
33
34
  "radio--checked": checked,
34
35
  "radio--disabled": this.disabled,
35
36
  "radio--invalid": this.invalid,
36
37
  "radio--unchecked": unchecked,
37
38
  });
38
- return (h(Host, null, h("label", { class: className, htmlFor: this.inputId }, h("span", { class: "radio__control" }, h("swirl-visually-hidden", null, h("input", { "aria-checked": ariaCheckedLabel, "aria-invalid": ariaInvalid, checked: checked, class: "radio__input", disabled: this.disabled, id: this.inputId, name: this.inputName, onChange: this.onChange, type: "radio", value: this.value })), h("span", { "aria-hidden": "true", class: "radio__box" })), h("span", { class: "radio__label-container" }, this.label && h("span", { class: "radio__label" }, this.label), this.description && (h("span", { class: "radio__description", innerHTML: this.description }))))));
39
+ return (h(Host, { style: { width: this.variant === "card" ? "100%" : undefined } }, h("label", { class: className, htmlFor: this.inputId }, h("span", { class: "radio__control" }, h("swirl-visually-hidden", null, h("input", { "aria-checked": ariaCheckedLabel, "aria-invalid": ariaInvalid, checked: checked, class: "radio__input", disabled: this.disabled, id: this.inputId, name: this.inputName, onChange: this.onChange, type: "radio", value: this.value })), h("span", { "aria-hidden": "true", class: "radio__box" })), h("span", { class: "radio__label-container" }, this.label && h("span", { class: "radio__label" }, this.label), this.description && (h("span", { class: "radio__description", innerHTML: this.description }))))));
39
40
  }
40
41
  static get is() { return "swirl-radio"; }
41
42
  static get encapsulation() { return "scoped"; }
@@ -193,6 +194,29 @@ export class SwirlRadio {
193
194
  },
194
195
  "attribute": "value",
195
196
  "reflect": false
197
+ },
198
+ "variant": {
199
+ "type": "string",
200
+ "mutable": false,
201
+ "complexType": {
202
+ "original": "SwirlRadioVariant",
203
+ "resolved": "\"card\" | \"default\"",
204
+ "references": {
205
+ "SwirlRadioVariant": {
206
+ "location": "local",
207
+ "path": "/home/runner/work/swirl/swirl/packages/swirl-components/src/components/swirl-radio/swirl-radio.tsx"
208
+ }
209
+ }
210
+ },
211
+ "required": false,
212
+ "optional": true,
213
+ "docs": {
214
+ "tags": [],
215
+ "text": ""
216
+ },
217
+ "attribute": "variant",
218
+ "reflect": false,
219
+ "defaultValue": "\"default\""
196
220
  }
197
221
  };
198
222
  }
@@ -8,7 +8,7 @@ describe("swirl-radio", () => {
8
8
  });
9
9
  expect(page.root).toMatchInlineSnapshot(`
10
10
  <swirl-radio checked="true" disabled="true" input-id="radio" input-name="radio" label="Label" value="Value">
11
- <label class="radio radio--checked radio--disabled" htmlfor="radio">
11
+ <label class="radio radio--checked radio--disabled radio--variant-default" htmlfor="radio">
12
12
  <span class="radio__control">
13
13
  <swirl-visually-hidden>
14
14
  <input aria-checked="true" checked="" class="radio__input" disabled="" id="radio" name="radio" type="radio" value="Value">
@@ -0,0 +1,7 @@
1
+ :host {
2
+ display: block;
3
+ }
4
+
5
+ :host * {
6
+ box-sizing: border-box;
7
+ }
@@ -0,0 +1,128 @@
1
+ import { h, Host } from "@stencil/core";
2
+ import { getActiveElement } from "../../utils";
3
+ export class SwirlToolbar {
4
+ constructor() {
5
+ this.onKeyDown = (event) => {
6
+ if (event.code === "ArrowDown" || event.code === "ArrowRight") {
7
+ event.preventDefault();
8
+ this.focusNextItem();
9
+ }
10
+ else if (event.code === "ArrowUp" || event.code === "ArrowLeft") {
11
+ event.preventDefault();
12
+ this.focusPreviousItem();
13
+ }
14
+ };
15
+ this.label = undefined;
16
+ this.orientation = "horizontal";
17
+ }
18
+ componentDidLoad() {
19
+ const items = this.getItems();
20
+ this.deactivateTabIndexes(items);
21
+ const firstButton = items[0]?.querySelector("button");
22
+ if (!Boolean(firstButton)) {
23
+ return;
24
+ }
25
+ firstButton.tabIndex = 0;
26
+ }
27
+ getItems() {
28
+ return Array.from(this.el.querySelectorAll("swirl-button, swirl-chip"));
29
+ }
30
+ focusNextItem() {
31
+ const items = this.getItems();
32
+ const activeItemIndex = this.getActiveItemIndex(items);
33
+ const newIndex = (activeItemIndex + 1) % items.length;
34
+ this.focusItem(items[newIndex]);
35
+ }
36
+ focusPreviousItem() {
37
+ const items = this.getItems();
38
+ const activeItemIndex = this.getActiveItemIndex(items);
39
+ const newIndex = activeItemIndex === 0 ? items.length - 1 : activeItemIndex - 1;
40
+ this.focusItem(items[newIndex]);
41
+ }
42
+ getActiveItemIndex(items) {
43
+ const activeElement = getActiveElement();
44
+ return items.findIndex((item) => item === activeElement?.closest("swirl-button, swirl-chip"));
45
+ }
46
+ focusItem(item) {
47
+ const items = this.getItems();
48
+ this.deactivateTabIndexes(items);
49
+ if (!Boolean(item)) {
50
+ return;
51
+ }
52
+ const button = item.querySelector("button");
53
+ if (!Boolean(button)) {
54
+ return;
55
+ }
56
+ button.tabIndex = 0;
57
+ button.focus();
58
+ }
59
+ deactivateTabIndexes(items) {
60
+ items.forEach((item) => {
61
+ const button = item.querySelector("button");
62
+ if (!Boolean(button)) {
63
+ return;
64
+ }
65
+ button.tabIndex = -1;
66
+ });
67
+ }
68
+ render() {
69
+ return (h(Host, null, h("swirl-stack", { align: "center", "aria-label": this.label, "aria-orientation": this.orientation, role: "toolbar", onKeyDown: this.onKeyDown, orientation: this.orientation, spacing: "8" }, h("slot", null))));
70
+ }
71
+ static get is() { return "swirl-toolbar"; }
72
+ static get encapsulation() { return "shadow"; }
73
+ static get originalStyleUrls() {
74
+ return {
75
+ "$": ["swirl-toolbar.css"]
76
+ };
77
+ }
78
+ static get styleUrls() {
79
+ return {
80
+ "$": ["swirl-toolbar.css"]
81
+ };
82
+ }
83
+ static get properties() {
84
+ return {
85
+ "label": {
86
+ "type": "string",
87
+ "mutable": false,
88
+ "complexType": {
89
+ "original": "string",
90
+ "resolved": "string",
91
+ "references": {}
92
+ },
93
+ "required": false,
94
+ "optional": false,
95
+ "docs": {
96
+ "tags": [],
97
+ "text": ""
98
+ },
99
+ "attribute": "label",
100
+ "reflect": false
101
+ },
102
+ "orientation": {
103
+ "type": "string",
104
+ "mutable": false,
105
+ "complexType": {
106
+ "original": "SwirlToolbarOrientation",
107
+ "resolved": "\"horizontal\" | \"vertical\"",
108
+ "references": {
109
+ "SwirlToolbarOrientation": {
110
+ "location": "local",
111
+ "path": "/home/runner/work/swirl/swirl/packages/swirl-components/src/components/swirl-toolbar/swirl-toolbar.tsx"
112
+ }
113
+ }
114
+ },
115
+ "required": false,
116
+ "optional": true,
117
+ "docs": {
118
+ "tags": [],
119
+ "text": ""
120
+ },
121
+ "attribute": "orientation",
122
+ "reflect": false,
123
+ "defaultValue": "\"horizontal\""
124
+ }
125
+ };
126
+ }
127
+ static get elementRef() { return "el"; }
128
+ }
@@ -0,0 +1,26 @@
1
+ import { newSpecPage } from "@stencil/core/testing";
2
+ import { SwirlToolbar } from "./swirl-toolbar";
3
+ describe("swirl-toolbar", () => {
4
+ it("renders", async () => {
5
+ const page = await newSpecPage({
6
+ components: [SwirlToolbar],
7
+ html: `
8
+ <swirl-toolbar>
9
+ <swirl-chip label="Remove" pressed="true"></swirl-chip>
10
+ <swirl-button icon="<swirl-icon-add></swirl-icon-add>" label="Add"></swirl-button>
11
+ </swirl-toolbar>
12
+ `,
13
+ });
14
+ expect(page.root).toEqualHtml(`
15
+ <swirl-toolbar>
16
+ <mock:shadow-root>
17
+ <swirl-stack align="center" aria-orientation="horizontal" orientation="horizontal" role="toolbar" spacing="8">
18
+ <slot></slot>
19
+ </swirl-stack>
20
+ </mock:shadow-root>
21
+ <swirl-chip label="Remove" pressed="true"></swirl-chip>
22
+ <swirl-button icon="<swirl-icon-add></swirl-icon-add>" label="Add"></swirl-button>
23
+ </swirl-toolbar>
24
+ `);
25
+ });
26
+ });
@@ -0,0 +1,24 @@
1
+ import { generateStoryElement } from "../../utils";
2
+ import Docs from "./swirl-toolbar.mdx";
3
+ export default {
4
+ component: "swirl-toolbar",
5
+ tags: ["autodocs"],
6
+ parameters: {
7
+ docs: {
8
+ page: Docs,
9
+ },
10
+ },
11
+ title: "Components/SwirlToolbar",
12
+ };
13
+ const Template = (args) => {
14
+ const element = generateStoryElement("swirl-toolbar", args);
15
+ element.innerHTML = `
16
+ <swirl-chip label="Remove" pressed="true"></swirl-chip>
17
+ <swirl-button icon="<swirl-icon-add></swirl-icon-add>" label="Add"></swirl-button>
18
+ `;
19
+ return element;
20
+ };
21
+ export const SwirlToolbar = Template.bind({});
22
+ SwirlToolbar.args = {
23
+ label: "Label",
24
+ };