@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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +177 -0
  3. package/dist/button.cjs +288 -0
  4. package/dist/button.cjs.map +1 -0
  5. package/dist/button.d.cts +142 -0
  6. package/dist/button.d.ts +142 -0
  7. package/dist/button.js +282 -0
  8. package/dist/button.js.map +1 -0
  9. package/dist/checkbox.cjs +158 -0
  10. package/dist/checkbox.cjs.map +1 -0
  11. package/dist/checkbox.d.cts +98 -0
  12. package/dist/checkbox.d.ts +98 -0
  13. package/dist/checkbox.js +155 -0
  14. package/dist/checkbox.js.map +1 -0
  15. package/dist/fieldset.cjs +179 -0
  16. package/dist/fieldset.cjs.map +1 -0
  17. package/dist/fieldset.d.cts +63 -0
  18. package/dist/fieldset.d.ts +63 -0
  19. package/dist/fieldset.js +176 -0
  20. package/dist/fieldset.js.map +1 -0
  21. package/dist/index.cjs +1600 -0
  22. package/dist/index.cjs.map +1 -0
  23. package/dist/index.d.cts +14 -0
  24. package/dist/index.d.ts +14 -0
  25. package/dist/index.js +1576 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/input.cjs +235 -0
  28. package/dist/input.cjs.map +1 -0
  29. package/dist/input.d.cts +175 -0
  30. package/dist/input.d.ts +175 -0
  31. package/dist/input.js +230 -0
  32. package/dist/input.js.map +1 -0
  33. package/dist/label.cjs +156 -0
  34. package/dist/label.cjs.map +1 -0
  35. package/dist/label.d.cts +39 -0
  36. package/dist/label.d.ts +39 -0
  37. package/dist/label.js +153 -0
  38. package/dist/label.js.map +1 -0
  39. package/dist/radio.cjs +158 -0
  40. package/dist/radio.cjs.map +1 -0
  41. package/dist/radio.d.cts +98 -0
  42. package/dist/radio.d.ts +98 -0
  43. package/dist/radio.js +155 -0
  44. package/dist/radio.js.map +1 -0
  45. package/dist/select.cjs +272 -0
  46. package/dist/select.cjs.map +1 -0
  47. package/dist/select.d.cts +130 -0
  48. package/dist/select.d.ts +130 -0
  49. package/dist/select.js +268 -0
  50. package/dist/select.js.map +1 -0
  51. package/dist/textarea.cjs +423 -0
  52. package/dist/textarea.cjs.map +1 -0
  53. package/dist/textarea.d.cts +156 -0
  54. package/dist/textarea.d.ts +156 -0
  55. package/dist/textarea.js +420 -0
  56. package/dist/textarea.js.map +1 -0
  57. package/package.json +124 -0
@@ -0,0 +1,98 @@
1
+ import * as lit_html from 'lit-html';
2
+ import { LitElement } from 'lit';
3
+
4
+ interface SpectreRadioProps {
5
+ autofocus?: boolean;
6
+ checked?: boolean;
7
+ disabled?: boolean;
8
+ invalid?: boolean;
9
+ label?: string;
10
+ name?: string;
11
+ required?: boolean;
12
+ title?: string;
13
+ value?: string;
14
+ }
15
+ declare class SpectreRadioElement extends LitElement implements SpectreRadioProps {
16
+ static properties: {
17
+ ariaLabel: {
18
+ attribute: string;
19
+ type: StringConstructor;
20
+ };
21
+ ariaLabelledBy: {
22
+ attribute: string;
23
+ type: StringConstructor;
24
+ };
25
+ ariaDescribedBy: {
26
+ attribute: string;
27
+ type: StringConstructor;
28
+ };
29
+ autofocus: {
30
+ type: BooleanConstructor;
31
+ reflect: boolean;
32
+ };
33
+ checked: {
34
+ type: BooleanConstructor;
35
+ reflect: boolean;
36
+ };
37
+ disabled: {
38
+ type: BooleanConstructor;
39
+ reflect: boolean;
40
+ };
41
+ invalid: {
42
+ type: BooleanConstructor;
43
+ reflect: boolean;
44
+ };
45
+ label: {
46
+ type: StringConstructor;
47
+ reflect: boolean;
48
+ };
49
+ name: {
50
+ type: StringConstructor;
51
+ };
52
+ required: {
53
+ type: BooleanConstructor;
54
+ reflect: boolean;
55
+ };
56
+ title: {
57
+ type: StringConstructor;
58
+ reflect: boolean;
59
+ };
60
+ value: {
61
+ type: StringConstructor;
62
+ };
63
+ };
64
+ ariaLabel: string | null;
65
+ ariaLabelledBy: string | null;
66
+ ariaDescribedBy: string | null;
67
+ autofocus: boolean;
68
+ checked: boolean;
69
+ disabled: boolean;
70
+ invalid: boolean;
71
+ label: string;
72
+ name?: string;
73
+ required: boolean;
74
+ title: string;
75
+ value: string;
76
+ private _id?;
77
+ get id(): string;
78
+ set id(value: string);
79
+ createRenderRoot(): this;
80
+ connectedCallback(): void;
81
+ getAttribute(qualifiedName: string): string | null;
82
+ hasAttribute(qualifiedName: string): boolean;
83
+ setAttribute(qualifiedName: string, value: string): void;
84
+ removeAttribute(qualifiedName: string): void;
85
+ protected willUpdate(changedProperties: Map<PropertyKey, unknown>): void;
86
+ private get nativeInput();
87
+ private get forwardedAriaLabel();
88
+ private get forwardedAriaLabelledBy();
89
+ private get forwardedAriaDescribedBy();
90
+ private handleInput;
91
+ private handleChange;
92
+ focus(options?: FocusOptions): void;
93
+ blur(): void;
94
+ render(): lit_html.TemplateResult<1>;
95
+ }
96
+ declare function defineSpectreRadio(tagName?: string): typeof SpectreRadioElement;
97
+
98
+ export { SpectreRadioElement, type SpectreRadioProps, defineSpectreRadio };
@@ -0,0 +1,98 @@
1
+ import * as lit_html from 'lit-html';
2
+ import { LitElement } from 'lit';
3
+
4
+ interface SpectreRadioProps {
5
+ autofocus?: boolean;
6
+ checked?: boolean;
7
+ disabled?: boolean;
8
+ invalid?: boolean;
9
+ label?: string;
10
+ name?: string;
11
+ required?: boolean;
12
+ title?: string;
13
+ value?: string;
14
+ }
15
+ declare class SpectreRadioElement extends LitElement implements SpectreRadioProps {
16
+ static properties: {
17
+ ariaLabel: {
18
+ attribute: string;
19
+ type: StringConstructor;
20
+ };
21
+ ariaLabelledBy: {
22
+ attribute: string;
23
+ type: StringConstructor;
24
+ };
25
+ ariaDescribedBy: {
26
+ attribute: string;
27
+ type: StringConstructor;
28
+ };
29
+ autofocus: {
30
+ type: BooleanConstructor;
31
+ reflect: boolean;
32
+ };
33
+ checked: {
34
+ type: BooleanConstructor;
35
+ reflect: boolean;
36
+ };
37
+ disabled: {
38
+ type: BooleanConstructor;
39
+ reflect: boolean;
40
+ };
41
+ invalid: {
42
+ type: BooleanConstructor;
43
+ reflect: boolean;
44
+ };
45
+ label: {
46
+ type: StringConstructor;
47
+ reflect: boolean;
48
+ };
49
+ name: {
50
+ type: StringConstructor;
51
+ };
52
+ required: {
53
+ type: BooleanConstructor;
54
+ reflect: boolean;
55
+ };
56
+ title: {
57
+ type: StringConstructor;
58
+ reflect: boolean;
59
+ };
60
+ value: {
61
+ type: StringConstructor;
62
+ };
63
+ };
64
+ ariaLabel: string | null;
65
+ ariaLabelledBy: string | null;
66
+ ariaDescribedBy: string | null;
67
+ autofocus: boolean;
68
+ checked: boolean;
69
+ disabled: boolean;
70
+ invalid: boolean;
71
+ label: string;
72
+ name?: string;
73
+ required: boolean;
74
+ title: string;
75
+ value: string;
76
+ private _id?;
77
+ get id(): string;
78
+ set id(value: string);
79
+ createRenderRoot(): this;
80
+ connectedCallback(): void;
81
+ getAttribute(qualifiedName: string): string | null;
82
+ hasAttribute(qualifiedName: string): boolean;
83
+ setAttribute(qualifiedName: string, value: string): void;
84
+ removeAttribute(qualifiedName: string): void;
85
+ protected willUpdate(changedProperties: Map<PropertyKey, unknown>): void;
86
+ private get nativeInput();
87
+ private get forwardedAriaLabel();
88
+ private get forwardedAriaLabelledBy();
89
+ private get forwardedAriaDescribedBy();
90
+ private handleInput;
91
+ private handleChange;
92
+ focus(options?: FocusOptions): void;
93
+ blur(): void;
94
+ render(): lit_html.TemplateResult<1>;
95
+ }
96
+ declare function defineSpectreRadio(tagName?: string): typeof SpectreRadioElement;
97
+
98
+ export { SpectreRadioElement, type SpectreRadioProps, defineSpectreRadio };
package/dist/radio.js ADDED
@@ -0,0 +1,155 @@
1
+ import { LitElement, html } from 'lit';
2
+ import { ifDefined } from 'lit/directives/if-defined.js';
3
+
4
+ // src/components/radio/sp-radio.ts
5
+ var SpectreRadioElement = class extends LitElement {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.ariaLabel = null;
9
+ this.ariaLabelledBy = null;
10
+ this.ariaDescribedBy = null;
11
+ this.autofocus = false;
12
+ this.checked = false;
13
+ this.disabled = false;
14
+ this.invalid = false;
15
+ this.label = "";
16
+ this.required = false;
17
+ this.title = "";
18
+ this.value = "on";
19
+ }
20
+ get id() {
21
+ return this._id ?? "";
22
+ }
23
+ set id(value) {
24
+ if ((this._id ?? "") === value) {
25
+ return;
26
+ }
27
+ this._id = value;
28
+ const host = this;
29
+ if (HTMLElement.prototype.hasAttribute.call(host, "id")) {
30
+ HTMLElement.prototype.removeAttribute.call(host, "id");
31
+ }
32
+ this.requestUpdate();
33
+ }
34
+ createRenderRoot() {
35
+ return this;
36
+ }
37
+ connectedCallback() {
38
+ super.connectedCallback();
39
+ const hostId = super.getAttribute("id");
40
+ if (hostId !== null) {
41
+ this.id = hostId;
42
+ }
43
+ }
44
+ getAttribute(qualifiedName) {
45
+ if (qualifiedName === "id") {
46
+ return this.id || null;
47
+ }
48
+ return super.getAttribute(qualifiedName);
49
+ }
50
+ hasAttribute(qualifiedName) {
51
+ if (qualifiedName === "id") {
52
+ return this.id !== "";
53
+ }
54
+ return super.hasAttribute(qualifiedName);
55
+ }
56
+ setAttribute(qualifiedName, value) {
57
+ if (qualifiedName === "id") {
58
+ this.id = value;
59
+ return;
60
+ }
61
+ super.setAttribute(qualifiedName, value);
62
+ }
63
+ removeAttribute(qualifiedName) {
64
+ if (qualifiedName === "id") {
65
+ this.id = "";
66
+ return;
67
+ }
68
+ super.removeAttribute(qualifiedName);
69
+ }
70
+ willUpdate(changedProperties) {
71
+ if (changedProperties.has("value") && this.value == null) {
72
+ this.value = "on";
73
+ }
74
+ }
75
+ get nativeInput() {
76
+ return this.querySelector("[data-sp-radio-native]");
77
+ }
78
+ get forwardedAriaLabel() {
79
+ const value = this.ariaLabel?.trim();
80
+ return value ? value : void 0;
81
+ }
82
+ get forwardedAriaLabelledBy() {
83
+ const value = this.ariaLabelledBy?.trim();
84
+ return value ? value : void 0;
85
+ }
86
+ get forwardedAriaDescribedBy() {
87
+ const value = this.ariaDescribedBy?.trim();
88
+ return value ? value : void 0;
89
+ }
90
+ handleInput(event) {
91
+ const input = event.currentTarget;
92
+ this.checked = input.checked;
93
+ }
94
+ handleChange(event) {
95
+ const input = event.currentTarget;
96
+ this.checked = input.checked;
97
+ }
98
+ focus(options) {
99
+ this.nativeInput?.focus(options);
100
+ }
101
+ blur() {
102
+ this.nativeInput?.blur();
103
+ }
104
+ render() {
105
+ return html`
106
+ <label>
107
+ <input
108
+ aria-describedby=${ifDefined(this.forwardedAriaDescribedBy)}
109
+ aria-invalid=${ifDefined(this.invalid ? "true" : void 0)}
110
+ aria-label=${ifDefined(this.forwardedAriaLabel)}
111
+ aria-labelledby=${ifDefined(this.forwardedAriaLabelledBy)}
112
+ ?autofocus=${this.autofocus}
113
+ data-sp-radio-native
114
+ ?checked=${this.checked}
115
+ ?disabled=${this.disabled}
116
+ id=${ifDefined(this.id || void 0)}
117
+ name=${ifDefined(this.name)}
118
+ ?required=${this.required}
119
+ title=${ifDefined(this.title || void 0)}
120
+ type='radio'
121
+ value=${ifDefined(this.value || void 0)}
122
+ @change=${this.handleChange}
123
+ @input=${this.handleInput}
124
+ />
125
+ <span class='sp-label'>${this.label}</span>
126
+ </label>
127
+ `;
128
+ }
129
+ };
130
+ SpectreRadioElement.properties = {
131
+ ariaLabel: { attribute: "aria-label", type: String },
132
+ ariaLabelledBy: { attribute: "aria-labelledby", type: String },
133
+ ariaDescribedBy: { attribute: "aria-describedby", type: String },
134
+ autofocus: { type: Boolean, reflect: true },
135
+ checked: { type: Boolean, reflect: true },
136
+ disabled: { type: Boolean, reflect: true },
137
+ invalid: { type: Boolean, reflect: true },
138
+ label: { type: String, reflect: true },
139
+ name: { type: String },
140
+ required: { type: Boolean, reflect: true },
141
+ title: { type: String, reflect: true },
142
+ value: { type: String }
143
+ };
144
+ function defineSpectreRadio(tagName = "sp-radio") {
145
+ const existingElement = customElements.get(tagName);
146
+ if (existingElement) {
147
+ return existingElement;
148
+ }
149
+ customElements.define(tagName, SpectreRadioElement);
150
+ return SpectreRadioElement;
151
+ }
152
+
153
+ export { SpectreRadioElement, defineSpectreRadio };
154
+ //# sourceMappingURL=radio.js.map
155
+ //# sourceMappingURL=radio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/radio/sp-radio.ts"],"names":[],"mappings":";;;;AAeO,IAAM,mBAAA,GAAN,cAAkC,UAAA,CAAwC;AAAA,EAA1E,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,IAAA,IAAI,YAAY,SAAA,CAAU,YAAA,CAAa,IAAA,CAAK,IAAA,EAAM,IAAI,CAAA,EAAG;AACvD,MAAA,WAAA,CAAY,SAAA,CAAU,eAAA,CAAgB,IAAA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A,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,kBAAA,CAAmB,UAAU,UAAA,EAAwC;AACnF,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,mBAAmB,CAAA;AAClD,EAAA,OAAO,mBAAA;AACT","file":"radio.js","sourcesContent":["import { LitElement, html } from 'lit';\nimport { ifDefined } from 'lit/directives/if-defined.js';\n\nexport interface SpectreRadioProps {\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 SpectreRadioElement extends LitElement implements SpectreRadioProps {\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-radio-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-radio-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='radio'\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 defineSpectreRadio(tagName = 'sp-radio'): typeof SpectreRadioElement {\n const existingElement = customElements.get(tagName);\n\n if (existingElement) {\n return existingElement as unknown as typeof SpectreRadioElement;\n }\n\n customElements.define(tagName, SpectreRadioElement);\n return SpectreRadioElement;\n}\n"]}
@@ -0,0 +1,272 @@
1
+ 'use strict';
2
+
3
+ var lit = require('lit');
4
+ var live_js = require('lit/directives/live.js');
5
+ var ifDefined_js = require('lit/directives/if-defined.js');
6
+ var spectreUi = require('@phcdevworks/spectre-ui');
7
+
8
+ // src/components/select/sp-select.ts
9
+ var spectreSelectSizes = ["sm", "md", "lg"];
10
+ function isSelectSize(value) {
11
+ return spectreSelectSizes.includes(value);
12
+ }
13
+ function isSelectableContent(node) {
14
+ if (node.nodeType === Node.ELEMENT_NODE) {
15
+ const tagName = node.tagName;
16
+ return tagName === "OPTION" || tagName === "OPTGROUP";
17
+ }
18
+ if (node.nodeType === Node.TEXT_NODE) {
19
+ return (node.textContent?.trim().length ?? 0) > 0;
20
+ }
21
+ return false;
22
+ }
23
+ var SpectreSelectElement = class extends lit.LitElement {
24
+ constructor() {
25
+ super(...arguments);
26
+ this.ariaLabel = null;
27
+ this.ariaLabelledBy = null;
28
+ this.ariaDescribedBy = null;
29
+ this.autofocus = false;
30
+ this.disabled = false;
31
+ this.fullWidth = false;
32
+ this.invalid = false;
33
+ this.loading = false;
34
+ this.pill = false;
35
+ this.required = false;
36
+ this.size = "md";
37
+ this.success = false;
38
+ this.title = "";
39
+ this.value = "";
40
+ this.projectedOptions = [];
41
+ }
42
+ get id() {
43
+ return this._id ?? "";
44
+ }
45
+ set id(value) {
46
+ if ((this._id ?? "") === value) {
47
+ return;
48
+ }
49
+ this._id = value;
50
+ const host = this;
51
+ if (HTMLElement.prototype.hasAttribute.call(host, "id")) {
52
+ HTMLElement.prototype.removeAttribute.call(host, "id");
53
+ }
54
+ this.requestUpdate();
55
+ }
56
+ createRenderRoot() {
57
+ return this;
58
+ }
59
+ connectedCallback() {
60
+ super.connectedCallback();
61
+ const hostId = super.getAttribute("id");
62
+ if (hostId !== null) {
63
+ this.id = hostId;
64
+ }
65
+ this.syncProjectedOptions();
66
+ this.startContentObserver();
67
+ }
68
+ disconnectedCallback() {
69
+ this.stopContentObserver();
70
+ super.disconnectedCallback();
71
+ }
72
+ getAttribute(qualifiedName) {
73
+ if (qualifiedName === "id") {
74
+ return this.id || null;
75
+ }
76
+ return super.getAttribute(qualifiedName);
77
+ }
78
+ hasAttribute(qualifiedName) {
79
+ if (qualifiedName === "id") {
80
+ return this.id !== "";
81
+ }
82
+ return super.hasAttribute(qualifiedName);
83
+ }
84
+ setAttribute(qualifiedName, value) {
85
+ if (qualifiedName === "id") {
86
+ this.id = value;
87
+ return;
88
+ }
89
+ super.setAttribute(qualifiedName, value);
90
+ }
91
+ removeAttribute(qualifiedName) {
92
+ if (qualifiedName === "id") {
93
+ this.id = "";
94
+ return;
95
+ }
96
+ super.removeAttribute(qualifiedName);
97
+ }
98
+ willUpdate(changedProperties) {
99
+ if (changedProperties.has("size") && !isSelectSize(this.size)) {
100
+ this.size = "md";
101
+ }
102
+ if (changedProperties.has("value") && this.value == null) {
103
+ this.value = "";
104
+ }
105
+ }
106
+ update(changedProperties) {
107
+ this.stopContentObserver();
108
+ super.update(changedProperties);
109
+ this.startContentObserver();
110
+ }
111
+ updated(changedProperties) {
112
+ super.updated(changedProperties);
113
+ const nativeSelect = this.nativeSelect;
114
+ if (!nativeSelect) {
115
+ return;
116
+ }
117
+ if (this.value !== "" && nativeSelect.value !== this.value) {
118
+ nativeSelect.value = this.value;
119
+ return;
120
+ }
121
+ if (this.value === "" && !this.hasAttribute("value")) {
122
+ const nativeValue = nativeSelect.value ?? "";
123
+ if (nativeValue !== "") {
124
+ this.value = nativeValue;
125
+ }
126
+ }
127
+ }
128
+ get selectClasses() {
129
+ return spectreUi.getInputClasses({
130
+ fullWidth: this.fullWidth,
131
+ pill: this.pill,
132
+ size: this.size,
133
+ state: this.isDisabled ? this.disabled ? "disabled" : "loading" : this.invalid ? "error" : this.success ? "success" : "default"
134
+ });
135
+ }
136
+ get isDisabled() {
137
+ return this.disabled || this.loading;
138
+ }
139
+ get nativeSelect() {
140
+ return this.querySelector("[data-sp-select-native]");
141
+ }
142
+ get forwardedAriaLabel() {
143
+ const ariaLabel = this.ariaLabel?.trim();
144
+ return ariaLabel ? ariaLabel : void 0;
145
+ }
146
+ get forwardedAriaLabelledBy() {
147
+ const ariaLabelledBy = this.ariaLabelledBy?.trim();
148
+ return ariaLabelledBy ? ariaLabelledBy : void 0;
149
+ }
150
+ get forwardedAriaDescribedBy() {
151
+ const ariaDescribedBy = this.ariaDescribedBy?.trim();
152
+ return ariaDescribedBy ? ariaDescribedBy : void 0;
153
+ }
154
+ startContentObserver() {
155
+ if (this.contentObserver) {
156
+ return;
157
+ }
158
+ this.contentObserver = new MutationObserver((mutations) => {
159
+ const isInternalMovement = mutations.every((mutation) => {
160
+ return Array.from(mutation.removedNodes).every(
161
+ (node) => this.isInternalSelectNode(node) || this.contains(node)
162
+ ) && Array.from(mutation.addedNodes).every((node) => this.isInternalSelectNode(node));
163
+ });
164
+ if (isInternalMovement) {
165
+ return;
166
+ }
167
+ if (this.syncProjectedOptions()) {
168
+ this.requestUpdate();
169
+ }
170
+ });
171
+ this.contentObserver.observe(this, {
172
+ childList: true
173
+ });
174
+ }
175
+ stopContentObserver() {
176
+ this.contentObserver?.disconnect();
177
+ this.contentObserver = void 0;
178
+ }
179
+ syncProjectedOptions() {
180
+ const nextProjectedOptions = [];
181
+ Array.from(this.childNodes).forEach((node) => {
182
+ if (this.isInternalSelectNode(node)) {
183
+ this.projectedOptions.forEach((projectedNode) => {
184
+ if (projectedNode.parentNode !== this && this.contains(projectedNode)) {
185
+ nextProjectedOptions.push(projectedNode);
186
+ }
187
+ });
188
+ return;
189
+ }
190
+ if (isSelectableContent(node)) {
191
+ nextProjectedOptions.push(node);
192
+ }
193
+ });
194
+ const hasChanged = nextProjectedOptions.length !== this.projectedOptions.length || nextProjectedOptions.some((node, index) => node !== this.projectedOptions[index]);
195
+ if (hasChanged) {
196
+ this.projectedOptions = nextProjectedOptions;
197
+ }
198
+ return hasChanged;
199
+ }
200
+ isInternalSelectNode(node) {
201
+ return node.nodeType === Node.ELEMENT_NODE && node.hasAttribute("data-sp-select-native");
202
+ }
203
+ handleInput(event) {
204
+ const select = event.currentTarget;
205
+ this.value = select.value;
206
+ }
207
+ handleChange(event) {
208
+ const select = event.currentTarget;
209
+ this.value = select.value;
210
+ }
211
+ focus(options) {
212
+ this.nativeSelect?.focus(options);
213
+ }
214
+ blur() {
215
+ this.nativeSelect?.blur();
216
+ }
217
+ render() {
218
+ return lit.html`
219
+ <select
220
+ aria-busy=${this.loading ? "true" : "false"}
221
+ aria-describedby=${ifDefined_js.ifDefined(this.forwardedAriaDescribedBy)}
222
+ aria-invalid=${ifDefined_js.ifDefined(this.invalid ? "true" : void 0)}
223
+ aria-label=${ifDefined_js.ifDefined(this.forwardedAriaLabel)}
224
+ aria-labelledby=${ifDefined_js.ifDefined(this.forwardedAriaLabelledBy)}
225
+ ?autofocus=${this.autofocus}
226
+ class=${this.selectClasses}
227
+ data-sp-select-native
228
+ ?disabled=${this.isDisabled}
229
+ id=${ifDefined_js.ifDefined(this.id || void 0)}
230
+ name=${ifDefined_js.ifDefined(this.name)}
231
+ ?required=${this.required}
232
+ title=${ifDefined_js.ifDefined(this.title || void 0)}
233
+ .value=${live_js.live(this.value)}
234
+ @change=${this.handleChange}
235
+ @input=${this.handleInput}
236
+ >
237
+ ${this.projectedOptions.length > 0 ? this.projectedOptions : lit.nothing}
238
+ </select>
239
+ `;
240
+ }
241
+ };
242
+ SpectreSelectElement.properties = {
243
+ ariaLabel: { attribute: "aria-label", type: String },
244
+ ariaLabelledBy: { attribute: "aria-labelledby", type: String },
245
+ ariaDescribedBy: { attribute: "aria-describedby", type: String },
246
+ autofocus: { type: Boolean, reflect: true },
247
+ disabled: { type: Boolean, reflect: true },
248
+ fullWidth: { attribute: "full-width", type: Boolean, reflect: true },
249
+ invalid: { type: Boolean, reflect: true },
250
+ loading: { type: Boolean, reflect: true },
251
+ name: { type: String },
252
+ pill: { type: Boolean, reflect: true },
253
+ required: { type: Boolean, reflect: true },
254
+ size: { type: String, reflect: true },
255
+ success: { type: Boolean, reflect: true },
256
+ title: { type: String, reflect: true },
257
+ value: { type: String }
258
+ };
259
+ function defineSpectreSelect(tagName = "sp-select") {
260
+ const existingElement = customElements.get(tagName);
261
+ if (existingElement) {
262
+ return existingElement;
263
+ }
264
+ customElements.define(tagName, SpectreSelectElement);
265
+ return SpectreSelectElement;
266
+ }
267
+
268
+ exports.SpectreSelectElement = SpectreSelectElement;
269
+ exports.defineSpectreSelect = defineSpectreSelect;
270
+ exports.spectreSelectSizes = spectreSelectSizes;
271
+ //# sourceMappingURL=select.cjs.map
272
+ //# sourceMappingURL=select.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/select/sp-select.ts"],"names":["LitElement","getInputClasses","html","ifDefined","live","n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AAA;AACjB,CAAA;AAkSK,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":"select.cjs","sourcesContent":["import { LitElement, html, nothing } from 'lit';\nimport { live } from 'lit/directives/live.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\n\nimport {\n getInputClasses,\n type InputSize,\n} from '@phcdevworks/spectre-ui';\n\nexport const spectreSelectSizes = ['sm', 'md', 'lg'] as const;\n\nexport type SpectreSelectSize = (typeof spectreSelectSizes)[number];\n\nexport interface SpectreSelectProps {\n autofocus?: boolean;\n disabled?: boolean;\n fullWidth?: boolean;\n invalid?: boolean;\n loading?: boolean;\n name?: string;\n pill?: boolean;\n required?: boolean;\n size?: SpectreSelectSize;\n success?: boolean;\n title?: string;\n value?: string;\n}\n\nfunction isSelectSize(value: string): value is InputSize {\n return (spectreSelectSizes as readonly string[]).includes(value);\n}\n\nfunction isSelectableContent(node: Node): boolean {\n if (node.nodeType === Node.ELEMENT_NODE) {\n const tagName = (node as Element).tagName;\n return tagName === 'OPTION' || tagName === 'OPTGROUP';\n }\n\n if (node.nodeType === Node.TEXT_NODE) {\n return (node.textContent?.trim().length ?? 0) > 0;\n }\n\n return false;\n}\n\nexport class SpectreSelectElement extends LitElement implements SpectreSelectProps {\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 invalid: { type: Boolean, reflect: true },\n loading: { type: Boolean, reflect: true },\n name: { type: String },\n pill: { type: Boolean, reflect: true },\n required: { type: Boolean, reflect: true },\n size: { type: String, reflect: true },\n success: { 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 disabled = false;\n fullWidth = false;\n invalid = false;\n loading = false;\n name?: string;\n pill = false;\n required = false;\n size: SpectreSelectSize = 'md';\n success = false;\n override title = '';\n value = '';\n private _id?: string;\n private projectedOptions: Node[] = [];\n private contentObserver?: MutationObserver | undefined;\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 // Spectre components intentionally render in light DOM so the global\n // 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.syncProjectedOptions();\n this.startContentObserver();\n }\n\n override disconnectedCallback(): void {\n this.stopContentObserver();\n super.disconnectedCallback();\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('size') && !isSelectSize(this.size)) {\n this.size = 'md';\n }\n\n if (changedProperties.has('value') && this.value == null) {\n this.value = '';\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 protected override updated(changedProperties: Map<PropertyKey, unknown>): void {\n super.updated(changedProperties);\n\n const nativeSelect = this.nativeSelect;\n if (!nativeSelect) {\n return;\n }\n\n if (this.value !== '' && nativeSelect.value !== this.value) {\n nativeSelect.value = this.value;\n return;\n }\n\n if (this.value === '' && !this.hasAttribute('value')) {\n const nativeValue = nativeSelect.value ?? '';\n if (nativeValue !== '') {\n this.value = nativeValue;\n }\n }\n }\n\n private get selectClasses(): string {\n return getInputClasses({\n fullWidth: this.fullWidth,\n pill: this.pill,\n size: this.size,\n state: this.isDisabled\n ? this.disabled\n ? 'disabled'\n : 'loading'\n : this.invalid\n ? 'error'\n : this.success\n ? 'success'\n : 'default',\n });\n }\n\n private get isDisabled(): boolean {\n return this.disabled || this.loading;\n }\n\n private get nativeSelect(): HTMLSelectElement | null {\n return this.querySelector('[data-sp-select-native]');\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.isInternalSelectNode(node) || this.contains(node),\n ) &&\n Array.from(mutation.addedNodes).every((node) => this.isInternalSelectNode(node))\n );\n });\n\n if (isInternalMovement) {\n return;\n }\n\n if (this.syncProjectedOptions()) {\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 syncProjectedOptions(): boolean {\n const nextProjectedOptions: Node[] = [];\n\n Array.from(this.childNodes).forEach((node) => {\n if (this.isInternalSelectNode(node)) {\n this.projectedOptions.forEach((projectedNode) => {\n if (projectedNode.parentNode !== this && this.contains(projectedNode)) {\n nextProjectedOptions.push(projectedNode);\n }\n });\n return;\n }\n\n if (isSelectableContent(node)) {\n nextProjectedOptions.push(node);\n }\n });\n\n const hasChanged =\n nextProjectedOptions.length !== this.projectedOptions.length ||\n nextProjectedOptions.some((node, index) => node !== this.projectedOptions[index]);\n\n if (hasChanged) {\n this.projectedOptions = nextProjectedOptions;\n }\n\n return hasChanged;\n }\n\n private isInternalSelectNode(node: Node): boolean {\n return (\n node.nodeType === Node.ELEMENT_NODE && (node as Element).hasAttribute('data-sp-select-native')\n );\n }\n\n private handleInput(event: Event): void {\n const select = event.currentTarget as HTMLSelectElement;\n this.value = select.value;\n }\n\n private handleChange(event: Event): void {\n const select = event.currentTarget as HTMLSelectElement;\n this.value = select.value;\n }\n\n override focus(options?: FocusOptions): void {\n this.nativeSelect?.focus(options);\n }\n\n override blur(): void {\n this.nativeSelect?.blur();\n }\n\n\n override render() {\n return html`\n <select\n aria-busy=${this.loading ? 'true' : 'false'}\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 class=${this.selectClasses}\n data-sp-select-native\n ?disabled=${this.isDisabled}\n id=${ifDefined(this.id || undefined)}\n name=${ifDefined(this.name)}\n ?required=${this.required}\n title=${ifDefined(this.title || undefined)}\n .value=${live(this.value)}\n @change=${this.handleChange}\n @input=${this.handleInput}\n >\n ${this.projectedOptions.length > 0 ? this.projectedOptions : nothing}\n </select>\n `;\n }\n}\n\nexport function defineSpectreSelect(tagName = 'sp-select'): typeof SpectreSelectElement {\n const existingElement = customElements.get(tagName);\n\n if (existingElement) {\n return existingElement as unknown as typeof SpectreSelectElement;\n }\n\n customElements.define(tagName, SpectreSelectElement);\n return SpectreSelectElement;\n}\n"]}