@getflip/swirl-components 0.163.0 → 0.165.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 (29) hide show
  1. package/components.json +78 -5
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/swirl-avatar.cjs.entry.js +38 -4
  4. package/dist/cjs/swirl-components.cjs.js +1 -1
  5. package/dist/cjs/swirl-image-grid-item.cjs.entry.js +16 -2
  6. package/dist/collection/assets/pdfjs/pdf.worker.min.js +1 -1
  7. package/dist/collection/components/swirl-avatar/swirl-avatar.css +3 -3
  8. package/dist/collection/components/swirl-avatar/swirl-avatar.js +95 -5
  9. package/dist/collection/components/swirl-avatar/swirl-avatar.stories.js +1 -0
  10. package/dist/collection/components/swirl-image-grid-item/swirl-image-grid-item.css +14 -0
  11. package/dist/collection/components/swirl-image-grid-item/swirl-image-grid-item.js +48 -2
  12. package/dist/collection/components/swirl-image-grid-item/swirl-image-grid-item.stories.js +1 -1
  13. package/dist/components/assets/pdfjs/pdf.worker.min.js +1 -1
  14. package/dist/components/swirl-avatar.js +44 -6
  15. package/dist/components/swirl-image-grid-item.js +25 -4
  16. package/dist/esm/loader.js +1 -1
  17. package/dist/esm/swirl-avatar.entry.js +39 -5
  18. package/dist/esm/swirl-components.js +1 -1
  19. package/dist/esm/swirl-image-grid-item.entry.js +17 -3
  20. package/dist/swirl-components/p-21c1a36c.entry.js +1 -0
  21. package/dist/swirl-components/p-c178103e.entry.js +1 -0
  22. package/dist/swirl-components/swirl-components.esm.js +1 -1
  23. package/dist/types/components/swirl-avatar/swirl-avatar.d.ts +13 -0
  24. package/dist/types/components/swirl-image-grid-item/swirl-image-grid-item.d.ts +5 -0
  25. package/dist/types/components.d.ts +16 -2
  26. package/package.json +1 -1
  27. package/vscode-data.json +18 -0
  28. package/dist/swirl-components/p-3aa956d6.entry.js +0 -1
  29. package/dist/swirl-components/p-b4c0ac86.entry.js +0 -1
@@ -250,16 +250,16 @@
250
250
  }
251
251
 
252
252
  .avatar__initials {
253
+ position: absolute;
253
254
  display: inline-flex;
254
- width: 100%;
255
255
  min-width: 0;
256
- height: 100%;
257
256
  padding-right: 0.0625rem;
258
257
  padding-left: 0.0625rem;
259
258
  justify-content: center;
260
259
  align-items: center;
261
260
  border-radius: 50%;
262
261
  font-weight: var(--s-font-weight-medium);
262
+ inset: 0;
263
263
  }
264
264
 
265
265
  .avatar__initials > span {
@@ -295,8 +295,8 @@
295
295
 
296
296
  .avatar__tool {
297
297
  position: absolute;
298
- bottom: 0;
299
298
  right: 0;
299
+ bottom: 0;
300
300
  display: inline-flex;
301
301
  transform: translate3d(25%, 25%, 0);
302
302
  }
@@ -1,4 +1,4 @@
1
- import { h, Host } from "@stencil/core";
1
+ import { h, Host, } from "@stencil/core";
2
2
  import classnames from "classnames";
3
3
  const swirlAvatarSizeMappings = {
4
4
  "3xs": 20,
@@ -17,9 +17,15 @@ export class SwirlAvatar {
17
17
  constructor() {
18
18
  this.setImageAvailable = () => {
19
19
  this.imageAvailable = true;
20
+ this.loadingError = false;
21
+ this.loaded = true;
22
+ this.imageLoad.emit();
20
23
  };
21
24
  this.setImageUnavailable = () => {
22
25
  this.imageAvailable = false;
26
+ this.loaded = true;
27
+ this.loadingError = true;
28
+ this.imageError.emit();
23
29
  };
24
30
  this.onKeydown = (event) => {
25
31
  // The interactive avatar is activated by the space key on the keyup event,
@@ -47,20 +53,46 @@ export class SwirlAvatar {
47
53
  this.initials = undefined;
48
54
  this.interactive = false;
49
55
  this.label = undefined;
56
+ this.loading = undefined;
50
57
  this.showLabel = false;
51
58
  this.size = "m";
52
59
  this.src = undefined;
53
60
  this.toolPosition = "bottom";
54
61
  this.variant = "round";
62
+ this.loadingError = false;
63
+ this.loaded = false;
55
64
  this.imageAvailable = undefined;
65
+ this.inViewport = false;
66
+ }
67
+ componentDidLoad() {
68
+ this.setupIntersectionObserver();
69
+ }
70
+ disconnectedCallback() {
71
+ this.intersectionObserver?.disconnect();
56
72
  }
57
73
  watchSrcProp() {
58
74
  this.imageAvailable = undefined;
59
75
  }
76
+ setupIntersectionObserver() {
77
+ if (this.loading !== "intersecting") {
78
+ return;
79
+ }
80
+ this.intersectionObserver = new IntersectionObserver(this.onVisibilityChange.bind(this), {
81
+ threshold: 0,
82
+ });
83
+ this.intersectionObserver.observe(this.element);
84
+ }
85
+ onVisibilityChange(entries) {
86
+ if (entries[0].isIntersecting) {
87
+ this.inViewport = true;
88
+ }
89
+ }
60
90
  render() {
61
91
  const showImage = Boolean(this.src) &&
62
- (this.imageAvailable || this.imageAvailable === undefined);
63
- const showInitials = !showImage && Boolean(this.initials);
92
+ (this.imageAvailable || this.imageAvailable === undefined) &&
93
+ (this.loading !== "intersecting" || this.inViewport);
94
+ const showInitials = (!showImage || (!this.loaded && !this.loadingError)) &&
95
+ Boolean(this.initials);
64
96
  const showIcon = !showImage && !showInitials && Boolean(this.icon);
65
97
  const showFallbackIcon = !showImage && !showInitials && !showIcon;
66
98
  const showBadge = Boolean(this.badge) && this.size === "m";
@@ -72,7 +104,7 @@ export class SwirlAvatar {
72
104
  });
73
105
  const badgeClassName = classnames("avatar__badge", `avatar__badge--position-${this.badgePosition}`);
74
106
  const toolClassName = classnames("avatar__tool", `avatar__tool--position-${this.toolPosition}`);
75
- return (h(Host, { "aria-label": this.label, onKeydown: this.interactive ? this.onKeydown : undefined, onKeyup: this.interactive ? this.onKeyup : undefined, role: role, tabIndex: this.interactive ? 0 : undefined }, h("span", { class: className, part: "avatar" }, showImage && (h("span", { class: "avatar__image" }, h("img", { alt: "", height: swirlAvatarSizeMappings[this.size], onError: this.setImageUnavailable, onLoad: this.setImageAvailable, src: this.src, width: swirlAvatarSizeMappings[this.size] }))), showInitials && (h("span", { class: "avatar__initials" }, h("span", null, this.initials))), showIcon && h("span", { class: "avatar__icon", innerHTML: this.icon }), showFallbackIcon && (h("span", { class: "avatar__icon" }, h("swirl-icon-person", null))), showBadge && (h("span", { class: badgeClassName, innerHTML: this.badge })), h("span", { class: toolClassName }, h("slot", { name: "tool" }))), this.showLabel && (h("span", { "aria-hidden": true, class: "avatar__label" }, this.label))));
107
+ return (h(Host, { "aria-label": this.label, onKeydown: this.interactive ? this.onKeydown : undefined, onKeyup: this.interactive ? this.onKeyup : undefined, role: role, tabIndex: this.interactive ? 0 : undefined }, h("span", { class: className, part: "avatar" }, showImage && (h("span", { class: "avatar__image" }, h("img", { alt: "", height: swirlAvatarSizeMappings[this.size], loading: this.loading !== "intersecting" ? this.loading : undefined, onError: this.setImageUnavailable, onLoad: this.setImageAvailable, src: this.src, width: swirlAvatarSizeMappings[this.size] }))), showInitials && (h("span", { class: "avatar__initials" }, h("span", null, this.initials))), showIcon && h("span", { class: "avatar__icon", innerHTML: this.icon }), showFallbackIcon && (h("span", { class: "avatar__icon" }, h("swirl-icon-person", null))), showBadge && (h("span", { class: badgeClassName, innerHTML: this.badge })), h("span", { class: toolClassName }, h("slot", { name: "tool" }))), this.showLabel && (h("span", { "aria-hidden": true, class: "avatar__label" }, this.label))));
76
108
  }
77
109
  static get is() { return "swirl-avatar"; }
78
110
  static get encapsulation() { return "shadow"; }
@@ -220,6 +252,28 @@ export class SwirlAvatar {
220
252
  "attribute": "label",
221
253
  "reflect": false
222
254
  },
255
+ "loading": {
256
+ "type": "string",
257
+ "mutable": false,
258
+ "complexType": {
259
+ "original": "SwirlAvatarLoading",
260
+ "resolved": "\"auto\" | \"eager\" | \"intersecting\" | \"lazy\"",
261
+ "references": {
262
+ "SwirlAvatarLoading": {
263
+ "location": "local",
264
+ "path": "/home/runner/work/swirl/swirl/packages/swirl-components/src/components/swirl-avatar/swirl-avatar.tsx"
265
+ }
266
+ }
267
+ },
268
+ "required": false,
269
+ "optional": true,
270
+ "docs": {
271
+ "tags": [],
272
+ "text": ""
273
+ },
274
+ "attribute": "loading",
275
+ "reflect": false
276
+ },
223
277
  "showLabel": {
224
278
  "type": "boolean",
225
279
  "mutable": false,
@@ -328,9 +382,45 @@ export class SwirlAvatar {
328
382
  }
329
383
  static get states() {
330
384
  return {
331
- "imageAvailable": {}
385
+ "loadingError": {},
386
+ "loaded": {},
387
+ "imageAvailable": {},
388
+ "inViewport": {}
332
389
  };
333
390
  }
391
+ static get events() {
392
+ return [{
393
+ "method": "imageError",
394
+ "name": "imageError",
395
+ "bubbles": true,
396
+ "cancelable": true,
397
+ "composed": true,
398
+ "docs": {
399
+ "tags": [],
400
+ "text": ""
401
+ },
402
+ "complexType": {
403
+ "original": "void",
404
+ "resolved": "void",
405
+ "references": {}
406
+ }
407
+ }, {
408
+ "method": "imageLoad",
409
+ "name": "imageLoad",
410
+ "bubbles": true,
411
+ "cancelable": true,
412
+ "composed": true,
413
+ "docs": {
414
+ "tags": [],
415
+ "text": ""
416
+ },
417
+ "complexType": {
418
+ "original": "void",
419
+ "resolved": "void",
420
+ "references": {}
421
+ }
422
+ }];
423
+ }
334
424
  static get elementRef() { return "element"; }
335
425
  static get watchers() {
336
426
  return [{
@@ -43,5 +43,6 @@ const Template = (args) => {
43
43
  export const SwirlAvatar = Template.bind({});
44
44
  SwirlAvatar.args = {
45
45
  label: "John Doe",
46
+ initials: "PS",
46
47
  src: "https://picsum.photos/id/433/144/144",
47
48
  };
@@ -46,6 +46,10 @@ button.image-grid-item:focus-visible {
46
46
  outline-offset: var(--s-space-2);
47
47
  }
48
48
 
49
+ .image-grid-item--has-error .image-grid-item__image {
50
+ display: none;
51
+ }
52
+
49
53
  .image-grid-item--has-overlay .image-grid-item__image {
50
54
  scale: 1.1;
51
55
  filter: blur(5px);
@@ -117,3 +121,13 @@ button.image-grid-item:focus-visible {
117
121
  background-color: rgba(0, 0, 0, 0.4);
118
122
  inset: 0;
119
123
  }
124
+
125
+ .image-grid-item__error {
126
+ position: absolute;
127
+ z-index: 3;
128
+ display: flex;
129
+ justify-content: center;
130
+ align-items: center;
131
+ background-color: rgba(0, 0, 0, 0.1);
132
+ inset: 0;
133
+ }
@@ -1,9 +1,16 @@
1
- import { h, Host } from "@stencil/core";
1
+ import { h, Host, } from "@stencil/core";
2
2
  import classnames from "classnames";
3
3
  export class SwirlImageGridItem {
4
4
  constructor() {
5
5
  this.onLoad = () => {
6
+ this.error = false;
6
7
  this.loaded = true;
8
+ this.imageLoad.emit();
9
+ };
10
+ this.onError = () => {
11
+ this.loaded = true;
12
+ this.error = true;
13
+ this.imageError.emit();
7
14
  };
8
15
  this.alt = undefined;
9
16
  this.icon = undefined;
@@ -11,6 +18,7 @@ export class SwirlImageGridItem {
11
18
  this.loading = undefined;
12
19
  this.overlay = undefined;
13
20
  this.src = undefined;
21
+ this.error = false;
14
22
  this.loaded = false;
15
23
  this.inViewport = false;
16
24
  }
@@ -37,6 +45,7 @@ export class SwirlImageGridItem {
37
45
  render() {
38
46
  const Tag = this.interactive ? "button" : "div";
39
47
  const className = classnames("image-grid-item", {
48
+ "image-grid-item--has-error": this.error,
40
49
  "image-grid-item--has-overlay": this.overlay,
41
50
  });
42
51
  return (h(Host, { role: "listitem" }, h(Tag, { class: className, type: this.interactive ? "button" : undefined }, h("div", { class: "image-grid-item__background", style: {
@@ -45,7 +54,10 @@ export class SwirlImageGridItem {
45
54
  this.loaded
46
55
  ? `url(${this.src})`
47
56
  : undefined,
48
- } }), this.loading !== "intersecting" || this.inViewport ? (h("img", { alt: this.alt, class: "image-grid-item__image", loading: this.loading !== "intersecting" ? this.loading : undefined, onLoad: this.onLoad, src: this.src })) : (h("div", { class: "image-grid-item__loading-placeholder" })), this.loaded && this.icon && !Boolean(this.overlay) && (h("div", { class: "image-grid-item__icon", innerHTML: this.icon })), this.overlay && (h("div", { class: "image-grid-item__overlay" }, this.overlay)), !this.loaded && (h("div", { class: "image-grid-item__spinner" }, h("swirl-spinner", null))))));
57
+ } }), this.loading !== "intersecting" || this.inViewport ? (h("img", { alt: this.alt, class: "image-grid-item__image", loading: this.loading !== "intersecting" ? this.loading : undefined, onError: this.onError, onLoad: this.onLoad, src: this.src })) : (h("div", { class: "image-grid-item__loading-placeholder" })), this.loaded &&
58
+ !this.error &&
59
+ this.icon &&
60
+ !Boolean(this.overlay) && (h("div", { class: "image-grid-item__icon", innerHTML: this.icon })), this.overlay && (h("div", { class: "image-grid-item__overlay" }, this.overlay)), !this.loaded && (h("div", { class: "image-grid-item__spinner" }, h("swirl-spinner", null))), this.loaded && this.error && (h("div", { class: "image-grid-item__error" }, h("swirl-icon-error", { color: "critical" }))))));
49
61
  }
50
62
  static get is() { return "swirl-image-grid-item"; }
51
63
  static get encapsulation() { return "shadow"; }
@@ -172,9 +184,43 @@ export class SwirlImageGridItem {
172
184
  }
173
185
  static get states() {
174
186
  return {
187
+ "error": {},
175
188
  "loaded": {},
176
189
  "inViewport": {}
177
190
  };
178
191
  }
192
+ static get events() {
193
+ return [{
194
+ "method": "imageError",
195
+ "name": "imageError",
196
+ "bubbles": true,
197
+ "cancelable": true,
198
+ "composed": true,
199
+ "docs": {
200
+ "tags": [],
201
+ "text": ""
202
+ },
203
+ "complexType": {
204
+ "original": "void",
205
+ "resolved": "void",
206
+ "references": {}
207
+ }
208
+ }, {
209
+ "method": "imageLoad",
210
+ "name": "imageLoad",
211
+ "bubbles": true,
212
+ "cancelable": true,
213
+ "composed": true,
214
+ "docs": {
215
+ "tags": [],
216
+ "text": ""
217
+ },
218
+ "complexType": {
219
+ "original": "void",
220
+ "resolved": "void",
221
+ "references": {}
222
+ }
223
+ }];
224
+ }
179
225
  static get elementRef() { return "el"; }
180
226
  }
@@ -20,5 +20,5 @@ export const SwirlImageGridItem = Template.bind({});
20
20
  SwirlImageGridItem.args = {
21
21
  alt: "Dog in a blanket",
22
22
  icon: "<swirl-icon-play-arrow></swirl-icon-play-arrow>",
23
- src: "/sample.jpg",
23
+ src: "/sampledsds.jpg",
24
24
  };