@phcdevworks/spectre-components 0.0.1
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/LICENSE +21 -0
- package/README.md +177 -0
- package/dist/button.cjs +288 -0
- package/dist/button.cjs.map +1 -0
- package/dist/button.d.cts +142 -0
- package/dist/button.d.ts +142 -0
- package/dist/button.js +282 -0
- package/dist/button.js.map +1 -0
- package/dist/checkbox.cjs +158 -0
- package/dist/checkbox.cjs.map +1 -0
- package/dist/checkbox.d.cts +98 -0
- package/dist/checkbox.d.ts +98 -0
- package/dist/checkbox.js +155 -0
- package/dist/checkbox.js.map +1 -0
- package/dist/fieldset.cjs +179 -0
- package/dist/fieldset.cjs.map +1 -0
- package/dist/fieldset.d.cts +63 -0
- package/dist/fieldset.d.ts +63 -0
- package/dist/fieldset.js +176 -0
- package/dist/fieldset.js.map +1 -0
- package/dist/index.cjs +1600 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +1576 -0
- package/dist/index.js.map +1 -0
- package/dist/input.cjs +235 -0
- package/dist/input.cjs.map +1 -0
- package/dist/input.d.cts +175 -0
- package/dist/input.d.ts +175 -0
- package/dist/input.js +230 -0
- package/dist/input.js.map +1 -0
- package/dist/label.cjs +156 -0
- package/dist/label.cjs.map +1 -0
- package/dist/label.d.cts +39 -0
- package/dist/label.d.ts +39 -0
- package/dist/label.js +153 -0
- package/dist/label.js.map +1 -0
- package/dist/radio.cjs +158 -0
- package/dist/radio.cjs.map +1 -0
- package/dist/radio.d.cts +98 -0
- package/dist/radio.d.ts +98 -0
- package/dist/radio.js +155 -0
- package/dist/radio.js.map +1 -0
- package/dist/select.cjs +272 -0
- package/dist/select.cjs.map +1 -0
- package/dist/select.d.cts +130 -0
- package/dist/select.d.ts +130 -0
- package/dist/select.js +268 -0
- package/dist/select.js.map +1 -0
- package/dist/textarea.cjs +423 -0
- package/dist/textarea.cjs.map +1 -0
- package/dist/textarea.d.cts +156 -0
- package/dist/textarea.d.ts +156 -0
- package/dist/textarea.js +420 -0
- package/dist/textarea.js.map +1 -0
- package/package.json +124 -0
package/dist/button.d.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { LitElement, TemplateResult } from 'lit';
|
|
2
|
+
|
|
3
|
+
declare const spectreButtonVariants: readonly ["primary", "secondary", "ghost", "danger", "success", "cta", "accent"];
|
|
4
|
+
declare const spectreButtonSizes: readonly ["sm", "md", "lg"];
|
|
5
|
+
declare const spectreButtonTypes: readonly ["button", "submit", "reset"];
|
|
6
|
+
type SpectreButtonVariant = (typeof spectreButtonVariants)[number];
|
|
7
|
+
type SpectreButtonSize = (typeof spectreButtonSizes)[number];
|
|
8
|
+
type SpectreButtonType = (typeof spectreButtonTypes)[number];
|
|
9
|
+
interface SpectreButtonProps {
|
|
10
|
+
autofocus?: boolean;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
fullWidth?: boolean;
|
|
13
|
+
label?: string;
|
|
14
|
+
loading?: boolean;
|
|
15
|
+
loadingLabel?: string;
|
|
16
|
+
name?: string;
|
|
17
|
+
pill?: boolean;
|
|
18
|
+
size?: SpectreButtonSize;
|
|
19
|
+
title?: string;
|
|
20
|
+
type?: SpectreButtonType;
|
|
21
|
+
variant?: SpectreButtonVariant;
|
|
22
|
+
value?: string;
|
|
23
|
+
}
|
|
24
|
+
declare class SpectreButtonElement extends LitElement implements SpectreButtonProps {
|
|
25
|
+
static properties: {
|
|
26
|
+
ariaLabel: {
|
|
27
|
+
attribute: string;
|
|
28
|
+
type: StringConstructor;
|
|
29
|
+
};
|
|
30
|
+
ariaLabelledBy: {
|
|
31
|
+
attribute: string;
|
|
32
|
+
type: StringConstructor;
|
|
33
|
+
};
|
|
34
|
+
ariaDescribedBy: {
|
|
35
|
+
attribute: string;
|
|
36
|
+
type: StringConstructor;
|
|
37
|
+
};
|
|
38
|
+
autofocus: {
|
|
39
|
+
type: BooleanConstructor;
|
|
40
|
+
reflect: boolean;
|
|
41
|
+
};
|
|
42
|
+
disabled: {
|
|
43
|
+
type: BooleanConstructor;
|
|
44
|
+
reflect: boolean;
|
|
45
|
+
};
|
|
46
|
+
fullWidth: {
|
|
47
|
+
attribute: string;
|
|
48
|
+
type: BooleanConstructor;
|
|
49
|
+
reflect: boolean;
|
|
50
|
+
};
|
|
51
|
+
label: {
|
|
52
|
+
type: StringConstructor;
|
|
53
|
+
reflect: boolean;
|
|
54
|
+
};
|
|
55
|
+
loading: {
|
|
56
|
+
type: BooleanConstructor;
|
|
57
|
+
reflect: boolean;
|
|
58
|
+
};
|
|
59
|
+
loadingLabel: {
|
|
60
|
+
attribute: string;
|
|
61
|
+
type: StringConstructor;
|
|
62
|
+
reflect: boolean;
|
|
63
|
+
};
|
|
64
|
+
name: {
|
|
65
|
+
type: StringConstructor;
|
|
66
|
+
reflect: boolean;
|
|
67
|
+
};
|
|
68
|
+
pill: {
|
|
69
|
+
type: BooleanConstructor;
|
|
70
|
+
reflect: boolean;
|
|
71
|
+
};
|
|
72
|
+
size: {
|
|
73
|
+
type: StringConstructor;
|
|
74
|
+
reflect: boolean;
|
|
75
|
+
};
|
|
76
|
+
title: {
|
|
77
|
+
type: StringConstructor;
|
|
78
|
+
reflect: boolean;
|
|
79
|
+
};
|
|
80
|
+
type: {
|
|
81
|
+
type: StringConstructor;
|
|
82
|
+
reflect: boolean;
|
|
83
|
+
};
|
|
84
|
+
variant: {
|
|
85
|
+
type: StringConstructor;
|
|
86
|
+
reflect: boolean;
|
|
87
|
+
};
|
|
88
|
+
value: {
|
|
89
|
+
type: StringConstructor;
|
|
90
|
+
reflect: boolean;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
ariaLabel: string | null;
|
|
94
|
+
ariaLabelledBy: string | null;
|
|
95
|
+
ariaDescribedBy: string | null;
|
|
96
|
+
autofocus: boolean;
|
|
97
|
+
disabled: boolean;
|
|
98
|
+
fullWidth: boolean;
|
|
99
|
+
label?: string;
|
|
100
|
+
loading: boolean;
|
|
101
|
+
loadingLabel: string;
|
|
102
|
+
name?: string;
|
|
103
|
+
pill: boolean;
|
|
104
|
+
size: SpectreButtonSize;
|
|
105
|
+
title: string;
|
|
106
|
+
type: SpectreButtonType;
|
|
107
|
+
variant: SpectreButtonVariant;
|
|
108
|
+
value?: string;
|
|
109
|
+
private _id?;
|
|
110
|
+
get id(): string;
|
|
111
|
+
set id(value: string);
|
|
112
|
+
private projectedContent;
|
|
113
|
+
private contentObserver?;
|
|
114
|
+
createRenderRoot(): this;
|
|
115
|
+
connectedCallback(): void;
|
|
116
|
+
getAttribute(qualifiedName: string): string | null;
|
|
117
|
+
hasAttribute(qualifiedName: string): boolean;
|
|
118
|
+
setAttribute(qualifiedName: string, value: string): void;
|
|
119
|
+
removeAttribute(qualifiedName: string): void;
|
|
120
|
+
disconnectedCallback(): void;
|
|
121
|
+
protected willUpdate(changedProperties: Map<PropertyKey, unknown>): void;
|
|
122
|
+
protected update(changedProperties: Map<PropertyKey, unknown>): void;
|
|
123
|
+
private get buttonClasses();
|
|
124
|
+
private get isDisabled();
|
|
125
|
+
private get hasProjectedContent();
|
|
126
|
+
private get visibleLabelFallback();
|
|
127
|
+
private get forwardedAriaLabel();
|
|
128
|
+
private get forwardedAriaLabelledBy();
|
|
129
|
+
private get forwardedAriaDescribedBy();
|
|
130
|
+
private startContentObserver;
|
|
131
|
+
private stopContentObserver;
|
|
132
|
+
private syncProjectedContent;
|
|
133
|
+
private isInternalButtonNode;
|
|
134
|
+
private get nativeButton();
|
|
135
|
+
focus(options?: FocusOptions): void;
|
|
136
|
+
blur(): void;
|
|
137
|
+
private renderButtonContent;
|
|
138
|
+
render(): TemplateResult<1>;
|
|
139
|
+
}
|
|
140
|
+
declare function defineSpectreButton(tagName?: string): typeof SpectreButtonElement;
|
|
141
|
+
|
|
142
|
+
export { SpectreButtonElement, type SpectreButtonProps, type SpectreButtonSize, type SpectreButtonType, type SpectreButtonVariant, defineSpectreButton, spectreButtonSizes, spectreButtonTypes, spectreButtonVariants };
|
package/dist/button.js
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { LitElement, nothing, html } from 'lit';
|
|
2
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
3
|
+
import { getButtonClasses } from '@phcdevworks/spectre-ui';
|
|
4
|
+
|
|
5
|
+
// src/components/button/sp-button.ts
|
|
6
|
+
var spectreButtonVariants = [
|
|
7
|
+
"primary",
|
|
8
|
+
"secondary",
|
|
9
|
+
"ghost",
|
|
10
|
+
"danger",
|
|
11
|
+
"success",
|
|
12
|
+
"cta",
|
|
13
|
+
"accent"
|
|
14
|
+
];
|
|
15
|
+
var spectreButtonSizes = ["sm", "md", "lg"];
|
|
16
|
+
var spectreButtonTypes = ["button", "submit", "reset"];
|
|
17
|
+
function isButtonVariant(value) {
|
|
18
|
+
return spectreButtonVariants.includes(value);
|
|
19
|
+
}
|
|
20
|
+
function isButtonSize(value) {
|
|
21
|
+
return spectreButtonSizes.includes(value);
|
|
22
|
+
}
|
|
23
|
+
function isButtonType(value) {
|
|
24
|
+
return spectreButtonTypes.includes(value);
|
|
25
|
+
}
|
|
26
|
+
function hasMeaningfulContent(nodes) {
|
|
27
|
+
return nodes.some((node) => {
|
|
28
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
32
|
+
return (node.textContent?.trim().length ?? 0) > 0;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
var SpectreButtonElement = class extends LitElement {
|
|
38
|
+
constructor() {
|
|
39
|
+
super(...arguments);
|
|
40
|
+
this.ariaLabel = null;
|
|
41
|
+
this.ariaLabelledBy = null;
|
|
42
|
+
this.ariaDescribedBy = null;
|
|
43
|
+
this.autofocus = false;
|
|
44
|
+
this.disabled = false;
|
|
45
|
+
this.fullWidth = false;
|
|
46
|
+
this.loading = false;
|
|
47
|
+
this.loadingLabel = "Loading";
|
|
48
|
+
this.pill = false;
|
|
49
|
+
this.size = "md";
|
|
50
|
+
this.title = "";
|
|
51
|
+
this.type = "button";
|
|
52
|
+
this.variant = "primary";
|
|
53
|
+
// Native slot projection is a Shadow DOM feature, so in light DOM we keep
|
|
54
|
+
// host-provided content reactive by tracking and reusing the host nodes.
|
|
55
|
+
this.projectedContent = [];
|
|
56
|
+
}
|
|
57
|
+
get id() {
|
|
58
|
+
return this._id ?? "";
|
|
59
|
+
}
|
|
60
|
+
set id(value) {
|
|
61
|
+
if ((this._id ?? "") === value) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this._id = value;
|
|
65
|
+
const host = this;
|
|
66
|
+
if (HTMLElement.prototype.hasAttribute.call(host, "id")) {
|
|
67
|
+
HTMLElement.prototype.removeAttribute.call(host, "id");
|
|
68
|
+
}
|
|
69
|
+
this.requestUpdate();
|
|
70
|
+
}
|
|
71
|
+
createRenderRoot() {
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
connectedCallback() {
|
|
75
|
+
super.connectedCallback();
|
|
76
|
+
const hostId = super.getAttribute("id");
|
|
77
|
+
if (hostId !== null) {
|
|
78
|
+
this.id = hostId;
|
|
79
|
+
}
|
|
80
|
+
this.syncProjectedContent();
|
|
81
|
+
this.startContentObserver();
|
|
82
|
+
}
|
|
83
|
+
getAttribute(qualifiedName) {
|
|
84
|
+
if (qualifiedName === "id") {
|
|
85
|
+
return this.id || null;
|
|
86
|
+
}
|
|
87
|
+
return super.getAttribute(qualifiedName);
|
|
88
|
+
}
|
|
89
|
+
hasAttribute(qualifiedName) {
|
|
90
|
+
if (qualifiedName === "id") {
|
|
91
|
+
return this.id !== "";
|
|
92
|
+
}
|
|
93
|
+
return super.hasAttribute(qualifiedName);
|
|
94
|
+
}
|
|
95
|
+
setAttribute(qualifiedName, value) {
|
|
96
|
+
if (qualifiedName === "id") {
|
|
97
|
+
this.id = value;
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
super.setAttribute(qualifiedName, value);
|
|
101
|
+
}
|
|
102
|
+
removeAttribute(qualifiedName) {
|
|
103
|
+
if (qualifiedName === "id") {
|
|
104
|
+
this.id = "";
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
super.removeAttribute(qualifiedName);
|
|
108
|
+
}
|
|
109
|
+
disconnectedCallback() {
|
|
110
|
+
this.stopContentObserver();
|
|
111
|
+
super.disconnectedCallback();
|
|
112
|
+
}
|
|
113
|
+
willUpdate(changedProperties) {
|
|
114
|
+
if (changedProperties.has("variant") && !isButtonVariant(this.variant)) {
|
|
115
|
+
this.variant = "primary";
|
|
116
|
+
}
|
|
117
|
+
if (changedProperties.has("size") && !isButtonSize(this.size)) {
|
|
118
|
+
this.size = "md";
|
|
119
|
+
}
|
|
120
|
+
if (changedProperties.has("type") && !isButtonType(this.type)) {
|
|
121
|
+
this.type = "button";
|
|
122
|
+
}
|
|
123
|
+
if (changedProperties.has("loadingLabel")) {
|
|
124
|
+
if (this.loadingLabel == null || this.loadingLabel.trim() === "") {
|
|
125
|
+
this.loadingLabel = "Loading";
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
update(changedProperties) {
|
|
130
|
+
this.stopContentObserver();
|
|
131
|
+
super.update(changedProperties);
|
|
132
|
+
this.startContentObserver();
|
|
133
|
+
}
|
|
134
|
+
get buttonClasses() {
|
|
135
|
+
return getButtonClasses({
|
|
136
|
+
disabled: this.isDisabled,
|
|
137
|
+
fullWidth: this.fullWidth,
|
|
138
|
+
loading: this.loading,
|
|
139
|
+
pill: this.pill,
|
|
140
|
+
size: this.size,
|
|
141
|
+
variant: this.variant
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
get isDisabled() {
|
|
145
|
+
return this.disabled || this.loading;
|
|
146
|
+
}
|
|
147
|
+
get hasProjectedContent() {
|
|
148
|
+
return hasMeaningfulContent(this.projectedContent);
|
|
149
|
+
}
|
|
150
|
+
get visibleLabelFallback() {
|
|
151
|
+
const trimmedLabel = this.label?.trim();
|
|
152
|
+
return trimmedLabel ? trimmedLabel : void 0;
|
|
153
|
+
}
|
|
154
|
+
get forwardedAriaLabel() {
|
|
155
|
+
const ariaLabel = this.ariaLabel?.trim();
|
|
156
|
+
return ariaLabel ? ariaLabel : void 0;
|
|
157
|
+
}
|
|
158
|
+
get forwardedAriaLabelledBy() {
|
|
159
|
+
const ariaLabelledBy = this.ariaLabelledBy?.trim();
|
|
160
|
+
return ariaLabelledBy ? ariaLabelledBy : void 0;
|
|
161
|
+
}
|
|
162
|
+
get forwardedAriaDescribedBy() {
|
|
163
|
+
const ariaDescribedBy = this.ariaDescribedBy?.trim();
|
|
164
|
+
return ariaDescribedBy ? ariaDescribedBy : void 0;
|
|
165
|
+
}
|
|
166
|
+
startContentObserver() {
|
|
167
|
+
if (this.contentObserver) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
this.contentObserver = new MutationObserver((mutations) => {
|
|
171
|
+
const isInternalMovement = mutations.every((mutation) => {
|
|
172
|
+
return Array.from(mutation.removedNodes).every(
|
|
173
|
+
(node) => this.isInternalButtonNode(node) || this.contains(node)
|
|
174
|
+
) && Array.from(mutation.addedNodes).every((node) => this.isInternalButtonNode(node));
|
|
175
|
+
});
|
|
176
|
+
if (isInternalMovement) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (this.syncProjectedContent()) {
|
|
180
|
+
this.requestUpdate();
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
this.contentObserver.observe(this, {
|
|
184
|
+
childList: true
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
stopContentObserver() {
|
|
188
|
+
this.contentObserver?.disconnect();
|
|
189
|
+
this.contentObserver = void 0;
|
|
190
|
+
}
|
|
191
|
+
syncProjectedContent() {
|
|
192
|
+
const nextProjectedContent = [];
|
|
193
|
+
Array.from(this.childNodes).forEach((node) => {
|
|
194
|
+
if (this.isInternalButtonNode(node)) {
|
|
195
|
+
this.projectedContent.forEach((pNode) => {
|
|
196
|
+
if (pNode.parentNode !== this && this.contains(pNode)) {
|
|
197
|
+
nextProjectedContent.push(pNode);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
} else {
|
|
201
|
+
nextProjectedContent.push(node);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
const hasChanged = nextProjectedContent.length !== this.projectedContent.length || nextProjectedContent.some((node, index) => node !== this.projectedContent[index]);
|
|
205
|
+
if (hasChanged) {
|
|
206
|
+
this.projectedContent = nextProjectedContent;
|
|
207
|
+
}
|
|
208
|
+
return hasChanged;
|
|
209
|
+
}
|
|
210
|
+
isInternalButtonNode(node) {
|
|
211
|
+
return node.nodeType === Node.ELEMENT_NODE && node.hasAttribute("data-sp-button-native");
|
|
212
|
+
}
|
|
213
|
+
get nativeButton() {
|
|
214
|
+
return this.querySelector("[data-sp-button-native]");
|
|
215
|
+
}
|
|
216
|
+
focus(options) {
|
|
217
|
+
this.nativeButton?.focus(options);
|
|
218
|
+
}
|
|
219
|
+
blur() {
|
|
220
|
+
this.nativeButton?.blur();
|
|
221
|
+
}
|
|
222
|
+
renderButtonContent() {
|
|
223
|
+
if (this.loading) {
|
|
224
|
+
return this.loadingLabel;
|
|
225
|
+
}
|
|
226
|
+
if (this.hasProjectedContent) {
|
|
227
|
+
return this.projectedContent;
|
|
228
|
+
}
|
|
229
|
+
return this.visibleLabelFallback ?? "";
|
|
230
|
+
}
|
|
231
|
+
render() {
|
|
232
|
+
return html`
|
|
233
|
+
<button
|
|
234
|
+
aria-busy=${this.loading ? "true" : "false"}
|
|
235
|
+
aria-describedby=${ifDefined(this.forwardedAriaDescribedBy)}
|
|
236
|
+
aria-label=${ifDefined(this.forwardedAriaLabel)}
|
|
237
|
+
aria-labelledby=${ifDefined(this.forwardedAriaLabelledBy)}
|
|
238
|
+
?autofocus=${this.autofocus}
|
|
239
|
+
class=${this.buttonClasses}
|
|
240
|
+
data-sp-button-native
|
|
241
|
+
?disabled=${this.isDisabled}
|
|
242
|
+
id=${ifDefined(this.id || void 0)}
|
|
243
|
+
name=${ifDefined(this.name)}
|
|
244
|
+
title=${ifDefined(this.title || void 0)}
|
|
245
|
+
type=${this.type}
|
|
246
|
+
value=${ifDefined(this.value)}
|
|
247
|
+
>
|
|
248
|
+
${this.renderButtonContent() || nothing}
|
|
249
|
+
</button>
|
|
250
|
+
`;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
SpectreButtonElement.properties = {
|
|
254
|
+
ariaLabel: { attribute: "aria-label", type: String },
|
|
255
|
+
ariaLabelledBy: { attribute: "aria-labelledby", type: String },
|
|
256
|
+
ariaDescribedBy: { attribute: "aria-describedby", type: String },
|
|
257
|
+
autofocus: { type: Boolean, reflect: true },
|
|
258
|
+
disabled: { type: Boolean, reflect: true },
|
|
259
|
+
fullWidth: { attribute: "full-width", type: Boolean, reflect: true },
|
|
260
|
+
label: { type: String, reflect: true },
|
|
261
|
+
loading: { type: Boolean, reflect: true },
|
|
262
|
+
loadingLabel: { attribute: "loading-label", type: String, reflect: true },
|
|
263
|
+
name: { type: String, reflect: true },
|
|
264
|
+
pill: { type: Boolean, reflect: true },
|
|
265
|
+
size: { type: String, reflect: true },
|
|
266
|
+
title: { type: String, reflect: true },
|
|
267
|
+
type: { type: String, reflect: true },
|
|
268
|
+
variant: { type: String, reflect: true },
|
|
269
|
+
value: { type: String, reflect: true }
|
|
270
|
+
};
|
|
271
|
+
function defineSpectreButton(tagName = "sp-button") {
|
|
272
|
+
const existingElement = customElements.get(tagName);
|
|
273
|
+
if (existingElement) {
|
|
274
|
+
return existingElement;
|
|
275
|
+
}
|
|
276
|
+
customElements.define(tagName, SpectreButtonElement);
|
|
277
|
+
return SpectreButtonElement;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export { SpectreButtonElement, defineSpectreButton, spectreButtonSizes, spectreButtonTypes, spectreButtonVariants };
|
|
281
|
+
//# sourceMappingURL=button.js.map
|
|
282
|
+
//# sourceMappingURL=button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/button/sp-button.ts"],"names":[],"mappings":";;;;;AASO,IAAM,qBAAA,GAAwB;AAAA,EACnC,SAAA;AAAA,EACA,WAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA;AAAA,EACA,SAAA;AAAA,EACA,KAAA;AAAA,EACA;AACF;AAEO,IAAM,kBAAA,GAAqB,CAAC,IAAA,EAAM,IAAA,EAAM,IAAI;AAC5C,IAAM,kBAAA,GAAqB,CAAC,QAAA,EAAU,QAAA,EAAU,OAAO;AAsB9D,SAAS,gBAAgB,KAAA,EAAuC;AAC9D,EAAA,OAAQ,qBAAA,CAA4C,SAAS,KAAK,CAAA;AACpE;AAEA,SAAS,aAAa,KAAA,EAAoC;AACxD,EAAA,OAAQ,kBAAA,CAAyC,SAAS,KAAK,CAAA;AACjE;AAEA,SAAS,aAAa,KAAA,EAA2C;AAC/D,EAAA,OAAQ,kBAAA,CAAyC,SAAS,KAAK,CAAA;AACjE;AAEA,SAAS,qBAAqB,KAAA,EAAiC;AAC7D,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,CAAC,IAAA,KAAS;AAC1B,IAAA,IAAI,IAAA,CAAK,QAAA,KAAa,IAAA,CAAK,YAAA,EAAc;AACvC,MAAA,OAAO,IAAA;AAAA,IACT;AAEA,IAAA,IAAI,IAAA,CAAK,QAAA,KAAa,IAAA,CAAK,SAAA,EAAW;AACpC,MAAA,OAAA,CAAQ,IAAA,CAAK,WAAA,EAAa,IAAA,EAAK,CAAE,UAAU,CAAA,IAAK,CAAA;AAAA,IAClD;AAEA,IAAA,OAAO,KAAA;AAAA,EACT,CAAC,CAAA;AACH;AAEO,IAAM,oBAAA,GAAN,cAAmC,UAAA,CAAyC;AAAA,EAA5E,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA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EACrC,IAAA,EAAM,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,IAAA,EAAK;AAAA,EACpC,KAAA,EAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,IAAA,EAAK;AAAA,EACrC,IAAA,EAAM,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,IAAA,EAAK;AAAA,EACpC,OAAA,EAAS,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,IAAA,EAAK;AAAA,EACvC,KAAA,EAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,IAAA;AAClC,CAAA;AAwRK,SAAS,mBAAA,CAAoB,UAAU,WAAA,EAA0C;AACtF,EAAA,MAAM,eAAA,GAAkB,cAAA,CAAe,GAAA,CAAI,OAAO,CAAA;AAElD,EAAA,IAAI,eAAA,EAAiB;AACnB,IAAA,OAAO,eAAA;AAAA,EACT;AAEA,EAAA,cAAA,CAAe,MAAA,CAAO,SAAS,oBAAoB,CAAA;AACnD,EAAA,OAAO,oBAAA;AACT","file":"button.js","sourcesContent":["import { LitElement, html, nothing, type TemplateResult } from 'lit';\nimport { ifDefined } from 'lit/directives/if-defined.js';\n\nimport {\n getButtonClasses,\n type ButtonSize,\n type ButtonVariant,\n} from '@phcdevworks/spectre-ui';\n\nexport const spectreButtonVariants = [\n 'primary',\n 'secondary',\n 'ghost',\n 'danger',\n 'success',\n 'cta',\n 'accent',\n] as const;\n\nexport const spectreButtonSizes = ['sm', 'md', 'lg'] as const;\nexport const spectreButtonTypes = ['button', 'submit', 'reset'] as const;\n\nexport type SpectreButtonVariant = (typeof spectreButtonVariants)[number];\nexport type SpectreButtonSize = (typeof spectreButtonSizes)[number];\nexport type SpectreButtonType = (typeof spectreButtonTypes)[number];\n\nexport interface SpectreButtonProps {\n autofocus?: boolean;\n disabled?: boolean;\n fullWidth?: boolean;\n label?: string;\n loading?: boolean;\n loadingLabel?: string;\n name?: string;\n pill?: boolean;\n size?: SpectreButtonSize;\n title?: string;\n type?: SpectreButtonType;\n variant?: SpectreButtonVariant;\n value?: string;\n}\n\nfunction isButtonVariant(value: string): value is ButtonVariant {\n return (spectreButtonVariants as readonly string[]).includes(value);\n}\n\nfunction isButtonSize(value: string): value is ButtonSize {\n return (spectreButtonSizes as readonly string[]).includes(value);\n}\n\nfunction isButtonType(value: string): value is SpectreButtonType {\n return (spectreButtonTypes as readonly string[]).includes(value);\n}\n\nfunction hasMeaningfulContent(nodes: readonly Node[]): boolean {\n return nodes.some((node) => {\n if (node.nodeType === Node.ELEMENT_NODE) {\n return true;\n }\n\n if (node.nodeType === Node.TEXT_NODE) {\n return (node.textContent?.trim().length ?? 0) > 0;\n }\n\n return false;\n });\n}\n\nexport class SpectreButtonElement extends LitElement implements SpectreButtonProps {\n static properties = {\n ariaLabel: { attribute: 'aria-label', type: String },\n ariaLabelledBy: { attribute: 'aria-labelledby', type: String },\n ariaDescribedBy: { attribute: 'aria-describedby', type: String },\n autofocus: { type: Boolean, reflect: true },\n disabled: { type: Boolean, reflect: true },\n fullWidth: { attribute: 'full-width', type: Boolean, reflect: true },\n label: { type: String, reflect: true },\n loading: { type: Boolean, reflect: true },\n loadingLabel: { attribute: 'loading-label', type: String, reflect: true },\n name: { type: String, reflect: true },\n pill: { type: Boolean, reflect: true },\n size: { type: String, reflect: true },\n title: { type: String, reflect: true },\n type: { type: String, reflect: true },\n variant: { type: String, reflect: true },\n value: { type: String, reflect: true },\n };\n\n ariaLabel: string | null = null;\n ariaLabelledBy: string | null = null;\n ariaDescribedBy: string | null = null;\n autofocus = false;\n disabled = false;\n fullWidth = false;\n label?: string;\n loading = false;\n loadingLabel = 'Loading';\n name?: string;\n pill = false;\n size: SpectreButtonSize = 'md';\n override title = '';\n type: SpectreButtonType = 'button';\n variant: SpectreButtonVariant = 'primary';\n value?: string;\n private _id?: string;\n\n override get id(): string {\n return this._id ?? '';\n }\n\n override set id(value: string) {\n if ((this._id ?? '') === value) {\n return;\n }\n\n this._id = value;\n\n const host = this as unknown as HTMLElement;\n if (HTMLElement.prototype.hasAttribute.call(host, 'id')) {\n HTMLElement.prototype.removeAttribute.call(host, 'id');\n }\n\n this.requestUpdate();\n }\n\n // Native slot projection is a Shadow DOM feature, so in light DOM we keep\n // host-provided content reactive by tracking and reusing the host nodes.\n private projectedContent: Node[] = [];\n private contentObserver?: MutationObserver | undefined;\n\n createRenderRoot(): this {\n // Spectre components intentionally render in light DOM so the global\n // `@phcdevworks/spectre-ui` styling contract can apply directly.\n return this;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n\n const hostId = super.getAttribute('id');\n\n if (hostId !== null) {\n this.id = hostId;\n }\n\n this.syncProjectedContent();\n this.startContentObserver();\n }\n\n override getAttribute(qualifiedName: string): string | null {\n if (qualifiedName === 'id') {\n return this.id || null;\n }\n\n return super.getAttribute(qualifiedName);\n }\n\n override hasAttribute(qualifiedName: string): boolean {\n if (qualifiedName === 'id') {\n return this.id !== '';\n }\n\n return super.hasAttribute(qualifiedName);\n }\n\n override setAttribute(qualifiedName: string, value: string): void {\n if (qualifiedName === 'id') {\n this.id = value;\n return;\n }\n\n super.setAttribute(qualifiedName, value);\n }\n\n override removeAttribute(qualifiedName: string): void {\n if (qualifiedName === 'id') {\n this.id = '';\n return;\n }\n\n super.removeAttribute(qualifiedName);\n }\n\n override disconnectedCallback(): void {\n this.stopContentObserver();\n super.disconnectedCallback();\n }\n\n protected override willUpdate(changedProperties: Map<PropertyKey, unknown>): void {\n if (changedProperties.has('variant') && !isButtonVariant(this.variant)) {\n this.variant = 'primary';\n }\n\n if (changedProperties.has('size') && !isButtonSize(this.size)) {\n this.size = 'md';\n }\n\n if (changedProperties.has('type') && !isButtonType(this.type)) {\n this.type = 'button';\n }\n\n if (changedProperties.has('loadingLabel')) {\n if (this.loadingLabel == null || this.loadingLabel.trim() === '') {\n this.loadingLabel = 'Loading';\n }\n }\n }\n\n protected override update(changedProperties: Map<PropertyKey, unknown>): void {\n this.stopContentObserver();\n super.update(changedProperties);\n this.startContentObserver();\n }\n\n private get buttonClasses(): string {\n return getButtonClasses({\n disabled: this.isDisabled,\n fullWidth: this.fullWidth,\n loading: this.loading,\n pill: this.pill,\n size: this.size,\n variant: this.variant,\n });\n }\n\n private get isDisabled(): boolean {\n return this.disabled || this.loading;\n }\n\n private get hasProjectedContent(): boolean {\n return hasMeaningfulContent(this.projectedContent);\n }\n\n private get visibleLabelFallback(): string | undefined {\n const trimmedLabel = this.label?.trim();\n return trimmedLabel ? trimmedLabel : undefined;\n }\n\n private get forwardedAriaLabel(): string | undefined {\n const ariaLabel = this.ariaLabel?.trim();\n return ariaLabel ? ariaLabel : undefined;\n }\n\n private get forwardedAriaLabelledBy(): string | undefined {\n const ariaLabelledBy = this.ariaLabelledBy?.trim();\n return ariaLabelledBy ? ariaLabelledBy : undefined;\n }\n\n private get forwardedAriaDescribedBy(): string | undefined {\n const ariaDescribedBy = this.ariaDescribedBy?.trim();\n return ariaDescribedBy ? ariaDescribedBy : undefined;\n }\n\n private startContentObserver(): void {\n if (this.contentObserver) {\n return;\n }\n\n this.contentObserver = new MutationObserver((mutations) => {\n const isInternalMovement = mutations.every((mutation) => {\n return (\n Array.from(mutation.removedNodes).every(\n (node) => this.isInternalButtonNode(node) || this.contains(node),\n ) &&\n Array.from(mutation.addedNodes).every((node) => this.isInternalButtonNode(node))\n );\n });\n\n if (isInternalMovement) {\n return;\n }\n\n if (this.syncProjectedContent()) {\n this.requestUpdate();\n }\n });\n\n this.contentObserver.observe(this, {\n childList: true,\n });\n }\n\n private stopContentObserver(): void {\n this.contentObserver?.disconnect();\n this.contentObserver = undefined;\n }\n\n private syncProjectedContent(): boolean {\n const nextProjectedContent: Node[] = [];\n\n Array.from(this.childNodes).forEach((node) => {\n if (this.isInternalButtonNode(node)) {\n this.projectedContent.forEach((pNode) => {\n if (pNode.parentNode !== this && this.contains(pNode)) {\n nextProjectedContent.push(pNode);\n }\n });\n } else {\n nextProjectedContent.push(node);\n }\n });\n\n const hasChanged =\n nextProjectedContent.length !== this.projectedContent.length ||\n nextProjectedContent.some((node, index) => node !== this.projectedContent[index]);\n\n if (hasChanged) {\n this.projectedContent = nextProjectedContent;\n }\n\n return hasChanged;\n }\n\n private isInternalButtonNode(node: Node): boolean {\n return (\n node.nodeType === Node.ELEMENT_NODE && (node as Element).hasAttribute('data-sp-button-native')\n );\n }\n\n private get nativeButton(): HTMLButtonElement | null {\n return this.querySelector('[data-sp-button-native]');\n }\n\n override focus(options?: FocusOptions): void {\n this.nativeButton?.focus(options);\n }\n\n override blur(): void {\n this.nativeButton?.blur();\n }\n\n private renderButtonContent(): TemplateResult | Node[] | string {\n if (this.loading) {\n return this.loadingLabel;\n }\n\n if (this.hasProjectedContent) {\n return this.projectedContent;\n }\n\n return this.visibleLabelFallback ?? '';\n }\n\n override render() {\n return html`\n <button\n aria-busy=${this.loading ? 'true' : 'false'}\n aria-describedby=${ifDefined(this.forwardedAriaDescribedBy)}\n aria-label=${ifDefined(this.forwardedAriaLabel)}\n aria-labelledby=${ifDefined(this.forwardedAriaLabelledBy)}\n ?autofocus=${this.autofocus}\n class=${this.buttonClasses}\n data-sp-button-native\n ?disabled=${this.isDisabled}\n id=${ifDefined(this.id || undefined)}\n name=${ifDefined(this.name)}\n title=${ifDefined(this.title || undefined)}\n type=${this.type}\n value=${ifDefined(this.value)}\n >\n ${this.renderButtonContent() || nothing}\n </button>\n `;\n }\n}\n\nexport function defineSpectreButton(tagName = 'sp-button'): typeof SpectreButtonElement {\n const existingElement = customElements.get(tagName);\n\n if (existingElement) {\n return existingElement as unknown as typeof SpectreButtonElement;\n }\n\n customElements.define(tagName, SpectreButtonElement);\n return SpectreButtonElement;\n}\n"]}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var lit = require('lit');
|
|
4
|
+
var ifDefined_js = require('lit/directives/if-defined.js');
|
|
5
|
+
|
|
6
|
+
// src/components/checkbox/sp-checkbox.ts
|
|
7
|
+
var SpectreCheckboxElement = class extends lit.LitElement {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.ariaLabel = null;
|
|
11
|
+
this.ariaLabelledBy = null;
|
|
12
|
+
this.ariaDescribedBy = null;
|
|
13
|
+
this.autofocus = false;
|
|
14
|
+
this.checked = false;
|
|
15
|
+
this.disabled = false;
|
|
16
|
+
this.invalid = false;
|
|
17
|
+
this.label = "";
|
|
18
|
+
this.required = false;
|
|
19
|
+
this.title = "";
|
|
20
|
+
this.value = "on";
|
|
21
|
+
}
|
|
22
|
+
get id() {
|
|
23
|
+
return this._id ?? "";
|
|
24
|
+
}
|
|
25
|
+
set id(value) {
|
|
26
|
+
if ((this._id ?? "") === value) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
this._id = value;
|
|
30
|
+
const host = this;
|
|
31
|
+
if (HTMLElement.prototype.hasAttribute.call(host, "id")) {
|
|
32
|
+
HTMLElement.prototype.removeAttribute.call(host, "id");
|
|
33
|
+
}
|
|
34
|
+
this.requestUpdate();
|
|
35
|
+
}
|
|
36
|
+
createRenderRoot() {
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
connectedCallback() {
|
|
40
|
+
super.connectedCallback();
|
|
41
|
+
const hostId = super.getAttribute("id");
|
|
42
|
+
if (hostId !== null) {
|
|
43
|
+
this.id = hostId;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
getAttribute(qualifiedName) {
|
|
47
|
+
if (qualifiedName === "id") {
|
|
48
|
+
return this.id || null;
|
|
49
|
+
}
|
|
50
|
+
return super.getAttribute(qualifiedName);
|
|
51
|
+
}
|
|
52
|
+
hasAttribute(qualifiedName) {
|
|
53
|
+
if (qualifiedName === "id") {
|
|
54
|
+
return this.id !== "";
|
|
55
|
+
}
|
|
56
|
+
return super.hasAttribute(qualifiedName);
|
|
57
|
+
}
|
|
58
|
+
setAttribute(qualifiedName, value) {
|
|
59
|
+
if (qualifiedName === "id") {
|
|
60
|
+
this.id = value;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
super.setAttribute(qualifiedName, value);
|
|
64
|
+
}
|
|
65
|
+
removeAttribute(qualifiedName) {
|
|
66
|
+
if (qualifiedName === "id") {
|
|
67
|
+
this.id = "";
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
super.removeAttribute(qualifiedName);
|
|
71
|
+
}
|
|
72
|
+
willUpdate(changedProperties) {
|
|
73
|
+
if (changedProperties.has("value") && this.value == null) {
|
|
74
|
+
this.value = "on";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
get nativeInput() {
|
|
78
|
+
return this.querySelector("[data-sp-checkbox-native]");
|
|
79
|
+
}
|
|
80
|
+
get forwardedAriaLabel() {
|
|
81
|
+
const value = this.ariaLabel?.trim();
|
|
82
|
+
return value ? value : void 0;
|
|
83
|
+
}
|
|
84
|
+
get forwardedAriaLabelledBy() {
|
|
85
|
+
const value = this.ariaLabelledBy?.trim();
|
|
86
|
+
return value ? value : void 0;
|
|
87
|
+
}
|
|
88
|
+
get forwardedAriaDescribedBy() {
|
|
89
|
+
const value = this.ariaDescribedBy?.trim();
|
|
90
|
+
return value ? value : void 0;
|
|
91
|
+
}
|
|
92
|
+
handleInput(event) {
|
|
93
|
+
const input = event.currentTarget;
|
|
94
|
+
this.checked = input.checked;
|
|
95
|
+
}
|
|
96
|
+
handleChange(event) {
|
|
97
|
+
const input = event.currentTarget;
|
|
98
|
+
this.checked = input.checked;
|
|
99
|
+
}
|
|
100
|
+
focus(options) {
|
|
101
|
+
this.nativeInput?.focus(options);
|
|
102
|
+
}
|
|
103
|
+
blur() {
|
|
104
|
+
this.nativeInput?.blur();
|
|
105
|
+
}
|
|
106
|
+
render() {
|
|
107
|
+
return lit.html`
|
|
108
|
+
<label>
|
|
109
|
+
<input
|
|
110
|
+
aria-describedby=${ifDefined_js.ifDefined(this.forwardedAriaDescribedBy)}
|
|
111
|
+
aria-invalid=${ifDefined_js.ifDefined(this.invalid ? "true" : void 0)}
|
|
112
|
+
aria-label=${ifDefined_js.ifDefined(this.forwardedAriaLabel)}
|
|
113
|
+
aria-labelledby=${ifDefined_js.ifDefined(this.forwardedAriaLabelledBy)}
|
|
114
|
+
?autofocus=${this.autofocus}
|
|
115
|
+
data-sp-checkbox-native
|
|
116
|
+
?checked=${this.checked}
|
|
117
|
+
?disabled=${this.disabled}
|
|
118
|
+
id=${ifDefined_js.ifDefined(this.id || void 0)}
|
|
119
|
+
name=${ifDefined_js.ifDefined(this.name)}
|
|
120
|
+
?required=${this.required}
|
|
121
|
+
title=${ifDefined_js.ifDefined(this.title || void 0)}
|
|
122
|
+
type='checkbox'
|
|
123
|
+
value=${ifDefined_js.ifDefined(this.value || void 0)}
|
|
124
|
+
@change=${this.handleChange}
|
|
125
|
+
@input=${this.handleInput}
|
|
126
|
+
/>
|
|
127
|
+
<span class='sp-label'>${this.label}</span>
|
|
128
|
+
</label>
|
|
129
|
+
`;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
SpectreCheckboxElement.properties = {
|
|
133
|
+
ariaLabel: { attribute: "aria-label", type: String },
|
|
134
|
+
ariaLabelledBy: { attribute: "aria-labelledby", type: String },
|
|
135
|
+
ariaDescribedBy: { attribute: "aria-describedby", type: String },
|
|
136
|
+
autofocus: { type: Boolean, reflect: true },
|
|
137
|
+
checked: { type: Boolean, reflect: true },
|
|
138
|
+
disabled: { type: Boolean, reflect: true },
|
|
139
|
+
invalid: { type: Boolean, reflect: true },
|
|
140
|
+
label: { type: String, reflect: true },
|
|
141
|
+
name: { type: String },
|
|
142
|
+
required: { type: Boolean, reflect: true },
|
|
143
|
+
title: { type: String, reflect: true },
|
|
144
|
+
value: { type: String }
|
|
145
|
+
};
|
|
146
|
+
function defineSpectreCheckbox(tagName = "sp-checkbox") {
|
|
147
|
+
const existingElement = customElements.get(tagName);
|
|
148
|
+
if (existingElement) {
|
|
149
|
+
return existingElement;
|
|
150
|
+
}
|
|
151
|
+
customElements.define(tagName, SpectreCheckboxElement);
|
|
152
|
+
return SpectreCheckboxElement;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
exports.SpectreCheckboxElement = SpectreCheckboxElement;
|
|
156
|
+
exports.defineSpectreCheckbox = defineSpectreCheckbox;
|
|
157
|
+
//# sourceMappingURL=checkbox.cjs.map
|
|
158
|
+
//# sourceMappingURL=checkbox.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/checkbox/sp-checkbox.ts"],"names":["LitElement","html","ifDefined"],"mappings":";;;;;;AAeO,IAAM,sBAAA,GAAN,cAAqCA,cAAA,CAA2C;AAAA,EAAhF,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AAgBL,IAAA,IAAA,CAAA,SAAA,GAA2B,IAAA;AAC3B,IAAA,IAAA,CAAA,cAAA,GAAgC,IAAA;AAChC,IAAA,IAAA,CAAA,eAAA,GAAiC,IAAA;AACjC,IAAA,IAAA,CAAA,SAAA,GAAY,KAAA;AACZ,IAAA,IAAA,CAAA,OAAA,GAAU,KAAA;AACV,IAAA,IAAA,CAAA,QAAA,GAAW,KAAA;AACX,IAAA,IAAA,CAAA,OAAA,GAAU,KAAA;AACV,IAAA,IAAA,CAAA,KAAA,GAAQ,EAAA;AAER,IAAA,IAAA,CAAA,QAAA,GAAW,KAAA;AACX,IAAA,IAAA,CAAS,KAAA,GAAQ,EAAA;AACjB,IAAA,IAAA,CAAA,KAAA,GAAQ,IAAA;AAAA,EAAA;AAAA,EAGR,IAAa,EAAA,GAAa;AACxB,IAAA,OAAO,KAAK,GAAA,IAAO,EAAA;AAAA,EACrB;AAAA,EAEA,IAAa,GAAG,KAAA,EAAe;AAC7B,IAAA,IAAA,CAAK,IAAA,CAAK,GAAA,IAAO,EAAA,MAAQ,KAAA,EAAO;AAC9B,MAAA;AAAA,IACF;AAEA,IAAA,IAAA,CAAK,GAAA,GAAM,KAAA;AAEX,IAAA,MAAM,IAAA,GAAO,IAAA;AACb,I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A,EAAK;AAAA,EAC1C,OAAA,EAAS,EAAE,IAAA,EAAM,OAAA,EAAS,SAAS,IAAA,EAAK;AAAA,EACxC,QAAA,EAAU,EAAE,IAAA,EAAM,OAAA,EAAS,SAAS,IAAA,EAAK;AAAA,EACzC,OAAA,EAAS,EAAE,IAAA,EAAM,OAAA,EAAS,SAAS,IAAA,EAAK;AAAA,EACxC,KAAA,EAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,IAAA,EAAK;AAAA,EACrC,IAAA,EAAM,EAAE,IAAA,EAAM,MAAA,EAAO;AAAA,EACrB,QAAA,EAAU,EAAE,IAAA,EAAM,OAAA,EAAS,SAAS,IAAA,EAAK;AAAA,EACzC,KAAA,EAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,IAAA,EAAK;AAAA,EACrC,KAAA,EAAO,EAAE,IAAA,EAAM,MAAA;AACjB,CAAA;AAwJK,SAAS,qBAAA,CAAsB,UAAU,aAAA,EAA8C;AAC5F,EAAA,MAAM,eAAA,GAAkB,cAAA,CAAe,GAAA,CAAI,OAAO,CAAA;AAElD,EAAA,IAAI,eAAA,EAAiB;AACnB,IAAA,OAAO,eAAA;AAAA,EACT;AAEA,EAAA,cAAA,CAAe,MAAA,CAAO,SAAS,sBAAsB,CAAA;AACrD,EAAA,OAAO,sBAAA;AACT","file":"checkbox.cjs","sourcesContent":["import { LitElement, html } from 'lit';\nimport { ifDefined } from 'lit/directives/if-defined.js';\n\nexport interface SpectreCheckboxProps {\n autofocus?: boolean;\n checked?: boolean;\n disabled?: boolean;\n invalid?: boolean;\n label?: string;\n name?: string;\n required?: boolean;\n title?: string;\n value?: string;\n}\n\nexport class SpectreCheckboxElement extends LitElement implements SpectreCheckboxProps {\n static properties = {\n ariaLabel: { attribute: 'aria-label', type: String },\n ariaLabelledBy: { attribute: 'aria-labelledby', type: String },\n ariaDescribedBy: { attribute: 'aria-describedby', type: String },\n autofocus: { type: Boolean, reflect: true },\n checked: { type: Boolean, reflect: true },\n disabled: { type: Boolean, reflect: true },\n invalid: { type: Boolean, reflect: true },\n label: { type: String, reflect: true },\n name: { type: String },\n required: { type: Boolean, reflect: true },\n title: { type: String, reflect: true },\n value: { type: String },\n };\n\n ariaLabel: string | null = null;\n ariaLabelledBy: string | null = null;\n ariaDescribedBy: string | null = null;\n autofocus = false;\n checked = false;\n disabled = false;\n invalid = false;\n label = '';\n name?: string;\n required = false;\n override title = '';\n value = 'on';\n private _id?: string;\n\n override get id(): string {\n return this._id ?? '';\n }\n\n override set id(value: string) {\n if ((this._id ?? '') === value) {\n return;\n }\n\n this._id = value;\n\n const host = this as unknown as HTMLElement;\n if (HTMLElement.prototype.hasAttribute.call(host, 'id')) {\n HTMLElement.prototype.removeAttribute.call(host, 'id');\n }\n\n this.requestUpdate();\n }\n\n createRenderRoot(): this {\n return this;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n const hostId = super.getAttribute('id');\n\n if (hostId !== null) {\n this.id = hostId;\n }\n }\n\n override getAttribute(qualifiedName: string): string | null {\n if (qualifiedName === 'id') {\n return this.id || null;\n }\n\n return super.getAttribute(qualifiedName);\n }\n\n override hasAttribute(qualifiedName: string): boolean {\n if (qualifiedName === 'id') {\n return this.id !== '';\n }\n\n return super.hasAttribute(qualifiedName);\n }\n\n override setAttribute(qualifiedName: string, value: string): void {\n if (qualifiedName === 'id') {\n this.id = value;\n return;\n }\n\n super.setAttribute(qualifiedName, value);\n }\n\n override removeAttribute(qualifiedName: string): void {\n if (qualifiedName === 'id') {\n this.id = '';\n return;\n }\n\n super.removeAttribute(qualifiedName);\n }\n\n protected override willUpdate(changedProperties: Map<PropertyKey, unknown>): void {\n if (changedProperties.has('value') && this.value == null) {\n this.value = 'on';\n }\n }\n\n private get nativeInput(): HTMLInputElement | null {\n return this.querySelector('[data-sp-checkbox-native]');\n }\n\n private get forwardedAriaLabel(): string | undefined {\n const value = this.ariaLabel?.trim();\n return value ? value : undefined;\n }\n\n private get forwardedAriaLabelledBy(): string | undefined {\n const value = this.ariaLabelledBy?.trim();\n return value ? value : undefined;\n }\n\n private get forwardedAriaDescribedBy(): string | undefined {\n const value = this.ariaDescribedBy?.trim();\n return value ? value : undefined;\n }\n\n private handleInput(event: Event): void {\n const input = event.currentTarget as HTMLInputElement;\n this.checked = input.checked;\n }\n\n private handleChange(event: Event): void {\n const input = event.currentTarget as HTMLInputElement;\n this.checked = input.checked;\n }\n\n override focus(options?: FocusOptions): void {\n this.nativeInput?.focus(options);\n }\n\n override blur(): void {\n this.nativeInput?.blur();\n }\n\n override render() {\n return html`\n <label>\n <input\n aria-describedby=${ifDefined(this.forwardedAriaDescribedBy)}\n aria-invalid=${ifDefined(this.invalid ? 'true' : undefined)}\n aria-label=${ifDefined(this.forwardedAriaLabel)}\n aria-labelledby=${ifDefined(this.forwardedAriaLabelledBy)}\n ?autofocus=${this.autofocus}\n data-sp-checkbox-native\n ?checked=${this.checked}\n ?disabled=${this.disabled}\n id=${ifDefined(this.id || undefined)}\n name=${ifDefined(this.name)}\n ?required=${this.required}\n title=${ifDefined(this.title || undefined)}\n type='checkbox'\n value=${ifDefined(this.value || undefined)}\n @change=${this.handleChange}\n @input=${this.handleInput}\n />\n <span class='sp-label'>${this.label}</span>\n </label>\n `;\n }\n}\n\nexport function defineSpectreCheckbox(tagName = 'sp-checkbox'): typeof SpectreCheckboxElement {\n const existingElement = customElements.get(tagName);\n\n if (existingElement) {\n return existingElement as unknown as typeof SpectreCheckboxElement;\n }\n\n customElements.define(tagName, SpectreCheckboxElement);\n return SpectreCheckboxElement;\n}\n"]}
|