-
Notifications
You must be signed in to change notification settings - Fork 25
/
dropdown-button.js
79 lines (71 loc) · 1.69 KB
/
dropdown-button.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
import '../button/button.js';
import '../icons/icon.js';
import { css, html, LitElement } from 'lit';
import { DropdownOpenerMixin } from './dropdown-opener-mixin.js';
import { dropdownOpenerStyles } from './dropdown-opener-styles.js';
import { RtlMixin } from '../../mixins/rtl/rtl-mixin.js';
/**
* A "d2l-button" opener for dropdown content.
* @slot - Dropdown content (e.g., "d2l-dropdown-content", "d2l-dropdown-menu" or "d2l-dropdown-tabs")
*/
class DropdownButton extends DropdownOpenerMixin(RtlMixin(LitElement)) {
static get properties() {
return {
/**
* Optionally render button as primary button
* @type {boolean}
*/
primary: {
type: Boolean,
reflect: true
},
/**
* REQUIRED: Text for the button
* @type {string}
*/
text: {
type: String
}
};
}
static get styles() {
return [dropdownOpenerStyles, css`
d2l-icon {
height: 0.8rem;
margin-left: 0.6rem;
pointer-events: none;
width: 0.8rem;
}
:host([primary]) d2l-icon {
color: white;
}
:host([dir="rtl"]) d2l-icon {
margin-left: 0;
margin-right: 0.6rem;
}
d2l-button {
width: 100%;
}
`];
}
constructor() {
super();
this.primary = false;
}
render() {
return html`
<d2l-button ?primary=${this.primary} ?disabled=${this.disabled}>
${this.text}<d2l-icon icon="tier1:chevron-down"></d2l-icon>
</d2l-button>
<slot></slot>
`;
}
/**
* Gets the opener element with class "d2l-dropdown-opener" (required by dropdown-opener-mixin).
* @return {HTMLElement}
*/
getOpenerElement() {
return this.shadowRoot && this.shadowRoot.querySelector('d2l-button');
}
}
customElements.define('d2l-dropdown-button', DropdownButton);