@brightspace-ui/core 2.177.2 → 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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "2.177.2",
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",