-
Notifications
You must be signed in to change notification settings - Fork 25
/
selection-action.js
83 lines (71 loc) · 2.33 KB
/
selection-action.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
71
72
73
74
75
76
77
78
79
80
81
82
83
import '../button/button-subtle.js';
import { css, html, LitElement } from 'lit';
import { ButtonMixin } from '../button/button-mixin.js';
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 { SelectionActionMixin } from './selection-action-mixin.js';
import { SelectionInfo } from './selection-mixin.js';
/**
* A button action associated with a selection component.
* @fires d2l-selection-action-click - Dispatched when the user clicks the action button. The `SelectionInfo` is provided as the event `detail`. If `requires-selection` was specified then the event will only be dispatched if items are selected.
* @fires d2l-selection-observer-subscribe - Internal event
*/
class Action extends FocusMixin(LocalizeCoreElement(SelectionActionMixin(ButtonMixin(LitElement)))) {
static get properties() {
return {
/**
* Preset icon key (e.g. `tier1:gear`)
* @type {string}
*/
icon: { type: String, reflect: true },
/**
* REQUIRED: The text for the action
* @type {string}
*/
text: { type: String, reflect: true }
};
}
static get styles() {
return css`
:host {
display: inline-block;
}
:host([hidden]) {
display: none;
}
`;
}
static get focusElementSelector() {
return 'd2l-button-subtle';
}
connectedCallback() {
super.connectedCallback();
this.addEventListener('d2l-button-ghost-click', this._handleActionClick);
}
disconnectedCallback() {
super.disconnectedCallback();
this.removeEventListener('d2l-button-ghost-click', this._handleActionClick);
}
render() {
return html`
<d2l-button-subtle
class="vdiff-target"
@click="${this._handleActionClick}"
?disabled="${this.disabled}"
disabled-tooltip="${ifDefined(this.disabled ? this.localize('components.selection.action-hint') : undefined)}"
icon="${ifDefined(this.icon)}"
text="${this.text}">
</d2l-button-subtle>
`;
}
_handleActionClick(e) {
e.stopPropagation();
if (this.requiresSelection && this.selectionInfo.state === SelectionInfo.states.none) return;
this.dispatchEvent(new CustomEvent('d2l-selection-action-click', {
bubbles: true,
detail: this.selectionInfo
}));
}
}
customElements.define('d2l-selection-action', Action);