UNPKG

@nysds/nys-button

Version:

The Button component from the NYS Design System.

1,203 lines (1,146 loc) 44.1 kB
import { css as lt, LitElement as ct, html as _ } from "lit"; /*! * * ▒█▄░▒█ ▒█░░▒█ ▒█▀▀▀█ ▒█▀▀▄ ▒█▀▀▀█ * ▒█▒█▒█ ▒█▄▄▄█ ░▀▀▀▄▄ ▒█░▒█ ░▀▀▀▄▄ * ▒█░░▀█ ░░▒█░░ ▒█▄▄▄█ ▒█▄▄▀ ▒█▄▄▄█ * * Button 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 D = globalThis, B = D.ShadowRoot && (D.ShadyCSS === void 0 || D.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype, st = Symbol(), q = /* @__PURE__ */ new WeakMap(); let ht = class { constructor(t, e, o) { if (this._$cssResult$ = !0, o !== st) 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 (B && t === void 0) { const o = e !== void 0 && e.length === 1; o && (t = q.get(e)), t === void 0 && ((this.o = t = new CSSStyleSheet()).replaceSync(this.cssText), o && q.set(e, t)); } return t; } toString() { return this.cssText; } }; const dt = (r) => new ht(typeof r == "string" ? r : r + "", void 0, st), ft = (r, t) => { if (B) r.adoptedStyleSheets = t.map((e) => e instanceof CSSStyleSheet ? e : e.styleSheet); else for (const e of t) { const o = document.createElement("style"), s = D.litNonce; s !== void 0 && o.setAttribute("nonce", s), o.textContent = e.cssText, r.appendChild(o); } }, K = B ? (r) => r : (r) => r instanceof CSSStyleSheet ? ((t) => { let e = ""; for (const o of t.cssRules) e += o.cssText; return dt(e); })(r) : r; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const { is: ut, defineProperty: yt, getOwnPropertyDescriptor: bt, getOwnPropertyNames: vt, getOwnPropertySymbols: pt, getPrototypeOf: _t } = Object, x = globalThis, Z = x.trustedTypes, gt = Z ? Z.emptyScript : "", V = x.reactiveElementPolyfillSupport, C = (r, t) => r, z = { toAttribute(r, t) { switch (t) { case Boolean: r = r ? gt : null; break; case Object: case Array: r = r == null ? r : JSON.stringify(r); } return r; }, fromAttribute(r, t) { let e = r; switch (t) { case Boolean: e = r !== null; break; case Number: e = r === null ? null : Number(r); break; case Object: case Array: try { e = JSON.parse(r); } catch { e = null; } } return e; } }, G = (r, t) => !ut(r, t), J = { attribute: !0, type: String, converter: z, reflect: !1, hasChanged: G }; Symbol.metadata ?? (Symbol.metadata = Symbol("metadata")), x.litPropertyMetadata ?? (x.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 = J) { 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 && yt(this.prototype, t, s); } } static getPropertyDescriptor(t, e, o) { const { get: s, set: i } = bt(this.prototype, t) ?? { get() { return this[e]; }, set(n) { this[e] = n; } }; return { get() { return s == null ? void 0 : s.call(this); }, set(n) { const l = s == null ? void 0 : s.call(this); i.call(this, n), this.requestUpdate(t, l, o); }, configurable: !0, enumerable: !0 }; } static getPropertyOptions(t) { return this.elementProperties.get(t) ?? J; } static _$Ei() { if (this.hasOwnProperty(C("elementProperties"))) return; const t = _t(this); t.finalize(), t.l !== void 0 && (this.l = [...t.l]), this.elementProperties = new Map(t.elementProperties); } static finalize() { if (this.hasOwnProperty(C("finalized"))) return; if (this.finalized = !0, this._$Ei(), this.hasOwnProperty(C("properties"))) { const e = this.properties, o = [...vt(e), ...pt(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(K(s)); } else t !== void 0 && e.push(K(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 ft(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 i; const o = this.constructor.elementProperties.get(t), s = this.constructor._$Eu(t, o); if (s !== void 0 && o.reflect === !0) { const n = (((i = o.converter) == null ? void 0 : i.toAttribute) !== void 0 ? o.converter : z).toAttribute(e, o.type); this._$Em = t, n == null ? this.removeAttribute(s) : this.setAttribute(s, n), this._$Em = null; } } _$AK(t, e) { var i; const o = this.constructor, s = o._$Eh.get(t); if (s !== void 0 && this._$Em !== s) { const n = o.getPropertyOptions(s), l = typeof n.converter == "function" ? { fromAttribute: n.converter } : ((i = n.converter) == null ? void 0 : i.fromAttribute) !== void 0 ? n.converter : z; this._$Em = s, this[s] = l.fromAttribute(e, n.type), this._$Em = null; } } requestUpdate(t, e, o) { if (t !== void 0) { if (o ?? (o = this.constructor.getPropertyOptions(t)), !(o.hasChanged ?? G)(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 [i, n] of this._$Ep) this[i] = n; this._$Ep = void 0; } const s = this.constructor.elementProperties; if (s.size > 0) for (const [i, n] of s) n.wrapped !== !0 || this._$AL.has(i) || this[i] === void 0 || this.P(i, this[i], n); } let t = !1; const e = this._$AL; try { t = this.shouldUpdate(e), t ? (this.willUpdate(e), (o = this._$EO) == null || o.forEach((s) => { var i; return (i = s.hostUpdate) == null ? void 0 : i.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[C("elementProperties")] = /* @__PURE__ */ new Map(), P[C("finalized")] = /* @__PURE__ */ new Map(), V == null || V({ ReactiveElement: P }), (x.reactiveElementVersions ?? (x.reactiveElementVersions = [])).push("2.0.4"); /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const $t = { attribute: !0, type: String, converter: z, reflect: !1, hasChanged: G }, mt = (r = $t, t, e) => { const { kind: o, metadata: s } = e; let i = globalThis.litPropertyMetadata.get(s); if (i === void 0 && globalThis.litPropertyMetadata.set(s, i = /* @__PURE__ */ new Map()), i.set(e.name, r), o === "accessor") { const { name: n } = e; return { set(l) { const a = t.get.call(this); t.set.call(this, l), this.requestUpdate(n, a, r); }, init(l) { return l !== void 0 && this.P(n, void 0, r), l; } }; } if (o === "setter") { const { name: n } = e; return function(l) { const a = this[n]; t.call(this, l), this.requestUpdate(n, a, r); }; } throw Error("Unsupported decorator location: " + o); }; function d(r) { return (t, e) => typeof e == "object" ? mt(r, t, e) : ((o, s, i) => { const n = s.hasOwnProperty(i); return s.constructor.createProperty(i, n ? { ...o, wrapped: !0 } : o), n ? Object.getOwnPropertyDescriptor(s, i) : void 0; })(r, t, e); } const xt = lt` :host { /* Anything that can be overridden should be defined here */ /* Global Button Styles */ --_nys-button-width: fit-content; --_nys-button-height: var(--nys-size-600, 48px); --_nys-button-radius-left: var(--nys-radius-xl, 12px); --_nys-button-radius-right: var(--nys-radius-xl, 12px); --_nys-button-padding-y: var(--nys-space-150, 12px); --_nys-button-padding-x: var(--nys-space-250, 20px); --_nys-button-gap: var(--nys-space-100, 8px); --_nys-button-width-border: var(--nys-border-width-md, 2px); --_nys-button-width-focus: var(--nys-border-width-md, 2px); --_nys-button-offset-focus: var(--nys-space-2px, 2px); --_nys-button-color-focus: var(--nys-color-focus, #004dd1); /* Global Button Colors */ --_nys-button-color-bg: var(--nys-color-theme, #154973); --_nys-button-color-text: var(--nys-color-text-reverse, #ffffff); --_nys-button-color-border: var(--nys-color-theme, #154973); --_nys-button-color-bg-hover: var(--nys-color-theme-strong, #0e324f); --_nys-button-color-text-hover: var(--nys-color-text-reverse, #ffffff); --_nys-button-color-border-hover: var(--nys-color-theme-strong, #0e324f); --_nys-button-color-bg-active: var(--nys-color-theme-stronger, #081b2b); --_nys-button-color-text-active: var(--nys-color-text-reverse, #ffffff); --_nys-button-color-border-active: var(--nys-color-theme-stronger, #081b2b); --_nys-button-color-bg-disabled: var(--nys-color-neutral-10, #f6f6f6); --_nys-button-color-text-disabled: var(--nys-color-text-disabled, #bec0c1); --_nys-button-color-border-disabled: var(--nys-color-neutral-10, #f6f6f6); /* Typography */ --_nys-button-font-size: var(--nys-font-size-ui-md, 16px); --_nys-button-font-weight: var(--nys-font-weight-semibold, 600); --_nys-button-line-height: var(--nys-font-lineheight-ui-md, 24px); --_nys-button-font-family: var( --nys-font-family-ui, var( --nys-font-family-sans, "Proxima Nova", "Helvetica Neue", "Helvetica", "Arial", sans-serif ) ); } /* Sizes */ :host([size="sm"]) { --_nys-button-height: var(--nys-size-500, 40px); --_nys-button-padding-y: var(--nys-space-100, 8px); --_nys-button-padding-x: var(--nys-space-200, 16px); } :host([size="md"]) { --_nys-button-height: var(--nys-size-600, 48px); --_nys-button-padding-y: var(--nys-space-150, 12px); --_nys-button-padding-x: var(--nys-space-250, 20px); } :host([size="lg"]) { --_nys-button-height: var(--nys-size-700, 56px); --_nys-button-padding-y: var(--nys-space-200, 16px); --_nys-button-padding-x: var(--nys-space-300, 24px); } :host([fullWidth]) { --_nys-button-width: 100%; } /* VARIANTS */ /* Filled */ :host([variant="filled"]) { /* Filled - Default */ --_nys-button-color-bg: var(--nys-color-theme, #154973); --_nys-button-color-text: var(--nys-color-text-reverse, #ffffff); --_nys-button-color-border: var(--nys-color-transparent, #ffffff00); /* Filled - Hover */ --_nys-button-color-bg-hover: var(--nys-color-theme-strong, #0e324f); --_nys-button-color-text-hover: var(--nys-color-text-reverse, #ffffff); --_nys-button-color-border: var(--nys-color-transparent, #ffffff00); /* Filled - Pressed/Active */ --_nys-button-color-bg-active: var(--nys-color-theme-stronger, #081b2b); --_nys-button-color-text-active: var(--nys-color-text-reverse, #ffffff); --_nys-button-color-border: var(--nys-color-transparent, #ffffff00); /* Filled - Disabled */ --_nys-button-color-bg-disabled: var(--nys-color-neutral-10, #f6f6f6); --_nys-button-color-text-disabled: var(--nys-color-text-disabled, #bec0c1); --_nys-button-color-border: var(--nys-color-transparent, #ffffff00); } /* Outline */ :host([variant="outline"]) { /* Outline - Default */ --_nys-button-color-bg: var(--nys-color-surface, #ffffff); --_nys-button-color-text: var(--nys-color-theme, #154973); --_nys-button-color-border: var(--nys-color-theme, #154973); /* Outline - Hover */ --_nys-button-color-bg-hover: var(--nys-color-theme-weaker, #eff6fb); --_nys-button-color-text-hover: var(--nys-color-theme, #154973); --_nys-button-color-border-hover: var(--nys-color-theme, #154973); /* Outline - Pressed/Active */ --_nys-button-color-bg-active: var(--nys-color-theme-weak, #cddde9); --_nys-button-color-text-active: var(--nys-color-theme, #154973); --_nys-button-color-border-active: var(--nys-color-theme, #154973); /* Outline - Disabled */ --_nys-button-color-bg-disabled: var(--nys-color-surface, #ffffff); --_nys-button-color-text-disabled: var(--nys-color-text-disabled, #bec0c1); --_nys-button-color-border-disabled: var(--nys-color-neutral-100, #d0d0ce); } /* Text */ :host([variant="text"]) { --_nys-button-height: fit-content; --_nys-button-radius-left: var(--nys-radius-md, 4px); --_nys-button-radius-right: var(--nys-radius-md, 4px); --_nys-button-padding-y: var(--nys-space-2px, 2px); --_nys-button-padding-x: var(--nys-space-50, 4px); --_nys-button-width-border: 0px; --_nys-button-text-decoration: underline; /* Text - Default */ --_nys-button-color-bg: var(--nys-color-transparent, #ffffff00); --_nys-button-color-text: var(--nys-color-link, #004dd1); --_nys-button-color-border: var(--nys-color-transparent, #ffffff00); /* Text - Hover */ --_nys-button-color-bg-hover: var(--nys-color-transparent, #ffffff00); --_nys-button-color-text-hover: var(--nys-color-link-strong, #003ba1); --_nys-button-color-border-hover: var(--nys-color-transparent, #ffffff00); /* Text - Pressed/Active */ --_nys-button-color-bg-active: var(--nys-color-transparent, #ffffff00); --_nys-button-color-text-active: var(--nys-color-link-strongest, #002971); --_nys-button-color-border-active: var(--nys-color-transparent, #ffffff00); /* Text - Disabled */ --_nys-button-color-bg-disabled: var(--nys-color-transparent, #ffffff00); --_nys-button-color-text-disabled: var(--nys-color-text-disabled, #bec0c1); --_nys-button-color-border-disabled: var( --nys-color-transparent, #ffffff00 ); } /* Ghost */ :host([variant="ghost"]) { /* Ghost - Default */ --_nys-button-color-bg: var(--nys-color-transparent, #ffffff00); --_nys-button-color-text: var(--nys-color-text, #1b1b1b); --_nys-button-color-border: var(--nys-color-transparent, #ffffff00); /* Ghost - Hover */ --_nys-button-color-bg-hover: var( --nys-color-black-transparent-100, #0000001a ); --_nys-button-color-text-hover: var(--nys-color-text, #1b1b1b); --_nys-button-color-border-hover: var(--nys-color-transparent, #ffffff00); /* Ghost - Active */ --_nys-button-color-bg-active: var( --nys-color-black-transparent-200, #00000033 ); --_nys-button-color-text-active: var(--nys-color-text, #1b1b1b); --_nys-button-color-border-active: var(--nys-color-transparent, #ffffff00); /* Ghost - Disabled */ --_nys-button-color-bg-disabled: var(--nys-color-transparent, #ffffff00); --_nys-button-color-text-disabled: var(--nys-color-text-disabled, #bec0c1); --_nys-button-color-border-disabled: var( --nys-color-transparent, #ffffff00 ); } /* INVERTED VARIANTS */ /* Filled Inverted */ :host([variant="filled"][inverted]) { /* Filled Inverted - Default */ --_nys-button-color-bg: var(--nys-color-surface, #ffffff); --_nys-button-color-text: var(--nys-color-text, #1b1b1b); --_nys-button-color-border-disabled: var( --nys-color-transparent, #ffffff00 ); /* Filled Inverted - Hover */ --_nys-button-color-bg-hover: var(--nys-color-neutral-100, #d0d0ce); --_nys-button-color-text-hover: var(--nys-color-text, #1b1b1b); --_nys-button-color-border-disabled: var( --nys-color-transparent, #ffffff00 ); /* Filled Inverted - Pressed/Active */ --_nys-button-color-bg-active: var(--nys-color-neutral-300, #a7a9ab); --_nys-button-color-text-active: var(--nys-color-text, #1b1b1b); --_nys-button-color-border-disabled: var( --nys-color-transparent, #ffffff00 ); /* Filled Inverted - Disabled */ --_nys-button-color-bg-disabled: var(--nys-color-text, #1b1b1b); --_nys-button-color-text-disabled: var(--nys-color-text-disabled, #62666a); --_nys-button-color-border-disabled: var( --nys-color-transparent, #ffffff00 ); } /* Outline Inverted */ :host([variant="outline"][inverted]) { /* Outline Inverted - Default */ --_nys-button-color-bg: var(--nys-color-surface-reverse, #1b1b1b); --_nys-button-color-text: var(--nys-color-text-reverse, #ffffff); --_nys-button-color-border: var(--nys-color-ink-reverse, #ffffff); /* Outline Inverted - Hover */ --_nys-button-color-bg-hover: var(--nys-color-surface-reverse, #1b1b1b); --_nys-button-color-text-hover: var(--nys-color-text-reverse-weak, #d0d0ce); --_nys-button-color-border-hover: var(--nys-color-neutral-100, #d0d0ce); /* Outline Inverted - Pressed/Active */ --_nys-button-color-bg-active: var(--nys-color-surface-reverse, #1b1b1b); --_nys-button-color-text-active: var( --nys-color-text-reverse-weaker, #bec0c1 ); --_nys-button-color-border-active: var(--nys-color-neutral-300, #a7a9ab); /* Outline Inverted - Disabled */ --_nys-button-color-bg-disabled: var(--nys-color-surface-reverse, #1b1b1b); --_nys-button-color-text-disabled: var( --nys-color-text-reverse-disabled, #62666a ); --_nys-button-color-border-disabled: var(--nys-color-neutral-600, #62666a); } /* Text Inverted */ :host([variant="text"][inverted]) { --_nys-button-height: fit-content; --_nys-button-radius-left: var(--nys-radius-md, 4px); --_nys-button-radius-right: var(--nys-radius-md, 4px); --_nys-button-padding-y: var(--nys-space-2px, 2px); --_nys-button-padding-x: var(--nys-space-50, 4px); --_nys-button-width-border: 0px; --_nys-button-text-decoration: underline; /* Text Inverted - Default */ --_nys-button-color-bg: var(--nys-color-transparent, #ffffff00); --_nys-button-color-text: var(--nys-color-link-reverse, #a7a9ab); --_nys-button-color-border: var(--nys-color-transparent, #ffffff00); /* Text Inverted - Hover */ --_nys-button-color-bg-hover: var(--nys-color-transparent, #ffffff00); --_nys-button-color-text-hover: var( --nys-color-link-reverse-strong, #ededed ); --_nys-button-color-border-hover: var(--nys-color-transparent, #ffffff00); /* Text Inverted - Pressed/Active */ --_nys-button-color-bg-active: var(--nys-color-transparent, #ffffff00); --_nys-button-color-text-active: var( --nys-color-reverse-strongest, #ffffff ); --_nys-button-color-border-active: var(--nys-color-transparent, #ffffff00); /* Text Inverted - Disabled */ --_nys-button-color-bg-disabled: var(--nys-color-transparent, #ffffff00); --_nys-button-color-text-disabled: var( --nys-color-text-reverse-disabled, #62666a ); --_nys-button-color-border-disabled: var( --nys-color-transparent, #ffffff00 ); } /* Ghost Inverted */ :host([variant="ghost"][inverted]) { /* Ghost Inverted - Default */ --_nys-button-color-bg: var(--nys-color-transparent, #ffffff00); --_nys-button-color-text: var(--nys-color-text-reverse, #ffffff); --_nys-button-color-border: var(--nys-color-transparent, #ffffff00); /* Ghost Inverted - Hover */ --_nys-button-color-bg-hover: var( --nys-color-white-transparent-100, #ffffff1a ); --_nys-button-color-text-hover: var(--nys-color-text-reverse, #ffffff); --_nys-button-color-border-hover: var(--nys-color-transparent, #ffffff00); /* Ghost Inverted - Pressed/Active */ --_nys-button-color-bg-active: var( --nys-color-white-transparent-200, #ffffff33 ); --_nys-button-color-text-active: var(--nys-color-text-reverse, #ffffff); --_nys-button-color-border-active: var(--nys-color-transparent, #ffffff00); /* Ghost Inverted - Disabled */ --_nys-button-color-bg-disabled: var(--nys-color-transparent, #ffffff00); --_nys-button-color-text-disabled: var(--nys-color-text-disabled, #62666a); --_nys-button-color-border-disabled: var( --nys-color-transparent, #ffffff00 ); } /* Circle */ :host([circle]) { --_nys-button-width: var(--_nys-button-height); --_nys-button-radius-left: var(--nys-radius-round, 1776px); --_nys-button-radius-right: var(--nys-radius-round, 1776px); --_nys-button-padding-y: 0; --_nys-button-padding-x: 0; } .nys-button { width: var(--_nys-button-width); min-height: var(--_nys-button-height); /* set every corner individually */ border-top-left-radius: var(--_nys-button-radius-left); border-bottom-left-radius: var(--_nys-button-radius-left); border-top-right-radius: var(--_nys-button-radius-right); border-bottom-right-radius: var(--_nys-button-radius-right); padding: var(--_nys-button-padding-y) var(--_nys-button-padding-x); display: flex; align-items: center; justify-content: center; gap: var(--_nys-button-gap); font-family: var(--_nys-button-font-family); font-size: var(--_nys-button-font-size); font-weight: var(--_nys-button-font-weight); line-height: var(--_nys-button-line-height); text-decoration: var(--_nys-button-text-decoration); box-sizing: border-box; background-color: var(--_nys-button-color-bg); color: var(--_nys-button-color-text); border: solid var(--_nys-button-width-border) var(--_nys-button-color-border); cursor: pointer; } :host([circle]) .nys-button { max-width: var(--_nys-button-height); max-height: var(--_nys-button-height); } .nys-button:hover { background-color: var(--_nys-button-color-bg-hover); color: var(--_nys-button-color-text-hover); border-color: var(--_nys-button-color-border-hover); } .nys-button:active { background-color: var(--_nys-button-color-bg-active); color: var(--_nys-button-color-text-active); border-color: var(--_nys-button-color-border-active); } .nys-button:disabled, a[disabled] { background-color: var(--_nys-button-color-bg-disabled); color: var(--_nys-button-color-text-disabled); border-color: var(--_nys-button-color-border-disabled); cursor: not-allowed; } .nys-button__linkwrapper:has([disabled]) { cursor: not-allowed; width: fit-content; } /* Remove click functionality from disabled link button */ a[disabled] { pointer-events: none; } a[disabled]:hover { background-color: var(--_nys-button-color-bg-disabled); color: var(--_nys-button-color-text-disabled); border-color: var(--_nys-button-color-border-disabled); } .nys-button * { cursor: pointer; } .nys-button:disabled * { cursor: not-allowed; } .nys-button:focus-visible { outline-offset: var(--_nys-button-offset-focus); outline: solid var(--_nys-button-width-focus) var(--_nys-button-color-focus); } .nys-button__text { display: flex; align-items: center; user-select: none; } `; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const T = globalThis, N = T.trustedTypes, Y = N ? N.createPolicy("lit-html", { createHTML: (r) => r }) : void 0, rt = "$lit$", m = `lit$${Math.random().toFixed(9).slice(2)}$`, nt = "?" + m, At = `<${nt}>`, w = document, M = () => w.createComment(""), k = (r) => r === null || typeof r != "object" && typeof r != "function", W = Array.isArray, St = (r) => W(r) || typeof (r == null ? void 0 : r[Symbol.iterator]) == "function", F = `[ \f\r]`, I = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, Q = /-->/g, X = />/g, A = RegExp(`>|${F}(?:([^\\s"'>=/]+)(${F}*=${F}*(?:[^ \f\r"'\`<>=]|("|')|))|$)`, "g"), tt = /'/g, et = /"/g, it = /^(?:script|style|textarea|title)$/i, O = Symbol.for("lit-noChange"), u = Symbol.for("lit-nothing"), ot = /* @__PURE__ */ new WeakMap(), S = w.createTreeWalker(w, 129); function at(r, t) { if (!W(r) || !r.hasOwnProperty("raw")) throw Error("invalid template strings array"); return Y !== void 0 ? Y.createHTML(t) : t; } const wt = (r, t) => { const e = r.length - 1, o = []; let s, i = t === 2 ? "<svg>" : t === 3 ? "<math>" : "", n = I; for (let l = 0; l < e; l++) { const a = r[l]; let y, b, c = -1, g = 0; for (; g < a.length && (n.lastIndex = g, b = n.exec(a), b !== null); ) g = n.lastIndex, n === I ? b[1] === "!--" ? n = Q : b[1] !== void 0 ? n = X : b[2] !== void 0 ? (it.test(b[2]) && (s = RegExp("</" + b[2], "g")), n = A) : b[3] !== void 0 && (n = A) : n === A ? b[0] === ">" ? (n = s ?? I, c = -1) : b[1] === void 0 ? c = -2 : (c = n.lastIndex - b[2].length, y = b[1], n = b[3] === void 0 ? A : b[3] === '"' ? et : tt) : n === et || n === tt ? n = A : n === Q || n === X ? n = I : (n = A, s = void 0); const $ = n === A && r[l + 1].startsWith("/>") ? " " : ""; i += n === I ? a + At : c >= 0 ? (o.push(y), a.slice(0, c) + rt + a.slice(c) + m + $) : a + m + (c === -2 ? l : $); } return [at(r, i + (r[e] || "<?>") + (t === 2 ? "</svg>" : t === 3 ? "</math>" : "")), o]; }; class U { constructor({ strings: t, _$litType$: e }, o) { let s; this.parts = []; let i = 0, n = 0; const l = t.length - 1, a = this.parts, [y, b] = wt(t, e); if (this.el = U.createElement(y, o), S.currentNode = this.el.content, e === 2 || e === 3) { const c = this.el.content.firstChild; c.replaceWith(...c.childNodes); } for (; (s = S.nextNode()) !== null && a.length < l; ) { if (s.nodeType === 1) { if (s.hasAttributes()) for (const c of s.getAttributeNames()) if (c.endsWith(rt)) { const g = b[n++], $ = s.getAttribute(c).split(m), H = /([.?@])?(.*)/.exec(g); a.push({ type: 1, index: i, name: H[2], strings: $, ctor: H[1] === "." ? Pt : H[1] === "?" ? It : H[1] === "@" ? Ct : L }), s.removeAttribute(c); } else c.startsWith(m) && (a.push({ type: 6, index: i }), s.removeAttribute(c)); if (it.test(s.tagName)) { const c = s.textContent.split(m), g = c.length - 1; if (g > 0) { s.textContent = N ? N.emptyScript : ""; for (let $ = 0; $ < g; $++) s.append(c[$], M()), S.nextNode(), a.push({ type: 2, index: ++i }); s.append(c[g], M()); } } } else if (s.nodeType === 8) if (s.data === nt) a.push({ type: 2, index: i }); else { let c = -1; for (; (c = s.data.indexOf(m, c + 1)) !== -1; ) a.push({ type: 7, index: i }), c += m.length - 1; } i++; } } static createElement(t, e) { const o = w.createElement("template"); return o.innerHTML = t, o; } } function E(r, t, e = r, o) { var n, l; if (t === O) return t; let s = o !== void 0 ? (n = e._$Co) == null ? void 0 : n[o] : e._$Cl; const i = k(t) ? void 0 : t._$litDirective$; return (s == null ? void 0 : s.constructor) !== i && ((l = s == null ? void 0 : s._$AO) == null || l.call(s, !1), i === void 0 ? s = void 0 : (s = new i(r), s._$AT(r, e, o)), o !== void 0 ? (e._$Co ?? (e._$Co = []))[o] = s : e._$Cl = s), s !== void 0 && (t = E(r, s._$AS(r, t.values), s, o)), t; } class Et { constructor(t, e) { this._$AV = [], this._$AN = void 0, this._$AD = t, this._$AM = e; } get parentNode() { return this._$AM.parentNode; } get _$AU() { return this._$AM._$AU; } u(t) { const { el: { content: e }, parts: o } = this._$AD, s = ((t == null ? void 0 : t.creationScope) ?? w).importNode(e, !0); S.currentNode = s; let i = S.nextNode(), n = 0, l = 0, a = o[0]; for (; a !== void 0; ) { if (n === a.index) { let y; a.type === 2 ? y = new R(i, i.nextSibling, this, t) : a.type === 1 ? y = new a.ctor(i, a.name, a.strings, this, t) : a.type === 6 && (y = new Tt(i, this, t)), this._$AV.push(y), a = o[++l]; } n !== (a == null ? void 0 : a.index) && (i = S.nextNode(), n++); } return S.currentNode = w, s; } p(t) { let e = 0; for (const o of this._$AV) o !== void 0 && (o.strings !== void 0 ? (o._$AI(t, o, e), e += o.strings.length - 2) : o._$AI(t[e])), e++; } } class R { get _$AU() { var t; return ((t = this._$AM) == null ? void 0 : t._$AU) ?? this._$Cv; } constructor(t, e, o, s) { this.type = 2, this._$AH = u, this._$AN = void 0, this._$AA = t, this._$AB = e, this._$AM = o, this.options = s, this._$Cv = (s == null ? void 0 : s.isConnected) ?? !0; } get parentNode() { let t = this._$AA.parentNode; const e = this._$AM; return e !== void 0 && (t == null ? void 0 : t.nodeType) === 11 && (t = e.parentNode), t; } get startNode() { return this._$AA; } get endNode() { return this._$AB; } _$AI(t, e = this) { t = E(this, t, e), k(t) ? t === u || t == null || t === "" ? (this._$AH !== u && this._$AR(), this._$AH = u) : t !== this._$AH && t !== O && this._(t) : t._$litType$ !== void 0 ? this.$(t) : t.nodeType !== void 0 ? this.T(t) : St(t) ? this.k(t) : this._(t); } O(t) { return this._$AA.parentNode.insertBefore(t, this._$AB); } T(t) { this._$AH !== t && (this._$AR(), this._$AH = this.O(t)); } _(t) { this._$AH !== u && k(this._$AH) ? this._$AA.nextSibling.data = t : this.T(w.createTextNode(t)), this._$AH = t; } $(t) { var i; const { values: e, _$litType$: o } = t, s = typeof o == "number" ? this._$AC(t) : (o.el === void 0 && (o.el = U.createElement(at(o.h, o.h[0]), this.options)), o); if (((i = this._$AH) == null ? void 0 : i._$AD) === s) this._$AH.p(e); else { const n = new Et(s, this), l = n.u(this.options); n.p(e), this.T(l), this._$AH = n; } } _$AC(t) { let e = ot.get(t.strings); return e === void 0 && ot.set(t.strings, e = new U(t)), e; } k(t) { W(this._$AH) || (this._$AH = [], this._$AR()); const e = this._$AH; let o, s = 0; for (const i of t) s === e.length ? e.push(o = new R(this.O(M()), this.O(M()), this, this.options)) : o = e[s], o._$AI(i), s++; s < e.length && (this._$AR(o && o._$AB.nextSibling, s), e.length = s); } _$AR(t = this._$AA.nextSibling, e) { var o; for ((o = this._$AP) == null ? void 0 : o.call(this, !1, !0, e); t && t !== this._$AB; ) { const s = t.nextSibling; t.remove(), t = s; } } setConnected(t) { var e; this._$AM === void 0 && (this._$Cv = t, (e = this._$AP) == null || e.call(this, t)); } } class L { get tagName() { return this.element.tagName; } get _$AU() { return this._$AM._$AU; } constructor(t, e, o, s, i) { this.type = 1, this._$AH = u, this._$AN = void 0, this.element = t, this.name = e, this._$AM = s, this.options = i, o.length > 2 || o[0] !== "" || o[1] !== "" ? (this._$AH = Array(o.length - 1).fill(new String()), this.strings = o) : this._$AH = u; } _$AI(t, e = this, o, s) { const i = this.strings; let n = !1; if (i === void 0) t = E(this, t, e, 0), n = !k(t) || t !== this._$AH && t !== O, n && (this._$AH = t); else { const l = t; let a, y; for (t = i[0], a = 0; a < i.length - 1; a++) y = E(this, l[o + a], e, a), y === O && (y = this._$AH[a]), n || (n = !k(y) || y !== this._$AH[a]), y === u ? t = u : t !== u && (t += (y ?? "") + i[a + 1]), this._$AH[a] = y; } n && !s && this.j(t); } j(t) { t === u ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, t ?? ""); } } class Pt extends L { constructor() { super(...arguments), this.type = 3; } j(t) { this.element[this.name] = t === u ? void 0 : t; } } class It extends L { constructor() { super(...arguments), this.type = 4; } j(t) { this.element.toggleAttribute(this.name, !!t && t !== u); } } class Ct extends L { constructor(t, e, o, s, i) { super(t, e, o, s, i), this.type = 5; } _$AI(t, e = this) { if ((t = E(this, t, e, 0) ?? u) === O) return; const o = this._$AH, s = t === u && o !== u || t.capture !== o.capture || t.once !== o.once || t.passive !== o.passive, i = t !== u && (o === u || s); s && this.element.removeEventListener(this.name, this, o), i && this.element.addEventListener(this.name, this, t), this._$AH = t; } handleEvent(t) { var e; typeof this._$AH == "function" ? this._$AH.call(((e = this.options) == null ? void 0 : e.host) ?? this.element, t) : this._$AH.handleEvent(t); } } class Tt { constructor(t, e, o) { this.element = t, this.type = 6, this._$AN = void 0, this._$AM = e, this.options = o; } get _$AU() { return this._$AM._$AU; } _$AI(t) { E(this, t); } } const j = T.litHtmlPolyfillSupport; j == null || j(U, R), (T.litHtmlVersions ?? (T.litHtmlVersions = [])).push("3.2.1"); /** * @license * Copyright 2018 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const p = (r) => r ?? u; var kt = Object.defineProperty, Ot = Object.getOwnPropertyDescriptor, f = (r, t, e, o) => { for (var s = o > 1 ? void 0 : o ? Ot(t, e) : t, i = r.length - 1, n; i >= 0; i--) (n = r[i]) && (s = (o ? n(t, e, s) : n(s)) || s); return o && s && kt(t, e, s), s; }; let Ut = 0; var v; const h = (v = class extends ct { // allows use of elementInternals' API constructor() { super(), this.id = "", this.name = "", this._size = "md", this.fullWidth = !1, this._variant = "filled", this.inverted = !1, this.label = "", this.ariaLabel = "", this.prefixIcon = "", this.suffixIcon = "", this.circle = !1, this.icon = "", this.disabled = !1, this.form = "", this.value = "", this.ariaDescription = "", this._type = "button", this.onClick = () => { }, this.href = "", this._target = "_self", this._internals = this.attachInternals(); } get size() { return this._size; } set size(t) { this._size = v.VALID_SIZES.includes( t ) ? t : "md"; } get variant() { return this._variant; } set variant(t) { this._variant = v.VALID_VARIANTS.includes( t ) ? t : "filled"; } get type() { return this._type; } set type(t) { this._type = v.VALID_TYPES.includes( t ) ? t : "button"; } get target() { return this._target; } set target(t) { this._target = v.VALID_TARGETS.includes( t ) ? t : "_self"; } connectedCallback() { super.connectedCallback(), this.id || (this.id = this._generateUniqueId()); } /******************** Functions ********************/ _generateUniqueId() { return `nys-button-${Date.now()}-${Ut++}`; } _manageFormAction(t) { typeof this.onClick == "function" && this.onClick(t); const e = this._internals.form; if (e) switch (this.type) { case "submit": e.requestSubmit(); break; case "reset": e.reset(); break; } } /******************** Event Handlers ********************/ // Handle focus event _handleFocus() { this.dispatchEvent(new Event("nys-focus")); } // Handle blur event _handleBlur() { this.dispatchEvent(new Event("nys-blur")); } _handleClick(t) { if (this.disabled) { t.preventDefault(); return; } this._manageFormAction(t), this.dispatchEvent(new Event("nys-click")); } // Handle keydown for keyboard accessibility _handleKeydown(t) { (t.code === "Space" || t.code === "Enter" || t.key === " " || t.key === "Enter") && (t.preventDefault(), this.disabled || this._manageFormAction(t)); } render() { return _` ${this.href ? _` <div class="nys-button__linkwrapper"> <a class="nys-button" id=${p(this.id)} name=${p(this.name ? this.name : void 0)} ?disabled=${this.disabled} aria-disabled="${this.disabled ? "true" : "false"}" form=${p(this.form ? this.form : void 0)} value=${p(this.value ? this.value : void 0)} href=${this.href} target=${this.target} aria-label=${p( this.ariaLabel || this.label || (this.circle ? this.icon : null) || "button" )} aria-description=${p(this.ariaDescription || void 0)} @click=${this._handleClick} @focus="${this._handleFocus}" @blur="${this._handleBlur}" > ${this.prefixIcon && this.variant !== "text" ? _`<slot name="prefix-icon"> <nys-icon size="16" name=${this.prefixIcon}></nys-icon> </slot>` : ""} ${this.label && !this.circle ? _`<label class="nys-button__text">${this.label}</label>` : ""} ${this.suffixIcon && this.variant !== "text" ? _`<slot name="suffix-icon"> <nys-icon size="16" name=${this.suffixIcon}></nys-icon> </slot>` : ""} ${this.circle && this.icon ? _`<slot name="circle-icon" ><nys-icon size=${this.size === "sm" ? "24" : this.size === "lg" ? "40" : "32"} name=${this.icon} ></nys-icon ></slot>` : ""} </a> </div> ` : _` <button class="nys-button" id=${p(this.id)} name=${p(this.name ? this.name : void 0)} ?disabled=${this.disabled} form=${p(this.form ? this.form : void 0)} value=${p(this.value ? this.value : void 0)} type=${this.type} aria-label=${p( this.ariaLabel || this.label || (this.circle ? this.icon : null) || this.prefixIcon || this.suffixIcon || "button" )} aria-description=${p(this.ariaDescription || void 0)} @click=${this._handleClick} @focus="${this._handleFocus}" @blur="${this._handleBlur}" @keydown="${this._handleKeydown}" > ${this.prefixIcon && this.variant !== "text" ? _`<slot name="prefix-icon"> <nys-icon size="16" name=${this.prefixIcon}></nys-icon> </slot>` : ""} ${this.label && !this.circle ? _`<label class="nys-button__text">${this.label}</label>` : ""} ${this.suffixIcon && this.variant !== "text" ? _`<slot name="suffix-icon"> <nys-icon size="16" name=${this.suffixIcon}></nys-icon> </slot>` : ""} ${this.circle && this.icon ? _`<slot name="circle-icon"> <nys-icon size=${this.size === "sm" ? "24" : this.size === "lg" ? "40" : "32"} name=${this.icon} ></nys-icon> </slot>` : ""} </button> `} `; } }, v.VALID_SIZES = ["sm", "md", "lg"], v.VALID_VARIANTS = [ "filled", "outline", "ghost", "text" ], v.VALID_TYPES = ["submit", "reset", "button"], v.VALID_TARGETS = [ "_self", "_blank", "_parent", "_top", "framename" ], v.styles = xt, v.formAssociated = !0, v); f([ d({ type: String }) ], h.prototype, "id", 2); f([ d({ type: String, reflect: !0 }) ], h.prototype, "name", 2); f([ d({ reflect: !0 }) ], h.prototype, "size", 1); f([ d({ type: Boolean, reflect: !0 }) ], h.prototype, "fullWidth", 2); f([ d({ reflect: !0 }) ], h.prototype, "variant", 1); f([ d({ type: Boolean, reflect: !0 }) ], h.prototype, "inverted", 2); f([ d({ type: String }) ], h.prototype, "label", 2); f([ d({ type: String }) ], h.prototype, "ariaLabel", 2); f([ d({ type: String }) ], h.prototype, "prefixIcon", 2); f([ d({ type: String }) ], h.prototype, "suffixIcon", 2); f([ d({ type: Boolean, reflect: !0 }) ], h.prototype, "circle", 2); f([ d({ type: String }) ], h.prototype, "icon", 2); f([ d({ type: Boolean, reflect: !0 }) ], h.prototype, "disabled", 2); f([ d({ type: String }) ], h.prototype, "form", 2); f([ d({ type: String }) ], h.prototype, "value", 2); f([ d({ type: String }) ], h.prototype, "ariaDescription", 2); f([ d({ reflect: !0 }) ], h.prototype, "type", 1); f([ d({ type: Function }) ], h.prototype, "onClick", 2); f([ d({ type: String }) ], h.prototype, "href", 2); f([ d({ reflect: !0 }) ], h.prototype, "target", 1); let Ht = h; customElements.get("nys-button") || customElements.define("nys-button", Ht); export { Ht as NysButton }; //# sourceMappingURL=nys-button.js.map