-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnav-item.js
60 lines (49 loc) · 1.56 KB
/
nav-item.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
import ShadowElement, {html, template, css, adoptedStyleSheets, define, reflectBooleanProperties, reflectStringProperties} from '@cfware/shadow-element';
class NavItem extends ShadowElement {
constructor() {
super();
const observer = new MutationObserver(() => this.dispatchEvent(new Event('hiddenchange')));
observer.observe(this, {
attributes: true,
attributeFilter: ['hidden']
});
}
get pathname() {
return new URL(this.href, document.baseURI).pathname;
}
static [adoptedStyleSheets] = [
css`
a {
display: block;
position: relative;
margin-left: .85rem;
padding: .83rem .95rem .83rem .85rem;
color: #000a;
text-decoration: none;
line-height: 1;
border-left: .2rem solid transparent;
}
a:hover {
color: #005d90;
}
a:focus {
background-color: #8881;
}
a:active {
background-color: #0001;
}
:host(:not(:first-child)) a {
border-top: 1px solid #8882;
}
:host([active]) a {
border-left-color: unset;
}
`
];
get [template]() {
return html`<a href=${this.href}>${this.title}</a>`;
}
}
reflectBooleanProperties(NavItem, ['active']);
reflectStringProperties(NavItem, {title: '', href: '.'});
NavItem[define]('nav-item');