@puzzleitc/puzzle-shell
Version:
The standard design for Puzzle tools
107 lines (103 loc) • 3.23 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { LitElement, css, html } from "lit";
import { customElement } from "lit/decorators/custom-element.js";
import { property } from "lit/decorators/property.js";
import { classMap } from "lit/directives/class-map.js";
import { theme } from "../utils/theme";
/**
* Application navigation item to be used in pzsh-nav and pzsh-subnav
* components.
*
* @slot - Navigation item label
* @attr {Boolean} active - Whether the item is currently active
*/
let NavItem = class NavItem extends LitElement {
constructor() {
super(...arguments);
this.href = "#";
this.active = false;
}
focus(options) {
this.shadowRoot?.querySelector("a")?.focus(options);
}
render() {
return html `<a
class=${classMap({ active: this.active })}
href="${this.href}"
role="menuitem"
part="pzsh-nav-item"
>
<div><slot></slot></div>
</a>`;
}
};
NavItem.styles = [
theme,
css `
a {
display: block;
padding: var(--pzsh-menu-item-padding-vertical)
var(--pzsh-menu-item-padding-horizontal);
color: var(--pzsh-menu-fg);
text-decoration: none;
white-space: nowrap;
}
:host {
margin: calc(0.5 * var(--pzsh-menu-item-gap)) 0;
background-color: var(--pzsh-menu-bg-alt);
}
:host(:focus) a,
a:hover,
a:active,
a:focus {
color: var(--pzsh-menu-active);
}
@media (min-width: ${theme.breakpoint}px) {
:host {
line-height: var(--pzsh-nav-line-height);
margin: 0;
background-color: transparent;
}
a {
margin: 0;
padding: 0 var(--pzsh-nav-item-padding-horizontal-desktop);
color: var(--pzsh-nav-fg);
background-color: transparent;
}
a,
:host(:focus) a,
a:hover,
a:active,
a:focus {
color: var(--pzsh-nav-fg);
}
a > div {
padding: var(--pzsh-nav-item-padding-horizontal-desktop) 0
calc(var(--pzsh-nav-item-padding-horizontal-desktop) - 5px) 0;
border-bottom: 5px solid transparent;
}
:host(:focus) a > div,
a:hover > div,
a:active > div,
a:focus > div,
a.active > div {
border-color: var(--pzsh-nav-active);
}
}
`,
];
__decorate([
property({ type: String })
], NavItem.prototype, "href", void 0);
__decorate([
property({ type: Boolean })
], NavItem.prototype, "active", void 0);
NavItem = __decorate([
customElement("pzsh-nav-item")
], NavItem);
export { NavItem };