@justeattakeaway/pie-button 0.40.1 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +96 -95
- package/package.json +2 -2
- package/src/index.ts +9 -3
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { unsafeCSS as wt, LitElement as xt, html as N, nothing as
|
|
1
|
+
import { unsafeCSS as wt, LitElement as xt, html as N, nothing as W } from "lit";
|
|
2
2
|
import { property as h } from "lit/decorators.js";
|
|
3
3
|
import { ifDefined as Et } from "lit/directives/if-defined.js";
|
|
4
4
|
import { validPropertyValues as R, defineCustomElement as kt } from "@justeattakeaway/pie-webc-core";
|
|
@@ -16,7 +16,7 @@ const zt = ["xsmall", "small-productive", "small-expressive", "medium", "large"]
|
|
|
16
16
|
], Lt = ["leading", "trailing"], Pt = ["application/x-www-form-urlencoded", "multipart/form-data", "text/plain"], Dt = ["post", "get", "dialog"], $t = ["_self", "_blank", "_parent", "_top"], Ft = `*,*:before,*:after{box-sizing:border-box}.o-btn{--btn-border-radius: var(--dt-radius-rounded-e);--btn-font-family: var(--dt-font-interactive-m-family);--btn-font-weight: var(--dt-font-interactive-m-weight);--btn-bg-color: var(--dt-color-interactive-brand);--btn-text-color: var(--dt-color-content-interactive-primary);--btn-height--xsmall: 32px;--btn-height--small: 40px;--btn-height--medium: 48px;--btn-height--large: 56px;position:relative;display:flex;gap:var(--dt-spacing-b);align-items:center;justify-content:center;box-sizing:border-box;height:var(--btn-height);padding:var(--btn-padding);border:none;border-radius:var(--btn-border-radius);outline:none;background-color:var(--btn-bg-color);font-family:var(--btn-font-family);font-size:var(--btn-font-size);font-weight:var(--btn-font-weight);color:var(--btn-text-color);line-height:var(--btn-line-height);cursor:pointer;user-select:none;inline-size:var(--btn-inline-size)}.o-btn[variant=primary]:hover:not(:disabled){--hover-modifier: calc(-1 * var(--dt-color-hover-01));--btn-bg-color: hsl(var(--dt-color-interactive-brand-h), var(--dt-color-interactive-brand-s), calc(var(--dt-color-interactive-brand-l) + var(--hover-modifier)))}.o-btn[variant=primary]:active:not(:disabled),.o-btn[variant=primary][isLoading]:not(:disabled){--active-modifier: calc(-1 * var(--dt-color-active-01));--btn-bg-color: hsl(var(--dt-color-interactive-brand-h), var(--dt-color-interactive-brand-s), calc(var(--dt-color-interactive-brand-l) + var(--active-modifier)))}.o-btn[variant=primary][size=xsmall],.o-btn[variant=primary][size=small-productive]{--btn-bg-color: var(--dt-color-interactive-primary)}.o-btn[variant=primary][size=xsmall]:hover:not(:disabled),.o-btn[variant=primary][size=small-productive]:hover:not(:disabled){--hover-modifier: var(--dt-color-hover-02);--btn-bg-color: hsl(var(--dt-color-interactive-primary-h), var(--dt-color-interactive-primary-s), calc(var(--dt-color-interactive-primary-l) + var(--hover-modifier)))}.o-btn[variant=primary][size=xsmall]:active:not(:disabled),.o-btn[variant=primary][size=xsmall][isLoading]:not(:disabled),.o-btn[variant=primary][size=small-productive]:active:not(:disabled),.o-btn[variant=primary][size=small-productive][isLoading]:not(:disabled){--active-modifier: var(--dt-color-active-02);--btn-bg-color: hsl(var(--dt-color-interactive-primary-h), var(--dt-color-interactive-primary-s), calc(var(--dt-color-interactive-primary-l) + var(--active-modifier)))}.o-btn[variant=secondary]{--btn-bg-color: var(--dt-color-interactive-secondary);--btn-text-color: var(--dt-color-content-interactive-secondary)}.o-btn[variant=secondary]:hover:not(:disabled){--hover-modifier: calc(-1 * var(--dt-color-hover-01));--btn-bg-color: hsl(var(--dt-color-interactive-secondary-h), var(--dt-color-interactive-secondary-s), calc(var(--dt-color-interactive-secondary-l) + var(--hover-modifier)))}.o-btn[variant=secondary]:active:not(:disabled),.o-btn[variant=secondary][isLoading]:not(:disabled){--active-modifier: calc(-1 * var(--dt-color-active-01));--btn-bg-color: hsl(var(--dt-color-interactive-secondary-h), var(--dt-color-interactive-secondary-s), calc(var(--dt-color-interactive-secondary-l) + var(--active-modifier)))}.o-btn[variant=outline]{--btn-bg-color: transparent;--btn-text-color: var(--dt-color-content-interactive-secondary);border:1px solid var(--dt-color-border-strong)}.o-btn[variant=outline]:hover:not(:disabled){--hover-modifier: calc(-1 * var(--dt-color-hover-01));--hover-modifier: var(--dt-color-hover-01);--btn-bg-color: hsl(var(--dt-color-black-h), var(--dt-color-black-s), var(--dt-color-black-l), var(--hover-modifier))}.o-btn[variant=outline]:active:not(:disabled),.o-btn[variant=outline][isLoading]:not(:disabled){--active-modifier: calc(-1 * var(--dt-color-active-01));--active-modifier: var(--dt-color-active-01);--btn-bg-color: hsl(var(--dt-color-black-h), var(--dt-color-black-s), var(--dt-color-black-l), var(--active-modifier))}.o-btn[variant=ghost]{--btn-bg-color: transparent;--btn-text-color: var(--dt-color-content-link)}.o-btn[variant=ghost]:hover:not(:disabled){--hover-modifier: calc(-1 * var(--dt-color-hover-01));--hover-modifier: var(--dt-color-hover-01);--btn-bg-color: hsl(var(--dt-color-black-h), var(--dt-color-black-s), var(--dt-color-black-l), var(--hover-modifier))}.o-btn[variant=ghost]:active:not(:disabled),.o-btn[variant=ghost][isLoading]:not(:disabled){--active-modifier: calc(-1 * var(--dt-color-active-01));--active-modifier: var(--dt-color-active-01);--btn-bg-color: hsl(var(--dt-color-black-h), var(--dt-color-black-s), var(--dt-color-black-l), var(--active-modifier))}.o-btn[variant=inverse]{--btn-bg-color: var(--dt-color-interactive-inverse);--btn-text-color: var(--dt-color-content-interactive-secondary)}.o-btn[variant=inverse]:hover:not(:disabled){--hover-modifier: calc(-1 * var(--dt-color-hover-01));--btn-bg-color: hsl(var(--dt-color-interactive-inverse-h), var(--dt-color-interactive-inverse-s), calc(var(--dt-color-interactive-inverse-l) + var(--hover-modifier)))}.o-btn[variant=inverse]:active:not(:disabled),.o-btn[variant=inverse][isLoading]:not(:disabled){--active-modifier: calc(-1 * var(--dt-color-active-01));--btn-bg-color: hsl(var(--dt-color-interactive-inverse-h), var(--dt-color-interactive-inverse-s), calc(var(--dt-color-interactive-inverse-l) + var(--active-modifier)))}.o-btn[variant=ghost-inverse],.o-btn[variant=outline-inverse]{--btn-bg-color: transparent;--btn-text-color: var(--dt-color-content-interactive-primary)}.o-btn[variant=ghost-inverse]:hover:not(:disabled),.o-btn[variant=outline-inverse]:hover:not(:disabled){--hover-modifier: calc(-1 * var(--dt-color-hover-01));--hover-modifier: var(--dt-color-hover-01);--btn-bg-color: hsl(var(--dt-color-container-default-h), var(--dt-color-container-default-s), var(--dt-color-container-default-l), var(--hover-modifier))}.o-btn[variant=ghost-inverse]:active:not(:disabled),.o-btn[variant=ghost-inverse][isLoading]:not(:disabled),.o-btn[variant=outline-inverse]:active:not(:disabled),.o-btn[variant=outline-inverse][isLoading]:not(:disabled){--active-modifier: calc(-1 * var(--dt-color-active-01));--active-modifier: var(--dt-color-active-01);--btn-bg-color: hsl(var(--dt-color-container-default-h), var(--dt-color-container-default-s), var(--dt-color-container-default-l), var(--active-modifier))}.o-btn[variant=outline-inverse]{border:1px solid var(--dt-color-border-strong)}.o-btn[variant=destructive]{--btn-bg-color: var(--dt-color-support-error)}.o-btn[variant=destructive]:hover:not(:disabled){--hover-modifier: calc(-1 * var(--dt-color-hover-01));--btn-bg-color: hsl(var(--dt-color-support-error-h), var(--dt-color-support-error-s), calc(var(--dt-color-support-error-l) + var(--hover-modifier)))}.o-btn[variant=destructive]:active:not(:disabled),.o-btn[variant=destructive][isLoading]:not(:disabled){--active-modifier: calc(-1 * var(--dt-color-active-01));--btn-bg-color: hsl(var(--dt-color-support-error-h), var(--dt-color-support-error-s), calc(var(--dt-color-support-error-l) + var(--active-modifier)))}.o-btn[variant=destructive-ghost]{--btn-bg-color: transparent;--btn-text-color: var(--dt-color-content-interactive-error)}.o-btn[variant=destructive-ghost]:hover:not(:disabled){--hover-modifier: calc(-1 * var(--dt-color-hover-01));--hover-modifier: var(--dt-color-hover-01);--btn-bg-color: hsl(var(--dt-color-black-h), var(--dt-color-black-s), var(--dt-color-black-l), var(--hover-modifier))}.o-btn[variant=destructive-ghost]:active:not(:disabled),.o-btn[variant=destructive-ghost][isLoading]:not(:disabled){--active-modifier: calc(-1 * var(--dt-color-active-01));--active-modifier: var(--dt-color-active-01);--btn-bg-color: hsl(var(--dt-color-black-h), var(--dt-color-black-s), var(--dt-color-black-l), var(--active-modifier))}.o-btn[isFullWidth]{--btn-inline-size: 100%}.o-btn[disabled]{--btn-text-color: var(--dt-color-content-disabled) !important;cursor:not-allowed}.o-btn[disabled]:not([variant=ghost],[variant=ghost-inverse],[variant=destructive-ghost]){--btn-bg-color: var(--dt-color-disabled-01) !important}.o-btn[disabled][variant=outline]{border-color:var(--dt-color-disabled-01)!important}.o-btn[size=xsmall]{--btn-height: var(--btn-height--xsmall);--btn-padding: 6px var(--dt-spacing-b);--btn-font-size: calc(var(--dt-font-size-14) * 1px);--btn-line-height: calc(var(--dt-font-size-14-line-height) * 1px);--btn-icon-size: 16px}@media (min-width: 768px){.o-btn[size=xsmall][isResponsive]{--btn-height: var(--btn-height--small);--btn-padding: 8px var(--dt-spacing-d);--btn-font-size: calc(var(--dt-font-size-16) * 1px);--btn-line-height: calc(var(--dt-font-size-16-line-height) * 1px);--btn-icon-size: 20px}.o-btn[size=xsmall][isResponsive][responsiveSize=expressive]{--btn-height: var(--btn-height--small);--btn-padding: 6px var(--dt-spacing-d);--btn-font-size: calc(var(--dt-font-size-20) * 1px);--btn-line-height: calc(var(--dt-font-size-20-line-height) * 1px);--btn-icon-size: 20px}}.o-btn[size=small-expressive]{--btn-height: var(--btn-height--small);--btn-padding: 6px var(--dt-spacing-d);--btn-font-size: calc(var(--dt-font-size-20) * 1px);--btn-line-height: calc(var(--dt-font-size-20-line-height) * 1px);--btn-icon-size: 20px}@media (min-width: 768px){.o-btn[size=small-expressive][isResponsive]{--btn-height: var(--btn-height--medium);--btn-padding: 10px var(--dt-spacing-e);--btn-font-size: calc(var(--dt-font-size-20) * 1px);--btn-line-height: calc(var(--dt-font-size-20-line-height) * 1px);--btn-icon-size: 24px}}.o-btn[size=small-productive]{--btn-height: var(--btn-height--small);--btn-padding: 8px var(--dt-spacing-d);--btn-font-size: calc(var(--dt-font-size-16) * 1px);--btn-line-height: calc(var(--dt-font-size-16-line-height) * 1px);--btn-icon-size: 20px}@media (min-width: 768px){.o-btn[size=small-productive][isResponsive]{--btn-height: var(--btn-height--medium);--btn-padding: 10px var(--dt-spacing-e);--btn-font-size: calc(var(--dt-font-size-20) * 1px);--btn-line-height: calc(var(--dt-font-size-20-line-height) * 1px);--btn-icon-size: 24px}}.o-btn[size=medium]{--btn-height: var(--btn-height--medium);--btn-padding: 10px var(--dt-spacing-e);--btn-font-size: calc(var(--dt-font-size-20) * 1px);--btn-line-height: calc(var(--dt-font-size-20-line-height) * 1px);--btn-icon-size: 24px}@media (min-width: 768px){.o-btn[size=medium][isResponsive]{--btn-height: var(--btn-height--large);--btn-padding: 14px var(--dt-spacing-e);--btn-font-size: calc(var(--dt-font-size-20) * 1px);--btn-line-height: calc(var(--dt-font-size-20-line-height) * 1px);--btn-icon-size: 24px}}.o-btn[size=large]{--btn-height: var(--btn-height--large);--btn-padding: 14px var(--dt-spacing-e);--btn-font-size: calc(var(--dt-font-size-20) * 1px);--btn-line-height: calc(var(--dt-font-size-20-line-height) * 1px);--btn-icon-size: 24px}.o-btn[isLoading]>*:not(pie-spinner){visibility:hidden}.o-btn[isLoading] pie-spinner{position:absolute}.o-btn:focus-visible{box-shadow:0 0 0 2px var(--dt-color-focus-inner),0 0 0 4px var(--dt-color-focus-outer);outline:none}::slotted(svg){height:var(--btn-icon-size);width:var(--btn-icon-size)}
|
|
17
17
|
`;
|
|
18
18
|
(function() {
|
|
19
|
-
const p = /* @__PURE__ */ new WeakMap(), s = /* @__PURE__ */ new WeakMap(), a = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(),
|
|
19
|
+
const p = /* @__PURE__ */ new WeakMap(), s = /* @__PURE__ */ new WeakMap(), a = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new WeakMap(), f = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), H = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), F = /* @__PURE__ */ new WeakMap(), S = {
|
|
20
20
|
ariaAtomic: "aria-atomic",
|
|
21
21
|
ariaAutoComplete: "aria-autocomplete",
|
|
22
22
|
ariaBusy: "aria-busy",
|
|
@@ -73,11 +73,11 @@ const zt = ["xsmall", "small-productive", "small-expressive", "medium", "large"]
|
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
|
-
function
|
|
76
|
+
function U(i) {
|
|
77
77
|
const t = c.get(i), { form: e } = t;
|
|
78
|
-
|
|
78
|
+
Y(i, e, t), X(i, t.labels);
|
|
79
79
|
}
|
|
80
|
-
const
|
|
80
|
+
const j = (i, t = !1) => {
|
|
81
81
|
const e = document.createTreeWalker(i, NodeFilter.SHOW_ELEMENT, {
|
|
82
82
|
acceptNode(l) {
|
|
83
83
|
return c.has(l) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
@@ -87,10 +87,10 @@ const zt = ["xsmall", "small-productive", "small-expressive", "medium", "large"]
|
|
|
87
87
|
const o = !t || i.disabled;
|
|
88
88
|
for (; r; )
|
|
89
89
|
r.formDisabledCallback && o && D(r, i.disabled), r = e.nextNode();
|
|
90
|
-
},
|
|
90
|
+
}, G = { attributes: !0, attributeFilter: ["disabled", "name"] }, z = T() ? new MutationObserver((i) => {
|
|
91
91
|
for (const t of i) {
|
|
92
92
|
const e = t.target;
|
|
93
|
-
if (t.attributeName === "disabled" && (e.constructor.formAssociated ? D(e, e.hasAttribute("disabled")) : e.localName === "fieldset" &&
|
|
93
|
+
if (t.attributeName === "disabled" && (e.constructor.formAssociated ? D(e, e.hasAttribute("disabled")) : e.localName === "fieldset" && j(e)), t.attributeName === "name" && e.constructor.formAssociated) {
|
|
94
94
|
const r = c.get(e), o = M.get(e);
|
|
95
95
|
r.setFormValue(o);
|
|
96
96
|
}
|
|
@@ -100,11 +100,11 @@ const zt = ["xsmall", "small-productive", "small-expressive", "medium", "large"]
|
|
|
100
100
|
i.forEach((t) => {
|
|
101
101
|
const { addedNodes: e, removedNodes: r } = t, o = Array.from(e), l = Array.from(r);
|
|
102
102
|
o.forEach((n) => {
|
|
103
|
-
var
|
|
104
|
-
if (c.has(n) && n.constructor.formAssociated &&
|
|
103
|
+
var u;
|
|
104
|
+
if (c.has(n) && n.constructor.formAssociated && U(n), k.has(n)) {
|
|
105
105
|
const d = k.get(n);
|
|
106
|
-
Object.keys(S).filter((
|
|
107
|
-
n.setAttribute(S[
|
|
106
|
+
Object.keys(S).filter((w) => d[w] !== null).forEach((w) => {
|
|
107
|
+
n.setAttribute(S[w], d[w]);
|
|
108
108
|
}), k.delete(n);
|
|
109
109
|
}
|
|
110
110
|
if (F.has(n)) {
|
|
@@ -112,19 +112,19 @@ const zt = ["xsmall", "small-productive", "small-expressive", "medium", "large"]
|
|
|
112
112
|
n.setAttribute("internals-valid", d.validity.valid.toString()), n.setAttribute("internals-invalid", (!d.validity.valid).toString()), n.setAttribute("aria-invalid", (!d.validity.valid).toString()), F.delete(n);
|
|
113
113
|
}
|
|
114
114
|
if (n.localName === "form") {
|
|
115
|
-
const d =
|
|
116
|
-
acceptNode(
|
|
117
|
-
return c.has(
|
|
115
|
+
const d = y.get(n), E = document.createTreeWalker(n, NodeFilter.SHOW_ELEMENT, {
|
|
116
|
+
acceptNode(O) {
|
|
117
|
+
return c.has(O) && O.constructor.formAssociated && !(d && d.has(O)) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
118
118
|
}
|
|
119
119
|
});
|
|
120
|
-
let
|
|
121
|
-
for (;
|
|
122
|
-
|
|
120
|
+
let w = E.nextNode();
|
|
121
|
+
for (; w; )
|
|
122
|
+
U(w), w = E.nextNode();
|
|
123
123
|
}
|
|
124
|
-
n.localName === "fieldset" && ((
|
|
124
|
+
n.localName === "fieldset" && ((u = z.observe) == null || u.call(z, n, G), j(n, !0));
|
|
125
125
|
}), l.forEach((n) => {
|
|
126
|
-
const
|
|
127
|
-
|
|
126
|
+
const u = c.get(n);
|
|
127
|
+
u && a.get(u) && J(u), g.has(n) && g.get(n).disconnect();
|
|
128
128
|
});
|
|
129
129
|
});
|
|
130
130
|
}
|
|
@@ -132,15 +132,15 @@ const zt = ["xsmall", "small-productive", "small-expressive", "medium", "large"]
|
|
|
132
132
|
i.forEach((t) => {
|
|
133
133
|
const { removedNodes: e } = t;
|
|
134
134
|
e.forEach((r) => {
|
|
135
|
-
const o =
|
|
136
|
-
c.has(r) &&
|
|
135
|
+
const o = K.get(t.target);
|
|
136
|
+
c.has(r) && tt(r), o.disconnect();
|
|
137
137
|
});
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
140
|
const nt = (i) => {
|
|
141
141
|
var e;
|
|
142
142
|
const t = new MutationObserver(at);
|
|
143
|
-
(e = t.observe) == null || e.call(t, i, { childList: !0 }),
|
|
143
|
+
(e = t.observe) == null || e.call(t, i, { childList: !0 }), K.set(i, t);
|
|
144
144
|
};
|
|
145
145
|
T() && new MutationObserver(_);
|
|
146
146
|
const P = {
|
|
@@ -148,24 +148,24 @@ const zt = ["xsmall", "small-productive", "small-expressive", "medium", "large"]
|
|
|
148
148
|
subtree: !0
|
|
149
149
|
}, D = (i, t) => {
|
|
150
150
|
i.toggleAttribute("internals-disabled", t), t ? i.setAttribute("aria-disabled", "true") : i.removeAttribute("aria-disabled"), i.formDisabledCallback && i.formDisabledCallback.apply(i, [t]);
|
|
151
|
-
},
|
|
151
|
+
}, J = (i) => {
|
|
152
152
|
a.get(i).forEach((e) => {
|
|
153
153
|
e.remove();
|
|
154
154
|
}), a.set(i, []);
|
|
155
|
-
},
|
|
155
|
+
}, Q = (i, t) => {
|
|
156
156
|
const e = document.createElement("input");
|
|
157
157
|
return e.type = "hidden", e.name = i.getAttribute("name"), i.after(e), a.get(t).push(e), e;
|
|
158
158
|
}, st = (i, t) => {
|
|
159
159
|
var e;
|
|
160
|
-
a.set(t, []), (e = z.observe) == null || e.call(z, i,
|
|
161
|
-
},
|
|
160
|
+
a.set(t, []), (e = z.observe) == null || e.call(z, i, G);
|
|
161
|
+
}, X = (i, t) => {
|
|
162
162
|
if (t.length) {
|
|
163
163
|
Array.from(t).forEach((r) => r.addEventListener("click", i.click.bind(i)));
|
|
164
164
|
let e = t[0].id;
|
|
165
165
|
t[0].id || (e = `${t[0].htmlFor}_Label`, t[0].id = e), i.setAttribute("aria-labelledby", e);
|
|
166
166
|
}
|
|
167
167
|
}, A = (i) => {
|
|
168
|
-
const t = Array.from(i.elements).filter((l) => !l.tagName.includes("-") && l.validity).map((l) => l.validity.valid), e =
|
|
168
|
+
const t = Array.from(i.elements).filter((l) => !l.tagName.includes("-") && l.validity).map((l) => l.validity.valid), e = y.get(i) || [], r = Array.from(e).filter((l) => l.isConnected).map((l) => c.get(l).validity.valid), o = [...t, ...r].includes(!1);
|
|
169
169
|
i.toggleAttribute("internals-invalid", o), i.toggleAttribute("internals-valid", !o);
|
|
170
170
|
}, lt = (i) => {
|
|
171
171
|
A(I(i.target));
|
|
@@ -175,45 +175,45 @@ const zt = ["xsmall", "small-productive", "small-expressive", "medium", "large"]
|
|
|
175
175
|
const t = ["button[type=submit]", "input[type=submit]", "button:not([type])"].map((e) => `${e}:not([disabled])`).map((e) => `${e}:not([form])${i.id ? `,${e}[form='${i.id}']` : ""}`).join(",");
|
|
176
176
|
i.addEventListener("click", (e) => {
|
|
177
177
|
if (e.target.closest(t)) {
|
|
178
|
-
const o =
|
|
178
|
+
const o = y.get(i);
|
|
179
179
|
if (i.noValidate)
|
|
180
180
|
return;
|
|
181
|
-
o.size && Array.from(o).reverse().map((
|
|
181
|
+
o.size && Array.from(o).reverse().map((u) => c.get(u).reportValidity()).includes(!1) && e.preventDefault();
|
|
182
182
|
}
|
|
183
183
|
});
|
|
184
184
|
}, vt = (i) => {
|
|
185
|
-
const t =
|
|
185
|
+
const t = y.get(i.target);
|
|
186
186
|
t && t.size && t.forEach((e) => {
|
|
187
187
|
e.constructor.formAssociated && e.formResetCallback && e.formResetCallback.apply(e);
|
|
188
188
|
});
|
|
189
|
-
},
|
|
189
|
+
}, Y = (i, t, e) => {
|
|
190
190
|
if (t) {
|
|
191
|
-
const r =
|
|
191
|
+
const r = y.get(t);
|
|
192
192
|
if (r)
|
|
193
193
|
r.add(i);
|
|
194
194
|
else {
|
|
195
195
|
const o = /* @__PURE__ */ new Set();
|
|
196
|
-
o.add(i),
|
|
196
|
+
o.add(i), y.set(t, o), dt(t), t.addEventListener("reset", vt), t.addEventListener("input", lt), t.addEventListener("change", ct);
|
|
197
197
|
}
|
|
198
|
-
|
|
198
|
+
f.set(t, { ref: i, internals: e }), i.constructor.formAssociated && i.formAssociatedCallback && setTimeout(() => {
|
|
199
199
|
i.formAssociatedCallback.apply(i, [t]);
|
|
200
200
|
}, 0), A(t);
|
|
201
201
|
}
|
|
202
202
|
}, I = (i) => {
|
|
203
203
|
let t = i.parentNode;
|
|
204
204
|
return t && t.tagName !== "FORM" && (t = I(t)), t;
|
|
205
|
-
},
|
|
205
|
+
}, x = (i, t, e = DOMException) => {
|
|
206
206
|
if (!i.constructor.formAssociated)
|
|
207
207
|
throw new e(t);
|
|
208
|
-
},
|
|
209
|
-
const r =
|
|
208
|
+
}, Z = (i, t, e) => {
|
|
209
|
+
const r = y.get(i);
|
|
210
210
|
return r && r.size && r.forEach((o) => {
|
|
211
211
|
c.get(o)[e]() || (t = !1);
|
|
212
212
|
}), t;
|
|
213
|
-
},
|
|
213
|
+
}, tt = (i) => {
|
|
214
214
|
if (i.constructor.formAssociated) {
|
|
215
215
|
const t = c.get(i), { labels: e, form: r } = t;
|
|
216
|
-
|
|
216
|
+
X(i, e), Y(i, r, t);
|
|
217
217
|
}
|
|
218
218
|
};
|
|
219
219
|
function T() {
|
|
@@ -230,7 +230,7 @@ const zt = ["xsmall", "small-productive", "small-expressive", "medium", "large"]
|
|
|
230
230
|
e !== "valid" && i[e] !== !1 && (t = !1);
|
|
231
231
|
return t;
|
|
232
232
|
}, $ = /* @__PURE__ */ new WeakMap();
|
|
233
|
-
function
|
|
233
|
+
function et(i, t) {
|
|
234
234
|
i.toggleAttribute(t, !0), i.part && i.part.add(t);
|
|
235
235
|
}
|
|
236
236
|
class V extends Set {
|
|
@@ -246,8 +246,8 @@ const zt = ["xsmall", "small-productive", "small-expressive", "medium", "large"]
|
|
|
246
246
|
if (!/^--/.test(t) || typeof t != "string")
|
|
247
247
|
throw new DOMException(`Failed to execute 'add' on 'CustomStateSet': The specified value ${t} must start with '--'.`);
|
|
248
248
|
const e = super.add(t), r = $.get(this), o = `state${t}`;
|
|
249
|
-
return r.isConnected ?
|
|
250
|
-
|
|
249
|
+
return r.isConnected ? et(r, o) : setTimeout(() => {
|
|
250
|
+
et(r, o);
|
|
251
251
|
}), e;
|
|
252
252
|
}
|
|
253
253
|
clear() {
|
|
@@ -262,7 +262,7 @@ const zt = ["xsmall", "small-productive", "small-expressive", "medium", "large"]
|
|
|
262
262
|
}), e;
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
|
-
function
|
|
265
|
+
function it(i, t, e, r) {
|
|
266
266
|
if (e === "a" && !r)
|
|
267
267
|
throw new TypeError("Private accessor was defined without a getter");
|
|
268
268
|
if (typeof t == "function" ? i !== t || !r : !t.has(i))
|
|
@@ -289,10 +289,10 @@ const zt = ["xsmall", "small-productive", "small-expressive", "medium", "large"]
|
|
|
289
289
|
Object.freeze(this);
|
|
290
290
|
}
|
|
291
291
|
get length() {
|
|
292
|
-
return
|
|
292
|
+
return it(this, C, "f").length;
|
|
293
293
|
}
|
|
294
294
|
[(C = /* @__PURE__ */ new WeakMap(), Symbol.iterator)]() {
|
|
295
|
-
return
|
|
295
|
+
return it(this, C, "f")[Symbol.iterator]();
|
|
296
296
|
}
|
|
297
297
|
item(t) {
|
|
298
298
|
return this[t] == null ? null : this[t];
|
|
@@ -308,24 +308,24 @@ const zt = ["xsmall", "small-productive", "small-expressive", "medium", "large"]
|
|
|
308
308
|
HTMLFormElement.prototype.reportValidity = r;
|
|
309
309
|
function e(...l) {
|
|
310
310
|
let n = i.apply(this, l);
|
|
311
|
-
return
|
|
311
|
+
return Z(this, n, "checkValidity");
|
|
312
312
|
}
|
|
313
313
|
function r(...l) {
|
|
314
314
|
let n = t.apply(this, l);
|
|
315
|
-
return
|
|
315
|
+
return Z(this, n, "reportValidity");
|
|
316
316
|
}
|
|
317
317
|
const { get: o } = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, "elements");
|
|
318
318
|
Object.defineProperty(HTMLFormElement.prototype, "elements", {
|
|
319
319
|
get(...l) {
|
|
320
|
-
const n = o.call(this, ...l),
|
|
321
|
-
if (
|
|
320
|
+
const n = o.call(this, ...l), u = Array.from(y.get(this) || []);
|
|
321
|
+
if (u.length === 0)
|
|
322
322
|
return n;
|
|
323
|
-
const d = Array.from(n).concat(
|
|
323
|
+
const d = Array.from(n).concat(u).sort((E, w) => E.compareDocumentPosition ? E.compareDocumentPosition(w) & 2 ? 1 : -1 : 0);
|
|
324
324
|
return new ft(d);
|
|
325
325
|
}
|
|
326
326
|
});
|
|
327
327
|
}
|
|
328
|
-
class
|
|
328
|
+
class rt {
|
|
329
329
|
static get isPolyfilled() {
|
|
330
330
|
return !0;
|
|
331
331
|
}
|
|
@@ -337,7 +337,7 @@ const zt = ["xsmall", "small-productive", "small-expressive", "medium", "large"]
|
|
|
337
337
|
}
|
|
338
338
|
checkValidity() {
|
|
339
339
|
const t = p.get(this);
|
|
340
|
-
if (
|
|
340
|
+
if (x(t, "Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
|
|
341
341
|
return !0;
|
|
342
342
|
const e = s.get(this);
|
|
343
343
|
if (!e.valid) {
|
|
@@ -352,36 +352,36 @@ const zt = ["xsmall", "small-productive", "small-expressive", "medium", "large"]
|
|
|
352
352
|
}
|
|
353
353
|
get form() {
|
|
354
354
|
const t = p.get(this);
|
|
355
|
-
|
|
355
|
+
x(t, "Failed to read the 'form' property from 'ElementInternals': The target element is not a form-associated custom element.");
|
|
356
356
|
let e;
|
|
357
357
|
return t.constructor.formAssociated === !0 && (e = I(t)), e;
|
|
358
358
|
}
|
|
359
359
|
get labels() {
|
|
360
360
|
const t = p.get(this);
|
|
361
|
-
|
|
361
|
+
x(t, "Failed to read the 'labels' property from 'ElementInternals': The target element is not a form-associated custom element.");
|
|
362
362
|
const e = t.getAttribute("id"), r = t.getRootNode();
|
|
363
363
|
return r && e ? r.querySelectorAll(`[for="${e}"]`) : [];
|
|
364
364
|
}
|
|
365
365
|
reportValidity() {
|
|
366
366
|
const t = p.get(this);
|
|
367
|
-
if (
|
|
367
|
+
if (x(t, "Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
|
|
368
368
|
return !0;
|
|
369
|
-
const e = this.checkValidity(), r =
|
|
369
|
+
const e = this.checkValidity(), r = B.get(this);
|
|
370
370
|
if (r && !t.constructor.formAssociated)
|
|
371
371
|
throw new DOMException("Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element.");
|
|
372
372
|
return !e && r && (t.focus(), r.focus()), e;
|
|
373
373
|
}
|
|
374
374
|
setFormValue(t) {
|
|
375
375
|
const e = p.get(this);
|
|
376
|
-
if (
|
|
376
|
+
if (x(e, "Failed to execute 'setFormValue' on 'ElementInternals': The target element is not a form-associated custom element."), J(this), t != null && !(t instanceof FormData)) {
|
|
377
377
|
if (e.getAttribute("name")) {
|
|
378
|
-
const r =
|
|
378
|
+
const r = Q(e, this);
|
|
379
379
|
r.value = t;
|
|
380
380
|
}
|
|
381
381
|
} else
|
|
382
382
|
t != null && t instanceof FormData && Array.from(t).reverse().forEach(([r, o]) => {
|
|
383
383
|
if (typeof o == "string") {
|
|
384
|
-
const l =
|
|
384
|
+
const l = Q(e, this);
|
|
385
385
|
l.name = r, l.value = o;
|
|
386
386
|
}
|
|
387
387
|
});
|
|
@@ -389,35 +389,35 @@ const zt = ["xsmall", "small-productive", "small-expressive", "medium", "large"]
|
|
|
389
389
|
}
|
|
390
390
|
setValidity(t, e, r) {
|
|
391
391
|
const o = p.get(this);
|
|
392
|
-
if (
|
|
392
|
+
if (x(o, "Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !t)
|
|
393
393
|
throw new TypeError("Failed to execute 'setValidity' on 'ElementInternals': 1 argument required, but only 0 present.");
|
|
394
|
-
|
|
394
|
+
B.set(this, r);
|
|
395
395
|
const l = s.get(this), n = {};
|
|
396
|
-
for (const
|
|
397
|
-
n[
|
|
396
|
+
for (const E in t)
|
|
397
|
+
n[E] = t[E];
|
|
398
398
|
Object.keys(n).length === 0 && mt(l);
|
|
399
|
-
const
|
|
400
|
-
delete
|
|
401
|
-
const { valid: d } = pt(l,
|
|
399
|
+
const u = { ...l, ...n };
|
|
400
|
+
delete u.valid;
|
|
401
|
+
const { valid: d } = pt(l, u, this.form);
|
|
402
402
|
if (!d && !e)
|
|
403
403
|
throw new DOMException("Failed to execute 'setValidity' on 'ElementInternals': The second argument should not be empty if one or more flags in the first argument are true.");
|
|
404
|
-
|
|
404
|
+
b.set(this, d ? "" : e), o.isConnected ? (o.toggleAttribute("internals-invalid", !d), o.toggleAttribute("internals-valid", d), o.setAttribute("aria-invalid", `${!d}`)) : F.set(o, this);
|
|
405
405
|
}
|
|
406
406
|
get shadowRoot() {
|
|
407
|
-
const t = p.get(this), e =
|
|
407
|
+
const t = p.get(this), e = H.get(t);
|
|
408
408
|
return e || null;
|
|
409
409
|
}
|
|
410
410
|
get validationMessage() {
|
|
411
411
|
const t = p.get(this);
|
|
412
|
-
return
|
|
412
|
+
return x(t, "Failed to read the 'validationMessage' property from 'ElementInternals': The target element is not a form-associated custom element."), b.get(this);
|
|
413
413
|
}
|
|
414
414
|
get validity() {
|
|
415
415
|
const t = p.get(this);
|
|
416
|
-
return
|
|
416
|
+
return x(t, "Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element."), s.get(this);
|
|
417
417
|
}
|
|
418
418
|
get willValidate() {
|
|
419
419
|
const t = p.get(this);
|
|
420
|
-
return
|
|
420
|
+
return x(t, "Failed to read the 'willValidate' property from 'ElementInternals': The target element is not a form-associated custom element."), !(t.disabled || t.hasAttribute("disabled") || t.hasAttribute("readonly"));
|
|
421
421
|
}
|
|
422
422
|
}
|
|
423
423
|
function yt() {
|
|
@@ -454,13 +454,13 @@ const zt = ["xsmall", "small-productive", "small-expressive", "medium", "large"]
|
|
|
454
454
|
};
|
|
455
455
|
}
|
|
456
456
|
} else {
|
|
457
|
-
if (typeof window < "u" && (window.ElementInternals =
|
|
457
|
+
if (typeof window < "u" && (window.ElementInternals = rt), typeof CustomElementRegistry < "u") {
|
|
458
458
|
const i = CustomElementRegistry.prototype.define;
|
|
459
459
|
CustomElementRegistry.prototype.define = function(t, e, r) {
|
|
460
460
|
if (e.formAssociated) {
|
|
461
461
|
const o = e.prototype.connectedCallback;
|
|
462
462
|
e.prototype.connectedCallback = function() {
|
|
463
|
-
|
|
463
|
+
q.has(this) || (q.set(this, !0), this.hasAttribute("disabled") && D(this, !0)), o != null && o.apply(this), tt(this);
|
|
464
464
|
};
|
|
465
465
|
}
|
|
466
466
|
i.call(this, t, e, r);
|
|
@@ -474,13 +474,13 @@ const zt = ["xsmall", "small-productive", "small-expressive", "medium", "large"]
|
|
|
474
474
|
return {};
|
|
475
475
|
if (c.has(this))
|
|
476
476
|
throw new DOMException("DOMException: Failed to execute 'attachInternals' on 'HTMLElement': ElementInternals for the specified element was already attached.");
|
|
477
|
-
return new
|
|
477
|
+
return new rt(this);
|
|
478
478
|
}), typeof Element < "u") {
|
|
479
479
|
let i = function(...e) {
|
|
480
480
|
const r = t.apply(this, e);
|
|
481
|
-
if (
|
|
481
|
+
if (H.set(this, r), T()) {
|
|
482
482
|
const o = new MutationObserver(_);
|
|
483
|
-
window.ShadyDOM ? o.observe(this, P) : o.observe(r, P),
|
|
483
|
+
window.ShadyDOM ? o.observe(this, P) : o.observe(r, P), g.set(this, o);
|
|
484
484
|
}
|
|
485
485
|
return r;
|
|
486
486
|
};
|
|
@@ -491,9 +491,9 @@ const zt = ["xsmall", "small-productive", "small-expressive", "medium", "large"]
|
|
|
491
491
|
}
|
|
492
492
|
})();
|
|
493
493
|
var St = Object.defineProperty, At = Object.getOwnPropertyDescriptor, m = (p, s, a, c) => {
|
|
494
|
-
for (var
|
|
495
|
-
(
|
|
496
|
-
return c &&
|
|
494
|
+
for (var b = c > 1 ? void 0 : c ? At(s, a) : s, f = p.length - 1, g; f >= 0; f--)
|
|
495
|
+
(g = p[f]) && (b = (c ? g(s, a, b) : g(b)) || b);
|
|
496
|
+
return c && b && St(s, a, b), b;
|
|
497
497
|
};
|
|
498
498
|
const L = "pie-button";
|
|
499
499
|
class v extends xt {
|
|
@@ -547,11 +547,12 @@ class v extends xt {
|
|
|
547
547
|
* @private
|
|
548
548
|
*/
|
|
549
549
|
renderSpinner() {
|
|
550
|
-
const
|
|
551
|
-
|
|
550
|
+
const { size: s, variant: a, disabled: c } = this, b = s.includes("small") ? "small" : "medium";
|
|
551
|
+
let f;
|
|
552
|
+
return c ? f = a === "ghost-inverse" ? "inverse" : "secondary" : f = ["primary", "destructive", "outline-inverse", "ghost-inverse"].includes(this.variant) ? "inverse" : "secondary", N`
|
|
552
553
|
<pie-spinner
|
|
553
|
-
size="${
|
|
554
|
-
variant="${
|
|
554
|
+
size="${b}"
|
|
555
|
+
variant="${f}"
|
|
555
556
|
</pie-spinner>`;
|
|
556
557
|
}
|
|
557
558
|
render() {
|
|
@@ -559,10 +560,10 @@ class v extends xt {
|
|
|
559
560
|
type: s,
|
|
560
561
|
disabled: a,
|
|
561
562
|
isFullWidth: c,
|
|
562
|
-
variant:
|
|
563
|
-
size:
|
|
564
|
-
isLoading:
|
|
565
|
-
isResponsive:
|
|
563
|
+
variant: b,
|
|
564
|
+
size: f,
|
|
565
|
+
isLoading: g,
|
|
566
|
+
isResponsive: y,
|
|
566
567
|
iconPlacement: M,
|
|
567
568
|
responsiveSize: k
|
|
568
569
|
} = this;
|
|
@@ -571,17 +572,17 @@ class v extends xt {
|
|
|
571
572
|
@click=${this._handleClick}
|
|
572
573
|
class="o-btn"
|
|
573
574
|
type=${s}
|
|
574
|
-
variant=${
|
|
575
|
-
size=${
|
|
575
|
+
variant=${b}
|
|
576
|
+
size=${f}
|
|
576
577
|
responsiveSize=${Et(k)}
|
|
577
578
|
?disabled=${a}
|
|
578
579
|
?isFullWidth=${c}
|
|
579
|
-
?isResponsive=${
|
|
580
|
-
?isLoading=${
|
|
581
|
-
${
|
|
582
|
-
${M === "leading" ? N`<slot name="icon"></slot>` :
|
|
580
|
+
?isResponsive=${y}
|
|
581
|
+
?isLoading=${g}>
|
|
582
|
+
${g ? this.renderSpinner() : W}
|
|
583
|
+
${M === "leading" ? N`<slot name="icon"></slot>` : W}
|
|
583
584
|
<slot></slot>
|
|
584
|
-
${M === "trailing" ? N`<slot name="icon"></slot>` :
|
|
585
|
+
${M === "trailing" ? N`<slot name="icon"></slot>` : W}
|
|
585
586
|
</button>`;
|
|
586
587
|
}
|
|
587
588
|
focus() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/pie-button",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.0",
|
|
4
4
|
"description": "PIE design system button built using web components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -39,6 +39,6 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@justeattakeaway/pie-spinner": "0.3.1",
|
|
41
41
|
"@justeattakeaway/pie-webc-core": "0.13.0",
|
|
42
|
-
"element-internals-polyfill": "1.3.
|
|
42
|
+
"element-internals-polyfill": "1.3.9"
|
|
43
43
|
}
|
|
44
44
|
}
|
package/src/index.ts
CHANGED
|
@@ -210,9 +210,15 @@ export class PieButton extends LitElement implements ButtonProps {
|
|
|
210
210
|
* @private
|
|
211
211
|
*/
|
|
212
212
|
private renderSpinner (): TemplateResult {
|
|
213
|
-
const
|
|
214
|
-
const
|
|
215
|
-
|
|
213
|
+
const { size, variant, disabled } = this;
|
|
214
|
+
const spinnerSize = size.includes('small') ? 'small' : 'medium'; // includes("small") matches for any small size value and xsmall
|
|
215
|
+
let spinnerVariant;
|
|
216
|
+
if (disabled) {
|
|
217
|
+
spinnerVariant = variant === 'ghost-inverse' ? 'inverse' : 'secondary';
|
|
218
|
+
} else {
|
|
219
|
+
const inverseVariants: ButtonProps['variant'][] = ['primary', 'destructive', 'outline-inverse', 'ghost-inverse'];
|
|
220
|
+
spinnerVariant = inverseVariants.includes(this.variant) ? 'inverse' : 'secondary';
|
|
221
|
+
}
|
|
216
222
|
|
|
217
223
|
return html`
|
|
218
224
|
<pie-spinner
|