@nysds/nys-globalfooter
Version:
The Globalfooter component from the NYS Design System.
549 lines (535 loc) • 18.5 kB
JavaScript
import { css as U, LitElement as A, html as f } from "lit";
/*!
* ▒█▄░▒█ ▒█░░▒█ ▒█▀▀▀█ ▒█▀▀▄ ▒█▀▀▀█
* ▒█▒█▒█ ▒█▄▄▄█ ░▀▀▀▄▄ ▒█░▒█ ░▀▀▀▄▄
* ▒█░░▀█ ░░▒█░░ ▒█▄▄▄█ ▒█▄▄▀ ▒█▄▄▄█
*
* Global Footer Component
* Part of the New York State Design System
* Repository: https://github.com/its-hcd/nysds
* License: MIT
*/
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const g = globalThis, m = g.ShadowRoot && (g.ShadyCSS === void 0 || g.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype, P = Symbol(), S = /* @__PURE__ */ new WeakMap();
let O = class {
constructor(t, e, o) {
if (this._$cssResult$ = !0, o !== P) throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");
this.cssText = t, this.t = e;
}
get styleSheet() {
let t = this.o;
const e = this.t;
if (m && t === void 0) {
const o = e !== void 0 && e.length === 1;
o && (t = S.get(e)), t === void 0 && ((this.o = t = new CSSStyleSheet()).replaceSync(this.cssText), o && S.set(e, t));
}
return t;
}
toString() {
return this.cssText;
}
};
const z = (n) => new O(typeof n == "string" ? n : n + "", void 0, P), L = (n, t) => {
if (m) n.adoptedStyleSheets = t.map((e) => e instanceof CSSStyleSheet ? e : e.styleSheet);
else for (const e of t) {
const o = document.createElement("style"), s = g.litNonce;
s !== void 0 && o.setAttribute("nonce", s), o.textContent = e.cssText, n.appendChild(o);
}
}, $ = m ? (n) => n : (n) => n instanceof CSSStyleSheet ? ((t) => {
let e = "";
for (const o of t.cssRules) e += o.cssText;
return z(e);
})(n) : n;
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const { is: M, defineProperty: N, getOwnPropertyDescriptor: T, getOwnPropertyNames: R, getOwnPropertySymbols: j, getPrototypeOf: D } = Object, l = globalThis, w = l.trustedTypes, q = w ? w.emptyScript : "", u = l.reactiveElementPolyfillSupport, d = (n, t) => n, y = { toAttribute(n, t) {
switch (t) {
case Boolean:
n = n ? q : null;
break;
case Object:
case Array:
n = n == null ? n : JSON.stringify(n);
}
return n;
}, fromAttribute(n, t) {
let e = n;
switch (t) {
case Boolean:
e = n !== null;
break;
case Number:
e = n === null ? null : Number(n);
break;
case Object:
case Array:
try {
e = JSON.parse(n);
} catch {
e = null;
}
}
return e;
} }, _ = (n, t) => !M(n, t), x = { attribute: !0, type: String, converter: y, reflect: !1, hasChanged: _ };
Symbol.metadata ?? (Symbol.metadata = Symbol("metadata")), l.litPropertyMetadata ?? (l.litPropertyMetadata = /* @__PURE__ */ new WeakMap());
class p extends HTMLElement {
static addInitializer(t) {
this._$Ei(), (this.l ?? (this.l = [])).push(t);
}
static get observedAttributes() {
return this.finalize(), this._$Eh && [...this._$Eh.keys()];
}
static createProperty(t, e = x) {
if (e.state && (e.attribute = !1), this._$Ei(), this.elementProperties.set(t, e), !e.noAccessor) {
const o = Symbol(), s = this.getPropertyDescriptor(t, o, e);
s !== void 0 && N(this.prototype, t, s);
}
}
static getPropertyDescriptor(t, e, o) {
const { get: s, set: r } = T(this.prototype, t) ?? { get() {
return this[e];
}, set(i) {
this[e] = i;
} };
return { get() {
return s == null ? void 0 : s.call(this);
}, set(i) {
const a = s == null ? void 0 : s.call(this);
r.call(this, i), this.requestUpdate(t, a, o);
}, configurable: !0, enumerable: !0 };
}
static getPropertyOptions(t) {
return this.elementProperties.get(t) ?? x;
}
static _$Ei() {
if (this.hasOwnProperty(d("elementProperties"))) return;
const t = D(this);
t.finalize(), t.l !== void 0 && (this.l = [...t.l]), this.elementProperties = new Map(t.elementProperties);
}
static finalize() {
if (this.hasOwnProperty(d("finalized"))) return;
if (this.finalized = !0, this._$Ei(), this.hasOwnProperty(d("properties"))) {
const e = this.properties, o = [...R(e), ...j(e)];
for (const s of o) this.createProperty(s, e[s]);
}
const t = this[Symbol.metadata];
if (t !== null) {
const e = litPropertyMetadata.get(t);
if (e !== void 0) for (const [o, s] of e) this.elementProperties.set(o, s);
}
this._$Eh = /* @__PURE__ */ new Map();
for (const [e, o] of this.elementProperties) {
const s = this._$Eu(e, o);
s !== void 0 && this._$Eh.set(s, e);
}
this.elementStyles = this.finalizeStyles(this.styles);
}
static finalizeStyles(t) {
const e = [];
if (Array.isArray(t)) {
const o = new Set(t.flat(1 / 0).reverse());
for (const s of o) e.unshift($(s));
} else t !== void 0 && e.push($(t));
return e;
}
static _$Eu(t, e) {
const o = e.attribute;
return o === !1 ? void 0 : typeof o == "string" ? o : typeof t == "string" ? t.toLowerCase() : void 0;
}
constructor() {
super(), this._$Ep = void 0, this.isUpdatePending = !1, this.hasUpdated = !1, this._$Em = null, this._$Ev();
}
_$Ev() {
var t;
this._$ES = new Promise((e) => this.enableUpdating = e), this._$AL = /* @__PURE__ */ new Map(), this._$E_(), this.requestUpdate(), (t = this.constructor.l) == null || t.forEach((e) => e(this));
}
addController(t) {
var e;
(this._$EO ?? (this._$EO = /* @__PURE__ */ new Set())).add(t), this.renderRoot !== void 0 && this.isConnected && ((e = t.hostConnected) == null || e.call(t));
}
removeController(t) {
var e;
(e = this._$EO) == null || e.delete(t);
}
_$E_() {
const t = /* @__PURE__ */ new Map(), e = this.constructor.elementProperties;
for (const o of e.keys()) this.hasOwnProperty(o) && (t.set(o, this[o]), delete this[o]);
t.size > 0 && (this._$Ep = t);
}
createRenderRoot() {
const t = this.shadowRoot ?? this.attachShadow(this.constructor.shadowRootOptions);
return L(t, this.constructor.elementStyles), t;
}
connectedCallback() {
var t;
this.renderRoot ?? (this.renderRoot = this.createRenderRoot()), this.enableUpdating(!0), (t = this._$EO) == null || t.forEach((e) => {
var o;
return (o = e.hostConnected) == null ? void 0 : o.call(e);
});
}
enableUpdating(t) {
}
disconnectedCallback() {
var t;
(t = this._$EO) == null || t.forEach((e) => {
var o;
return (o = e.hostDisconnected) == null ? void 0 : o.call(e);
});
}
attributeChangedCallback(t, e, o) {
this._$AK(t, o);
}
_$EC(t, e) {
var r;
const o = this.constructor.elementProperties.get(t), s = this.constructor._$Eu(t, o);
if (s !== void 0 && o.reflect === !0) {
const i = (((r = o.converter) == null ? void 0 : r.toAttribute) !== void 0 ? o.converter : y).toAttribute(e, o.type);
this._$Em = t, i == null ? this.removeAttribute(s) : this.setAttribute(s, i), this._$Em = null;
}
}
_$AK(t, e) {
var r;
const o = this.constructor, s = o._$Eh.get(t);
if (s !== void 0 && this._$Em !== s) {
const i = o.getPropertyOptions(s), a = typeof i.converter == "function" ? { fromAttribute: i.converter } : ((r = i.converter) == null ? void 0 : r.fromAttribute) !== void 0 ? i.converter : y;
this._$Em = s, this[s] = a.fromAttribute(e, i.type), this._$Em = null;
}
}
requestUpdate(t, e, o) {
if (t !== void 0) {
if (o ?? (o = this.constructor.getPropertyOptions(t)), !(o.hasChanged ?? _)(this[t], e)) return;
this.P(t, e, o);
}
this.isUpdatePending === !1 && (this._$ES = this._$ET());
}
P(t, e, o) {
this._$AL.has(t) || this._$AL.set(t, e), o.reflect === !0 && this._$Em !== t && (this._$Ej ?? (this._$Ej = /* @__PURE__ */ new Set())).add(t);
}
async _$ET() {
this.isUpdatePending = !0;
try {
await this._$ES;
} catch (e) {
Promise.reject(e);
}
const t = this.scheduleUpdate();
return t != null && await t, !this.isUpdatePending;
}
scheduleUpdate() {
return this.performUpdate();
}
performUpdate() {
var o;
if (!this.isUpdatePending) return;
if (!this.hasUpdated) {
if (this.renderRoot ?? (this.renderRoot = this.createRenderRoot()), this._$Ep) {
for (const [r, i] of this._$Ep) this[r] = i;
this._$Ep = void 0;
}
const s = this.constructor.elementProperties;
if (s.size > 0) for (const [r, i] of s) i.wrapped !== !0 || this._$AL.has(r) || this[r] === void 0 || this.P(r, this[r], i);
}
let t = !1;
const e = this._$AL;
try {
t = this.shouldUpdate(e), t ? (this.willUpdate(e), (o = this._$EO) == null || o.forEach((s) => {
var r;
return (r = s.hostUpdate) == null ? void 0 : r.call(s);
}), this.update(e)) : this._$EU();
} catch (s) {
throw t = !1, this._$EU(), s;
}
t && this._$AE(e);
}
willUpdate(t) {
}
_$AE(t) {
var e;
(e = this._$EO) == null || e.forEach((o) => {
var s;
return (s = o.hostUpdated) == null ? void 0 : s.call(o);
}), this.hasUpdated || (this.hasUpdated = !0, this.firstUpdated(t)), this.updated(t);
}
_$EU() {
this._$AL = /* @__PURE__ */ new Map(), this.isUpdatePending = !1;
}
get updateComplete() {
return this.getUpdateComplete();
}
getUpdateComplete() {
return this._$ES;
}
shouldUpdate(t) {
return !0;
}
update(t) {
this._$Ej && (this._$Ej = this._$Ej.forEach((e) => this._$EC(e, this[e]))), this._$EU();
}
updated(t) {
}
firstUpdated(t) {
}
}
p.elementStyles = [], p.shadowRootOptions = { mode: "open" }, p[d("elementProperties")] = /* @__PURE__ */ new Map(), p[d("finalized")] = /* @__PURE__ */ new Map(), u == null || u({ ReactiveElement: p }), (l.reactiveElementVersions ?? (l.reactiveElementVersions = [])).push("2.0.4");
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const H = { attribute: !0, type: String, converter: y, reflect: !1, hasChanged: _ }, B = (n = H, t, e) => {
const { kind: o, metadata: s } = e;
let r = globalThis.litPropertyMetadata.get(s);
if (r === void 0 && globalThis.litPropertyMetadata.set(s, r = /* @__PURE__ */ new Map()), r.set(e.name, n), o === "accessor") {
const { name: i } = e;
return { set(a) {
const h = t.get.call(this);
t.set.call(this, a), this.requestUpdate(i, h, n);
}, init(a) {
return a !== void 0 && this.P(i, void 0, n), a;
} };
}
if (o === "setter") {
const { name: i } = e;
return function(a) {
const h = this[i];
t.call(this, a), this.requestUpdate(i, h, n);
};
}
throw Error("Unsupported decorator location: " + o);
};
function b(n) {
return (t, e) => typeof e == "object" ? B(n, t, e) : ((o, s, r) => {
const i = s.hasOwnProperty(r);
return s.constructor.createProperty(r, i ? { ...o, wrapped: !0 } : o), i ? Object.getOwnPropertyDescriptor(s, r) : void 0;
})(n, t, e);
}
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
function J(n) {
return b({ ...n, state: !0, attribute: !1 });
}
const K = U`
:host {
/* Global Footer Styles */
--_nys-globalfooter-text-color: var(
--nys-color-text,
var(--nys-color-neutral-900, #1b1b1b)
);
--_nys-globalfooter-link-color: var(
--nys-color-link-neutral,
var(--nys-color-neutral-900, #1b1b1b)
);
--_nys-globalfooter-background: var(
--nys-color-theme-weaker,
var(--nys-color-state-blue-50, #eff6fb)
);
--_nys-globalfooter-gap-spacing: var(--nys-space-300, 24px);
--_nys-globalfooter-padding: var(--nys-space-400, 32px);
--_nys-globalfooter-gutter: var(--nys-gutter-sm, 20px);
--_nys-globalfooter-font-size: var(
--nys-font-size-agency-xl,
var(--nys-font-size-2xl, 22px)
);
--_nys-globalfooter-font-size-links: var(
--nys-font-size-body-md,
var(--nys-font-size-md, 16px)
);
--_nys-globalfooter-lineheight: normal;
--_nys-globalfooter-font-weight-semibold: var(
--nys-font-weight-semibold,
600
);
--_nys-globalfooter-content-max-width: var(--nys-max-content-width, 1280px);
/* Agency Name */
--_nys-globalfooter-font-family-agency: var(
--nys-font-family-agency,
"D Sari",
Arial,
sans-serif
);
/* Links */
--_nys-globalfooter-link-gap-spacing-row: var(--nys-space-400, 32px);
--_nys-globalfooter-link-gap-spacing-column: var(--nys-space-400, 32px);
--_nys-globalfooter-lineheight-links: var(
--nys-font-lineheight-ui-md,
24px
);
--_nys-globalfooter-link-letterspacing: var(
--nys-font-letterspacing-ui-md,
var(--nys-font-letterspacing-400, 0.044px)
);
--_nys-globalfooter-link-font-family: var(
--nys-font-family-ui,
var(
--nys-font-family-sans,
"Proxima Nova",
"Helvetica Neue",
"Helvetica",
"Arial",
sans-serif
)
);
--_nys-globalfooter-link-weight-decoration: var(--nys-size-2px, 2px);
}
.nys-globalfooter {
display: flex;
padding: var(--_nys-globalfooter-padding) var(--_nys-globalfooter-gutter);
justify-content: center;
background-color: var(--_nys-globalfooter-background);
color: var(--_nys-globalfooter-text-color);
width: 100%;
box-sizing: border-box;
}
/* Main Container */
.nys-globalfooter__main-container {
display: flex;
flex-direction: column;
gap: var(--_nys-globalfooter-gap-spacing);
width: 100%;
max-width: var(--_nys-globalfooter-content-max-width);
}
/* The Agency Name */
.nys-globalfooter__name {
text-align: left;
margin: 0;
color: var(--_nys-globalfooter-text-color);
font-family: var(--_nys-globalfooter-font-family-agency);
font-size: var(--_nys-globalfooter-font-size);
font-style: normal;
font-weight: var(--_nys-globalfooter-font-weight-semibold);
line-height: var(--_nys-globalfooter-lineheight);
letter-spacing: normal;
}
/* Slotted content (menu links) basic resets */
ul {
list-style-type: none;
padding: 0;
margin: 0;
}
li {
margin: 0;
padding: 0;
}
a {
color: var(--_nys-globalfooter-link-color);
text-decoration: none;
font-family: var(--_nys-globalfooter-link-font-family);
font-size: var(--_nys-globalfooter-font-size-links);
font-style: normal;
font-weight: var(--_nys-globalfooter-font-weight-semibold);
line-height: var(--_nys-globalfooter-lineheight-links);
letter-spacing: var(--_nys-globalfooter-link-letterspacing);
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration-thickness: var(--_nys-globalfooter-link-weight-decoration);
}
/* Specific layout for menu links (grouped or singular list of menus) */
.nys-globalfooter__content {
width: 100%;
}
.nys-globalfooter__content ul {
display: flex;
gap: var(--_nys-globalfooter-link-gap-spacing-row)
var(--_nys-globalfooter-link-gap-spacing-column);
flex-wrap: wrap;
}
/* Breakpoints using NYSDS Guidelines (Menu Links) */
(min-width: 768px) {
/* Tablet (MD - Above 768px) */
:host {
--_nys-globalfooter-gutter: var(--nys-gutter-lg, 32px);
--_nys-globalfooter-link-gap-spacing-column: var(--nys-space-600, 48px);
}
}
(min-width: 1280px) {
/* Large Desktop (XL - Above 1280px) */
:host {
--_nys-globalfooter-gutter: var(--nys-gutter-xl, 64px);
}
}
`;
var W = Object.defineProperty, v = (n, t, e, o) => {
for (var s = void 0, r = n.length - 1, i; r >= 0; r--)
(i = n[r]) && (s = i(t, e, s) || s);
return s && W(t, e, s), s;
};
const E = class E extends A {
constructor() {
super(...arguments), this.agencyName = "", this.homepageLink = "", this.slotHasContent = !0;
}
/**************** Lifecycle Methods ****************/
firstUpdated() {
var e;
const t = (e = this.shadowRoot) == null ? void 0 : e.querySelector("slot");
t == null || t.addEventListener("slotchange", () => this._handleSlotChange()), this._handleSlotChange();
}
/******************** Functions ********************/
// Gets called when the slot content changes and directly appends the slotted elements into the shadow DOM
async _handleSlotChange() {
var r, i;
const t = (r = this.shadowRoot) == null ? void 0 : r.querySelector("slot");
if (!t) return;
const e = t == null ? void 0 : t.assignedNodes({ flatten: !0 }).filter((a) => a.nodeType === Node.ELEMENT_NODE);
await Promise.resolve(), this.slotHasContent = e.length > 0;
const o = (i = this.shadowRoot) == null ? void 0 : i.querySelector(
".nys-globalfooter__content"
), s = e == null ? void 0 : e.some(
(a) => a.tagName === "H4"
);
o && (o.classList.toggle("columns", s), o.classList.toggle("small", !s), o.innerHTML = "", e.forEach((a) => {
if (a.nodeType === Node.ELEMENT_NODE) {
const h = a.cloneNode(!0);
["script", "iframe", "object", "embed", "img"].forEach((k) => {
h.querySelectorAll(k).forEach((C) => C.remove());
}), o.appendChild(h), a.remove();
}
}));
}
render() {
var t, e;
return f`
<footer class="nys-globalfooter">
<div class="nys-globalfooter__main-container">
${(t = this.homepageLink) != null && t.trim() ? f`<a href=${(e = this.homepageLink) == null ? void 0 : e.trim()}>
<p class="nys-globalfooter__name">${this.agencyName}</p>
</a>` : f`<p class="nys-globalfooter__name">${this.agencyName}</p>`}
${this.slotHasContent ? f`<div class="nys-globalfooter__content">
<slot
style="display: hidden"
="${this._handleSlotChange}"
></slot>
</div>` : ""}
</div>
</footer>
`;
}
};
E.styles = K;
let c = E;
v([
b({ type: String })
], c.prototype, "agencyName");
v([
b({ type: String })
], c.prototype, "homepageLink");
v([
J()
], c.prototype, "slotHasContent");
customElements.get("nys-globalfooter") || customElements.define("nys-globalfooter", c);
export {
c as NysGlobalFooter
};
//# sourceMappingURL=nys-globalfooter.js.map