@brightspace-ui/core 2.177.1 → 2.177.3

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.
@@ -163,6 +163,99 @@ The `d2l-list` is the container to create a styled list of items using `d2l-list
163
163
  - Image: max dimensions: `width: 216px` and `height: 120px` and has `20px margin` from the main content;
164
164
  - default break: `843px < x` where `x` is the width of the component.
165
165
 
166
+ ### add-button Property
167
+
168
+ The `add-button` attribute inserts the `d2l-button-add` component above and below each item in a list. Each nested list that wants to have this functionality will need to have this attribute on the nested `d2l-list` as well. Each list item needs to have its own `key` in order to communicate where a new item should be positioned.
169
+
170
+ Adding new items to the list is handled entirely by consumers by listening for the `d2l-list-add-button-click` event. A simple example scenario is below.
171
+
172
+ <!-- docs: demo code display:block -->
173
+ ```html
174
+ <script type="module">
175
+ import '@brightspace-ui/core/components/list/list.js';
176
+ import '@brightspace-ui/core/components/list/list-controls.js';
177
+ import '@brightspace-ui/core/components/list/list-item.js';
178
+ import '@brightspace-ui/core/components/list/list-item-content.js';
179
+ import '@brightspace-ui/core/components/selection/selection-action.js';
180
+ import { css, html, LitElement } from 'lit';
181
+ import { getUniqueId } from '@brightspace-ui/core/helpers/uniqueId.js';
182
+
183
+ class ListDemoAddButton extends LitElement {
184
+
185
+ _handleListAddButtonClick(e) {
186
+ const newItem = this._newItem();
187
+ const siblingItem = this.shadowRoot.querySelector(`[key="${e.detail.key}"]`);
188
+
189
+ if (e.detail.position === 'before') {
190
+ siblingItem.insertAdjacentElement('beforebegin', newItem);
191
+ } else {
192
+ siblingItem.insertAdjacentElement('afterend', newItem);
193
+ }
194
+ }
195
+
196
+ _newItem() {
197
+ const elem = document.createElement('d2l-list-item');
198
+ const key = getUniqueId();
199
+ elem.key = key;
200
+ elem.label = 'New Item';
201
+ elem.selectable = true;
202
+
203
+ const childElem = document.createElement('d2l-list-item-content');
204
+ childElem.textContent = `Item ${key}`;
205
+
206
+ elem.appendChild(childElem);
207
+ return elem;
208
+ }
209
+
210
+ render() {
211
+ return html`
212
+ <d2l-list grid add-button @d2l-list-add-button-click="${this._handleListAddButtonClick}">
213
+ <d2l-list-controls slot="controls">
214
+ <d2l-selection-action icon="tier1:delete" text="Delete" requires-selection></d2l-selection-action>
215
+ </d2l-list-controls>
216
+ <d2l-list-item selectable expandable key="expand-1" label="Expandable item #1">
217
+ <d2l-list-item-content>
218
+ <div>Expandable item #1</div>
219
+ <div slot="supporting-info">Supporting information</div>
220
+ </d2l-list-item-content>
221
+ <d2l-list grid add-button slot="nested" @d2l-list-add-button-click="${this._handleListAddButtonClick}">
222
+ <d2l-list-item selectable key="nested-1" label="Nested 1">
223
+ <d2l-list-item-content><div>Nested item #1</div></d2l-list-item-content>
224
+ </d2l-list-item>
225
+ <d2l-list-item selectable key="nested-2" label="Nested 2">
226
+ <d2l-list-item-content><div>Nested item #2</div></d2l-list-item-content>
227
+ </d2l-list-item>
228
+ </d2l-list>
229
+ </d2l-list-item>
230
+ <d2l-list-item selectable expandable expanded key="expand-2" label="Expandable item #2">
231
+ <d2l-list-item-content>
232
+ <div>Expandable Item #2</div>
233
+ <div slot="supporting-info">Supporting information</div>
234
+ </d2l-list-item-content>
235
+ <d2l-list grid add-button slot="nested" @d2l-list-add-button-click="${this._handleListAddButtonClick}">
236
+ <d2l-list-item selectable key="nested-3" label="Nested 3">
237
+ <d2l-list-item-content><div>Nested item #3</div></d2l-list-item-content>
238
+ </d2l-list-item>
239
+ <d2l-list-item selectable key="nested-4" label="Nested 4">
240
+ <d2l-list-item-content><div>Nested item #4</div></d2l-list-item-content>
241
+ </d2l-list-item>
242
+ </d2l-list>
243
+ </d2l-list-item>
244
+ <d2l-list-item selectable key="expand-3" label="Item with no children">
245
+ <d2l-list-item-content>
246
+ <div>Item with no children</div>
247
+ <div slot="supporting-info">Supporting information</div>
248
+ </d2l-list-item-content>
249
+ </d2l-list-item>
250
+ </d2l-list>
251
+ `;
252
+ }
253
+ }
254
+ customElements.define('d2l-list-demo-add-button', ListDemoAddButton);
255
+ </script>
256
+ <d2l-list-demo-add-button></d2l-list-demo-add-button>
257
+ ```
258
+
166
259
  ### Methods
167
260
 
168
261
  - `getItems()` (Array): returns the list items within the list
@@ -19,6 +19,7 @@ class ListDemoNested extends LitElement {
19
19
 
20
20
  static get properties() {
21
21
  return {
22
+ addButton: { type: Boolean, attribute: 'add-button' },
22
23
  demoItemKey: { type: String, attribute: 'demo-item-key' },
23
24
  isDraggable: { attribute: 'is-draggable', type: Boolean },
24
25
  selectable: { type: Boolean },
@@ -169,7 +170,11 @@ class ListDemoNested extends LitElement {
169
170
 
170
171
  _renderList(items, nested, includeControls = false, showLoadMore = false) {
171
172
  return html`
172
- <d2l-list ?grid="${!this.disableListGrid}" drag-multiple slot="${ifDefined(nested ? 'nested' : undefined)}" item-count="${this._items.length}">
173
+ <d2l-list
174
+ ?grid="${!this.disableListGrid}"
175
+ drag-multiple slot="${ifDefined(nested ? 'nested' : undefined)}"
176
+ item-count="${this._items.length}"
177
+ ?add-button="${this.addButton}">
173
178
  ${ includeControls ? this._renderListControls() : nothing }
174
179
  ${repeat(items, item => item.key, item => html`
175
180
  ${this._renderListItem(item)}
@@ -38,6 +38,14 @@
38
38
  </template>
39
39
  </d2l-demo-snippet>
40
40
 
41
+ <h2>Add Button</h2>
42
+
43
+ <d2l-demo-snippet>
44
+ <template>
45
+ <d2l-demo-list-nested add-button demo-item-key="imgPrimaryAndSupporting" is-draggable selectable></d2l-demo-list-nested>
46
+ </template>
47
+ </d2l-demo-snippet>
48
+
41
49
 
42
50
  </d2l-demo-page>
43
51
 
@@ -18,6 +18,7 @@
18
18
  <template>
19
19
  <d2l-demo-list-nested
20
20
  demo-item-key="imgPrimaryAndSupporting"
21
+ add-button
21
22
  is-draggable
22
23
  selectable
23
24
  expandable
@@ -45,6 +46,7 @@
45
46
  <template>
46
47
  <d2l-demo-list-nested
47
48
  demo-item-key="imgPrimaryAndSupporting"
49
+ add-button
48
50
  is-draggable
49
51
  selectable
50
52
  expandable
@@ -131,7 +131,7 @@
131
131
  <div>Earth Sciences (L1)</div>
132
132
  <div slot="supporting-info">Earth science or geoscience includes all fields of natural science related to planet Earth. This is a branch of science dealing with the physical and chemical constitution of Earth and its atmosphere. Earth science can be considered to be a branch of planetary science, but with a much older history.</div>
133
133
  </d2l-list-item-content>
134
- <d2l-list slot="nested" grid separators="all">
134
+ <d2l-list add-button slot="nested" grid separators="all">
135
135
  <d2l-list-item selectable key="L2-1" label="Label for L2-1">
136
136
  <d2l-list-item-content>
137
137
  <div>Introductory Earth Sciences (L2)</div>
@@ -153,8 +153,8 @@ export const ListItemMixin = superclass => class extends composeMixins(
153
153
  :host([_focusing-primary-action]) [slot="control-container"]::after,
154
154
  :host([selected]:not([selection-disabled]):not([skeleton])) [slot="control-container"]::before,
155
155
  :host([selected]:not([selection-disabled]):not([skeleton])) [slot="control-container"]::after,
156
- :host([_show-add-button]) [slot="control-container"]::after,
157
156
  :host([_show-add-button]) [slot="control-container"]::before,
157
+ :host([_show-add-button]) [slot="control-container"]::after,
158
158
  :host(:first-of-type[_nested]) [slot="control-container"]::before {
159
159
  border-top-color: transparent;
160
160
  }
@@ -413,7 +413,9 @@ export const ListItemMixin = superclass => class extends composeMixins(
413
413
  margin-top: -11.5px;
414
414
  }
415
415
  :host([draggable][selectable][_hovering]) [slot="add"],
416
- :host([draggable][selectable][_focusing]) [slot="add"] {
416
+ :host([draggable][selectable][_focusing]) [slot="add"],
417
+ :host([draggable][selectable][_hovering]) [slot="add-top"],
418
+ :host([draggable][selectable][_focusing]) [slot="add-top"] {
417
419
  padding-inline-end: 6px;
418
420
  }
419
421
  .dragging [slot="add"] {
@@ -719,7 +721,7 @@ export const ListItemMixin = superclass => class extends composeMixins(
719
721
  class="d2l-list-item-actions-container">
720
722
  <slot name="actions" class="d2l-list-item-actions">${actions}</slot>
721
723
  </div>
722
- ${this._showAddButton && !this._hasNestedListAddButton ? html`
724
+ ${this._showAddButton && (!this._hasNestedListAddButton || (this.expandable && !this.expanded)) ? html`
723
725
  <div slot="add">
724
726
  <d2l-button-add text="${addButtonText}" mode="icon-when-interacted" @click="${this._handleButtonAddClick}"></d2l-button-add>
725
727
  </div>
@@ -7785,6 +7785,10 @@
7785
7785
  "name": "d2l-demo-list-nested",
7786
7786
  "path": "./components/list/demo/demo-list-nested.js",
7787
7787
  "attributes": [
7788
+ {
7789
+ "name": "add-button",
7790
+ "type": "boolean"
7791
+ },
7788
7792
  {
7789
7793
  "name": "demo-item-key",
7790
7794
  "type": "string"
@@ -7835,6 +7839,11 @@
7835
7839
  }
7836
7840
  ],
7837
7841
  "properties": [
7842
+ {
7843
+ "name": "addButton",
7844
+ "attribute": "add-button",
7845
+ "type": "boolean"
7846
+ },
7838
7847
  {
7839
7848
  "name": "demoItemKey",
7840
7849
  "attribute": "demo-item-key",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "2.177.1",
3
+ "version": "2.177.3",
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",