-
Notifications
You must be signed in to change notification settings - Fork 25
/
selection-select-all.js
70 lines (59 loc) · 2.08 KB
/
selection-select-all.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import '../inputs/input-checkbox.js';
import { css, html, LitElement } from 'lit';
import { FocusMixin } from '../../mixins/focus/focus-mixin.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import { LocalizeCoreElement } from '../../helpers/localize-core-element.js';
import { SelectionInfo } from './selection-mixin.js';
import { SelectionObserverMixin } from './selection-observer-mixin.js';
/**
* A checkbox that provides select-all behavior for selection components such as tables and lists.
* @fires d2l-selection-observer-subscribe - Internal event
*/
class SelectAll extends FocusMixin(LocalizeCoreElement(SelectionObserverMixin(LitElement))) {
static get properties() {
return {
/**
* Disables the select all checkbox
* @type {boolean}
*/
disabled: { type: Boolean }
};
}
static get styles() {
return css`
:host {
display: inline-block;
line-height: normal;
}
:host([hidden]) {
display: none;
}
`;
}
constructor() {
super();
this.disabled = false;
}
static get focusElementSelector() {
return 'd2l-input-checkbox';
}
render() {
if (!this._provider || this._provider.selectionSingle) return;
const summary = (this.selectionInfo.state === SelectionInfo.states.none ? this.localize('components.selection.select-all')
: this.localize('components.selection.selected', 'count', this.selectionInfo.keys.length));
return html`
<d2l-input-checkbox
aria-label="${this.localize('components.selection.select-all')}"
@change="${this._handleCheckboxChange}"
?checked="${this.selectionInfo.state === SelectionInfo.states.all || this.selectionInfo.state === SelectionInfo.states.allPages}"
?disabled="${this.disabled}"
description="${ifDefined(this.selectionInfo.state !== SelectionInfo.states.none ? summary : undefined)}"
?indeterminate="${this.selectionInfo.state === SelectionInfo.states.some}">
</d2l-input-checkbox>
`;
}
_handleCheckboxChange(e) {
if (this._provider) this._provider.setSelectionForAll(e.target.checked, false);
}
}
customElements.define('d2l-selection-select-all', SelectAll);