forked from BrightspaceUILabs/navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd2l-navigation-band.js
129 lines (120 loc) · 3.87 KB
/
d2l-navigation-band.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
import 'd2l-colors/d2l-colors.js';
import './d2l-navigation-shared-styles';
import {PolymerElement, html} from '@polymer/polymer/polymer-element.js';
import { navigationSharedStyle } from './d2l-navigation-shared-styles';
/**
`d2l-navigation-band`
Polymer-based web component for a solid colour band that runs along the top of the navigational header
*/
class D2LNavigationBand extends PolymerElement {
static get properties() {
return {
customScroll: {
type: Boolean,
readOnly: true,
value: function() {
const userAgent = navigator.userAgent.toLowerCase();
return (userAgent.indexOf('win') > -1 && userAgent.indexOf('mobile') === -1);
}
}
};
}
static get template() {
const template = html`
${navigationSharedStyle}
<style>
:host {
background: linear-gradient(180deg, var(--d2l-branding-primary-color, var(--d2l-color-celestine)) var(--d2l-navigation-band-slot-height, 1.5rem), #ffffff 0%);
display: block;
min-height: 10px;
position: relative; /* Needed for Firefox */
}
.d2l-navigation-scroll {
overflow-x: auto;
overflow-y: hidden;
scroll-behavior: smooth;
}
.d2l-navigation-scroll[custom-scroll] {
/* Firefox Styles */
scrollbar-color: var(--d2l-color-galena) var(--d2l-color-sylvite);
scrollbar-width: thin;
/* IE Styles */
scrollbar-face-color: var(--d2l-color-galena);
scrollbar-arrow-color: var(--d2l-color-sylvite);
scrollbar-track-color: var(--d2l-color-sylvite);
scrollbar-shadow-color: var(--d2l-color-sylvite);
}
/* Webkit Styles */
.d2l-navigation-scroll[custom-scroll]::-webkit-scrollbar {
border-radius: 8px;
background-color: var(--d2l-color-sylvite);
height: 9px;
}
.d2l-navigation-scroll[custom-scroll]::-webkit-scrollbar-thumb {
background-color: var(--d2l-color-galena);
border-radius: 8px;
border-bottom: 1px solid var(--d2l-color-sylvite);
border-top: 1px solid var(--d2l-color-sylvite);
}
/* Faded edges styles */
.d2l-navigation-scroll:before,
.d2l-navigation-scroll:after {
content: '';
position: absolute;
height: 100%;
max-height: var(--d2l-navigation-band-slot-height, 1.5rem);
pointer-events: none;
top: 0;
z-index: 2;
}
.d2l-navigation-scroll:before {
left: 0;
background: linear-gradient(to right, var(--d2l-branding-primary-color, var(--d2l-color-celestine)), transparent);
}
.d2l-navigation-scroll:after {
right: 0;
background: linear-gradient(to left, var(--d2l-branding-primary-color, var(--d2l-color-celestine)), transparent);
}
/* Styles to ensure the right padding is respected when scrolling */
.d2l-navigation-centerer {
line-height: 0;
position: relative;
}
.d2l-navigation-gutters {
display: inline-block;
position: unset;
vertical-align: top;
}
</style>
<div class="d2l-navigation-centerer">
<div class="d2l-navigation-scroll" custom-scroll$=[[customScroll]]>
<div class="d2l-navigation-gutters">
<slot></slot>
</div>
</div>
</div>
`;
template.setAttribute('strip-whitespace', '');
return template;
}
connectedCallback() {
super.connectedCallback();
this.addEventListener('d2l-navigation-band-slot-scroll-request', this._handleScrollRequest);
}
disconnectedCallback() {
super.disconnectedCallback();
this.removeEventListener('d2l-navigation-band-slot-scroll-request', this._handleScrollRequest);
}
_handleScrollRequest(e) {
e.stopPropagation();
const dir = document.documentElement.getAttribute('dir') || 'ltr';
if (dir.toLowerCase() === 'rtl') {
return; // We turn off this feature in RTL due to browser inconsistencies
}
const scroll = this.shadowRoot.querySelector('.d2l-navigation-scroll');
requestAnimationFrame(() => {
scroll.scrollLeft = e.detail.pointToCenter - 0.5 * scroll.offsetWidth;
});
}
}
customElements.define('d2l-navigation-band', D2LNavigationBand);