kanto-ds 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -3
- package/dist/chunks/index-fzPIgxe2.js +74 -0
- package/dist/chunks/index-fzPIgxe2.js.map +1 -0
- package/dist/chunks/kt-element-mdd5cXZX.js +52 -0
- package/dist/chunks/kt-element-mdd5cXZX.js.map +1 -0
- package/dist/components/core/kt-avatar/kt-avatar.js +8 -7
- package/dist/components/core/kt-avatar/kt-avatar.js.map +1 -1
- package/dist/components/core/kt-badge/kt-badge.js +7 -6
- package/dist/components/core/kt-badge/kt-badge.js.map +1 -1
- package/dist/components/core/kt-button/kt-button.js +1 -1
- package/dist/components/core/kt-card/kt-card.js +1 -1
- package/dist/components/core/kt-code/kt-code.js +31 -30
- package/dist/components/core/kt-code/kt-code.js.map +1 -1
- package/dist/components/core/kt-icon/kt-icon.js +1 -1
- package/dist/components/core/kt-kbd/kt-kbd.js +1 -1
- package/dist/components/core/kt-split-button/kt-split-button.d.ts +2 -2
- package/dist/components/core/kt-split-button/kt-split-button.js +27 -26
- package/dist/components/core/kt-split-button/kt-split-button.js.map +1 -1
- package/dist/components/data/kt-chart/kt-chart.d.ts +2 -2
- package/dist/components/data/kt-chart/kt-chart.js +205 -204
- package/dist/components/data/kt-chart/kt-chart.js.map +1 -1
- package/dist/components/data/kt-meter/kt-meter.js +1 -1
- package/dist/components/data/kt-pagination/kt-pagination.d.ts +1 -1
- package/dist/components/data/kt-pagination/kt-pagination.js +29 -28
- package/dist/components/data/kt-pagination/kt-pagination.js.map +1 -1
- package/dist/components/data/kt-stat/kt-stat.js +1 -1
- package/dist/components/data/kt-table/kt-table.d.ts +2 -2
- package/dist/components/data/kt-table/kt-table.js +30 -29
- package/dist/components/data/kt-table/kt-table.js.map +1 -1
- package/dist/components/data/kt-timeline/kt-timeline.js +1 -1
- package/dist/components/feedback/kt-alert/kt-alert.js +17 -16
- package/dist/components/feedback/kt-alert/kt-alert.js.map +1 -1
- package/dist/components/feedback/kt-empty-state/kt-empty-state.js +1 -1
- package/dist/components/feedback/kt-progress-bar/kt-progress-bar.js +1 -1
- package/dist/components/feedback/kt-skeleton/kt-skeleton.js +1 -1
- package/dist/components/feedback/kt-toast/kt-toast.js +25 -19
- package/dist/components/feedback/kt-toast/kt-toast.js.map +1 -1
- package/dist/components/feedback/kt-toast-container/kt-toast-container.js +1 -1
- package/dist/components/feedback/kt-tooltip/kt-tooltip.js +1 -1
- package/dist/components/forms/kt-drag-drop/kt-drag-drop.d.ts +2 -2
- package/dist/components/forms/kt-drag-drop/kt-drag-drop.js +60 -57
- package/dist/components/forms/kt-drag-drop/kt-drag-drop.js.map +1 -1
- package/dist/components/forms/kt-form/kt-form.js +1 -1
- package/dist/components/forms/kt-input/kt-input.js +56 -55
- package/dist/components/forms/kt-input/kt-input.js.map +1 -1
- package/dist/components/forms/kt-input-menu/kt-input-menu.d.ts +1 -1
- package/dist/components/forms/kt-input-menu/kt-input-menu.js +57 -56
- package/dist/components/forms/kt-input-menu/kt-input-menu.js.map +1 -1
- package/dist/components/forms/kt-label-input/kt-label-input.js +1 -1
- package/dist/components/forms/kt-select/kt-select.d.ts +2 -2
- package/dist/components/forms/kt-select/kt-select.js +62 -61
- package/dist/components/forms/kt-select/kt-select.js.map +1 -1
- package/dist/components/forms/kt-textarea/kt-textarea.js +9 -8
- package/dist/components/forms/kt-textarea/kt-textarea.js.map +1 -1
- package/dist/components/forms/kt-toggle/kt-toggle.js +1 -1
- package/dist/components/navigation/kt-breadcrumb/kt-breadcrumb.d.ts +1 -1
- package/dist/components/navigation/kt-breadcrumb/kt-breadcrumb.js +6 -5
- package/dist/components/navigation/kt-breadcrumb/kt-breadcrumb.js.map +1 -1
- package/dist/components/navigation/kt-header/kt-header.js +11 -10
- package/dist/components/navigation/kt-header/kt-header.js.map +1 -1
- package/dist/components/navigation/kt-page-header/kt-page-header.js +1 -1
- package/dist/components/navigation/kt-segmented-control/kt-segmented-control.js +44 -43
- package/dist/components/navigation/kt-segmented-control/kt-segmented-control.js.map +1 -1
- package/dist/components/navigation/kt-sub-menu-navigation/kt-sub-menu-navigation.d.ts +1 -1
- package/dist/components/navigation/kt-sub-menu-navigation/kt-sub-menu-navigation.js +6 -5
- package/dist/components/navigation/kt-sub-menu-navigation/kt-sub-menu-navigation.js.map +1 -1
- package/dist/components/navigation/kt-tabs/kt-tabs.js +1 -1
- package/dist/components/navigation/kt-toggle-button/kt-toggle-button.js +1 -1
- package/dist/components/navigation/kt-toggle-button-group/kt-toggle-button-group.js +1 -1
- package/dist/components/overlays/kt-collapsible/kt-collapsible.js +1 -1
- package/dist/components/overlays/kt-confirm-dialog/kt-confirm-dialog.d.ts +3 -3
- package/dist/components/overlays/kt-confirm-dialog/kt-confirm-dialog.js +30 -27
- package/dist/components/overlays/kt-confirm-dialog/kt-confirm-dialog.js.map +1 -1
- package/dist/components/overlays/kt-dropdown/kt-dropdown.d.ts +1 -1
- package/dist/components/overlays/kt-dropdown/kt-dropdown.js +8 -7
- package/dist/components/overlays/kt-dropdown/kt-dropdown.js.map +1 -1
- package/dist/components/overlays/kt-modal/kt-modal.js +5 -4
- package/dist/components/overlays/kt-modal/kt-modal.js.map +1 -1
- package/dist/components/overlays/kt-side-panel/kt-side-panel.d.ts +1 -1
- package/dist/components/overlays/kt-side-panel/kt-side-panel.js +24 -23
- package/dist/components/overlays/kt-side-panel/kt-side-panel.js.map +1 -1
- package/dist/custom-elements.json +76 -76
- package/dist/index.d.ts +1 -0
- package/dist/index.js +24 -19
- package/dist/index.js.map +1 -1
- package/dist/internal/kt-element.d.ts +6 -1
- package/dist/internal/strings.d.ts +93 -0
- package/dist/strings/index.d.ts +11 -0
- package/dist/strings/index.js +8 -0
- package/dist/strings/index.js.map +1 -0
- package/dist/tokens/base.css +53 -0
- package/dist/web-types.json +39 -39
- package/package.json +11 -3
- package/dist/chunks/kt-element-B_jjQDhg.js +0 -38
- package/dist/chunks/kt-element-B_jjQDhg.js.map +0 -1
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { css as
|
|
2
|
-
import { query as
|
|
3
|
-
import { classMap as
|
|
4
|
-
import { live as
|
|
5
|
-
import { K as
|
|
6
|
-
import { u as
|
|
7
|
-
import { a as
|
|
8
|
-
import { a as
|
|
1
|
+
import { css as g, nothing as a, html as h } from "lit";
|
|
2
|
+
import { query as x, state as f, property as n } from "lit/decorators.js";
|
|
3
|
+
import { classMap as p } from "lit/directives/class-map.js";
|
|
4
|
+
import { live as w } from "lit/directives/live.js";
|
|
5
|
+
import { K as m, d as k } from "../../../chunks/kt-element-mdd5cXZX.js";
|
|
6
|
+
import { u as $, e as c } from "../../../chunks/events-Bjl5Zmmq.js";
|
|
7
|
+
import { a as I, s as q, b as D } from "../../../chunks/form-control-CxjBTt1c.js";
|
|
8
|
+
import { a as O, b as E, o as y, f as v, l as L, n as C } from "../../../chunks/listbox-Sm3nvsC6.js";
|
|
9
|
+
import { s as l } from "../../../chunks/index-fzPIgxe2.js";
|
|
9
10
|
import "../../core/kt-icon/kt-icon.js";
|
|
10
|
-
var
|
|
11
|
-
for (var
|
|
12
|
-
(b =
|
|
13
|
-
return
|
|
11
|
+
var P = Object.defineProperty, i = (d, t, o, r) => {
|
|
12
|
+
for (var s = void 0, u = d.length - 1, b; u >= 0; u--)
|
|
13
|
+
(b = d[u]) && (s = b(t, o, s) || s);
|
|
14
|
+
return s && P(t, o, s), s;
|
|
14
15
|
};
|
|
15
|
-
class e extends
|
|
16
|
+
class e extends m {
|
|
16
17
|
constructor() {
|
|
17
|
-
super(...arguments), this.internals = null, this.defaultValue = null, this.listId =
|
|
18
|
+
super(...arguments), this.internals = null, this.defaultValue = null, this.listId = $("kt-input-menu-list"), this.open = !1, this.query = "", this.activeIndex = -1, this.options = [], this.value = null, this.placeholder = "", this.name = "", this.disabled = !1, this.required = !1, this.error = "", this.label = "", this.emptyText = void 0, this.onDocumentPointerDown = (t) => {
|
|
18
19
|
t.composedPath().includes(this) || this.close();
|
|
19
20
|
};
|
|
20
21
|
}
|
|
@@ -23,9 +24,9 @@ class e extends f {
|
|
|
23
24
|
}
|
|
24
25
|
static {
|
|
25
26
|
this.styles = [
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
m.styles,
|
|
28
|
+
O,
|
|
29
|
+
g`
|
|
29
30
|
:host {
|
|
30
31
|
position: relative;
|
|
31
32
|
display: block;
|
|
@@ -128,19 +129,19 @@ class e extends f {
|
|
|
128
129
|
];
|
|
129
130
|
}
|
|
130
131
|
connectedCallback() {
|
|
131
|
-
super.connectedCallback(), this.internals ??=
|
|
132
|
+
super.connectedCallback(), this.internals ??= I(this), this.defaultValue = this.value, document.addEventListener("pointerdown", this.onDocumentPointerDown);
|
|
132
133
|
}
|
|
133
134
|
disconnectedCallback() {
|
|
134
135
|
super.disconnectedCallback(), document.removeEventListener("pointerdown", this.onDocumentPointerDown);
|
|
135
136
|
}
|
|
136
137
|
willUpdate(t) {
|
|
137
|
-
if (t.has("value") || t.has("required") || t.has("error")) {
|
|
138
|
-
|
|
138
|
+
if (t.has("value") || t.has("required") || t.has("error") || this.stringsChanged(t)) {
|
|
139
|
+
q(this.internals, this.value === null ? null : String(this.value));
|
|
139
140
|
const o = this.required && this.value === null;
|
|
140
|
-
|
|
141
|
+
D(
|
|
141
142
|
this.internals,
|
|
142
143
|
{ valueMissing: o, customError: !!this.error },
|
|
143
|
-
this.error || (o ?
|
|
144
|
+
this.error || (o ? l().selectOption : "")
|
|
144
145
|
);
|
|
145
146
|
}
|
|
146
147
|
}
|
|
@@ -168,22 +169,22 @@ class e extends f {
|
|
|
168
169
|
get displayValue() {
|
|
169
170
|
if (this.open && this.query) return this.query;
|
|
170
171
|
const t = this.selectedOption;
|
|
171
|
-
return t ?
|
|
172
|
+
return t ? y(t) : this.query;
|
|
172
173
|
}
|
|
173
174
|
openList() {
|
|
174
|
-
this.disabled || this.open || (this.open = !0, this.activeIndex =
|
|
175
|
+
this.disabled || this.open || (this.open = !0, this.activeIndex = v(this.visibleOptions));
|
|
175
176
|
}
|
|
176
177
|
close() {
|
|
177
178
|
this.open = !1, this.query = "", this.activeIndex = -1;
|
|
178
179
|
}
|
|
179
180
|
onInput(t) {
|
|
180
|
-
this.query = t.target.value, this.open = !0, this.activeIndex =
|
|
181
|
+
this.query = t.target.value, this.open = !0, this.activeIndex = v(this.visibleOptions), c(this, "kt-filter", { query: this.query });
|
|
181
182
|
}
|
|
182
183
|
choose(t) {
|
|
183
|
-
t.disabled || (this.value = t.id, this.close(),
|
|
184
|
+
t.disabled || (this.value = t.id, this.close(), c(this, "kt-change", { value: t.id, option: t }));
|
|
184
185
|
}
|
|
185
186
|
clear(t) {
|
|
186
|
-
t.stopPropagation(), this.value = null, this.query = "",
|
|
187
|
+
t.stopPropagation(), this.value = null, this.query = "", c(this, "kt-change", { value: null, option: null }), this.input?.focus();
|
|
187
188
|
}
|
|
188
189
|
onKeyDown(t) {
|
|
189
190
|
const o = this.visibleOptions;
|
|
@@ -199,11 +200,11 @@ class e extends f {
|
|
|
199
200
|
return;
|
|
200
201
|
case "Home":
|
|
201
202
|
if (!this.open) return;
|
|
202
|
-
t.preventDefault(), this.activeIndex =
|
|
203
|
+
t.preventDefault(), this.activeIndex = v(o);
|
|
203
204
|
return;
|
|
204
205
|
case "End":
|
|
205
206
|
if (!this.open) return;
|
|
206
|
-
t.preventDefault(), this.activeIndex =
|
|
207
|
+
t.preventDefault(), this.activeIndex = L(o);
|
|
207
208
|
return;
|
|
208
209
|
case "Enter": {
|
|
209
210
|
if (!this.open) return;
|
|
@@ -225,8 +226,8 @@ class e extends f {
|
|
|
225
226
|
}
|
|
226
227
|
render() {
|
|
227
228
|
const t = this.visibleOptions, o = this.selectedOption !== void 0 && !this.disabled;
|
|
228
|
-
return
|
|
229
|
-
class=${
|
|
229
|
+
return h`<div
|
|
230
|
+
class=${p({ open: this.open, error: !!this.error })}
|
|
230
231
|
@keydown=${this.onKeyDown}
|
|
231
232
|
>
|
|
232
233
|
<div part="control" class="control" @click=${this.openList}>
|
|
@@ -240,16 +241,16 @@ class e extends f {
|
|
|
240
241
|
aria-label=${this.label || a}
|
|
241
242
|
aria-invalid=${this.error ? "true" : a}
|
|
242
243
|
placeholder=${this.placeholder || a}
|
|
243
|
-
.value=${
|
|
244
|
+
.value=${w(this.displayValue)}
|
|
244
245
|
?disabled=${this.disabled}
|
|
245
246
|
@focus=${this.openList}
|
|
246
247
|
@input=${this.onInput}
|
|
247
248
|
/>
|
|
248
249
|
|
|
249
|
-
${o ?
|
|
250
|
+
${o ? h`<button
|
|
250
251
|
type="button"
|
|
251
252
|
class="icon-button clear"
|
|
252
|
-
aria-label
|
|
253
|
+
aria-label=${l().clear}
|
|
253
254
|
tabindex="-1"
|
|
254
255
|
@click=${this.clear}
|
|
255
256
|
>
|
|
@@ -259,7 +260,7 @@ class e extends f {
|
|
|
259
260
|
<button
|
|
260
261
|
type="button"
|
|
261
262
|
class="icon-button toggle"
|
|
262
|
-
aria-label=${this.open ?
|
|
263
|
+
aria-label=${this.open ? l().closeList : l().openList}
|
|
263
264
|
tabindex="-1"
|
|
264
265
|
@click=${(r) => {
|
|
265
266
|
r.stopPropagation(), this.open ? this.close() : this.openList();
|
|
@@ -272,25 +273,25 @@ class e extends f {
|
|
|
272
273
|
<ul
|
|
273
274
|
part="popup"
|
|
274
275
|
id=${this.listId}
|
|
275
|
-
class=${
|
|
276
|
+
class=${p({ popup: !0, open: this.open })}
|
|
276
277
|
role="listbox"
|
|
277
278
|
aria-label=${this.label || this.placeholder}
|
|
278
279
|
>
|
|
279
|
-
${t.length === 0 ?
|
|
280
|
-
(r,
|
|
280
|
+
${t.length === 0 ? h`<li class="empty">${this.emptyText ?? l().noOptions}</li>` : t.map(
|
|
281
|
+
(r, s) => h`<li
|
|
281
282
|
part="option"
|
|
282
|
-
id=${this.optionId(
|
|
283
|
-
class=${
|
|
283
|
+
id=${this.optionId(s)}
|
|
284
|
+
class=${p({
|
|
284
285
|
option: !0,
|
|
285
286
|
selected: r.id === this.value,
|
|
286
|
-
active:
|
|
287
|
+
active: s === this.activeIndex,
|
|
287
288
|
disabled: !!r.disabled
|
|
288
289
|
})}
|
|
289
290
|
role="option"
|
|
290
291
|
aria-selected=${r.id === this.value ? "true" : "false"}
|
|
291
292
|
@click=${() => this.choose(r)}
|
|
292
293
|
>
|
|
293
|
-
${
|
|
294
|
+
${y(r)}
|
|
294
295
|
</li>`
|
|
295
296
|
)}
|
|
296
297
|
</ul>
|
|
@@ -298,45 +299,45 @@ class e extends f {
|
|
|
298
299
|
}
|
|
299
300
|
}
|
|
300
301
|
i([
|
|
301
|
-
|
|
302
|
+
x("input")
|
|
302
303
|
], e.prototype, "input");
|
|
303
304
|
i([
|
|
304
|
-
|
|
305
|
+
f()
|
|
305
306
|
], e.prototype, "open");
|
|
306
307
|
i([
|
|
307
|
-
|
|
308
|
+
f()
|
|
308
309
|
], e.prototype, "query");
|
|
309
310
|
i([
|
|
310
|
-
|
|
311
|
+
f()
|
|
311
312
|
], e.prototype, "activeIndex");
|
|
312
313
|
i([
|
|
313
|
-
|
|
314
|
+
n({ attribute: !1 })
|
|
314
315
|
], e.prototype, "options");
|
|
315
316
|
i([
|
|
316
|
-
|
|
317
|
+
n({ type: String })
|
|
317
318
|
], e.prototype, "value");
|
|
318
319
|
i([
|
|
319
|
-
|
|
320
|
+
n({ type: String })
|
|
320
321
|
], e.prototype, "placeholder");
|
|
321
322
|
i([
|
|
322
|
-
|
|
323
|
+
n({ type: String })
|
|
323
324
|
], e.prototype, "name");
|
|
324
325
|
i([
|
|
325
|
-
|
|
326
|
+
n({ type: Boolean, reflect: !0 })
|
|
326
327
|
], e.prototype, "disabled");
|
|
327
328
|
i([
|
|
328
|
-
|
|
329
|
+
n({ type: Boolean, reflect: !0 })
|
|
329
330
|
], e.prototype, "required");
|
|
330
331
|
i([
|
|
331
|
-
|
|
332
|
+
n({ type: String, reflect: !0 })
|
|
332
333
|
], e.prototype, "error");
|
|
333
334
|
i([
|
|
334
|
-
|
|
335
|
+
n({ type: String })
|
|
335
336
|
], e.prototype, "label");
|
|
336
337
|
i([
|
|
337
|
-
|
|
338
|
+
n({ type: String, attribute: "empty-text" })
|
|
338
339
|
], e.prototype, "emptyText");
|
|
339
|
-
|
|
340
|
+
k("kt-input-menu", e);
|
|
340
341
|
export {
|
|
341
342
|
e as KtInputMenu
|
|
342
343
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kt-input-menu.js","sources":["../../../../src/components/forms/kt-input-menu/kt-input-menu.ts"],"sourcesContent":["import { css, html, nothing, type PropertyValues, type TemplateResult } from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { live } from 'lit/directives/live.js';\nimport { KtElement, defineElement } from '#internal/kt-element';\nimport { emit, uniqueId } from '#internal/events';\nimport {\n attachFormInternals,\n setFormValue,\n setValidity,\n type UsableInternals,\n} from '#internal/form-control';\nimport {\n filterOptions,\n firstEnabledIndex,\n lastEnabledIndex,\n listboxStyles,\n nextEnabledIndex,\n optionLabel,\n type KtOption,\n} from '#internal/listbox';\nimport '../../core/kt-icon/kt-icon.js';\n\n/**\n * A combobox: type to narrow the list, then pick.\n *\n * Reach for it over `<kt-select>` once the list is long enough that scanning it\n * is slower than typing three letters — somewhere around twenty options.\n *\n * @element kt-input-menu\n *\n * @csspart control - The field.\n * @csspart input - The native `<input>`.\n * @csspart popup - The option list.\n * @csspart option - An option row.\n *\n * @fires kt-change - An option was chosen or cleared. `detail: { value, option }`.\n * @fires kt-filter - The query changed. `detail: { query }`.\n */\nexport class KtInputMenu extends KtElement {\n static readonly formAssociated = true;\n\n static override styles = [\n KtElement.styles,\n listboxStyles,\n css`\n :host {\n position: relative;\n display: block;\n --field-height: var(--button-height);\n }\n\n .control {\n display: inline-flex;\n align-items: center;\n justify-content: space-between;\n gap: var(--gap-element);\n width: 100%;\n height: var(--field-height);\n padding: 0 var(--button-padding-x);\n color: var(--text-body);\n font: var(--font-input);\n background-color: var(--color-dark-20);\n border: none;\n border-radius: var(--radius-input);\n /* A resting hairline. A field is a fill on --surface-field, which is\n one ramp step from the page in dark and almost the same colour in\n light — so on a card or inside a modal it simply disappeared and\n read as a bare native control.\n\n A border rather than an outline, because the control inside fills\n the field exactly and a coincident outline is painted over by the\n native widget. A border insets the control by its own width, so it\n cannot be covered. box-sizing: border-box keeps the outer size.\n\n The hover and focus rings stay outlines on top of it, and the\n transparent resting outline is what they animate from: without it\n outline-color starts at the initial value, which resolves to the\n text colour, and hover flashed near-white before settling. */\n border: var(--border-width) solid var(--border-field);\n outline: var(--outline-width) solid transparent;\n cursor: text;\n transition:\n background-color var(--duration-instant),\n outline-color var(--duration-instant);\n }\n\n .control:hover {\n outline: var(--outline-width) solid var(--color-text-700);\n }\n .control:focus-within {\n background-color: var(--color-dark-12);\n outline: var(--outline-width) solid var(--color-primary-base);\n }\n\n .error .control,\n .error .control:hover,\n .error .control:focus-within {\n outline: var(--outline-width) solid var(--color-danger-base);\n }\n\n :host([disabled]) {\n pointer-events: none;\n opacity: 0.6;\n }\n\n input {\n width: 100%;\n min-width: 0;\n color: var(--text-body);\n font: var(--font-input);\n background: transparent;\n border: none;\n outline: none;\n }\n\n input::placeholder {\n color: var(--text-muted);\n }\n\n .icon-button {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n padding: 0;\n color: inherit;\n background: transparent;\n border: none;\n cursor: pointer;\n }\n\n .clear {\n transition: transform var(--duration-instant) ease-in-out;\n }\n .clear:hover {\n transform: rotate(90deg);\n }\n\n .toggle {\n transition: transform var(--duration-fast) ease-in-out;\n }\n .open .toggle {\n transform: scaleY(-1);\n }\n `,\n ];\n\n @query('input')\n private input!: HTMLInputElement;\n\n private internals: UsableInternals | null = null;\n private defaultValue: string | number | null = null;\n private readonly listId = uniqueId('kt-input-menu-list');\n\n @state()\n private open = false;\n\n @state()\n private query = '';\n\n @state()\n private activeIndex = -1;\n\n @property({ attribute: false })\n options: readonly KtOption[] = [];\n\n @property({ type: String })\n value: string | number | null = null;\n\n @property({ type: String })\n placeholder = '';\n\n @property({ type: String })\n name = '';\n\n @property({ type: Boolean, reflect: true })\n disabled = false;\n\n @property({ type: Boolean, reflect: true })\n required = false;\n\n @property({ type: String, reflect: true })\n error = '';\n\n @property({ type: String })\n label = '';\n\n @property({ type: String, attribute: 'empty-text' })\n emptyText = 'No options available';\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.internals ??= attachFormInternals(this);\n this.defaultValue = this.value;\n document.addEventListener('pointerdown', this.onDocumentPointerDown);\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n document.removeEventListener('pointerdown', this.onDocumentPointerDown);\n }\n\n override willUpdate(changed: PropertyValues<this>): void {\n if (changed.has('value') || changed.has('required') || changed.has('error')) {\n // The option id is what is submitted, never the label the field shows:\n // the label is for people, the id is for the server.\n setFormValue(this.internals, this.value === null ? null : String(this.value));\n\n const missing = this.required && this.value === null;\n setValidity(\n this.internals,\n { valueMissing: missing, customError: Boolean(this.error) },\n this.error || (missing ? 'Select an option.' : ''),\n );\n }\n }\n\n formResetCallback(): void {\n this.value = this.defaultValue;\n this.close();\n }\n\n formStateRestoreCallback(state: string): void {\n this.value = state;\n }\n\n override focus(options?: FocusOptions): void {\n this.input?.focus(options);\n }\n\n get selectedOption(): KtOption | undefined {\n return this.options.find((option) => option.id === this.value);\n }\n\n /** Options after the current query, which is what the keyboard walks. */\n private get visibleOptions(): readonly KtOption[] {\n return filterOptions(this.options, this.query);\n }\n\n /**\n * While filtering, the field shows the query; otherwise it shows the chosen\n * option. Keeping the two in one input is what makes it a combobox rather\n * than a search box that happens to sit above a list.\n */\n private get displayValue(): string {\n if (this.open && this.query) return this.query;\n const selected = this.selectedOption;\n return selected ? optionLabel(selected) : this.query;\n }\n\n private onDocumentPointerDown = (event: Event): void => {\n if (event.composedPath().includes(this)) return;\n this.close();\n };\n\n private openList(): void {\n if (this.disabled || this.open) return;\n this.open = true;\n this.activeIndex = firstEnabledIndex(this.visibleOptions);\n }\n\n private close(): void {\n this.open = false;\n this.query = '';\n this.activeIndex = -1;\n }\n\n private onInput(event: Event): void {\n this.query = (event.target as HTMLInputElement).value;\n this.open = true;\n this.activeIndex = firstEnabledIndex(this.visibleOptions);\n emit(this, 'kt-filter', { query: this.query });\n }\n\n private choose(option: KtOption): void {\n if (option.disabled) return;\n this.value = option.id;\n this.close();\n emit(this, 'kt-change', { value: option.id, option });\n }\n\n private clear(event: Event): void {\n event.stopPropagation();\n this.value = null;\n this.query = '';\n emit(this, 'kt-change', { value: null, option: null });\n this.input?.focus();\n }\n\n private onKeyDown(event: KeyboardEvent): void {\n const options = this.visibleOptions;\n\n switch (event.key) {\n case 'ArrowDown':\n case 'ArrowUp':\n event.preventDefault();\n if (!this.open) return this.openList();\n this.activeIndex = nextEnabledIndex(\n options,\n this.activeIndex,\n event.key === 'ArrowDown' ? 1 : -1,\n );\n return;\n case 'Home':\n if (!this.open) return;\n event.preventDefault();\n this.activeIndex = firstEnabledIndex(options);\n return;\n case 'End':\n if (!this.open) return;\n event.preventDefault();\n this.activeIndex = lastEnabledIndex(options);\n return;\n case 'Enter': {\n if (!this.open) return;\n event.preventDefault();\n const option = options[this.activeIndex];\n if (option) this.choose(option);\n return;\n }\n case 'Escape':\n if (!this.open) return;\n event.stopPropagation();\n this.close();\n return;\n case 'Tab':\n this.close();\n }\n }\n\n private optionId(index: number): string {\n return `${this.listId}-option-${index}`;\n }\n\n override render(): TemplateResult {\n const options = this.visibleOptions;\n const showClear = this.selectedOption !== undefined && !this.disabled;\n\n return html`<div\n class=${classMap({ open: this.open, error: Boolean(this.error) })}\n @keydown=${this.onKeyDown}\n >\n <div part=\"control\" class=\"control\" @click=${this.openList}>\n <input\n part=\"input\"\n role=\"combobox\"\n aria-expanded=${this.open ? 'true' : 'false'}\n aria-controls=${this.listId}\n aria-autocomplete=\"list\"\n aria-activedescendant=${\n this.open && this.activeIndex >= 0 ? this.optionId(this.activeIndex) : nothing\n }\n aria-label=${this.label || nothing}\n aria-invalid=${this.error ? 'true' : nothing}\n placeholder=${this.placeholder || nothing}\n .value=${live(this.displayValue)}\n ?disabled=${this.disabled}\n @focus=${this.openList}\n @input=${this.onInput}\n />\n\n ${\n showClear\n ? html`<button\n type=\"button\"\n class=\"icon-button clear\"\n aria-label=\"Clear\"\n tabindex=\"-1\"\n @click=${this.clear}\n >\n <kt-icon name=\"x\" size=\"18\"></kt-icon>\n </button>`\n : nothing\n }\n\n <button\n type=\"button\"\n class=\"icon-button toggle\"\n aria-label=${this.open ? 'Close list' : 'Open list'}\n tabindex=\"-1\"\n @click=${(event: Event) => {\n event.stopPropagation();\n if (this.open) this.close();\n else this.openList();\n }}\n >\n <kt-icon name=\"chevron-down\" size=\"18\"></kt-icon>\n </button>\n </div>\n\n <ul\n part=\"popup\"\n id=${this.listId}\n class=${classMap({ popup: true, open: this.open })}\n role=\"listbox\"\n aria-label=${this.label || this.placeholder}\n >\n ${\n options.length === 0\n ? html`<li class=\"empty\">${this.emptyText}</li>`\n : options.map(\n (option, index) =>\n html`<li\n part=\"option\"\n id=${this.optionId(index)}\n class=${classMap({\n option: true,\n selected: option.id === this.value,\n active: index === this.activeIndex,\n disabled: Boolean(option.disabled),\n })}\n role=\"option\"\n aria-selected=${option.id === this.value ? 'true' : 'false'}\n @click=${() => this.choose(option)}\n >\n ${optionLabel(option)}\n </li>`,\n )\n }\n </ul>\n </div>`;\n }\n}\n\ndefineElement('kt-input-menu', KtInputMenu);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'kt-input-menu': KtInputMenu;\n }\n}\n"],"names":["KtInputMenu","KtElement","uniqueId","event","listboxStyles","css","attachFormInternals","changed","setFormValue","missing","setValidity","state","options","option","filterOptions","selected","optionLabel","firstEnabledIndex","emit","nextEnabledIndex","lastEnabledIndex","index","showClear","html","classMap","nothing","live","__decorateClass","query","property","defineElement"],"mappings":";;;;;;;;;;;;;;AAuCO,MAAMA,UAAoBC,EAAU;AAAA,E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X,WAAA,OAAA;AAGA2B,EAAA;AAAA,EADCE,EAAS,EAAE,MAAM,OAAA,CAAQ;AAAA,GAlIf7B,EAmIX,WAAA,aAAA;AAGA2B,EAAA;AAAA,EADCE,EAAS,EAAE,MAAM,OAAA,CAAQ;AAAA,GArIf7B,EAsIX,WAAA,MAAA;AAGA2B,EAAA;AAAA,EADCE,EAAS,EAAE,MAAM,SAAS,SAAS,IAAM;AAAA,GAxI/B7B,EAyIX,WAAA,UAAA;AAGA2B,EAAA;AAAA,EADCE,EAAS,EAAE,MAAM,SAAS,SAAS,IAAM;AAAA,GA3I/B7B,EA4IX,WAAA,UAAA;AAGA2B,EAAA;AAAA,EADCE,EAAS,EAAE,MAAM,QAAQ,SAAS,IAAM;AAAA,GA9I9B7B,EA+IX,WAAA,OAAA;AAGA2B,EAAA;AAAA,EADCE,EAAS,EAAE,MAAM,OAAA,CAAQ;AAAA,GAjJf7B,EAkJX,WAAA,OAAA;AAGA2B,EAAA;AAAA,EADCE,EAAS,EAAE,MAAM,QAAQ,WAAW,cAAc;AAAA,GApJxC7B,EAqJX,WAAA,WAAA;AA4OF8B,EAAc,iBAAiB9B,CAAW;"}
|
|
1
|
+
{"version":3,"file":"kt-input-menu.js","sources":["../../../../src/components/forms/kt-input-menu/kt-input-menu.ts"],"sourcesContent":["import { css, html, nothing, type PropertyValues, type TemplateResult } from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { live } from 'lit/directives/live.js';\nimport { KtElement, defineElement } from '#internal/kt-element';\nimport { emit, uniqueId } from '#internal/events';\nimport {\n attachFormInternals,\n setFormValue,\n setValidity,\n type UsableInternals,\n} from '#internal/form-control';\nimport {\n filterOptions,\n firstEnabledIndex,\n lastEnabledIndex,\n listboxStyles,\n nextEnabledIndex,\n optionLabel,\n type KtOption,\n} from '#internal/listbox';\nimport { strings } from '#internal/strings';\nimport '../../core/kt-icon/kt-icon.js';\n\n/**\n * A combobox: type to narrow the list, then pick.\n *\n * Reach for it over `<kt-select>` once the list is long enough that scanning it\n * is slower than typing three letters — somewhere around twenty options.\n *\n * @element kt-input-menu\n *\n * @csspart control - The field.\n * @csspart input - The native `<input>`.\n * @csspart popup - The option list.\n * @csspart option - An option row.\n *\n * @fires kt-change - An option was chosen or cleared. `detail: { value, option }`.\n * @fires kt-filter - The query changed. `detail: { query }`.\n */\nexport class KtInputMenu extends KtElement {\n static readonly formAssociated = true;\n\n static override styles = [\n KtElement.styles,\n listboxStyles,\n css`\n :host {\n position: relative;\n display: block;\n --field-height: var(--button-height);\n }\n\n .control {\n display: inline-flex;\n align-items: center;\n justify-content: space-between;\n gap: var(--gap-element);\n width: 100%;\n height: var(--field-height);\n padding: 0 var(--button-padding-x);\n color: var(--text-body);\n font: var(--font-input);\n background-color: var(--color-dark-20);\n border: none;\n border-radius: var(--radius-input);\n /* A resting hairline. A field is a fill on --surface-field, which is\n one ramp step from the page in dark and almost the same colour in\n light — so on a card or inside a modal it simply disappeared and\n read as a bare native control.\n\n A border rather than an outline, because the control inside fills\n the field exactly and a coincident outline is painted over by the\n native widget. A border insets the control by its own width, so it\n cannot be covered. box-sizing: border-box keeps the outer size.\n\n The hover and focus rings stay outlines on top of it, and the\n transparent resting outline is what they animate from: without it\n outline-color starts at the initial value, which resolves to the\n text colour, and hover flashed near-white before settling. */\n border: var(--border-width) solid var(--border-field);\n outline: var(--outline-width) solid transparent;\n cursor: text;\n transition:\n background-color var(--duration-instant),\n outline-color var(--duration-instant);\n }\n\n .control:hover {\n outline: var(--outline-width) solid var(--color-text-700);\n }\n .control:focus-within {\n background-color: var(--color-dark-12);\n outline: var(--outline-width) solid var(--color-primary-base);\n }\n\n .error .control,\n .error .control:hover,\n .error .control:focus-within {\n outline: var(--outline-width) solid var(--color-danger-base);\n }\n\n :host([disabled]) {\n pointer-events: none;\n opacity: 0.6;\n }\n\n input {\n width: 100%;\n min-width: 0;\n color: var(--text-body);\n font: var(--font-input);\n background: transparent;\n border: none;\n outline: none;\n }\n\n input::placeholder {\n color: var(--text-muted);\n }\n\n .icon-button {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n padding: 0;\n color: inherit;\n background: transparent;\n border: none;\n cursor: pointer;\n }\n\n .clear {\n transition: transform var(--duration-instant) ease-in-out;\n }\n .clear:hover {\n transform: rotate(90deg);\n }\n\n .toggle {\n transition: transform var(--duration-fast) ease-in-out;\n }\n .open .toggle {\n transform: scaleY(-1);\n }\n `,\n ];\n\n @query('input')\n private input!: HTMLInputElement;\n\n private internals: UsableInternals | null = null;\n private defaultValue: string | number | null = null;\n private readonly listId = uniqueId('kt-input-menu-list');\n\n @state()\n private open = false;\n\n @state()\n private query = '';\n\n @state()\n private activeIndex = -1;\n\n @property({ attribute: false })\n options: readonly KtOption[] = [];\n\n @property({ type: String })\n value: string | number | null = null;\n\n @property({ type: String })\n placeholder = '';\n\n @property({ type: String })\n name = '';\n\n @property({ type: Boolean, reflect: true })\n disabled = false;\n\n @property({ type: Boolean, reflect: true })\n required = false;\n\n @property({ type: String, reflect: true })\n error = '';\n\n @property({ type: String })\n label = '';\n\n @property({ type: String, attribute: 'empty-text' })\n emptyText: string | undefined = undefined;\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.internals ??= attachFormInternals(this);\n this.defaultValue = this.value;\n document.addEventListener('pointerdown', this.onDocumentPointerDown);\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n document.removeEventListener('pointerdown', this.onDocumentPointerDown);\n }\n\n override willUpdate(changed: PropertyValues<this>): void {\n if (\n changed.has('value') ||\n changed.has('required') ||\n changed.has('error') ||\n this.stringsChanged(changed)\n ) {\n // The option id is what is submitted, never the label the field shows:\n // the label is for people, the id is for the server.\n setFormValue(this.internals, this.value === null ? null : String(this.value));\n\n const missing = this.required && this.value === null;\n setValidity(\n this.internals,\n { valueMissing: missing, customError: Boolean(this.error) },\n this.error || (missing ? strings().selectOption : ''),\n );\n }\n }\n\n formResetCallback(): void {\n this.value = this.defaultValue;\n this.close();\n }\n\n formStateRestoreCallback(state: string): void {\n this.value = state;\n }\n\n override focus(options?: FocusOptions): void {\n this.input?.focus(options);\n }\n\n get selectedOption(): KtOption | undefined {\n return this.options.find((option) => option.id === this.value);\n }\n\n /** Options after the current query, which is what the keyboard walks. */\n private get visibleOptions(): readonly KtOption[] {\n return filterOptions(this.options, this.query);\n }\n\n /**\n * While filtering, the field shows the query; otherwise it shows the chosen\n * option. Keeping the two in one input is what makes it a combobox rather\n * than a search box that happens to sit above a list.\n */\n private get displayValue(): string {\n if (this.open && this.query) return this.query;\n const selected = this.selectedOption;\n return selected ? optionLabel(selected) : this.query;\n }\n\n private onDocumentPointerDown = (event: Event): void => {\n if (event.composedPath().includes(this)) return;\n this.close();\n };\n\n private openList(): void {\n if (this.disabled || this.open) return;\n this.open = true;\n this.activeIndex = firstEnabledIndex(this.visibleOptions);\n }\n\n private close(): void {\n this.open = false;\n this.query = '';\n this.activeIndex = -1;\n }\n\n private onInput(event: Event): void {\n this.query = (event.target as HTMLInputElement).value;\n this.open = true;\n this.activeIndex = firstEnabledIndex(this.visibleOptions);\n emit(this, 'kt-filter', { query: this.query });\n }\n\n private choose(option: KtOption): void {\n if (option.disabled) return;\n this.value = option.id;\n this.close();\n emit(this, 'kt-change', { value: option.id, option });\n }\n\n private clear(event: Event): void {\n event.stopPropagation();\n this.value = null;\n this.query = '';\n emit(this, 'kt-change', { value: null, option: null });\n this.input?.focus();\n }\n\n private onKeyDown(event: KeyboardEvent): void {\n const options = this.visibleOptions;\n\n switch (event.key) {\n case 'ArrowDown':\n case 'ArrowUp':\n event.preventDefault();\n if (!this.open) return this.openList();\n this.activeIndex = nextEnabledIndex(\n options,\n this.activeIndex,\n event.key === 'ArrowDown' ? 1 : -1,\n );\n return;\n case 'Home':\n if (!this.open) return;\n event.preventDefault();\n this.activeIndex = firstEnabledIndex(options);\n return;\n case 'End':\n if (!this.open) return;\n event.preventDefault();\n this.activeIndex = lastEnabledIndex(options);\n return;\n case 'Enter': {\n if (!this.open) return;\n event.preventDefault();\n const option = options[this.activeIndex];\n if (option) this.choose(option);\n return;\n }\n case 'Escape':\n if (!this.open) return;\n event.stopPropagation();\n this.close();\n return;\n case 'Tab':\n this.close();\n }\n }\n\n private optionId(index: number): string {\n return `${this.listId}-option-${index}`;\n }\n\n override render(): TemplateResult {\n const options = this.visibleOptions;\n const showClear = this.selectedOption !== undefined && !this.disabled;\n\n return html`<div\n class=${classMap({ open: this.open, error: Boolean(this.error) })}\n @keydown=${this.onKeyDown}\n >\n <div part=\"control\" class=\"control\" @click=${this.openList}>\n <input\n part=\"input\"\n role=\"combobox\"\n aria-expanded=${this.open ? 'true' : 'false'}\n aria-controls=${this.listId}\n aria-autocomplete=\"list\"\n aria-activedescendant=${\n this.open && this.activeIndex >= 0 ? this.optionId(this.activeIndex) : nothing\n }\n aria-label=${this.label || nothing}\n aria-invalid=${this.error ? 'true' : nothing}\n placeholder=${this.placeholder || nothing}\n .value=${live(this.displayValue)}\n ?disabled=${this.disabled}\n @focus=${this.openList}\n @input=${this.onInput}\n />\n\n ${\n showClear\n ? html`<button\n type=\"button\"\n class=\"icon-button clear\"\n aria-label=${strings().clear}\n tabindex=\"-1\"\n @click=${this.clear}\n >\n <kt-icon name=\"x\" size=\"18\"></kt-icon>\n </button>`\n : nothing\n }\n\n <button\n type=\"button\"\n class=\"icon-button toggle\"\n aria-label=${this.open ? strings().closeList : strings().openList}\n tabindex=\"-1\"\n @click=${(event: Event) => {\n event.stopPropagation();\n if (this.open) this.close();\n else this.openList();\n }}\n >\n <kt-icon name=\"chevron-down\" size=\"18\"></kt-icon>\n </button>\n </div>\n\n <ul\n part=\"popup\"\n id=${this.listId}\n class=${classMap({ popup: true, open: this.open })}\n role=\"listbox\"\n aria-label=${this.label || this.placeholder}\n >\n ${\n options.length === 0\n ? html`<li class=\"empty\">${this.emptyText ?? strings().noOptions}</li>`\n : options.map(\n (option, index) =>\n html`<li\n part=\"option\"\n id=${this.optionId(index)}\n class=${classMap({\n option: true,\n selected: option.id === this.value,\n active: index === this.activeIndex,\n disabled: Boolean(option.disabled),\n })}\n role=\"option\"\n aria-selected=${option.id === this.value ? 'true' : 'false'}\n @click=${() => this.choose(option)}\n >\n ${optionLabel(option)}\n </li>`,\n )\n }\n </ul>\n </div>`;\n }\n}\n\ndefineElement('kt-input-menu', KtInputMenu);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'kt-input-menu': KtInputMenu;\n }\n}\n"],"names":["KtInputMenu","KtElement","uniqueId","event","listboxStyles","css","attachFormInternals","changed","setFormValue","missing","setValidity","strings","state","options","option","filterOptions","selected","optionLabel","firstEnabledIndex","emit","nextEnabledIndex","lastEnabledIndex","index","showClear","html","classMap","nothing","live","__decorateClass","query","property","defineElement"],"mappings":";;;;;;;;;;;;;;;AAwCO,MAAMA,UAAoBC,EAAU;AAAA,EAApC,cAAA;AAAA,UAAA,GAAA,SAAA,GA+GL,KAAQ,YAAoC,MAC5C,KAAQ,eAAuC,MAC/C,KAAiB,SAASC,EAAS,oBAAoB,GAGvD,KAAQ,OAAO,IAGf,KAAQ,QAAQ,IAGhB,KAAQ,cAAc,IAGtB,KAAA,UAA+B,CAAA,GAG/B,KAAA,QAAgC,MAGhC,KAAA,cAAc,IAGd,KAAA,OAAO,IAGP,KAAA,WAAW,IAGX,KAAA,WAAW,IAGX,KAAA,QAAQ,IAGR,KAAA,QAAQ,IAGR,KAAA,YAAgC,QAmEhC,KAAQ,wBAAwB,CAACC,MAAuB;AACtD,MAAIA,EAAM,aAAA,EAAe,SAAS,IAAI,KACtC,KAAK,MAAA;AAAA,IACP;AAAA,EAAA;AAAA,EA1NA,OAAA;AAAA,SAAgB,iBAAiB;AAAA,EAAA;AAAA,EAEjC,OAAA;AAAA,SAAgB,SAAS;AAAA,MACvBF,EAAU;AAAA,MACVG;AAAA,MACAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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AAA;AAAA,EADCE,EAAS,EAAE,MAAM,QAAQ,WAAW,cAAc;AAAA,GApJxC9B,EAqJX,WAAA,WAAA;AAiPF+B,EAAc,iBAAiB/B,CAAW;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { css as p, html as i } from "lit";
|
|
2
2
|
import { query as d, property as f } from "lit/decorators.js";
|
|
3
|
-
import { K as u, d as c } from "../../../chunks/kt-element-
|
|
3
|
+
import { K as u, d as c } from "../../../chunks/kt-element-mdd5cXZX.js";
|
|
4
4
|
var b = Object.defineProperty, a = (r, t, s, h) => {
|
|
5
5
|
for (var e = void 0, o = r.length - 1, n; o >= 0; o--)
|
|
6
6
|
(n = r[o]) && (e = n(t, s, e) || e);
|
|
@@ -42,7 +42,7 @@ export declare class KtSelect extends KtElement {
|
|
|
42
42
|
options: readonly KtOption[];
|
|
43
43
|
/** The selected option's id, or `null`. */
|
|
44
44
|
value: string | number | null;
|
|
45
|
-
placeholder: string;
|
|
45
|
+
placeholder: string | undefined;
|
|
46
46
|
name: string;
|
|
47
47
|
size: KtSelectSize;
|
|
48
48
|
disabled: boolean;
|
|
@@ -54,7 +54,7 @@ export declare class KtSelect extends KtElement {
|
|
|
54
54
|
/** Accessible name, when no `<kt-label-input>` wraps the control. */
|
|
55
55
|
label: string;
|
|
56
56
|
/** Shown when `options` is empty. */
|
|
57
|
-
emptyText: string;
|
|
57
|
+
emptyText: string | undefined;
|
|
58
58
|
connectedCallback(): void;
|
|
59
59
|
disconnectedCallback(): void;
|
|
60
60
|
willUpdate(changed: PropertyValues<this>): void;
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import { css as
|
|
2
|
-
import { state as
|
|
3
|
-
import { classMap as
|
|
4
|
-
import { K as
|
|
5
|
-
import { u as
|
|
6
|
-
import { a as
|
|
7
|
-
import { a as
|
|
1
|
+
import { css as y, nothing as n, html as d } from "lit";
|
|
2
|
+
import { state as m, property as o } from "lit/decorators.js";
|
|
3
|
+
import { classMap as h } from "lit/directives/class-map.js";
|
|
4
|
+
import { K as v, d as x } from "../../../chunks/kt-element-mdd5cXZX.js";
|
|
5
|
+
import { u as w, e as f } from "../../../chunks/events-Bjl5Zmmq.js";
|
|
6
|
+
import { a as k, s as $, b as I } from "../../../chunks/form-control-CxjBTt1c.js";
|
|
7
|
+
import { a as D, f as b, l as L, n as S, o as g } from "../../../chunks/listbox-Sm3nvsC6.js";
|
|
8
|
+
import { s as l } from "../../../chunks/index-fzPIgxe2.js";
|
|
8
9
|
import "../../core/kt-icon/kt-icon.js";
|
|
9
|
-
var
|
|
10
|
-
for (var
|
|
11
|
-
(
|
|
12
|
-
return
|
|
10
|
+
var E = Object.defineProperty, i = (c, e, s, a) => {
|
|
11
|
+
for (var r = void 0, p = c.length - 1, u; p >= 0; p--)
|
|
12
|
+
(u = c[p]) && (r = u(e, s, r) || r);
|
|
13
|
+
return r && E(e, s, r), r;
|
|
13
14
|
};
|
|
14
|
-
class t extends
|
|
15
|
+
class t extends v {
|
|
15
16
|
constructor() {
|
|
16
|
-
super(...arguments), this.internals = null, this.defaultValue = null, this.listId =
|
|
17
|
+
super(...arguments), this.internals = null, this.defaultValue = null, this.listId = w("kt-select-list"), this.open = !1, this.activeIndex = -1, this.options = [], this.value = null, this.placeholder = void 0, this.name = "", this.size = "medium", this.disabled = !1, this.required = !1, this.error = "", this.clearable = !0, this.label = "", this.emptyText = void 0, this.onDocumentPointerDown = (e) => {
|
|
17
18
|
e.composedPath().includes(this) || (this.open = !1);
|
|
18
19
|
};
|
|
19
20
|
}
|
|
@@ -22,9 +23,9 @@ class t extends u {
|
|
|
22
23
|
}
|
|
23
24
|
static {
|
|
24
25
|
this.styles = [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
v.styles,
|
|
27
|
+
D,
|
|
28
|
+
y`
|
|
28
29
|
:host {
|
|
29
30
|
position: relative;
|
|
30
31
|
display: block;
|
|
@@ -137,19 +138,19 @@ class t extends u {
|
|
|
137
138
|
];
|
|
138
139
|
}
|
|
139
140
|
connectedCallback() {
|
|
140
|
-
super.connectedCallback(), this.internals ??=
|
|
141
|
+
super.connectedCallback(), this.internals ??= k(this), this.defaultValue = this.value, document.addEventListener("pointerdown", this.onDocumentPointerDown);
|
|
141
142
|
}
|
|
142
143
|
disconnectedCallback() {
|
|
143
144
|
super.disconnectedCallback(), document.removeEventListener("pointerdown", this.onDocumentPointerDown);
|
|
144
145
|
}
|
|
145
146
|
willUpdate(e) {
|
|
146
|
-
if (e.has("value") || e.has("required") || e.has("error")) {
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
|
|
147
|
+
if (e.has("value") || e.has("required") || e.has("error") || this.stringsChanged(e)) {
|
|
148
|
+
$(this.internals, this.value === null ? null : String(this.value));
|
|
149
|
+
const s = this.required && this.value === null;
|
|
150
|
+
I(
|
|
150
151
|
this.internals,
|
|
151
|
-
{ valueMissing:
|
|
152
|
-
this.error || (
|
|
152
|
+
{ valueMissing: s, customError: !!this.error },
|
|
153
|
+
this.error || (s ? l().selectOption : "")
|
|
153
154
|
);
|
|
154
155
|
}
|
|
155
156
|
}
|
|
@@ -169,8 +170,8 @@ class t extends u {
|
|
|
169
170
|
openList() {
|
|
170
171
|
if (this.disabled) return;
|
|
171
172
|
this.open = !0;
|
|
172
|
-
const e = this.options.findIndex((
|
|
173
|
-
this.activeIndex = e >= 0 ? e :
|
|
173
|
+
const e = this.options.findIndex((s) => s.id === this.value);
|
|
174
|
+
this.activeIndex = e >= 0 ? e : b(this.options);
|
|
174
175
|
}
|
|
175
176
|
closeList() {
|
|
176
177
|
this.open = !1, this.activeIndex = -1;
|
|
@@ -179,17 +180,17 @@ class t extends u {
|
|
|
179
180
|
this.open ? this.closeList() : this.openList();
|
|
180
181
|
}
|
|
181
182
|
choose(e) {
|
|
182
|
-
e.disabled || (this.value = e.id, this.closeList(), this.focus(),
|
|
183
|
+
e.disabled || (this.value = e.id, this.closeList(), this.focus(), f(this, "kt-change", { value: e.id, option: e }));
|
|
183
184
|
}
|
|
184
185
|
clear(e) {
|
|
185
|
-
e.stopPropagation(), this.value = null,
|
|
186
|
+
e.stopPropagation(), this.value = null, f(this, "kt-change", { value: null, option: null });
|
|
186
187
|
}
|
|
187
188
|
onKeyDown(e) {
|
|
188
189
|
switch (e.key) {
|
|
189
190
|
case "ArrowDown":
|
|
190
191
|
case "ArrowUp": {
|
|
191
192
|
if (e.preventDefault(), !this.open) return this.openList();
|
|
192
|
-
this.activeIndex =
|
|
193
|
+
this.activeIndex = S(
|
|
193
194
|
this.options,
|
|
194
195
|
this.activeIndex,
|
|
195
196
|
e.key === "ArrowDown" ? 1 : -1
|
|
@@ -198,17 +199,17 @@ class t extends u {
|
|
|
198
199
|
}
|
|
199
200
|
case "Home":
|
|
200
201
|
if (!this.open) return;
|
|
201
|
-
e.preventDefault(), this.activeIndex =
|
|
202
|
+
e.preventDefault(), this.activeIndex = b(this.options);
|
|
202
203
|
return;
|
|
203
204
|
case "End":
|
|
204
205
|
if (!this.open) return;
|
|
205
|
-
e.preventDefault(), this.activeIndex =
|
|
206
|
+
e.preventDefault(), this.activeIndex = L(this.options);
|
|
206
207
|
return;
|
|
207
208
|
case "Enter":
|
|
208
209
|
case " ": {
|
|
209
210
|
if (e.preventDefault(), !this.open) return this.openList();
|
|
210
|
-
const
|
|
211
|
-
|
|
211
|
+
const s = this.options[this.activeIndex];
|
|
212
|
+
s && this.choose(s);
|
|
212
213
|
return;
|
|
213
214
|
}
|
|
214
215
|
case "Escape":
|
|
@@ -223,9 +224,9 @@ class t extends u {
|
|
|
223
224
|
return `${this.listId}-option-${e}`;
|
|
224
225
|
}
|
|
225
226
|
render() {
|
|
226
|
-
const e = this.selectedOption,
|
|
227
|
-
return
|
|
228
|
-
class=${
|
|
227
|
+
const e = this.selectedOption, s = this.clearable && e !== void 0 && !this.disabled;
|
|
228
|
+
return d`<div
|
|
229
|
+
class=${h({ open: this.open, error: !!this.error })}
|
|
229
230
|
@keydown=${this.onKeyDown}
|
|
230
231
|
>
|
|
231
232
|
<button
|
|
@@ -242,15 +243,15 @@ class t extends u {
|
|
|
242
243
|
?disabled=${this.disabled}
|
|
243
244
|
@click=${this.toggleList}
|
|
244
245
|
>
|
|
245
|
-
<span class=${
|
|
246
|
-
${e ?
|
|
246
|
+
<span class=${h({ value: !0, placeholder: !e })}>
|
|
247
|
+
${e ? g(e) : this.placeholder ?? l().select}
|
|
247
248
|
</span>
|
|
248
249
|
<span class="icons">
|
|
249
|
-
${
|
|
250
|
+
${s ? d`<span
|
|
250
251
|
class="clear"
|
|
251
252
|
role="button"
|
|
252
253
|
tabindex="-1"
|
|
253
|
-
aria-label
|
|
254
|
+
aria-label=${l().clear}
|
|
254
255
|
@click=${this.clear}
|
|
255
256
|
>
|
|
256
257
|
<kt-icon name="x" size="18"></kt-icon>
|
|
@@ -262,18 +263,18 @@ class t extends u {
|
|
|
262
263
|
<ul
|
|
263
264
|
part="popup"
|
|
264
265
|
id=${this.listId}
|
|
265
|
-
class=${
|
|
266
|
+
class=${h({ popup: !0, open: this.open })}
|
|
266
267
|
role="listbox"
|
|
267
|
-
aria-label=${this.label || this.placeholder}
|
|
268
|
+
aria-label=${this.label || (this.placeholder ?? l().select)}
|
|
268
269
|
>
|
|
269
|
-
${this.options.length === 0 ?
|
|
270
|
-
(a,
|
|
270
|
+
${this.options.length === 0 ? d`<li class="empty">${this.emptyText ?? l().noOptions}</li>` : this.options.map(
|
|
271
|
+
(a, r) => d`<li
|
|
271
272
|
part="option"
|
|
272
|
-
id=${this.optionId(
|
|
273
|
-
class=${
|
|
273
|
+
id=${this.optionId(r)}
|
|
274
|
+
class=${h({
|
|
274
275
|
option: !0,
|
|
275
276
|
selected: a.id === this.value,
|
|
276
|
-
active:
|
|
277
|
+
active: r === this.activeIndex,
|
|
277
278
|
disabled: !!a.disabled
|
|
278
279
|
})}
|
|
279
280
|
role="option"
|
|
@@ -281,7 +282,7 @@ class t extends u {
|
|
|
281
282
|
aria-disabled=${a.disabled ? "true" : n}
|
|
282
283
|
@click=${() => this.choose(a)}
|
|
283
284
|
>
|
|
284
|
-
${
|
|
285
|
+
${g(a)}
|
|
285
286
|
</li>`
|
|
286
287
|
)}
|
|
287
288
|
</ul>
|
|
@@ -289,45 +290,45 @@ class t extends u {
|
|
|
289
290
|
}
|
|
290
291
|
}
|
|
291
292
|
i([
|
|
292
|
-
|
|
293
|
+
m()
|
|
293
294
|
], t.prototype, "open");
|
|
294
295
|
i([
|
|
295
|
-
|
|
296
|
+
m()
|
|
296
297
|
], t.prototype, "activeIndex");
|
|
297
298
|
i([
|
|
298
|
-
|
|
299
|
+
o({ attribute: !1 })
|
|
299
300
|
], t.prototype, "options");
|
|
300
301
|
i([
|
|
301
|
-
|
|
302
|
+
o({ type: String })
|
|
302
303
|
], t.prototype, "value");
|
|
303
304
|
i([
|
|
304
|
-
|
|
305
|
+
o({ type: String })
|
|
305
306
|
], t.prototype, "placeholder");
|
|
306
307
|
i([
|
|
307
|
-
|
|
308
|
+
o({ type: String })
|
|
308
309
|
], t.prototype, "name");
|
|
309
310
|
i([
|
|
310
|
-
|
|
311
|
+
o({ type: String, reflect: !0 })
|
|
311
312
|
], t.prototype, "size");
|
|
312
313
|
i([
|
|
313
|
-
|
|
314
|
+
o({ type: Boolean, reflect: !0 })
|
|
314
315
|
], t.prototype, "disabled");
|
|
315
316
|
i([
|
|
316
|
-
|
|
317
|
+
o({ type: Boolean, reflect: !0 })
|
|
317
318
|
], t.prototype, "required");
|
|
318
319
|
i([
|
|
319
|
-
|
|
320
|
+
o({ type: String, reflect: !0 })
|
|
320
321
|
], t.prototype, "error");
|
|
321
322
|
i([
|
|
322
|
-
|
|
323
|
+
o({ type: Boolean })
|
|
323
324
|
], t.prototype, "clearable");
|
|
324
325
|
i([
|
|
325
|
-
|
|
326
|
+
o({ type: String })
|
|
326
327
|
], t.prototype, "label");
|
|
327
328
|
i([
|
|
328
|
-
|
|
329
|
+
o({ type: String, attribute: "empty-text" })
|
|
329
330
|
], t.prototype, "emptyText");
|
|
330
|
-
|
|
331
|
+
x("kt-select", t);
|
|
331
332
|
export {
|
|
332
333
|
t as KtSelect
|
|
333
334
|
};
|