@getflip/swirl-components 0.106.0 → 0.108.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 (41) hide show
  1. package/components.json +19 -9
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/swirl-components.cjs.js +1 -1
  4. package/dist/cjs/swirl-heading.cjs.entry.js +3 -15
  5. package/dist/cjs/swirl-popover_2.cjs.entry.js +16 -10
  6. package/dist/cjs/swirl-text.cjs.entry.js +765 -8
  7. package/dist/collection/components/swirl-heading/swirl-heading.css +4 -0
  8. package/dist/collection/components/swirl-heading/swirl-heading.js +2 -23
  9. package/dist/collection/components/swirl-heading/swirl-heading.spec.js +2 -2
  10. package/dist/collection/components/swirl-modal/swirl-modal.stories.js +24 -26
  11. package/dist/collection/components/swirl-popover/swirl-popover.js +34 -10
  12. package/dist/collection/components/swirl-popover/swirl-popover.stories.js +3 -0
  13. package/dist/collection/components/swirl-resource-list-item/swirl-resource-list-item.stories.js +1 -0
  14. package/dist/collection/components/swirl-search/swirl-search.stories.js +0 -3
  15. package/dist/collection/components/swirl-theme-provider/swirl-theme-provider.stories.js +0 -3
  16. package/dist/collection/components/swirl-time-input/swirl-time-input.stories.js +0 -3
  17. package/dist/components/swirl-heading2.js +4 -16
  18. package/dist/components/swirl-popover2.js +17 -10
  19. package/dist/components/swirl-text2.js +759 -2
  20. package/dist/esm/loader.js +1 -1
  21. package/dist/esm/swirl-components.js +1 -1
  22. package/dist/esm/swirl-heading.entry.js +3 -15
  23. package/dist/esm/swirl-popover_2.entry.js +16 -10
  24. package/dist/esm/swirl-text.entry.js +759 -2
  25. package/dist/swirl-components/p-39cf2a0f.entry.js +8 -0
  26. package/dist/swirl-components/p-bff41b61.entry.js +1 -0
  27. package/dist/swirl-components/p-e2870d0c.entry.js +1 -0
  28. package/dist/swirl-components/swirl-components.esm.js +1 -1
  29. package/dist/types/components/swirl-heading/swirl-heading.d.ts +0 -4
  30. package/dist/types/components/swirl-popover/swirl-popover.d.ts +1 -0
  31. package/dist/types/components/swirl-popover/swirl-popover.stories.d.ts +3 -0
  32. package/dist/types/components.d.ts +2 -0
  33. package/package.json +2 -3
  34. package/vscode-data.json +4 -0
  35. package/dist/cjs/balancetext-562c7a48.js +0 -763
  36. package/dist/components/balancetext.js +0 -761
  37. package/dist/esm/balancetext-fa49c64f.js +0 -761
  38. package/dist/swirl-components/p-2cedaddb.entry.js +0 -1
  39. package/dist/swirl-components/p-52282426.entry.js +0 -8
  40. package/dist/swirl-components/p-d7af31e3.entry.js +0 -1
  41. package/dist/swirl-components/p-f83a5757.js +0 -1
@@ -15,6 +15,10 @@
15
15
  text-align: start;
16
16
  }
17
17
 
18
+ .heading--balanced {
19
+ text-wrap: balance;
20
+ }
21
+
18
22
  .heading--align-start {
19
23
  text-align: start;
20
24
  }
@@ -1,6 +1,5 @@
1
1
  import { h, Host } from "@stencil/core";
2
2
  import classnames from "classnames";
3
- import balanceText from "balance-text";
4
3
  export class SwirlHeading {
5
4
  constructor() {
6
5
  this.align = "start";
@@ -12,18 +11,6 @@ export class SwirlHeading {
12
11
  this.text = undefined;
13
12
  this.truncate = undefined;
14
13
  }
15
- componentDidRender() {
16
- this.rebalance();
17
- }
18
- onWindowResize() {
19
- this.rebalance();
20
- }
21
- rebalance() {
22
- if (!this.balance || !Boolean(this.headingEl) || Boolean(this.lines)) {
23
- return;
24
- }
25
- balanceText(this.headingEl);
26
- }
27
14
  render() {
28
15
  const Tag = this.as || `h${this.level}`;
29
16
  const styles = Boolean(this.lines)
@@ -36,9 +23,10 @@ export class SwirlHeading {
36
23
  }
37
24
  : undefined;
38
25
  const className = classnames("heading", `heading--align-${this.align}`, `heading--level-${this.level}`, {
26
+ "heading--balanced": this.balance,
39
27
  "heading--truncate": this.truncate,
40
28
  });
41
- return (h(Host, null, h(Tag, { class: className, id: this.headingId, ref: (el) => (this.headingEl = el), style: styles }, this.text)));
29
+ return (h(Host, null, h(Tag, { class: className, id: this.headingId, style: styles }, this.text)));
42
30
  }
43
31
  static get is() { return "swirl-heading"; }
44
32
  static get encapsulation() { return "scoped"; }
@@ -210,13 +198,4 @@ export class SwirlHeading {
210
198
  }
211
199
  };
212
200
  }
213
- static get listeners() {
214
- return [{
215
- "name": "resize",
216
- "method": "onWindowResize",
217
- "target": "window",
218
- "capture": false,
219
- "passive": true
220
- }];
221
- }
222
201
  }
@@ -9,7 +9,7 @@ describe("swirl-heading", () => {
9
9
  expect(page.root).toEqualHtml(`
10
10
  <swirl-heading heading-id="id" level="3">
11
11
  Heading
12
- <h3 class="heading heading--align-start heading--level-3" id="id"></h3>
12
+ <h3 class="heading heading--align-start heading--balanced heading--level-3" id="id"></h3>
13
13
  </swirl-heading>
14
14
  `);
15
15
  });
@@ -21,7 +21,7 @@ describe("swirl-heading", () => {
21
21
  expect(page.root).toEqualHtml(`
22
22
  <swirl-heading as="h6" heading-id="id" level="3">
23
23
  Heading
24
- <h6 class="heading heading--align-start heading--level-3" id="id"></h6>
24
+ <h6 class="heading heading--align-start heading--balanced heading--level-3" id="id"></h6>
25
25
  </swirl-heading>
26
26
  `);
27
27
  });
@@ -37,32 +37,30 @@ const Template = (args) => {
37
37
  trigger.label = "Open modal";
38
38
  trigger.addEventListener("click", () => element.open());
39
39
  element.innerHTML = `
40
- <swirl-box padding-block-start="16">
41
- <swirl-text>
42
- Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
43
- eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
44
- voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet
45
- clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit
46
- amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
47
- nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed
48
- diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
49
- Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor
50
- sit amet.
51
- </swirl-text>
52
- </swirl-box>
53
-
54
- <swirl-box cover slot="secondary-content">
55
- <swirl-card elevated="false" height="100%" intent="default-subdued" is-borderless>
56
- <swirl-text slot="content">
57
- Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
58
- eirmod tempor invidunt.
59
- </swirl-text>
60
- </swirl-card>
61
- </swirl-box>
62
-
63
- <swirl-box padding-block-start="4" padding-block-end="16" slot="header-tools">
64
- <swirl-search auto-focus label="Search"></swirl-search>
65
- </div>
40
+ <swirl-box padding-block-start="16">
41
+ <swirl-text>
42
+ Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
43
+ eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
44
+ voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet
45
+ clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit
46
+ amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
47
+ nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed
48
+ diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
49
+ Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor
50
+ sit amet.
51
+ </swirl-text>
52
+ </swirl-box>
53
+ <swirl-box cover slot="secondary-content">
54
+ <swirl-card elevated="false" height="100%" intent="default-subdued" is-borderless>
55
+ <swirl-text slot="content">
56
+ Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
57
+ eirmod tempor invidunt.
58
+ </swirl-text>
59
+ </swirl-card>
60
+ </swirl-box>
61
+ <swirl-box padding-block-start="4" padding-block-end="16" slot="header-tools">
62
+ <swirl-search auto-focus label="Search"></swirl-search>
63
+ </div>
66
64
  `;
67
65
  container.append(trigger, element);
68
66
  return container;
@@ -56,6 +56,7 @@ export class SwirlPopover {
56
56
  this.offset = 8;
57
57
  this.popoverId = undefined;
58
58
  this.placement = "bottom-start";
59
+ this.returnFocusToTrigger = true;
59
60
  this.trigger = undefined;
60
61
  this.triggerContainer = undefined;
61
62
  this.useContainerWidth = undefined;
@@ -78,18 +79,21 @@ export class SwirlPopover {
78
79
  return;
79
80
  }
80
81
  const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
82
+ const isWKWebView = "webkit" in window;
83
+ const isSafariOrWKWebView = isSafari || isWKWebView;
81
84
  const target = event.target;
82
85
  const relatedTarget = event.relatedTarget;
83
86
  const activeElement = getActiveElement();
84
- const popoverLostFocus = !this.el.contains(target) &&
85
- !this.el.contains(activeElement) &&
86
- target !== this.triggerEl &&
87
- !this.triggerEl?.contains(target) &&
88
- (!isSafari ||
89
- (isSafari &&
90
- !this.el.contains(relatedTarget || target) &&
91
- relatedTarget !== this.el));
92
- if (popoverLostFocus) {
87
+ // Check if the focus has moved outside the popover or its trigger.
88
+ const focusIsOutsidePopover = !this.el.contains(target) && !this.el.contains(activeElement);
89
+ const focusIsNotOnTrigger = target !== this.triggerEl && !this.triggerEl?.contains(target);
90
+ const extraCheckForSafariOrWKWebView = isSafariOrWKWebView &&
91
+ !this.el.contains(relatedTarget || target) &&
92
+ relatedTarget !== this.el;
93
+ // Close the popover if the focus is outside and additional checks for Safari or WKWebView pass.
94
+ if (focusIsOutsidePopover &&
95
+ focusIsNotOnTrigger &&
96
+ (!isSafariOrWKWebView || extraCheckForSafariOrWKWebView)) {
93
97
  this.close();
94
98
  }
95
99
  }
@@ -128,7 +132,9 @@ export class SwirlPopover {
128
132
  this.updateTriggerAttributes();
129
133
  }, 150);
130
134
  this.unlockBodyScroll();
131
- this.getNativeTriggerElement()?.focus();
135
+ if (this.returnFocusToTrigger) {
136
+ this.getNativeTriggerElement()?.focus();
137
+ }
132
138
  }
133
139
  /**
134
140
  * Open the popover.
@@ -430,6 +436,24 @@ export class SwirlPopover {
430
436
  "reflect": false,
431
437
  "defaultValue": "\"bottom-start\""
432
438
  },
439
+ "returnFocusToTrigger": {
440
+ "type": "boolean",
441
+ "mutable": false,
442
+ "complexType": {
443
+ "original": "boolean",
444
+ "resolved": "boolean",
445
+ "references": {}
446
+ },
447
+ "required": false,
448
+ "optional": true,
449
+ "docs": {
450
+ "tags": [],
451
+ "text": ""
452
+ },
453
+ "attribute": "return-focus-to-trigger",
454
+ "reflect": false,
455
+ "defaultValue": "true"
456
+ },
433
457
  "trigger": {
434
458
  "type": "string",
435
459
  "mutable": false,
@@ -12,6 +12,9 @@ export default {
12
12
  type: "number",
13
13
  },
14
14
  },
15
+ returnFocusToTrigger: {
16
+ description: "By default, the focus is returned to the trigger element when the popover is closed. Pass false to disable this behavior.",
17
+ },
15
18
  trigger: {
16
19
  description: "**Deprecated! Please use the swirl-popover-trigger component instead.** ID of the trigger element or the trigger DOM element.",
17
20
  control: {
@@ -53,6 +53,7 @@ const Template = (args) => {
53
53
  popover.animation = "scale-in-y";
54
54
  popover.label = "Options";
55
55
  popover.placement = "bottom-end";
56
+ popover.returnFocusToTrigger = false;
56
57
  popover.innerHTML = `
57
58
  <swirl-action-list>
58
59
  <swirl-action-list-item
@@ -12,9 +12,6 @@ export default {
12
12
  };
13
13
  const Template = (args) => {
14
14
  const element = generateStoryElement("swirl-search", args);
15
- element.addEventListener("inputInput", (event) => {
16
- console.log(event);
17
- });
18
15
  return element;
19
16
  };
20
17
  export const SwirlSearch = Template.bind({});
@@ -77,9 +77,6 @@ const Template = (args) => {
77
77
  element.resetPreferredTheme();
78
78
  });
79
79
  element.append(lightModeButton, darkModeButton, tenantButton, resetButton);
80
- element.addEventListener("themeChange", (event) => {
81
- console.log(event.detail);
82
- });
83
80
  return element;
84
81
  };
85
82
  export const SwirlThemeProvider = Template.bind({});
@@ -29,9 +29,6 @@ const Template = (args) => {
29
29
  const element = generateStoryElement("swirl-time-input", args);
30
30
  formControl.setAttribute("label", "Time");
31
31
  formControl.append("\n ", element, "\n");
32
- element.addEventListener("valueChange", (event) => {
33
- console.log(event);
34
- });
35
32
  return formControl;
36
33
  };
37
34
  export const SwirlTimeInput = Template.bind({});
@@ -1,8 +1,7 @@
1
1
  import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
2
2
  import { c as classnames } from './index2.js';
3
- import { b as balancetext } from './balancetext.js';
4
3
 
5
- const swirlHeadingCss = ".sc-swirl-heading-h{display:block;width:100%}.sc-swirl-heading-h *.sc-swirl-heading{box-sizing:border-box}.heading.sc-swirl-heading{display:block;width:100%;margin:0;padding:0;text-align:start}.heading--align-start.sc-swirl-heading{text-align:start}.heading--align-center.sc-swirl-heading{text-align:center}.heading--align-end.sc-swirl-heading{text-align:end}.heading--level-1.sc-swirl-heading{font-size:var(--s-font-size-2xl);font-weight:var(--s-font-weight-bold);line-height:var(--s-line-height-2xl);letter-spacing:var(--s-letter-spacing-tight)}.heading--level-2.sc-swirl-heading{font-size:var(--s-font-size-xl);font-weight:var(--s-font-weight-bold);line-height:var(--s-line-height-xl)}.heading--level-3.sc-swirl-heading{font-size:var(--s-font-size-lg);font-weight:var(--s-font-weight-semibold);line-height:var(--s-line-height-lg)}.heading--level-4.sc-swirl-heading{font-size:var(--s-font-size-base);font-weight:var(--s-font-weight-semibold);line-height:var(--s-line-height-base)}.heading--level-5.sc-swirl-heading,.heading--level-6.sc-swirl-heading{font-size:var(--s-font-size-sm);font-weight:var(--s-font-weight-semibold);line-height:var(--s-line-height-sm)}.heading--truncate.sc-swirl-heading{overflow:hidden;white-space:nowrap;text-overflow:ellipsis}";
4
+ const swirlHeadingCss = ".sc-swirl-heading-h{display:block;width:100%}.sc-swirl-heading-h *.sc-swirl-heading{box-sizing:border-box}.heading.sc-swirl-heading{display:block;width:100%;margin:0;padding:0;text-align:start}.heading--balanced.sc-swirl-heading{text-wrap:balance}.heading--align-start.sc-swirl-heading{text-align:start}.heading--align-center.sc-swirl-heading{text-align:center}.heading--align-end.sc-swirl-heading{text-align:end}.heading--level-1.sc-swirl-heading{font-size:var(--s-font-size-2xl);font-weight:var(--s-font-weight-bold);line-height:var(--s-line-height-2xl);letter-spacing:var(--s-letter-spacing-tight)}.heading--level-2.sc-swirl-heading{font-size:var(--s-font-size-xl);font-weight:var(--s-font-weight-bold);line-height:var(--s-line-height-xl)}.heading--level-3.sc-swirl-heading{font-size:var(--s-font-size-lg);font-weight:var(--s-font-weight-semibold);line-height:var(--s-line-height-lg)}.heading--level-4.sc-swirl-heading{font-size:var(--s-font-size-base);font-weight:var(--s-font-weight-semibold);line-height:var(--s-line-height-base)}.heading--level-5.sc-swirl-heading,.heading--level-6.sc-swirl-heading{font-size:var(--s-font-size-sm);font-weight:var(--s-font-weight-semibold);line-height:var(--s-line-height-sm)}.heading--truncate.sc-swirl-heading{overflow:hidden;white-space:nowrap;text-overflow:ellipsis}";
6
5
 
7
6
  const SwirlHeading = /*@__PURE__*/ proxyCustomElement(class SwirlHeading extends HTMLElement {
8
7
  constructor() {
@@ -17,18 +16,6 @@ const SwirlHeading = /*@__PURE__*/ proxyCustomElement(class SwirlHeading extends
17
16
  this.text = undefined;
18
17
  this.truncate = undefined;
19
18
  }
20
- componentDidRender() {
21
- this.rebalance();
22
- }
23
- onWindowResize() {
24
- this.rebalance();
25
- }
26
- rebalance() {
27
- if (!this.balance || !Boolean(this.headingEl) || Boolean(this.lines)) {
28
- return;
29
- }
30
- balancetext(this.headingEl);
31
- }
32
19
  render() {
33
20
  const Tag = this.as || `h${this.level}`;
34
21
  const styles = Boolean(this.lines)
@@ -41,9 +28,10 @@ const SwirlHeading = /*@__PURE__*/ proxyCustomElement(class SwirlHeading extends
41
28
  }
42
29
  : undefined;
43
30
  const className = classnames("heading", `heading--align-${this.align}`, `heading--level-${this.level}`, {
31
+ "heading--balanced": this.balance,
44
32
  "heading--truncate": this.truncate,
45
33
  });
46
- return (h(Host, null, h(Tag, { class: className, id: this.headingId, ref: (el) => (this.headingEl = el), style: styles }, this.text)));
34
+ return (h(Host, null, h(Tag, { class: className, id: this.headingId, style: styles }, this.text)));
47
35
  }
48
36
  static get style() { return swirlHeadingCss; }
49
37
  }, [2, "swirl-heading", {
@@ -55,7 +43,7 @@ const SwirlHeading = /*@__PURE__*/ proxyCustomElement(class SwirlHeading extends
55
43
  "lines": [2],
56
44
  "text": [1],
57
45
  "truncate": [4]
58
- }, [[9, "resize", "onWindowResize"]]]);
46
+ }]);
59
47
  function defineCustomElement() {
60
48
  if (typeof customElements === "undefined") {
61
49
  return;
@@ -61,6 +61,7 @@ const SwirlPopover = /*@__PURE__*/ proxyCustomElement(class SwirlPopover extends
61
61
  this.offset = 8;
62
62
  this.popoverId = undefined;
63
63
  this.placement = "bottom-start";
64
+ this.returnFocusToTrigger = true;
64
65
  this.trigger = undefined;
65
66
  this.triggerContainer = undefined;
66
67
  this.useContainerWidth = undefined;
@@ -83,18 +84,21 @@ const SwirlPopover = /*@__PURE__*/ proxyCustomElement(class SwirlPopover extends
83
84
  return;
84
85
  }
85
86
  const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
87
+ const isWKWebView = "webkit" in window;
88
+ const isSafariOrWKWebView = isSafari || isWKWebView;
86
89
  const target = event.target;
87
90
  const relatedTarget = event.relatedTarget;
88
91
  const activeElement = getActiveElement();
89
- const popoverLostFocus = !this.el.contains(target) &&
90
- !this.el.contains(activeElement) &&
91
- target !== this.triggerEl &&
92
- !this.triggerEl?.contains(target) &&
93
- (!isSafari ||
94
- (isSafari &&
95
- !this.el.contains(relatedTarget || target) &&
96
- relatedTarget !== this.el));
97
- if (popoverLostFocus) {
92
+ // Check if the focus has moved outside the popover or its trigger.
93
+ const focusIsOutsidePopover = !this.el.contains(target) && !this.el.contains(activeElement);
94
+ const focusIsNotOnTrigger = target !== this.triggerEl && !this.triggerEl?.contains(target);
95
+ const extraCheckForSafariOrWKWebView = isSafariOrWKWebView &&
96
+ !this.el.contains(relatedTarget || target) &&
97
+ relatedTarget !== this.el;
98
+ // Close the popover if the focus is outside and additional checks for Safari or WKWebView pass.
99
+ if (focusIsOutsidePopover &&
100
+ focusIsNotOnTrigger &&
101
+ (!isSafariOrWKWebView || extraCheckForSafariOrWKWebView)) {
98
102
  this.close();
99
103
  }
100
104
  }
@@ -133,7 +137,9 @@ const SwirlPopover = /*@__PURE__*/ proxyCustomElement(class SwirlPopover extends
133
137
  this.updateTriggerAttributes();
134
138
  }, 150);
135
139
  this.unlockBodyScroll();
136
- this.getNativeTriggerElement()?.focus();
140
+ if (this.returnFocusToTrigger) {
141
+ this.getNativeTriggerElement()?.focus();
142
+ }
137
143
  }
138
144
  /**
139
145
  * Open the popover.
@@ -265,6 +271,7 @@ const SwirlPopover = /*@__PURE__*/ proxyCustomElement(class SwirlPopover extends
265
271
  "offset": [2],
266
272
  "popoverId": [1, "popover-id"],
267
273
  "placement": [1],
274
+ "returnFocusToTrigger": [4, "return-focus-to-trigger"],
268
275
  "trigger": [1],
269
276
  "triggerContainer": [16],
270
277
  "useContainerWidth": [8, "use-container-width"],