@brightspace-ui/core 2.36.1 → 2.37.2

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 (35) hide show
  1. package/components/empty-state/README.md +68 -28
  2. package/components/empty-state/demo/empty-state.html +34 -12
  3. package/components/empty-state/empty-state-action-button.js +100 -0
  4. package/components/empty-state/empty-state-action-link.js +73 -0
  5. package/components/empty-state/{empty-state-illustrated-mixin.js → empty-state-illustrated.js} +43 -16
  6. package/components/empty-state/{empty-state-simple-button.js → empty-state-simple.js} +7 -28
  7. package/components/empty-state/empty-state-styles.js +19 -18
  8. package/components/menu/menu-item-mixin.js +1 -3
  9. package/components/menu/menu-item-styles.js +23 -4
  10. package/components/menu/menu.js +1 -2
  11. package/components/paging/pager-load-more.js +3 -2
  12. package/components/typography/styles.js +60 -33
  13. package/custom-elements.json +56 -132
  14. package/lang/ar.js +1 -1
  15. package/lang/cy.js +1 -1
  16. package/lang/da.js +1 -1
  17. package/lang/de.js +1 -1
  18. package/lang/en.js +1 -1
  19. package/lang/es-es.js +1 -1
  20. package/lang/es.js +1 -1
  21. package/lang/fr-fr.js +1 -1
  22. package/lang/fr.js +1 -1
  23. package/lang/hi.js +1 -1
  24. package/lang/ja.js +1 -1
  25. package/lang/ko.js +1 -1
  26. package/lang/nl.js +1 -1
  27. package/lang/pt.js +1 -1
  28. package/lang/sv.js +1 -1
  29. package/lang/tr.js +1 -1
  30. package/lang/zh-cn.js +1 -1
  31. package/lang/zh-tw.js +1 -1
  32. package/package.json +1 -1
  33. package/components/empty-state/empty-state-illustrated-button.js +0 -71
  34. package/components/empty-state/empty-state-illustrated-link.js +0 -57
  35. package/components/empty-state/empty-state-simple-link.js +0 -74
@@ -1,26 +1,31 @@
1
1
  # Empty State
2
+
2
3
  Empty state components are used to convey that there is no data available to be displayed, or that a search or filter has returned no results.
3
4
 
4
5
  <!-- docs: demo align:start -->
5
6
  ```html
6
7
  <script type="module">
7
- import '@brightspace-ui/core/components/empty-state/empty-state-simple-button.js';
8
- import '@brightspace-ui/core/components/empty-state/empty-state-illustrated-button.js';
8
+ import '@brightspace-ui/core/components/empty-state/empty-state-action-link.js';
9
+ import '@brightspace-ui/core/components/empty-state/empty-state-illustrated.js';
10
+ import '@brightspace-ui/core/components/empty-state/empty-state-simple.js';
9
11
  </script>
10
12
  <style>
11
13
  body {
12
14
  overflow-y: scroll;
13
15
  }
14
- d2l-empty-state-illustrated-button,
15
- d2l-empty-state-simple-button {
16
+ d2l-empty-state-illustrated,
17
+ d2l-empty-state-simple {
16
18
  max-width: 500px;
17
19
  width: 100%;
18
20
  }
19
21
  </style>
20
22
 
21
- <d2l-empty-state-simple-button description="There are no assignments to display." action-text="Create an Assignment"></d2l-empty-state-simple-button>
22
- <d2l-empty-state-illustrated-button illustration-name="desert-road" title-text="No Learning Paths Yet" description="Get started by clicking below to create your first learning path." action-text="Create Learning Paths"> </d2l-empty-state-illustrated-button>
23
-
23
+ <d2l-empty-state-simple description="There are no assignments to display.">
24
+ <d2l-empty-state-action-link text="Create an Assignment" href="#"></d2l-empty-state-action-link>
25
+ </d2l-empty-state-simple>
26
+ <d2l-empty-state-illustrated illustration-name="desert-road" title-text="No Learning Paths Yet" description="Get started by clicking below to create your first learning path.">
27
+ <d2l-empty-state-action-link text="Create Learning Paths" href="#"></d2l-empty-state-action-link>
28
+ </d2l-empty-state-illustrated>
24
29
  ```
25
30
 
26
31
  ## Best Practices
@@ -40,67 +45,102 @@ Empty state components are used to convey that there is no data available to be
40
45
  <!-- docs: end donts -->
41
46
  <!-- docs: end best practices -->
42
47
 
43
- ## Empty State Simple Button [d2l-empty-state-simple-button]
48
+ ## Empty State Simple [d2l-empty-state-simple]
44
49
 
45
- The `d2l-empty-state-simple-button` component is an empty state component that displays a description and action button.
50
+ The `d2l-empty-state-simple` component is an empty state component that displays a description. An [empty state action component](#d2l-empty-state-action-button) can be placed inside of the default slot to add an optional action.
46
51
 
47
- <!-- docs: demo live name:d2l-empty-state-simple-button -->
52
+ <!-- docs: demo live name:d2l-empty-state-simple -->
48
53
  ```html
49
54
  <script type="module">
50
- import '@brightspace-ui/core/components/empty-state/empty-state-simple-button.js';
55
+ import '@brightspace-ui/core/components/empty-state/empty-state-simple.js';
51
56
  </script>
52
57
 
53
- <d2l-empty-state-simple-button description="There are no assignments to display." action-text="Create an Assignment"></d2l-empty-state-simple-button>
58
+ <d2l-empty-state-simple description="There are no assignments to display."></d2l-empty-state-simple>
54
59
  ```
55
60
 
56
- ## Empty State Simple Link [d2l-empty-state-simple-link]
61
+ ## Empty State Illustrated [d2l-empty-state-illustrated]
62
+
63
+ The `d2l-empty-state-illustrated` component is an empty state component that displays a title and description with an illustration. An [empty state action component](#d2l-empty-state-action-button) can be placed inside of the default slot to add an optional action.
57
64
 
58
- The `d2l-empty-state-simple-link` component is an empty state component that displays a description and action link.
65
+ The `illustration-name` property can be set to use one of the preset illustrations or a custom SVG illustration can be added in the `illustration` slot. The catalogue of preset empty state illustrations can be found [here](#preset-empty-state-illustrations).
59
66
 
60
- <!-- docs: demo live name:d2l-empty-state-simple-link -->
67
+ <!-- docs: demo live name:d2l-empty-state-illustrated -->
61
68
  ```html
62
69
  <script type="module">
63
- import '@brightspace-ui/core/components/empty-state/empty-state-simple-link.js';
70
+ import '@brightspace-ui/core/components/empty-state/empty-state-illustrated.js';
64
71
  </script>
65
-
66
- <d2l-empty-state-simple-link description="There are no assignments to display." action-text="Create an Assignment" action-href='https://d2l.com'></d2l-empty-state-simple-link>
72
+ <!-- docs: start hidden content -->
73
+ <style>
74
+ body {
75
+ overflow-y: scroll;
76
+ }
77
+ </style>
78
+ <!-- docs: end hidden content -->
79
+ <d2l-empty-state-illustrated illustration-name="desert-road" title-text="No Learning Paths Yet" description="Get started by clicking below to create your first learning path."></d2l-empty-state-illustrated>
67
80
  ```
68
- ## Empty State Illustrated Button [d2l-empty-state-illustrated-button]
69
81
 
70
- The `d2l-empty-state-illustrated-button` component is an empty state component that displays a title and description with an illustration and action button. The `illustration-name` property can be set to use one of the preset illustrations or a custom SVG illustration can be added in the default slot.
82
+ ## Empty State Action Button [d2l-empty-state-action-button]
83
+
84
+ `d2l-empty-state-action-button` is an empty state action component that can be placed inside of the default slot of `empty-state-simple` or `empty-state-illustrated` to add a button action to the component. Only a single action can be placed within an empty state component.
85
+
86
+ The `primary` attribute can be set to render a primary button in place of the default subtle button. Note that the `primary` attribute is only valid when placed within `empty-state-illustrated` components and will have no effect on `empty-state-simple`.
71
87
 
72
- <!-- docs: demo live name:d2l-empty-state-illustrated-button -->
88
+ <!-- docs: demo live name:d2l-empty-state-action-button -->
73
89
  ```html
74
90
  <script type="module">
75
- import '@brightspace-ui/core/components/empty-state/empty-state-illustrated-button.js';
91
+ import '@brightspace-ui/core/components/empty-state/empty-state-action-button.js';
92
+ import '@brightspace-ui/core/components/empty-state/empty-state-illustrated.js';
93
+ import '@brightspace-ui/core/components/empty-state/empty-state-simple.js';
76
94
  </script>
77
95
  <!-- docs: start hidden content -->
78
96
  <style>
79
97
  body {
80
98
  overflow-y: scroll;
81
99
  }
100
+ d2l-empty-state-illustrated,
101
+ d2l-empty-state-simple {
102
+ max-width: 500px;
103
+ width: 100%;
104
+ }
82
105
  </style>
83
106
  <!-- docs: end hidden content -->
84
- <d2l-empty-state-illustrated-button illustration-name="desert-road" title-text="No Learning Paths Yet" description="Get started by clicking below to create your first learning path." action-text="Create Learning Paths"></d2l-empty-state-illustrated-button>
107
+ <d2l-empty-state-simple description="There are no assignments to display.">
108
+ <d2l-empty-state-action-button text="Create an Assignment"></d2l-empty-state-action-button>
109
+ </d2l-empty-state-simple>
110
+ <d2l-empty-state-illustrated illustration-name="desert-road" title-text="No Learning Paths Yet" description="Get started by clicking below to create your first learning path.">
111
+ <d2l-empty-state-action-button text="Create Learning Paths"></d2l-empty-state-action-button>
112
+ </d2l-empty-state-illustrated>
85
113
  ```
86
114
 
87
- ## Empty State Illustrated Link [d2l-empty-state-illustrated-link]
115
+ ## Empty State Action Link [d2l-empty-state-action-link]
88
116
 
89
- The `d2l-empty-state-illustrated-link` component is an empty state component that displays a title and description with an illustration and action link. The `illustration-name` property can be set to use one of the preset illustrations or a custom SVG illustration can be added in the default slot.
117
+ `d2l-empty-state-action-link` is an empty state action component that can be placed inside of the default slot of `empty-state-simple` or `empty-state-illustrated` to add a link action to the component. Only a single action can be placed within an empty state component.
90
118
 
91
- <!-- docs: demo live name:d2l-empty-state-illustrated-link -->
119
+ <!-- docs: demo live name:d2l-empty-state-action-link -->
92
120
  ```html
93
121
  <script type="module">
94
- import '@brightspace-ui/core/components/empty-state/empty-state-illustrated-link.js';
122
+ import '@brightspace-ui/core/components/empty-state/empty-state-action-link.js';
123
+ import '@brightspace-ui/core/components/empty-state/empty-state-illustrated.js';
124
+ import '@brightspace-ui/core/components/empty-state/empty-state-simple.js';
95
125
  </script>
96
126
  <!-- docs: start hidden content -->
97
127
  <style>
98
128
  body {
99
129
  overflow-y: scroll;
100
130
  }
131
+ d2l-empty-state-illustrated,
132
+ d2l-empty-state-simple {
133
+ max-width: 500px;
134
+ width: 100%;
135
+ }
101
136
  </style>
102
137
  <!-- docs: end hidden content -->
103
- <d2l-empty-state-illustrated-link illustration-name="desert-road" title-text="No Learning Paths Yet" description="Get started by clicking below to create your first learning path." action-text="Create Learning Paths" action-href='https://d2l.com'></d2l-empty-state-illustrated-link>
138
+ <d2l-empty-state-simple description="There are no assignments to display.">
139
+ <d2l-empty-state-action-link text="Create an Assignment" href="#"></d2l-empty-state-action-link>
140
+ </d2l-empty-state-simple>
141
+ <d2l-empty-state-illustrated illustration-name="desert-road" title-text="No Learning Paths Yet" description="Get started by clicking below to create your first learning path.">
142
+ <d2l-empty-state-action-link text="Create Learning Paths" href="#"></d2l-empty-state-action-link>
143
+ </d2l-empty-state-illustrated>
104
144
  ```
105
145
 
106
146
  ## Preset Empty State Illustrations
@@ -5,46 +5,68 @@
5
5
  <meta charset="UTF-8">
6
6
  <link rel="stylesheet" href="../../demo/styles.css" type="text/css">
7
7
  <script type="module">
8
+ import '../empty-state-action-button.js';
9
+ import '../empty-state-action-link.js';
10
+ import '../empty-state-illustrated.js';
11
+ import '../empty-state-simple.js';
8
12
  import '../../demo/demo-page.js';
9
- import '../empty-state-simple-button.js';
10
- import '../empty-state-simple-link.js';
11
- import '../empty-state-illustrated-button.js';
12
- import '../empty-state-illustrated-link.js';
13
13
  </script>
14
14
  </head>
15
15
  <body unresolved>
16
16
 
17
17
  <d2l-demo-page page-title="d2l-empty-state">
18
18
 
19
- <h2>Empty State Simple Button</h2>
19
+ <h2>Empty State Simple</h2>
20
20
 
21
+ <h5>No Action</h5>
21
22
  <d2l-demo-snippet>
22
23
  <template>
23
- <d2l-empty-state-simple-button description="There are no assignments to display." action-text="Create New Assignment"></d2l-empty-state-simple-button>
24
+ <d2l-empty-state-simple description="There are no assignments to display."></d2l-empty-state-simple>
24
25
  </template>
25
26
  </d2l-demo-snippet>
26
27
 
27
- <h2>Empty State Simple Link</h2>
28
+ <h5>Empty State Action Button</h5>
29
+ <d2l-demo-snippet>
30
+ <template>
31
+ <d2l-empty-state-simple description="There are no assignments to display.">
32
+ <d2l-empty-state-action-button text="Create New Assignment"></d2l-empty-state-action-button>
33
+ </d2l-empty-state-simple>
34
+ </template>
35
+ </d2l-demo-snippet>
28
36
 
37
+ <h5>Empty State Action Link</h5>
29
38
  <d2l-demo-snippet>
30
39
  <template>
31
- <d2l-empty-state-simple-link description="There are no assignments to display." action-text="Create New Assignment" action-href="https://www.d2l.com/"></d2l-empty-state-simple-link>
40
+ <d2l-empty-state-simple description="There are no assignments to display.">
41
+ <d2l-empty-state-action-link text="Create New Assignment" href="https://d2l.com"></d2l-empty-state-action-link>
42
+ </d2l-empty-state-simple>
32
43
  </template>
33
44
  </d2l-demo-snippet>
34
45
 
35
- <h2>Empty State Illustrated Button</h2>
46
+ <h2>Empty State Illustrated</h2>
36
47
 
48
+ <h5>No Action</h5>
37
49
  <d2l-demo-snippet>
38
50
  <template>
39
- <d2l-empty-state-illustrated-button illustration-name="fish-hook" title-text="No Learning Paths Yet" description="Get started by clicking below to create your first learning path." action-text="Create Learning Paths"></d2l-empty-state-illustrated-button>
51
+ <d2l-empty-state-illustrated illustration-name="fish-hook" title-text="No Learning Paths Yet" description="Get started by clicking below to create your first learning path."></d2l-empty-state-illustrated>
40
52
  </template>
41
53
  </d2l-demo-snippet>
42
54
 
43
- <h2>Empty State Illustrated Link</h2>
55
+ <h5>Empty State Action Button</h5>
56
+ <d2l-demo-snippet>
57
+ <template>
58
+ <d2l-empty-state-illustrated illustration-name="fish-hook" title-text="No Learning Paths Yet" description="Get started by clicking below to create your first learning path.">
59
+ <d2l-empty-state-action-button text="Create Learning Paths" primary></d2l-empty-state-action-button>
60
+ </d2l-empty-state-illustrated>
61
+ </template>
62
+ </d2l-demo-snippet>
44
63
 
64
+ <h5>Empty State Action Link</h5>
45
65
  <d2l-demo-snippet>
46
66
  <template>
47
- <d2l-empty-state-illustrated-link illustration-name="desert-road" title-text="No Learning Paths Yet" description="Get started by clicking below to create your first learning path." action-text="Create Learning Paths" action-href="https://www.d2l.com/"></d2l-empty-state-illustrated-link>
67
+ <d2l-empty-state-illustrated illustration-name="fish-hook" title-text="No Learning Paths Yet" description="Get started by clicking below to create your first learning path.">
68
+ <d2l-empty-state-action-link text="Create Learning Paths" href="https://d2l.com"></d2l-empty-state-action-link>
69
+ </d2l-empty-state-illustrated>
48
70
  </template>
49
71
  </d2l-demo-snippet>
50
72
 
@@ -0,0 +1,100 @@
1
+ import '../button/button.js';
2
+ import '../button/button-subtle.js';
3
+ import { css, html, LitElement, nothing } from 'lit';
4
+
5
+ /**
6
+ * `d2l-empty-state-action-button` is an empty state action component that can be placed inside of the default slot of `empty-state-simple` or `empty-state-illustrated` to add a button action to the component.
7
+ * @fires d2l-empty-state-action - Dispatched when the action button is clicked
8
+ */
9
+ class EmptyStateActionButton extends LitElement {
10
+
11
+ static get properties() {
12
+ return {
13
+ /**
14
+ * REQUIRED: The action text to be used in the button
15
+ * @type {string}
16
+ */
17
+ text: { type: String },
18
+ /**
19
+ * This will change the action button to use a primary button instead of the default subtle button. The primary attribute is only valid when `d2l-empty-state-action-button` is placed within `d2l-empty-state-illustrated` components
20
+ * @type {boolean}
21
+ */
22
+ primary: { type: Boolean },
23
+ _illustrated: { state: true }
24
+ };
25
+ }
26
+
27
+ static get styles() {
28
+ return css`
29
+ .d2l-empty-state-action {
30
+ vertical-align: top;
31
+ }
32
+ `;
33
+ }
34
+
35
+ constructor() {
36
+ super();
37
+ this._illustrated = false;
38
+ this._missingTextErrorHasBeenThrown = false;
39
+ this._validatingTextTimeout = null;
40
+ }
41
+
42
+ connectedCallback() {
43
+ super.connectedCallback();
44
+ requestAnimationFrame(() => {
45
+ const e = new CustomEvent('d2l-empty-state-illustrated-check', {
46
+ bubbles: true,
47
+ detail: {}
48
+ });
49
+ this.dispatchEvent(e);
50
+ this._illustrated = e.detail.illustrated | false;
51
+ });
52
+ }
53
+
54
+ firstUpdated(changedProperties) {
55
+ super.firstUpdated(changedProperties);
56
+ this._validateText();
57
+ }
58
+
59
+ render() {
60
+ let actionButton = nothing;
61
+ if (this.text) {
62
+ actionButton = this._illustrated && this.primary
63
+ ? html`<d2l-button
64
+ class="d2l-empty-state-action"
65
+ @click=${this._handleActionClick}
66
+ primary>
67
+ ${this.text}
68
+ </d2l-button>`
69
+ : html`<d2l-button-subtle
70
+ class="d2l-empty-state-action"
71
+ @click=${this._handleActionClick}
72
+ ?slim=${!this._illustrated}
73
+ text=${this.text}>
74
+ </d2l-button-subtle>`;
75
+ }
76
+ return html`${actionButton}`;
77
+ }
78
+
79
+ _handleActionClick(e) {
80
+ e.stopPropagation();
81
+ this.dispatchEvent(new CustomEvent('d2l-empty-state-action'));
82
+ }
83
+
84
+ _validateText() {
85
+ clearTimeout(this._validatingTextTimeout);
86
+ // don't error immediately in case it doesn't get set immediately
87
+ this._validatingTextTimeout = setTimeout(() => {
88
+ this._validatingTextTimeout = null;
89
+ const hasText = (typeof this.text === 'string') && this.text.length > 0;
90
+
91
+ if (!hasText && !this._missingTextErrorHasBeenThrown) {
92
+ this._missingTextErrorHasBeenThrown = true;
93
+ setTimeout(() => { throw new Error('<d2l-empty-state-action-button>: missing required "text" attribute.'); });
94
+ }
95
+ }, 3000);
96
+ }
97
+
98
+ }
99
+
100
+ customElements.define('d2l-empty-state-action-button', EmptyStateActionButton);
@@ -0,0 +1,73 @@
1
+ import { html, LitElement, nothing } from 'lit';
2
+ import { bodyCompactStyles } from '../typography/styles.js';
3
+ import { linkStyles } from '../link/link.js';
4
+
5
+ /**
6
+ * `d2l-empty-state-action-link` is an empty state action component that can be placed inside of the default slot of `empty-state-simple` or `empty-state-illustrated` to add a link action to the component.
7
+ */
8
+ class EmptyStateActionLink extends LitElement {
9
+
10
+ static get properties() {
11
+ return {
12
+ /**
13
+ * REQUIRED: The action text to be used in the subtle button
14
+ * @type {string}
15
+ */
16
+ text: { type: String },
17
+ /**
18
+ * REQUIRED: The action URL or URL fragment of the link
19
+ * @type {string}
20
+ */
21
+ href: { type: String },
22
+ };
23
+ }
24
+
25
+ static get styles() {
26
+ return [bodyCompactStyles, linkStyles];
27
+ }
28
+
29
+ constructor() {
30
+ super();
31
+ this._missingHrefErrorHasBeenThrown = false;
32
+ this._missingTextErrorHasBeenThrown = false;
33
+ this._validatingAttributesTimeout = null;
34
+ }
35
+
36
+ firstUpdated(changedProperties) {
37
+ super.firstUpdated(changedProperties);
38
+ this._validateAttributes();
39
+ }
40
+
41
+ render() {
42
+ const actionLink = this.text && this.href
43
+ ? html`
44
+ <a class="d2l-body-compact d2l-link" href=${this.href}>${this.text}</a>`
45
+ : nothing;
46
+
47
+ return html`${actionLink}`;
48
+ }
49
+
50
+ _validateAttributes() {
51
+ clearTimeout(this._validatingAttributesTimeout);
52
+ // don't error immediately in case it doesn't get set immediately
53
+ this._validatingAttributesTimeout = setTimeout(() => {
54
+ this._validatingAttributesTimeout = null;
55
+
56
+ const hasHref = (typeof this.href === 'string') && this.href.length > 0;
57
+ const hasText = (typeof this.text === 'string') && this.text.length > 0;
58
+
59
+ if (!hasHref && !this._missingHrefErrorHasBeenThrown) {
60
+ this._missingHrefErrorHasBeenThrown = true;
61
+ setTimeout(() => { throw new Error('<d2l-empty-state-action-link>: missing required "href" attribute.'); });
62
+ }
63
+
64
+ if (!hasText && !this._missingTextErrorHasBeenThrown) {
65
+ this._missingTextErrorHasBeenThrown = true;
66
+ setTimeout(() => { throw new Error('<d2l-empty-state-action-link>: missing required "text" attribute.'); });
67
+ }
68
+ }, 3000);
69
+ }
70
+
71
+ }
72
+
73
+ customElements.define('d2l-empty-state-action-link', EmptyStateActionLink);
@@ -1,22 +1,24 @@
1
1
  import { emptyStateIllustratedStyles, emptyStateStyles } from './empty-state-styles.js';
2
- import { html, nothing } from 'lit';
2
+ import { html, LitElement, nothing } from 'lit';
3
3
  import { bodyCompactStyles } from '../typography/styles.js';
4
+ import { classMap } from 'lit/directives/class-map.js';
4
5
  import { loadSvg } from '../../generated/empty-state/presetIllustrationLoader.js';
5
6
  import ResizeObserver from 'resize-observer-polyfill/dist/ResizeObserver.es.js';
6
- import { RtlMixin } from '../../mixins/rtl-mixin.js';
7
+ import { runAsync } from '../../directives/run-async/run-async.js';
8
+ import { styleMap } from 'lit/directives/style-map.js';
7
9
  import { unsafeSVG } from 'lit/directives/unsafe-svg.js';
8
10
 
9
11
  const illustrationAspectRatio = 500 / 330;
10
12
 
11
- export const EmptyStateIllustratedMixin = superclass => class extends RtlMixin(superclass) {
13
+ /**
14
+ * The `d2l-empty-state-illustrated` component is an empty state component that displays a title and description with an illustration. An empty state action component can be placed inside of the default slot to add an optional action.
15
+ * @slot - Slot for empty state actions
16
+ * @slot illustration - Slot for custom SVG content if `illustration-name` property is not set
17
+ */
18
+ class EmptyStateIllustrated extends LitElement {
12
19
 
13
20
  static get properties() {
14
21
  return {
15
- /**
16
- * The action text to be used in the subtle button
17
- * @type {string}
18
- */
19
- actionText: { type: String, attribute: 'action-text' },
20
22
  /**
21
23
  * REQUIRED: A description giving details about the empty state
22
24
  * @type {string}
@@ -33,7 +35,6 @@ export const EmptyStateIllustratedMixin = superclass => class extends RtlMixin(s
33
35
  */
34
36
  titleText: { type: String, attribute: 'title-text' },
35
37
  _contentHeight: { state: true },
36
- _illustratedComponentType: { state: true },
37
38
  _titleSmall: { state: true }
38
39
  };
39
40
  }
@@ -44,7 +45,6 @@ export const EmptyStateIllustratedMixin = superclass => class extends RtlMixin(s
44
45
 
45
46
  constructor() {
46
47
  super();
47
-
48
48
  this._contentHeight = 330;
49
49
  this._missingDescriptionErrorHasBeenThrown = false;
50
50
  this._missingTitleTextErrorHasBeenThrown = false;
@@ -55,11 +55,13 @@ export const EmptyStateIllustratedMixin = superclass => class extends RtlMixin(s
55
55
 
56
56
  connectedCallback() {
57
57
  super.connectedCallback();
58
+ this.addEventListener('d2l-empty-state-illustrated-check', this._handleEmptyStateIllustratedCheck);
58
59
  this._resizeObserver.observe(this);
59
60
  }
60
61
 
61
62
  disconnectedCallback() {
62
63
  super.disconnectedCallback();
64
+ this.removeEventListener('d2l-empty-state-illustrated-check', this._handleEmptyStateIllustratedCheck);
63
65
  this._resizeObserver.disconnect();
64
66
  }
65
67
 
@@ -68,7 +70,25 @@ export const EmptyStateIllustratedMixin = superclass => class extends RtlMixin(s
68
70
  this._validateAttributes();
69
71
  }
70
72
 
71
- async getIllustration(illustrationName) {
73
+ render() {
74
+ const illustrationContainerStyle = this._getIllustrationContainerStyle();
75
+ const titleClass = this._getTitleClass();
76
+
77
+ return html`
78
+ ${this.illustrationName
79
+ ? html`
80
+ <div style="${styleMap(illustrationContainerStyle)}">
81
+ ${runAsync(this.illustrationName, () => this._getIllustration(this.illustrationName), { success: (illustration) => illustration }, { pendingState: false })}
82
+ </div>`
83
+ : html`<slot class="illustration-slot" name="illustration"></slot>`}
84
+
85
+ <p class="${classMap(titleClass)}">${this.titleText}</p>
86
+ <p class="d2l-body-compact d2l-empty-state-description">${this.description}</p>
87
+ <slot class="action-slot"></slot>
88
+ `;
89
+ }
90
+
91
+ async _getIllustration(illustrationName) {
72
92
  if (!illustrationName) return;
73
93
 
74
94
  const svg = await loadSvg(illustrationName);
@@ -78,13 +98,13 @@ export const EmptyStateIllustratedMixin = superclass => class extends RtlMixin(s
78
98
  return svg ? html`${unsafeSVG(svg.val)}` : nothing;
79
99
  }
80
100
 
81
- getIllustrationContainerStyle() {
101
+ _getIllustrationContainerStyle() {
82
102
  return {
83
103
  height: `${this._contentHeight}px`,
84
104
  };
85
105
  }
86
106
 
87
- getTitleClass() {
107
+ _getTitleClass() {
88
108
  return {
89
109
  'd2l-empty-state-title': true,
90
110
  'd2l-empty-state-title-small': this._titleSmall,
@@ -92,6 +112,11 @@ export const EmptyStateIllustratedMixin = superclass => class extends RtlMixin(s
92
112
  };
93
113
  }
94
114
 
115
+ _handleEmptyStateIllustratedCheck(e) {
116
+ e.stopPropagation();
117
+ e.detail.illustrated = true;
118
+ }
119
+
95
120
  _onResize(entries) {
96
121
  if (!entries || entries.length === 0) return;
97
122
  const entry = entries[0];
@@ -110,17 +135,19 @@ export const EmptyStateIllustratedMixin = superclass => class extends RtlMixin(s
110
135
  if (!hasTitleText && !this._missingTitleTextErrorHasBeenThrown) {
111
136
  this._missingTitleTextErrorHasBeenThrown = true;
112
137
  setTimeout(() => {
113
- throw new Error(`<d2l-empty-state-illustrated-${this._illustratedComponentType}>: missing required "titleText" attribute.`);
138
+ throw new Error('<d2l-empty-state-illustrated>: missing required "titleText" attribute.');
114
139
  });
115
140
  }
116
141
 
117
142
  if (!hasDescription && !this._missingDescriptionErrorHasBeenThrown) {
118
143
  this._missingDescriptionErrorHasBeenThrown = true;
119
144
  setTimeout(() => {
120
- throw new Error(`<d2l-empty-state-illustrated-${this._illustratedComponentType}>: missing required "description" attribute.`);
145
+ throw new Error('<d2l-empty-state-illustrated>: missing required "description" attribute.');
121
146
  });
122
147
  }
123
148
  }, 3000);
124
149
  }
125
150
 
126
- };
151
+ }
152
+
153
+ customElements.define('d2l-empty-state-illustrated', EmptyStateIllustrated);
@@ -1,22 +1,17 @@
1
1
  import '../button/button-subtle.js';
2
2
  import { emptyStateSimpleStyles, emptyStateStyles } from './empty-state-styles.js';
3
- import { html, LitElement, nothing } from 'lit';
3
+ import { html, LitElement } from 'lit';
4
4
  import { bodyCompactStyles } from '../typography/styles.js';
5
5
  import { RtlMixin } from '../../mixins/rtl-mixin.js';
6
6
 
7
7
  /**
8
- * The `d2l-empty-state-simple-button` component is an empty state component that displays a description and action button.
9
- * @fires d2l-empty-state-action - Dispatched when the action button is clicked
8
+ * The `d2l-empty-state-simple` component is an empty state component that displays a description. An empty state action component can be placed inside of the default slot to add an optional action.
9
+ * @slot - Slot for empty state actions
10
10
  */
11
- class EmptyStateSimpleButton extends RtlMixin(LitElement) {
11
+ class EmptyStateSimple extends RtlMixin(LitElement) {
12
12
 
13
13
  static get properties() {
14
14
  return {
15
- /**
16
- * The action text to be used in the subtle button
17
- * @type {string}
18
- */
19
- actionText: { type: String, attribute: 'action-text' },
20
15
  /**
21
16
  * REQUIRED: A description giving details about the empty state
22
17
  * @type {string}
@@ -41,28 +36,12 @@ class EmptyStateSimpleButton extends RtlMixin(LitElement) {
41
36
  }
42
37
 
43
38
  render() {
44
- const actionButton = this.actionText
45
- ? html`
46
- <d2l-button-subtle
47
- class="d2l-empty-state-action"
48
- @click=${this._handleActionClick}
49
- h-align="text"
50
- text=${this.actionText}
51
- slim>
52
- </d2l-button-subtle>`
53
- : nothing;
54
-
55
39
  return html`
56
40
  <p class="d2l-body-compact d2l-empty-state-description">${this.description}</p>
57
- ${actionButton}
41
+ <slot class="action-slot"></slot>
58
42
  `;
59
43
  }
60
44
 
61
- _handleActionClick(e) {
62
- e.stopPropagation();
63
- this.dispatchEvent(new CustomEvent('d2l-empty-state-action'));
64
- }
65
-
66
45
  _validateDescription() {
67
46
  clearTimeout(this._validatingDescriptionTimeout);
68
47
  // don't error immediately in case it doesn't get set immediately
@@ -72,11 +51,11 @@ class EmptyStateSimpleButton extends RtlMixin(LitElement) {
72
51
 
73
52
  if (!hasDescription && !this._missingDescriptionErrorHasBeenThrown) {
74
53
  this._missingDescriptionErrorHasBeenThrown = true;
75
- setTimeout(() => { throw new Error('<d2l-empty-state-simple-button>: missing required "description" attribute.'); });
54
+ setTimeout(() => { throw new Error('<d2l-empty-state-simple>: missing required "description" attribute.'); });
76
55
  }
77
56
  }, 3000);
78
57
  }
79
58
 
80
59
  }
81
60
 
82
- customElements.define('d2l-empty-state-simple-button', EmptyStateSimpleButton);
61
+ customElements.define('d2l-empty-state-simple', EmptyStateSimple);