forked from BrightspaceUILabs/navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd2l-navigation-button.js
131 lines (115 loc) · 4.08 KB
/
d2l-navigation-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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import 'd2l-button/d2l-button-behavior.js';
import 'd2l-polymer-behaviors/d2l-focusable-behavior.js';
import 'd2l-polymer-behaviors/d2l-id.js';
import { highlightStyles } from './d2l-navigation-highlight-styles.js';
import 'd2l-offscreen/d2l-offscreen-shared-styles.js';
import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
import { mixinBehaviors } from '@polymer/polymer/lib/legacy/class.js';
/**
`d2l-navigation-button`
Polymer-based web component for buttons used in the navigational header.
@demo demo/d2l-navigation-button.html d2l-navigation-button
*/
class D2LNavigationButton extends mixinBehaviors([D2L.PolymerBehaviors.Button.Behavior, D2L.PolymerBehaviors.FocusableBehavior], PolymerElement) {
static get properties() {
return {
text: {
type: String,
reflectToAttribute: true
},
hideHighlight: {
type: Boolean,
value: false,
reflectToAttribute: true
},
ariaDescribedbyText: {
type: String
},
_ariaDescriptionId: {
type: String
}
};
}
static get template() {
const template = html`
${highlightStyles}
<style is="custom-style" include="d2l-offscreen-shared-styles">
:host {
display: inline-block;
height: 100%;
}
/* Firefox includes a hidden border which messes up button dimensions */
:host button::-moz-focus-inner {
border: 0;
}
:host button ::slotted(*) {
pointer-events: none;
}
:host button:hover,
:host button:focus,
:host button:hover ::slotted(*),
:host button:focus ::slotted(*) {
@apply --d2l-navigation-highlight-base-hover-focus;
}
/*
::slotted styles for Edge/IE11
*/
:host button:hover ::slotted(*) *,
:host button:focus ::slotted(*) * {
@apply --d2l-navigation-highlight-base-hover-focus;
}
:host button:hover .d2l-navigation-button-top-border,
:host button:focus .d2l-navigation-button-top-border {
@apply --d2l-navigation-highlight-border-hover-focus;
}
button {
@apply --d2l-navigation-highlight-base;
font-family: inherit;
outline: none; /* Needed for Edge, outline setting from css mixin is not being applied in Polymer 2 & 3 */
}
.d2l-navigation-button-top-border {
@apply --d2l-navigation-highlight-border;
}
.d2l-offscreen-description {
@apply --d2l-offscreen;
}
:host(:dir(rtl)) .d2l-offscreen-description {
@apply --d2l-offscreen-rtl;
}
:host([disabled]) button {
@apply --d2l-navigation-highlight-disabled;
}
:host([disabled]:hover) button,
:host([disabled]:hover) button ::slotted(*),
:host([disabled]:hover) button .d2l-navigation-button-top-border,
:host([disabled]:focus) button,
:host([disabled]:focus) button ::slotted(*),
:host([disabled]:focus) button .d2l-navigation-button-top-border {
@apply --d2l-navigation-highlight-hover-focus-disabled;
}
/*
::slotted styles for Edge/IE11
*/
:host([disabled]:hover) button ::slotted(*) *,
:host([disabled]:focus) button ::slotted(*) * {
@apply --d2l-navigation-highlight-hover-focus-disabled;
}
</style>
<button aria-describedby$="[[_ariaDescriptionId]]" aria-expanded$="[[ariaExpanded]]" aria-haspopup$="[[ariaHaspopup]]" aria-label$="[[text]]" class="d2l-focusable" disabled$="[[disabled]]" autofocus$="[[autofocus]]" form$="[[form]]" formaction$="[[formaction]]" formenctype$="[[formenctype]]" formmethod$="[[formmethod]]" formnovalidate$="[[formnovalidate]]" formtarget$="[[formtarget]]" name$="[[name]]" title$="[[text]]" type$="[[type]]">
<span class$="[[_getTopBorderClass()]]"></span>
<slot></slot>
</button>
<span id="[[_ariaDescriptionId]]" class="d2l-offscreen-description">[[ariaDescribedbyText]]</span>
`;
template.setAttribute('strip-whitespace', '');
return template;
}
_getTopBorderClass() {
return this.hideHighlight ? '' : 'd2l-navigation-button-top-border';
}
ready() {
super.ready();
this._ariaDescriptionId = D2L.Id.getUniqueId();
}
}
customElements.define('d2l-navigation-button', D2LNavigationButton);