@brightspace-ui/core 3.79.0 → 3.79.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,7 @@ import { emptyStateIllustratedStyles, emptyStateStyles } from './empty-state-sty
|
|
2
2
|
import { html, LitElement, nothing } from 'lit';
|
3
3
|
import { bodyCompactStyles } from '../typography/styles.js';
|
4
4
|
import { classMap } from 'lit/directives/class-map.js';
|
5
|
+
import { LoadingCompleteMixin } from '../../mixins/loading-complete/loading-complete-mixin.js';
|
5
6
|
import { loadSvg } from '../../generated/empty-state/presetIllustrationLoader.js';
|
6
7
|
import { PropertyRequiredMixin } from '../../mixins/property-required/property-required-mixin.js';
|
7
8
|
import ResizeObserver from 'resize-observer-polyfill/dist/ResizeObserver.es.js';
|
@@ -16,7 +17,7 @@ const illustrationAspectRatio = 500 / 330;
|
|
16
17
|
* @slot - Slot for empty state actions
|
17
18
|
* @slot illustration - Slot for custom SVG content if `illustration-name` property is not set
|
18
19
|
*/
|
19
|
-
class EmptyStateIllustrated extends PropertyRequiredMixin(LitElement) {
|
20
|
+
class EmptyStateIllustrated extends LoadingCompleteMixin(PropertyRequiredMixin(LitElement)) {
|
20
21
|
|
21
22
|
static get properties() {
|
22
23
|
return {
|
@@ -53,35 +54,41 @@ class EmptyStateIllustrated extends PropertyRequiredMixin(LitElement) {
|
|
53
54
|
|
54
55
|
connectedCallback() {
|
55
56
|
super.connectedCallback();
|
56
|
-
this.addEventListener('d2l-empty-state-illustrated-check', this
|
57
|
+
this.addEventListener('d2l-empty-state-illustrated-check', this.#handleEmptyStateIllustratedCheck);
|
57
58
|
this._resizeObserver.observe(this);
|
58
59
|
}
|
59
60
|
|
60
61
|
disconnectedCallback() {
|
61
62
|
super.disconnectedCallback();
|
62
|
-
this.removeEventListener('d2l-empty-state-illustrated-check', this
|
63
|
+
this.removeEventListener('d2l-empty-state-illustrated-check', this.#handleEmptyStateIllustratedCheck);
|
63
64
|
this._resizeObserver.disconnect();
|
64
65
|
}
|
65
66
|
|
66
67
|
render() {
|
67
|
-
const
|
68
|
-
|
68
|
+
const titleClass = {
|
69
|
+
'd2l-empty-state-title': true,
|
70
|
+
'd2l-empty-state-title-small': this._titleSmall,
|
71
|
+
'd2l-empty-state-title-large': !this._titleSmall,
|
72
|
+
};
|
69
73
|
|
70
74
|
return html`
|
71
|
-
${this
|
72
|
-
? html`
|
73
|
-
<div style="${styleMap(illustrationContainerStyle)}">
|
74
|
-
${runAsync(this.illustrationName, () => this._getIllustration(this.illustrationName), { success: (illustration) => illustration }, { pendingState: false })}
|
75
|
-
</div>`
|
76
|
-
: html`<slot class="illustration-slot" name="illustration"></slot>`}
|
77
|
-
|
75
|
+
${this.#renderIllustration()}
|
78
76
|
<p class="${classMap(titleClass)}">${this.titleText}</p>
|
79
77
|
<p class="d2l-body-compact d2l-empty-state-description">${this.description}</p>
|
80
78
|
<slot class="action-slot"></slot>
|
81
79
|
`;
|
82
80
|
}
|
83
81
|
|
84
|
-
|
82
|
+
_onResize(entries) {
|
83
|
+
if (!entries || entries.length === 0) return;
|
84
|
+
const entry = entries[0];
|
85
|
+
requestAnimationFrame(() => {
|
86
|
+
this._contentHeight = Math.min(entry.contentRect.right / illustrationAspectRatio, 330);
|
87
|
+
this._titleSmall = entry.contentRect.right <= 615;
|
88
|
+
});
|
89
|
+
}
|
90
|
+
|
91
|
+
async #getIllustration(illustrationName) {
|
85
92
|
if (!illustrationName) return;
|
86
93
|
|
87
94
|
const svg = await loadSvg(illustrationName);
|
@@ -91,32 +98,31 @@ class EmptyStateIllustrated extends PropertyRequiredMixin(LitElement) {
|
|
91
98
|
return svg ? html`${unsafeSVG(svg.val)}` : nothing;
|
92
99
|
}
|
93
100
|
|
94
|
-
|
95
|
-
return {
|
96
|
-
height: `${this._contentHeight}px`,
|
97
|
-
};
|
98
|
-
}
|
99
|
-
|
100
|
-
_getTitleClass() {
|
101
|
-
return {
|
102
|
-
'd2l-empty-state-title': true,
|
103
|
-
'd2l-empty-state-title-small': this._titleSmall,
|
104
|
-
'd2l-empty-state-title-large': !this._titleSmall,
|
105
|
-
};
|
106
|
-
}
|
107
|
-
|
108
|
-
_handleEmptyStateIllustratedCheck(e) {
|
101
|
+
#handleEmptyStateIllustratedCheck(e) {
|
109
102
|
e.stopPropagation();
|
110
103
|
e.detail.illustrated = true;
|
111
104
|
}
|
112
105
|
|
113
|
-
|
114
|
-
if (!
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
106
|
+
#renderIllustration() {
|
107
|
+
if (!this.illustrationName) {
|
108
|
+
this.resolveLoadingComplete();
|
109
|
+
return html`<slot class="illustration-slot" name="illustration"></slot>`;
|
110
|
+
}
|
111
|
+
const illustrationContainerStyle = {
|
112
|
+
height: `${this._contentHeight}px`,
|
113
|
+
};
|
114
|
+
const asyncVal = runAsync(
|
115
|
+
this.illustrationName,
|
116
|
+
() => this.#getIllustration(this.illustrationName),
|
117
|
+
{
|
118
|
+
success: illustration => {
|
119
|
+
this.resolveLoadingComplete();
|
120
|
+
return illustration;
|
121
|
+
}
|
122
|
+
},
|
123
|
+
{ pendingState: false }
|
124
|
+
);
|
125
|
+
return html`<div style="${styleMap(illustrationContainerStyle)}">${asyncVal}</div>`;
|
120
126
|
}
|
121
127
|
|
122
128
|
}
|
package/custom-elements.json
CHANGED
@@ -3742,6 +3742,14 @@
|
|
3742
3742
|
"attribute": "title-text",
|
3743
3743
|
"description": "REQUIRED: A title for the empty state",
|
3744
3744
|
"type": "string"
|
3745
|
+
},
|
3746
|
+
{
|
3747
|
+
"name": "loadingComplete",
|
3748
|
+
"type": "Promise<any>"
|
3749
|
+
},
|
3750
|
+
{
|
3751
|
+
"name": "resolveLoadingComplete",
|
3752
|
+
"type": "() => void"
|
3745
3753
|
}
|
3746
3754
|
],
|
3747
3755
|
"slots": [
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@brightspace-ui/core",
|
3
|
-
"version": "3.79.
|
3
|
+
"version": "3.79.1",
|
4
4
|
"description": "A collection of accessible, free, open-source web components for building Brightspace applications",
|
5
5
|
"type": "module",
|
6
6
|
"repository": "https://github.com/BrightspaceUI/core.git",
|