@solid-design-system/components 1.0.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.
Files changed (119) hide show
  1. package/LICENSE.md +20 -0
  2. package/README.md +15 -0
  3. package/dist/components/es/button.js +125 -0
  4. package/dist/components/es/classix.js +1 -0
  5. package/dist/components/es/component.styles.js +1 -0
  6. package/dist/components/es/icon.js +17 -0
  7. package/dist/components/es/if-defined.js +11 -0
  8. package/dist/components/es/include.js +1 -0
  9. package/dist/components/es/include.styles.js +1 -0
  10. package/dist/components/es/library.js +1 -0
  11. package/dist/components/es/library.system.js +1 -0
  12. package/dist/components/es/link.js +1 -0
  13. package/dist/components/es/lit-element.js +23 -0
  14. package/dist/components/es/request.js +1 -0
  15. package/dist/components/es/request2.js +1 -0
  16. package/dist/components/es/solid-components.js +1 -0
  17. package/dist/components/es/solid-element.js +21 -0
  18. package/dist/components/es/spinner.js +1 -0
  19. package/dist/components/es/state.js +6 -0
  20. package/dist/components/es/watch.js +1 -0
  21. package/dist/components/umd/solid-components.js +200 -0
  22. package/dist/custom-elements.json +1 -0
  23. package/dist/package/components/button/button.d.ts +48 -0
  24. package/dist/package/components/button/button.js +391 -0
  25. package/dist/package/components/icon/icon.d.ts +22 -0
  26. package/dist/package/components/icon/icon.js +129 -0
  27. package/dist/package/components/icon/library.d.ts +16 -0
  28. package/dist/package/components/icon/library.js +17 -0
  29. package/dist/package/components/icon/library.system.d.ts +7 -0
  30. package/dist/package/components/icon/library.system.js +26 -0
  31. package/dist/package/components/icon/request.d.ts +11 -0
  32. package/dist/package/components/icon/request.js +24 -0
  33. package/dist/package/components/include/include.d.ts +16 -0
  34. package/dist/package/components/include/include.js +72 -0
  35. package/dist/package/components/include/include.styles.d.ts +2 -0
  36. package/dist/package/components/include/include.styles.js +6 -0
  37. package/dist/package/components/include/request.d.ts +7 -0
  38. package/dist/package/components/include/request.js +18 -0
  39. package/dist/package/components/link/link.d.ts +22 -0
  40. package/dist/package/components/link/link.js +107 -0
  41. package/dist/package/components/spinner/spinner.d.ts +12 -0
  42. package/dist/package/components/spinner/spinner.js +46 -0
  43. package/dist/package/internal/form.d.ts +35 -0
  44. package/dist/package/internal/form.js +212 -0
  45. package/dist/package/internal/slot.d.ts +14 -0
  46. package/dist/package/internal/slot.js +47 -0
  47. package/dist/package/internal/solid-element.d.ts +26 -0
  48. package/dist/package/internal/solid-element.js +38 -0
  49. package/dist/package/internal/watch.d.ts +11 -0
  50. package/dist/package/internal/watch.js +28 -0
  51. package/dist/package/node_modules/.pnpm/@shoelace-style_localize@3.1.0/node_modules/@shoelace-style/localize/dist/index.js +103 -0
  52. package/dist/package/solid-components.d.ts +6 -0
  53. package/dist/package/solid-components.js +14 -0
  54. package/dist/package/styles/component.styles.d.ts +2 -0
  55. package/dist/package/styles/component.styles.js +5 -0
  56. package/dist/package/styles/tailwind.css.js +4 -0
  57. package/dist/package/translations/en.d.ts +3 -0
  58. package/dist/package/translations/en.js +31 -0
  59. package/dist/package/utilities/localize.d.ts +25 -0
  60. package/dist/package/utilities/localize.js +7 -0
  61. package/dist/versioned-components/es/button.js +125 -0
  62. package/dist/versioned-components/es/classix.js +1 -0
  63. package/dist/versioned-components/es/component.styles.js +1 -0
  64. package/dist/versioned-components/es/icon.js +17 -0
  65. package/dist/versioned-components/es/if-defined.js +11 -0
  66. package/dist/versioned-components/es/include.js +1 -0
  67. package/dist/versioned-components/es/include.styles.js +1 -0
  68. package/dist/versioned-components/es/library.js +1 -0
  69. package/dist/versioned-components/es/library.system.js +1 -0
  70. package/dist/versioned-components/es/link.js +1 -0
  71. package/dist/versioned-components/es/lit-element.js +23 -0
  72. package/dist/versioned-components/es/request.js +1 -0
  73. package/dist/versioned-components/es/request2.js +1 -0
  74. package/dist/versioned-components/es/solid-components.js +1 -0
  75. package/dist/versioned-components/es/solid-element.js +21 -0
  76. package/dist/versioned-components/es/spinner.js +1 -0
  77. package/dist/versioned-components/es/state.js +6 -0
  78. package/dist/versioned-components/es/watch.js +1 -0
  79. package/dist/versioned-package/components/button/button.d.ts +48 -0
  80. package/dist/versioned-package/components/button/button.js +391 -0
  81. package/dist/versioned-package/components/icon/icon.d.ts +22 -0
  82. package/dist/versioned-package/components/icon/icon.js +129 -0
  83. package/dist/versioned-package/components/icon/library.d.ts +16 -0
  84. package/dist/versioned-package/components/icon/library.js +17 -0
  85. package/dist/versioned-package/components/icon/library.system.d.ts +7 -0
  86. package/dist/versioned-package/components/icon/library.system.js +26 -0
  87. package/dist/versioned-package/components/icon/request.d.ts +11 -0
  88. package/dist/versioned-package/components/icon/request.js +24 -0
  89. package/dist/versioned-package/components/include/include.d.ts +16 -0
  90. package/dist/versioned-package/components/include/include.js +72 -0
  91. package/dist/versioned-package/components/include/include.styles.d.ts +2 -0
  92. package/dist/versioned-package/components/include/include.styles.js +6 -0
  93. package/dist/versioned-package/components/include/request.d.ts +7 -0
  94. package/dist/versioned-package/components/include/request.js +18 -0
  95. package/dist/versioned-package/components/link/link.d.ts +22 -0
  96. package/dist/versioned-package/components/link/link.js +107 -0
  97. package/dist/versioned-package/components/spinner/spinner.d.ts +12 -0
  98. package/dist/versioned-package/components/spinner/spinner.js +46 -0
  99. package/dist/versioned-package/internal/form.d.ts +35 -0
  100. package/dist/versioned-package/internal/form.js +212 -0
  101. package/dist/versioned-package/internal/slot.d.ts +14 -0
  102. package/dist/versioned-package/internal/slot.js +47 -0
  103. package/dist/versioned-package/internal/solid-element.d.ts +26 -0
  104. package/dist/versioned-package/internal/solid-element.js +38 -0
  105. package/dist/versioned-package/internal/watch.d.ts +11 -0
  106. package/dist/versioned-package/internal/watch.js +28 -0
  107. package/dist/versioned-package/node_modules/.pnpm/@shoelace-style_localize@3.1.0/node_modules/@shoelace-style/localize/dist/index.js +103 -0
  108. package/dist/versioned-package/solid-components.d.ts +6 -0
  109. package/dist/versioned-package/solid-components.js +14 -0
  110. package/dist/versioned-package/styles/component.styles.d.ts +2 -0
  111. package/dist/versioned-package/styles/component.styles.js +5 -0
  112. package/dist/versioned-package/styles/tailwind.css.js +4 -0
  113. package/dist/versioned-package/translations/en.d.ts +3 -0
  114. package/dist/versioned-package/translations/en.js +31 -0
  115. package/dist/versioned-package/utilities/localize.d.ts +25 -0
  116. package/dist/versioned-package/utilities/localize.js +7 -0
  117. package/dist/vscode.html-custom-data.json +661 -0
  118. package/dist/web-types.json +1449 -0
  119. package/package.json +185 -0
@@ -0,0 +1,391 @@
1
+ import "../spinner/spinner.js";
2
+ import { css } from "lit";
3
+ import { query, queryAssignedElements, state, property, customElement } from "lit/decorators.js";
4
+ import { FormControlController } from "../../internal/form.js";
5
+ import { HasSlotController } from "../../internal/slot.js";
6
+ import { literal, html } from "lit/static-html.js";
7
+ import { ifDefined } from "lit/directives/if-defined.js";
8
+ import { watch } from "../../internal/watch.js";
9
+ import componentStyles from "../../styles/component.styles.js";
10
+ import cx from "classix";
11
+ import SolidElement from "../../internal/solid-element.js";
12
+ var __defProp = Object.defineProperty;
13
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
14
+ var __decorateClass = (decorators, target, key, kind) => {
15
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
16
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
17
+ if (decorator = decorators[i])
18
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
19
+ if (kind && result)
20
+ __defProp(target, key, result);
21
+ return result;
22
+ };
23
+ let SdButton = class extends SolidElement {
24
+ constructor() {
25
+ super(...arguments);
26
+ this.formControlController = new FormControlController(this, {
27
+ form: (input) => {
28
+ if (input.hasAttribute("form")) {
29
+ const doc = input.getRootNode();
30
+ const formId = input.getAttribute("form");
31
+ return doc.getElementById(formId);
32
+ }
33
+ return input.closest("form");
34
+ }
35
+ });
36
+ this.hasSlotController = new HasSlotController(this, "[default]", "icon-left", "icon-right");
37
+ this.invalid = false;
38
+ this.title = "";
39
+ this.variant = "primary";
40
+ this.inverted = false;
41
+ this.size = "lg";
42
+ this.disabled = false;
43
+ this.loading = false;
44
+ this.type = "button";
45
+ this.name = "";
46
+ this.value = "";
47
+ this.href = "";
48
+ }
49
+ firstUpdated() {
50
+ if (this.isButton()) {
51
+ this.formControlController.updateValidity();
52
+ }
53
+ }
54
+ handleBlur() {
55
+ this.emit("sd-blur");
56
+ }
57
+ handleFocus() {
58
+ this.emit("sd-focus");
59
+ }
60
+ handleClick(event) {
61
+ if (this.disabled || this.loading) {
62
+ event.preventDefault();
63
+ event.stopPropagation();
64
+ return;
65
+ }
66
+ if (this.type === "submit") {
67
+ this.formControlController.submit(this);
68
+ }
69
+ if (this.type === "reset") {
70
+ this.formControlController.reset(this);
71
+ }
72
+ }
73
+ isButton() {
74
+ return this.href ? false : true;
75
+ }
76
+ isLink() {
77
+ return this.href ? true : false;
78
+ }
79
+ handleDisabledChange() {
80
+ if (this.isButton()) {
81
+ this.formControlController.setValidity(this.disabled);
82
+ }
83
+ }
84
+ /** Simulates a click on the button. */
85
+ click() {
86
+ this.button.click();
87
+ }
88
+ /** Sets focus on the button. */
89
+ focus(options) {
90
+ this.button.focus(options);
91
+ }
92
+ /** Removes focus from the button. */
93
+ blur() {
94
+ this.button.blur();
95
+ }
96
+ /** Checks for validity but does not show the browser's validation message. */
97
+ checkValidity() {
98
+ if (this.isButton()) {
99
+ return this.button.checkValidity();
100
+ }
101
+ return true;
102
+ }
103
+ /** Checks for validity and shows the browser's validation message if the control is invalid. */
104
+ reportValidity() {
105
+ if (this.isButton()) {
106
+ return this.button.reportValidity();
107
+ }
108
+ return true;
109
+ }
110
+ /** Sets a custom validation message. Pass an empty string to restore validity. */
111
+ setCustomValidity(message) {
112
+ if (this.isButton()) {
113
+ this.button.setCustomValidity(message);
114
+ this.formControlController.updateValidity();
115
+ }
116
+ }
117
+ render() {
118
+ const isLink = this.isLink();
119
+ const tag = isLink ? literal`a` : literal`button`;
120
+ const slots = {
121
+ label: this.hasSlotController.test("[default]"),
122
+ "icon-left": this.hasSlotController.test("icon-left"),
123
+ "icon-right": this.hasSlotController.test("icon-right"),
124
+ "icon-only": this._iconsInDefaultSlot.length > 0
125
+ };
126
+ return html`
127
+ <${tag}
128
+ part="base"
129
+ class=${cx(
130
+ `font-md leading-[calc(var(--tw-varspacing)-2px)] no-underline
131
+ w-full h-varspacing whitespace-nowrap align-middle inline-flex items-stretch justify-center
132
+ border transition-colors duration-200 ease-in-out rounded-md
133
+ select-none cursor-[inherit]`,
134
+ !this.inverted ? "focus-visible:focus-outline" : "focus-visible:focus-outline-inverted",
135
+ this.loading && "relative cursor-wait",
136
+ this.disabled && "cursor-not-allowed",
137
+ slots["icon-only"] && "px-0 w-varspacing",
138
+ /**
139
+ * Anatomy
140
+ * */
141
+ {
142
+ /* sizes, fonts */
143
+ sm: "text-sm varspacing-8 px-4",
144
+ md: "text-base varspacing-10 px-4",
145
+ lg: "text-base varspacing-12 px-4"
146
+ }[this.size],
147
+ {
148
+ /* variants */
149
+ primary: !this.inverted ? `text-white bg-primary border-transparent
150
+ hover:text-primary-100 hover:bg-primary-500
151
+ active:text-primary-200 active:bg-primary-800
152
+ disabled:bg-neutral-500` : `text-primary bg-white border-transparent
153
+ hover:text-primary-500 hover:bg-primary-100
154
+ active:text-primary-800 active:bg-primary-200
155
+ disabled:bg-neutral-600 disabled:text-white`,
156
+ secondary: !this.inverted ? `text-primary border-primary
157
+ hover:text-primary-500 hover:border-primary-500 hover:bg-primary-100
158
+ active:text-primary-800 active:border-primary-800 active:bg-primary-200
159
+ disabled:text-neutral-500 disabled:border-neutral-500` : `text-white border-white
160
+ hover:text-primary-100 hover:bg-primary-500 hover:border-primary-100
161
+ active:text-primary-200 active:bg-primary-800 active:border-primary-200
162
+ disabled:text-neutral-600 disabled:border-neutral-600`,
163
+ tertiary: !this.inverted ? `text-primary border-transparent
164
+ hover:text-primary-500 hover:bg-primary-100
165
+ active:text-primary-800 active:bg-primary-200
166
+ disabled:text-neutral-500` : `text-white border-transparent
167
+ hover:text-primary-100 hover:bg-primary-500
168
+ active:text-primary-200 active:bg-primary-800
169
+ disabled:text-neutral-600`,
170
+ cta: `text-white bg-accent border-transparent
171
+ hover:bg-accent-300
172
+ active:bg-accent-500
173
+ ${!this.inverted ? "disabled:bg-neutral-500" : "disabled:bg-neutral-600"} disabled:text-white`
174
+ }[this.variant]
175
+ )}
176
+ ?disabled=${ifDefined(isLink ? void 0 : this.disabled)}
177
+ type=${ifDefined(isLink ? void 0 : this.type)}
178
+ title=${this.title}
179
+ name=${ifDefined(isLink ? void 0 : this.name)}
180
+ value=${ifDefined(isLink ? void 0 : this.value)}
181
+ href=${ifDefined(isLink ? this.href : void 0)}
182
+ target=${ifDefined(isLink ? this.target : void 0)}
183
+ download=${ifDefined(isLink ? this.download : void 0)}
184
+ rel=${ifDefined(isLink && this.target ? "noreferrer noopener" : void 0)}
185
+ role=${ifDefined(isLink ? void 0 : "button")}
186
+ aria-disabled=${this.disabled ? "true" : "false"}
187
+ tabindex=${this.disabled ? "-1" : "0"}
188
+ @blur=${this.handleBlur}
189
+ @focus=${this.handleFocus}
190
+ @click=${this.handleClick}
191
+ >
192
+ <slot name="icon-left" part="icon-left" class=${cx(
193
+ "flex flex-auto items-center pointer-events-none",
194
+ slots["icon-only"] && "hidden",
195
+ this.loading && "invisible",
196
+ slots["icon-left"] && {
197
+ sm: "mr-1",
198
+ md: "mr-2",
199
+ lg: "mr-2"
200
+ }[this.size]
201
+ )}></slot>
202
+ <slot part="label" class=${cx(
203
+ slots["icon-only"] ? "flex flex-auto items-center pointer-events-none" : "inline-block",
204
+ this.loading && "invisible"
205
+ )}></slot>
206
+ <slot name="icon-right"
207
+ part="icon-right"
208
+ class=${cx(
209
+ "flex flex-auto items-center pointer-events-none",
210
+ this.loading && "invisible",
211
+ slots["icon-only"] && "hidden",
212
+ slots["icon-right"] && {
213
+ sm: "ml-1",
214
+ md: "ml-2",
215
+ lg: "ml-2"
216
+ }[this.size]
217
+ )}>
218
+ </slot>
219
+ ${this.loading ? html`<sd-spinner
220
+ class="${cx("absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2")}"
221
+ ></sd-spinner>` : ""}
222
+ </${tag}>
223
+ `;
224
+ }
225
+ };
226
+ SdButton.styles = [
227
+ componentStyles,
228
+ SolidElement.styles,
229
+ css`
230
+ :host {
231
+ display: inline-block;
232
+ position: relative;
233
+ width: auto;
234
+ cursor: pointer;
235
+ }
236
+
237
+ sd-spinner {
238
+ --indicator-color: currentColor;
239
+ --track-color: var(--tw-varcolor-200);
240
+ }
241
+
242
+ /*
243
+ * Badges:
244
+ * Slotted badges are positioned absolutely in the top right corner of the button.
245
+ */
246
+
247
+ ::slotted(sd-badge) {
248
+ position: absolute;
249
+ top: 0;
250
+ right: 0;
251
+ translate: 50% -50%;
252
+ pointer-events: none;
253
+ }
254
+
255
+ /**
256
+ * sd-icons should automatically resize correctly based on the button size.
257
+ */
258
+
259
+ ::slotted(sd-icon),
260
+ sd-spinner {
261
+ font-size: calc(var(--tw-varspacing) / 2);
262
+ }
263
+
264
+ ///*
265
+ // * Button groups support a variety of button types (e.g. buttons with tooltips, buttons as dropdown triggers, etc.).
266
+ // * This means buttons aren't always direct descendants of the button group, thus we can't target them with the
267
+ // * ::slotted selector. To work around this, the button group component does some magic to add these special classes to
268
+ // * buttons and we style them here instead.
269
+ // */
270
+
271
+ // :host(.sd-button-group__button--first:not(.sd-button-group__button--last)) .button {
272
+ // border-start-end-radius: 0;
273
+ // border-end-end-radius: 0;
274
+ // }
275
+
276
+ // :host(.sd-button-group__button--inner) .button {
277
+ // border-radius: 0;
278
+ // }
279
+
280
+ // :host(.sd-button-group__button--last:not(.sd-button-group__button--first)) .button {
281
+ // border-start-start-radius: 0;
282
+ // border-end-start-radius: 0;
283
+ // }
284
+
285
+ // /* All except the first */
286
+ // :host(.sd-button-group__button:not(.sd-button-group__button--first)) {
287
+ // margin-inline-start: calc(-1 * var(--sd-input-border-width));
288
+ // }
289
+
290
+ // /* Add a visual separator between solid buttons */
291
+ // :host(
292
+ // .sd-button-group__button:not(
293
+ // .sd-button-group__button--first,
294
+ // .sd-button-group__button--radio,
295
+ // [variant='default']
296
+ // ):not(:hover)
297
+ // )
298
+ // .button:after {
299
+ // content: '';
300
+ // position: absolute;
301
+ // top: 0;
302
+ // inset-inline-start: 0;
303
+ // bottom: 0;
304
+ // border-left: solid 1px rgb(128 128 128 / 33%);
305
+ // mix-blend-mode: multiply;
306
+ // }
307
+
308
+ // /* Bump hovered, focused, and checked buttons up so their focus ring isn't clipped */
309
+ // :host(.sd-button-group__button--hover) {
310
+ // z-index: 1;
311
+ // }
312
+
313
+ // /* Focus and checked are always on top */
314
+ // :host(.sd-button-group__button--focus),
315
+ // :host(.sd-button-group__button[checked]) {
316
+ // z-index: 2;
317
+ // }
318
+ `
319
+ ];
320
+ __decorateClass([
321
+ query("a, button")
322
+ ], SdButton.prototype, "button", 2);
323
+ __decorateClass([
324
+ queryAssignedElements({ selector: "sd-icon" })
325
+ ], SdButton.prototype, "_iconsInDefaultSlot", 2);
326
+ __decorateClass([
327
+ state()
328
+ ], SdButton.prototype, "invalid", 2);
329
+ __decorateClass([
330
+ property()
331
+ ], SdButton.prototype, "title", 2);
332
+ __decorateClass([
333
+ property({ reflect: true })
334
+ ], SdButton.prototype, "variant", 2);
335
+ __decorateClass([
336
+ property({ type: Boolean, reflect: true })
337
+ ], SdButton.prototype, "inverted", 2);
338
+ __decorateClass([
339
+ property({ reflect: true })
340
+ ], SdButton.prototype, "size", 2);
341
+ __decorateClass([
342
+ property({ type: Boolean, reflect: true })
343
+ ], SdButton.prototype, "disabled", 2);
344
+ __decorateClass([
345
+ property({ type: Boolean, reflect: true })
346
+ ], SdButton.prototype, "loading", 2);
347
+ __decorateClass([
348
+ property()
349
+ ], SdButton.prototype, "type", 2);
350
+ __decorateClass([
351
+ property()
352
+ ], SdButton.prototype, "name", 2);
353
+ __decorateClass([
354
+ property()
355
+ ], SdButton.prototype, "value", 2);
356
+ __decorateClass([
357
+ property()
358
+ ], SdButton.prototype, "href", 2);
359
+ __decorateClass([
360
+ property()
361
+ ], SdButton.prototype, "target", 2);
362
+ __decorateClass([
363
+ property()
364
+ ], SdButton.prototype, "download", 2);
365
+ __decorateClass([
366
+ property()
367
+ ], SdButton.prototype, "form", 2);
368
+ __decorateClass([
369
+ property({ attribute: "formaction" })
370
+ ], SdButton.prototype, "formAction", 2);
371
+ __decorateClass([
372
+ property({ attribute: "formenctype" })
373
+ ], SdButton.prototype, "formEnctype", 2);
374
+ __decorateClass([
375
+ property({ attribute: "formmethod" })
376
+ ], SdButton.prototype, "formMethod", 2);
377
+ __decorateClass([
378
+ property({ attribute: "formnovalidate", type: Boolean })
379
+ ], SdButton.prototype, "formNoValidate", 2);
380
+ __decorateClass([
381
+ property({ attribute: "formtarget" })
382
+ ], SdButton.prototype, "formTarget", 2);
383
+ __decorateClass([
384
+ watch("disabled", { waitUntilFirstUpdate: true })
385
+ ], SdButton.prototype, "handleDisabledChange", 1);
386
+ SdButton = __decorateClass([
387
+ customElement("sd-button")
388
+ ], SdButton);
389
+ export {
390
+ SdButton as default
391
+ };
@@ -0,0 +1,22 @@
1
+ import SolidElement from '../../internal/solid-element';
2
+ export default class SdIcon extends SolidElement {
3
+ private svg;
4
+ name?: string;
5
+ src?: string;
6
+ label: string;
7
+ library: string;
8
+ color: 'currentColor' | 'primary' | 'white';
9
+ connectedCallback(): void;
10
+ firstUpdated(): void;
11
+ disconnectedCallback(): void;
12
+ private getUrl;
13
+ handleLabelChange(): void;
14
+ setIcon(): Promise<void>;
15
+ render(): import("lit").TemplateResult<1>;
16
+ static styles: import("lit").CSSResult[];
17
+ }
18
+ declare global {
19
+ interface HTMLElementTagNameMap {
20
+ 'sd-icon': SdIcon;
21
+ }
22
+ }
@@ -0,0 +1,129 @@
1
+ import { css, html } from "lit";
2
+ import { state, property, customElement } from "lit/decorators.js";
3
+ import { unwatchIcon, getIconLibrary, watchIcon } from "./library.js";
4
+ import { requestIcon } from "./request.js";
5
+ import { unsafeSVG } from "lit/directives/unsafe-svg.js";
6
+ import { watch } from "../../internal/watch.js";
7
+ import componentStyles from "../../styles/component.styles.js";
8
+ import SolidElement from "../../internal/solid-element.js";
9
+ var __defProp = Object.defineProperty;
10
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
+ var __decorateClass = (decorators, target, key, kind) => {
12
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
13
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
14
+ if (decorator = decorators[i])
15
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
16
+ if (kind && result)
17
+ __defProp(target, key, result);
18
+ return result;
19
+ };
20
+ let parser;
21
+ let SdIcon = class extends SolidElement {
22
+ constructor() {
23
+ super(...arguments);
24
+ this.svg = "";
25
+ this.label = "";
26
+ this.library = "default";
27
+ this.color = "currentColor";
28
+ }
29
+ connectedCallback() {
30
+ super.connectedCallback();
31
+ watchIcon(this);
32
+ }
33
+ firstUpdated() {
34
+ this.setIcon();
35
+ }
36
+ disconnectedCallback() {
37
+ super.disconnectedCallback();
38
+ unwatchIcon(this);
39
+ }
40
+ getUrl() {
41
+ const library = getIconLibrary(this.library);
42
+ if (this.name && library) {
43
+ return library.resolver(this.name);
44
+ }
45
+ return this.src;
46
+ }
47
+ handleLabelChange() {
48
+ const hasLabel = typeof this.label === "string" && this.label.length > 0;
49
+ if (hasLabel) {
50
+ this.setAttribute("role", "img");
51
+ this.setAttribute("aria-label", this.label);
52
+ this.removeAttribute("aria-hidden");
53
+ } else {
54
+ this.removeAttribute("role");
55
+ this.removeAttribute("aria-label");
56
+ this.setAttribute("aria-hidden", "true");
57
+ }
58
+ }
59
+ async setIcon() {
60
+ var _a;
61
+ const library = getIconLibrary(this.library);
62
+ const url = this.getUrl();
63
+ if (!parser) {
64
+ parser = new DOMParser();
65
+ }
66
+ if (url) {
67
+ try {
68
+ const file = await requestIcon(url);
69
+ if (url !== this.getUrl()) {
70
+ } else if (file.ok) {
71
+ const doc = parser.parseFromString(file.svg, "text/html");
72
+ const svgEl = doc.body.querySelector("svg");
73
+ if (svgEl !== null) {
74
+ (_a = library == null ? void 0 : library.mutator) == null ? void 0 : _a.call(library, svgEl);
75
+ this.svg = svgEl.outerHTML;
76
+ this.emit("sd-load");
77
+ } else {
78
+ this.svg = "";
79
+ this.emit("sd-error");
80
+ }
81
+ } else {
82
+ this.svg = "";
83
+ this.emit("sd-error");
84
+ }
85
+ } catch {
86
+ this.emit("sd-error");
87
+ }
88
+ } else if (this.svg.length > 0) {
89
+ this.svg = "";
90
+ }
91
+ }
92
+ render() {
93
+ return html`${unsafeSVG(this.svg)}`;
94
+ }
95
+ };
96
+ SdIcon.styles = [
97
+ componentStyles,
98
+ css`:host{display:inline-block;width:1em;height:1em;box-sizing:content-box!important}svg{display:block;height:100%;width:100%}:host([color=primary]) svg{color:rgb(var(--sd-color-primary,0 53 142) / var(--tw-text-opacity,1))}// text-primary :host([color=white]) svg{color:rgb(var(--sd-color-white,255 255 255) / var(--tw-text-opacity,1))}`
99
+ ];
100
+ __decorateClass([
101
+ state()
102
+ ], SdIcon.prototype, "svg", 2);
103
+ __decorateClass([
104
+ property({ reflect: true })
105
+ ], SdIcon.prototype, "name", 2);
106
+ __decorateClass([
107
+ property()
108
+ ], SdIcon.prototype, "src", 2);
109
+ __decorateClass([
110
+ property()
111
+ ], SdIcon.prototype, "label", 2);
112
+ __decorateClass([
113
+ property({ reflect: true })
114
+ ], SdIcon.prototype, "library", 2);
115
+ __decorateClass([
116
+ property({ reflect: true })
117
+ ], SdIcon.prototype, "color", 2);
118
+ __decorateClass([
119
+ watch("label")
120
+ ], SdIcon.prototype, "handleLabelChange", 1);
121
+ __decorateClass([
122
+ watch(["name", "src", "library"])
123
+ ], SdIcon.prototype, "setIcon", 1);
124
+ SdIcon = __decorateClass([
125
+ customElement("sd-icon")
126
+ ], SdIcon);
127
+ export {
128
+ SdIcon as default
129
+ };
@@ -0,0 +1,16 @@
1
+ import type SdIcon from '../icon/icon';
2
+ export type IconLibraryResolver = (name: string) => string;
3
+ export type IconLibraryMutator = (svg: SVGElement) => void;
4
+ export interface IconLibrary {
5
+ name: string;
6
+ resolver: IconLibraryResolver;
7
+ mutator?: IconLibraryMutator;
8
+ }
9
+ export declare function watchIcon(icon: SdIcon): void;
10
+ export declare function unwatchIcon(icon: SdIcon): void;
11
+ export declare function getIconLibrary(name?: string): IconLibrary | undefined;
12
+ export declare function registerIconLibrary(name: string, options: {
13
+ resolver: IconLibraryResolver;
14
+ mutator?: IconLibraryMutator;
15
+ }): void;
16
+ export declare function unregisterIconLibrary(name: string): void;
@@ -0,0 +1,17 @@
1
+ import systemLibrary from "./library.system.js";
2
+ let registry = [systemLibrary];
3
+ let watchedIcons = [];
4
+ function watchIcon(icon) {
5
+ watchedIcons.push(icon);
6
+ }
7
+ function unwatchIcon(icon) {
8
+ watchedIcons = watchedIcons.filter((el) => el !== icon);
9
+ }
10
+ function getIconLibrary(name) {
11
+ return registry.find((lib) => lib.name === name);
12
+ }
13
+ export {
14
+ getIconLibrary,
15
+ unwatchIcon,
16
+ watchIcon
17
+ };
@@ -0,0 +1,7 @@
1
+ import type { IconLibrary } from './library';
2
+ export declare const icons: {
3
+ 'chevron-down': string;
4
+ 'chevron-up': string;
5
+ };
6
+ declare const systemLibrary: IconLibrary;
7
+ export default systemLibrary;
@@ -0,0 +1,26 @@
1
+ const icons = {
2
+ "chevron-down": `
3
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
4
+ <path d="M20.257 6.333l-8.257 9.173-8.257-9.173c-0.181-0.181-0.431-0.292-0.707-0.292-0.552 0-1 0.448-1 1 0 0.238 0.083 0.456 0.222 0.628l-0.001-0.002 9 10c0.184 0.204 0.449 0.331 0.743 0.331s0.56-0.127 0.743-0.33l0.001-0.001 9-10c0.137-0.17 0.22-0.388 0.22-0.626 0-0.552-0.448-1-1-1-0.276 0-0.526 0.112-0.707 0.293v0z"></path>
5
+ </svg>
6
+ `,
7
+ "chevron-up": `
8
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
9
+ <path d="M12.743 6.333c-0.188-0.195-0.452-0.316-0.743-0.316s-0.555 0.121-0.743 0.315l-0 0-9 10c-0.137 0.17-0.22 0.388-0.22 0.626 0 0.552 0.448 1 1 1 0.276 0 0.526-0.112 0.707-0.293v0l8.257-9.173 8.257 9.173c0.181 0.181 0.431 0.292 0.707 0.292 0.552 0 1-0.448 1-1 0-0.238-0.083-0.456-0.222-0.628l0.001 0.002z"></path>
10
+ </svg>
11
+ `
12
+ };
13
+ const systemLibrary = {
14
+ name: "system",
15
+ resolver: (name) => {
16
+ if (name in icons) {
17
+ return `data:image/svg+xml,${encodeURIComponent(icons[name])}`;
18
+ }
19
+ return "";
20
+ },
21
+ mutator: (svg) => svg.setAttribute("fill", "currentColor")
22
+ };
23
+ export {
24
+ systemLibrary as default,
25
+ icons
26
+ };
@@ -0,0 +1,11 @@
1
+ type IconFile = {
2
+ ok: true;
3
+ status: number;
4
+ svg: string;
5
+ } | {
6
+ ok: false;
7
+ status: number;
8
+ svg: null;
9
+ };
10
+ export declare function requestIcon(url: string): Promise<IconFile>;
11
+ export {};
@@ -0,0 +1,24 @@
1
+ import { requestInclude } from "../include/request.js";
2
+ const iconFiles = /* @__PURE__ */ new Map();
3
+ async function requestIcon(url) {
4
+ if (iconFiles.has(url)) {
5
+ return iconFiles.get(url);
6
+ }
7
+ const fileData = await requestInclude(url);
8
+ const iconFileData = {
9
+ ok: fileData.ok,
10
+ status: fileData.status,
11
+ svg: null
12
+ };
13
+ if (fileData.ok) {
14
+ const div = document.createElement("div");
15
+ div.innerHTML = fileData.html;
16
+ const svg = div.firstElementChild;
17
+ iconFileData.svg = (svg == null ? void 0 : svg.tagName.toLowerCase()) === "svg" ? svg.outerHTML : "";
18
+ }
19
+ iconFiles.set(url, iconFileData);
20
+ return iconFileData;
21
+ }
22
+ export {
23
+ requestIcon
24
+ };
@@ -0,0 +1,16 @@
1
+ import SolidElement from '../../internal/solid-element';
2
+ import type { CSSResultGroup } from 'lit';
3
+ export default class SdInclude extends SolidElement {
4
+ static styles: CSSResultGroup;
5
+ src: string;
6
+ mode: 'cors' | 'no-cors' | 'same-origin';
7
+ allowScripts: boolean;
8
+ private executeScript;
9
+ handleSrcChange(): Promise<void>;
10
+ render(): import("lit").TemplateResult<1>;
11
+ }
12
+ declare global {
13
+ interface HTMLElementTagNameMap {
14
+ 'sd-include': SdInclude;
15
+ }
16
+ }