@brightspace-ui/core 3.5.1 → 3.5.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.
@@ -132,7 +132,9 @@ For long tables, the header row can be made to "stick" in place as the user scro
132
132
 
133
133
  ## Sortable Column Buttons [d2l-table-col-sort-button]
134
134
 
135
- When tabular data can be sorted, the `<d2l-table-col-sort-button>` can be used to provide an interactive sort button as well as arrows to indicate the ascending/descending sort direction.
135
+ When tabular data can be sorted, the `<d2l-table-col-sort-button>` can be used to provide an interactive sort button as well as arrows to indicate the ascending/descending sort direction. This is meant to be used within a `d2l-table-wrapper`.
136
+
137
+ Note that the example below hides much of the implementation. See the code in [Multi-Faceted Sort Button](#multi-faceted-sort-button) for a more detailed implementation example.
136
138
 
137
139
  <!-- docs: demo -->
138
140
  ```html
@@ -210,15 +212,17 @@ When tabular data can be sorted, the `<d2l-table-col-sort-button>` can be used t
210
212
  ```
211
213
 
212
214
  ```html
213
- <table class="d2l-table">
214
- <thead>
215
- <tr>
216
- <th><d2l-table-col-sort-button>Ascending</d2l-table-col-sort-button></th>
217
- <th><d2l-table-col-sort-button desc>Descending</d2l-table-col-sort-button></th>
218
- <th><d2l-table-col-sort-button nosort>Not Sorted</d2l-table-col-sort-button></th>
219
- </tr>
220
- </thead>
221
- </table>
215
+ <d2l-table-wrapper>
216
+ <table class="d2l-table">
217
+ <thead>
218
+ <tr>
219
+ <th><d2l-table-col-sort-button>Ascending</d2l-table-col-sort-button></th>
220
+ <th><d2l-table-col-sort-button desc>Descending</d2l-table-col-sort-button></th>
221
+ <th><d2l-table-col-sort-button nosort>Not Sorted</d2l-table-col-sort-button></th>
222
+ </tr>
223
+ </thead>
224
+ </table>
225
+ </d2l-table-wrapper>
222
226
  ```
223
227
 
224
228
  ### Properties
@@ -228,7 +232,134 @@ When tabular data can be sorted, the `<d2l-table-col-sort-button>` can be used t
228
232
  | `desc` | boolean | Whether sort direction is descending | false |
229
233
  | `nosort` | boolean | Column is not currently sorted. Hides the ascending/descending sort icon. | false |
230
234
  | `position` | string | Position of the button content. Accepted values are 'start', 'center', and 'end'. | 'start' |
231
- | `source-type` | string | The type of data in the column. Used to set the title. Accepted values are 'words', 'numbers', and 'dates'. | 'unknown' |
235
+ | `source-type` | string | The type of data in the column. Used to set the title. Accepted values are 'words', 'numbers', and 'dates'. This is only applicable to cases that are not using the multi-faceted dropdown. | 'unknown' |
236
+
237
+ ### Slots
238
+ | Name | Description |
239
+ |---|---|
240
+ | `Default` | Column header text |
241
+ | `items` | Multi-facted sort items. Generally assigned to the `slot` attribute on a nested `d2l-table-col-sort-button-item`. |
242
+
243
+ ### Slotted Item [d2l-table-col-sort-button-item]
244
+
245
+ This is a radio menu item to be used within the `d2l-table-col-sort-button` component for a [multi-faceted sort](#multi-faceted-sort-button).
246
+
247
+ <!-- docs: demo code properties autoSize:false align:start name:d2l-table-col-sort-button-item -->
248
+ ```html
249
+ <script type="module">
250
+ import '@brightspace-ui/core/components/table/table-col-sort-button.js';
251
+ import '@brightspace-ui/core/components/table/table-col-sort-button-item.js';
252
+ </script>
253
+ <!-- docs: start hidden content -->
254
+ <style>
255
+ d2l-table-col-sort-button {
256
+ --d2l-table-cell-padding: 10px;
257
+ }
258
+ </style>
259
+ <!-- docs: end hidden content -->
260
+ <d2l-table-col-sort-button desc>
261
+ Items
262
+ <d2l-table-col-sort-button-item text="Item 1" slot="items" value="item1"></d2l-table-col-sort-button-item>
263
+ <d2l-table-col-sort-button-item text="Item 2" slot="items" value="item2"></d2l-table-col-sort-button-item>
264
+ </d2l-table-col-sort-button>
265
+ ```
266
+
267
+ ### Multi-Faceted Sort Button
268
+
269
+ When a single column is responsible for sorting in multiple facets (e.g., first name and last name), it is recommended to use the dropdown menu approach by slotting `d2l-table-col-sort-button-item` components within the `d2l-table-col-sort-button`. Please note that the consumer is responsible for all sort logic, including when `desc` and `nosort` are set on `d2l-table-col-sort-button`.
270
+
271
+ **WARNING**: Do NOT use this if the table is using `sticky-headers` AND multiple header rows. It is not currently supported. In that siuation, continue to put multiple `d2l-table-col-sort-button` components in the same column.
272
+
273
+ <!-- docs: demo code display:block -->
274
+ ```html
275
+ <script type="module">
276
+ import '@brightspace-ui/core/components/table/table-col-sort-button.js';
277
+ import '@brightspace-ui/core/components/table/table-col-sort-button-item.js';
278
+ import { html, LitElement } from 'lit';
279
+ import { tableStyles } from '@brightspace-ui/core/components/table/table-wrapper.js';
280
+ const data = () => [
281
+ { firstname: 'John', lastname: 'Smith', grade: 85 },
282
+ { firstname: 'Emily', lastname: 'Jones', grade: 92 },
283
+ { firstname: 'Michael', lastname: 'Davis', grade: 78 },
284
+ { firstname: 'Sarah', lastname: 'Brown', grade: 90 },
285
+ { firstname: 'David', lastname: 'Wilson', grade: 88 },
286
+ { firstname: 'Jessica', lastname: 'Taylor', grade: 95 },
287
+ { firstname: 'Christopher', lastname: 'Martinez', grade: 83 }
288
+ ];
289
+ class MyComplexSortableTableElem extends LitElement {
290
+ static get properties() {
291
+ return {
292
+ _desc: { state: true },
293
+ _field: { state: true }
294
+ };
295
+ }
296
+ static get styles() {
297
+ return tableStyles;
298
+ }
299
+ constructor() {
300
+ super();
301
+ this._data = data();
302
+ this._desc = false;
303
+ }
304
+ render() {
305
+ const rowData = this._field ? this._data.sort((a, b) => {
306
+ if (this._desc) {
307
+ if (a[this._field] > b[this._field]) return -1;
308
+ if (a[this._field] < b[this._field]) return 1;
309
+ } else {
310
+ if (a[this._field] < b[this._field]) return -1;
311
+ if (a[this._field] > b[this._field]) return 1;
312
+ }
313
+ return 0;
314
+ }) : this._data;
315
+ const rows = rowData.map(i => {
316
+ return html`<tr>
317
+ <td>${i.firstname} ${i.lastname}</td>
318
+ <td>${i.grade}</td>
319
+ </tr>
320
+ `;
321
+ });
322
+ return html`
323
+ <d2l-table-wrapper>
324
+ <table class="d2l-table">
325
+ <thead>
326
+ <tr>
327
+ <th>
328
+ <d2l-table-col-sort-button ?desc="${this._desc}" ?nosort="${this._field !== 'firstname' && this._field !== 'lastname'}">
329
+ Learner
330
+ <d2l-table-col-sort-button-item slot="items" text="First Name, A to Z" data-field="firstname" @d2l-table-col-sort-button-item-change="${this._handleSortComplex}" value="1"></d2l-table-col-sort-button-item>
331
+ <d2l-table-col-sort-button-item slot="items" text="First Name, Z to A" data-field="firstname" data-desc @d2l-table-col-sort-button-item-change="${this._handleSortComplex}" value="2"></d2l-table-col-sort-button-item>
332
+ <d2l-table-col-sort-button-item slot="items" text="Last Name, A to Z" data-field="lastname" @d2l-table-col-sort-button-item-change="${this._handleSortComplex}" value="3"></d2l-table-col-sort-button-item>
333
+ <d2l-table-col-sort-button-item slot="items" text="Last Name, Z to A" data-field="lastname" data-desc @d2l-table-col-sort-button-item-change="${this._handleSortComplex}" value="4"></d2l-table-col-sort-button-item>
334
+ </d2l-table-col-sort-button>
335
+ </th>
336
+ <th>
337
+ <d2l-table-col-sort-button ?desc="${this._desc}" data-field="grade" @click="${this._handleSort}" ?nosort="${this._field !== 'grade'}">Grade</d2l-table-col-sort-button>
338
+ </th>
339
+ </tr>
340
+ </thead>
341
+ <tbody>
342
+ ${rows}
343
+ </tbody>
344
+ </table>
345
+ </d2l-table-wrapper>
346
+ `;
347
+ }
348
+ _handleSort(e) {
349
+ const field = e.target.getAttribute('data-field');
350
+ const desc = e.target.hasAttribute('desc');
351
+ this._desc = field === this._field ? !desc : false;
352
+ this._field = field;
353
+ }
354
+ _handleSortComplex(e) {
355
+ this._field = e.target.getAttribute('data-field');
356
+ this._desc = e.target.hasAttribute('data-desc');
357
+ }
358
+ }
359
+ customElements.define('d2l-my-complex-sortable-table-elem', MyComplexSortableTableElem);
360
+ </script>
361
+ <d2l-my-complex-sortable-table-elem></d2l-my-complex-sortable-table-elem>
362
+ ```
232
363
 
233
364
  ## Selection
234
365
 
@@ -6,6 +6,9 @@ import { RtlMixin } from '../../mixins/rtl/rtl-mixin.js';
6
6
 
7
7
  /**
8
8
  * A radio menu item to be used within the d2l-table-col-sort-button component for a multi-faceted sort.
9
+ * @fires d2l-menu-item-change - Internal event
10
+ * @fires d2l-menu-item-select - Internal event
11
+ * @fires d2l-menu-item-visibility-change - Internal event
9
12
  */
10
13
  class TableColSortButtonItem extends RtlMixin(MenuItemRadioMixin(LitElement)) {
11
14
 
@@ -12118,21 +12118,21 @@
12118
12118
  }
12119
12119
  ],
12120
12120
  "events": [
12121
- {
12122
- "name": "d2l-table-col-sort-button-item-change",
12123
- "description": "Dispatched when the selected multi-faceted sort option changes"
12124
- },
12125
12121
  {
12126
12122
  "name": "d2l-menu-item-change",
12127
- "description": "Dispatched when the selected menu item changes"
12123
+ "description": "Internal event"
12128
12124
  },
12129
12125
  {
12130
12126
  "name": "d2l-menu-item-select",
12131
- "description": "Dispatched when the menu item is selected"
12127
+ "description": "Internal event"
12132
12128
  },
12133
12129
  {
12134
12130
  "name": "d2l-menu-item-visibility-change",
12135
- "description": "Dispatched when the visibility of the menu item changes"
12131
+ "description": "Internal event"
12132
+ },
12133
+ {
12134
+ "name": "d2l-table-col-sort-button-item-change",
12135
+ "description": "Dispatched when the selected multi-faceted sort option changes"
12136
12136
  }
12137
12137
  ]
12138
12138
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "3.5.1",
3
+ "version": "3.5.2",
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",