@20baht/ui 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +512 -2
- package/dist/components/baht-form.d.ts +206 -0
- package/dist/components/baht-form.js +630 -0
- package/dist/components/baht-workflow.d.ts +187 -0
- package/dist/components/baht-workflow.js +455 -0
- package/dist/components/base.d.ts +92 -0
- package/dist/components/base.js +138 -0
- package/dist/components/combobox-controller.d.ts +65 -0
- package/dist/components/combobox-controller.js +82 -0
- package/dist/components/define.d.ts +7 -0
- package/dist/components/define.js +16 -0
- package/dist/components/field-base.d.ts +84 -0
- package/dist/components/field-base.js +152 -0
- package/dist/components/floating.d.ts +84 -0
- package/dist/components/floating.js +182 -0
- package/dist/components/form-layout.d.ts +39 -0
- package/dist/components/form-layout.js +67 -0
- package/dist/components/form-options.d.ts +39 -0
- package/dist/components/form-options.js +65 -0
- package/dist/components/form-readonly.d.ts +20 -0
- package/dist/components/form-readonly.js +70 -0
- package/dist/components/layers.d.ts +4 -0
- package/dist/components/layers.js +15 -0
- package/dist/components/menu-controller.d.ts +65 -0
- package/dist/components/menu-controller.js +134 -0
- package/dist/components/motion.d.ts +9 -0
- package/dist/components/motion.js +16 -0
- package/dist/components/primitives/baht-accordion.d.ts +29 -0
- package/dist/components/primitives/baht-accordion.js +66 -0
- package/dist/components/primitives/baht-alert.d.ts +20 -0
- package/dist/components/primitives/baht-alert.js +62 -0
- package/dist/components/primitives/baht-app-shell.d.ts +81 -0
- package/dist/components/primitives/baht-app-shell.js +161 -0
- package/dist/components/primitives/baht-approval-chain.d.ts +59 -0
- package/dist/components/primitives/baht-approval-chain.js +80 -0
- package/dist/components/primitives/baht-avatar.d.ts +19 -0
- package/dist/components/primitives/baht-avatar.js +43 -0
- package/dist/components/primitives/baht-badge.d.ts +24 -0
- package/dist/components/primitives/baht-badge.js +41 -0
- package/dist/components/primitives/baht-bar-chart.d.ts +78 -0
- package/dist/components/primitives/baht-bar-chart.js +361 -0
- package/dist/components/primitives/baht-breadcrumbs.d.ts +23 -0
- package/dist/components/primitives/baht-breadcrumbs.js +45 -0
- package/dist/components/primitives/baht-button.d.ts +89 -0
- package/dist/components/primitives/baht-button.js +146 -0
- package/dist/components/primitives/baht-calendar.d.ts +96 -0
- package/dist/components/primitives/baht-calendar.js +398 -0
- package/dist/components/primitives/baht-card.d.ts +34 -0
- package/dist/components/primitives/baht-card.js +70 -0
- package/dist/components/primitives/baht-catalog-card.d.ts +52 -0
- package/dist/components/primitives/baht-catalog-card.js +90 -0
- package/dist/components/primitives/baht-checkbox.d.ts +7 -0
- package/dist/components/primitives/baht-checkbox.js +40 -0
- package/dist/components/primitives/baht-choice-group.d.ts +52 -0
- package/dist/components/primitives/baht-choice-group.js +71 -0
- package/dist/components/primitives/baht-code.d.ts +18 -0
- package/dist/components/primitives/baht-code.js +33 -0
- package/dist/components/primitives/baht-column-picker.d.ts +69 -0
- package/dist/components/primitives/baht-column-picker.js +234 -0
- package/dist/components/primitives/baht-comments.d.ts +38 -0
- package/dist/components/primitives/baht-comments.js +102 -0
- package/dist/components/primitives/baht-currency.d.ts +13 -0
- package/dist/components/primitives/baht-currency.js +69 -0
- package/dist/components/primitives/baht-datepicker.d.ts +77 -0
- package/dist/components/primitives/baht-datepicker.js +235 -0
- package/dist/components/primitives/baht-donut-chart.d.ts +24 -0
- package/dist/components/primitives/baht-donut-chart.js +88 -0
- package/dist/components/primitives/baht-edit-table.d.ts +45 -0
- package/dist/components/primitives/baht-edit-table.js +176 -0
- package/dist/components/primitives/baht-empty-state.d.ts +26 -0
- package/dist/components/primitives/baht-empty-state.js +51 -0
- package/dist/components/primitives/baht-error-state.d.ts +21 -0
- package/dist/components/primitives/baht-error-state.js +44 -0
- package/dist/components/primitives/baht-facts.d.ts +42 -0
- package/dist/components/primitives/baht-facts.js +49 -0
- package/dist/components/primitives/baht-fieldset.d.ts +19 -0
- package/dist/components/primitives/baht-fieldset.js +42 -0
- package/dist/components/primitives/baht-file.d.ts +27 -0
- package/dist/components/primitives/baht-file.js +158 -0
- package/dist/components/primitives/baht-filter-builder.d.ts +39 -0
- package/dist/components/primitives/baht-filter-builder.js +201 -0
- package/dist/components/primitives/baht-filter.d.ts +36 -0
- package/dist/components/primitives/baht-filter.js +64 -0
- package/dist/components/primitives/baht-heatmap.d.ts +49 -0
- package/dist/components/primitives/baht-heatmap.js +168 -0
- package/dist/components/primitives/baht-input.d.ts +10 -0
- package/dist/components/primitives/baht-input.js +44 -0
- package/dist/components/primitives/baht-keyvalue-editor.d.ts +28 -0
- package/dist/components/primitives/baht-keyvalue-editor.js +106 -0
- package/dist/components/primitives/baht-line-chart.d.ts +45 -0
- package/dist/components/primitives/baht-line-chart.js +183 -0
- package/dist/components/primitives/baht-link.d.ts +26 -0
- package/dist/components/primitives/baht-link.js +48 -0
- package/dist/components/primitives/baht-list.d.ts +29 -0
- package/dist/components/primitives/baht-list.js +79 -0
- package/dist/components/primitives/baht-loading-overlay.d.ts +15 -0
- package/dist/components/primitives/baht-loading-overlay.js +33 -0
- package/dist/components/primitives/baht-markdown-view.d.ts +17 -0
- package/dist/components/primitives/baht-markdown-view.js +39 -0
- package/dist/components/primitives/baht-markdown.d.ts +34 -0
- package/dist/components/primitives/baht-markdown.js +177 -0
- package/dist/components/primitives/baht-menu.d.ts +53 -0
- package/dist/components/primitives/baht-menu.js +100 -0
- package/dist/components/primitives/baht-meter.d.ts +67 -0
- package/dist/components/primitives/baht-meter.js +107 -0
- package/dist/components/primitives/baht-modal.d.ts +71 -0
- package/dist/components/primitives/baht-modal.js +164 -0
- package/dist/components/primitives/baht-multiselect.d.ts +8 -0
- package/dist/components/primitives/baht-multiselect.js +47 -0
- package/dist/components/primitives/baht-notification-bell.d.ts +54 -0
- package/dist/components/primitives/baht-notification-bell.js +143 -0
- package/dist/components/primitives/baht-number.d.ts +5 -0
- package/dist/components/primitives/baht-number.js +39 -0
- package/dist/components/primitives/baht-order-box.d.ts +24 -0
- package/dist/components/primitives/baht-order-box.js +50 -0
- package/dist/components/primitives/baht-otp.d.ts +49 -0
- package/dist/components/primitives/baht-otp.js +109 -0
- package/dist/components/primitives/baht-page-header.d.ts +43 -0
- package/dist/components/primitives/baht-page-header.js +78 -0
- package/dist/components/primitives/baht-pagination.d.ts +33 -0
- package/dist/components/primitives/baht-pagination.js +86 -0
- package/dist/components/primitives/baht-popover.d.ts +45 -0
- package/dist/components/primitives/baht-popover.js +112 -0
- package/dist/components/primitives/baht-progress-ring.d.ts +22 -0
- package/dist/components/primitives/baht-progress-ring.js +62 -0
- package/dist/components/primitives/baht-progress.d.ts +17 -0
- package/dist/components/primitives/baht-progress.js +48 -0
- package/dist/components/primitives/baht-radio.d.ts +7 -0
- package/dist/components/primitives/baht-radio.js +74 -0
- package/dist/components/primitives/baht-range.d.ts +38 -0
- package/dist/components/primitives/baht-range.js +88 -0
- package/dist/components/primitives/baht-rating.d.ts +40 -0
- package/dist/components/primitives/baht-rating.js +107 -0
- package/dist/components/primitives/baht-record-bar.d.ts +30 -0
- package/dist/components/primitives/baht-record-bar.js +60 -0
- package/dist/components/primitives/baht-reference-dialog.d.ts +87 -0
- package/dist/components/primitives/baht-reference-dialog.js +418 -0
- package/dist/components/primitives/baht-reference-picker.d.ts +110 -0
- package/dist/components/primitives/baht-reference-picker.js +321 -0
- package/dist/components/primitives/baht-repeater.d.ts +59 -0
- package/dist/components/primitives/baht-repeater.js +315 -0
- package/dist/components/primitives/baht-rule-builder.d.ts +24 -0
- package/dist/components/primitives/baht-rule-builder.js +177 -0
- package/dist/components/primitives/baht-saved-filters.d.ts +41 -0
- package/dist/components/primitives/baht-saved-filters.js +126 -0
- package/dist/components/primitives/baht-search.d.ts +34 -0
- package/dist/components/primitives/baht-search.js +71 -0
- package/dist/components/primitives/baht-section-header.d.ts +28 -0
- package/dist/components/primitives/baht-section-header.js +48 -0
- package/dist/components/primitives/baht-section.d.ts +23 -0
- package/dist/components/primitives/baht-section.js +49 -0
- package/dist/components/primitives/baht-select.d.ts +49 -0
- package/dist/components/primitives/baht-select.js +197 -0
- package/dist/components/primitives/baht-skeleton.d.ts +16 -0
- package/dist/components/primitives/baht-skeleton.js +37 -0
- package/dist/components/primitives/baht-sparkline.d.ts +23 -0
- package/dist/components/primitives/baht-sparkline.js +56 -0
- package/dist/components/primitives/baht-spinner.d.ts +13 -0
- package/dist/components/primitives/baht-spinner.js +30 -0
- package/dist/components/primitives/baht-split-button.d.ts +43 -0
- package/dist/components/primitives/baht-split-button.js +87 -0
- package/dist/components/primitives/baht-stat-chart.d.ts +14 -0
- package/dist/components/primitives/baht-stat-chart.js +38 -0
- package/dist/components/primitives/baht-stat.d.ts +56 -0
- package/dist/components/primitives/baht-stat.js +117 -0
- package/dist/components/primitives/baht-steps.d.ts +33 -0
- package/dist/components/primitives/baht-steps.js +60 -0
- package/dist/components/primitives/baht-swipe-row.d.ts +64 -0
- package/dist/components/primitives/baht-swipe-row.js +178 -0
- package/dist/components/primitives/baht-table.d.ts +315 -0
- package/dist/components/primitives/baht-table.js +640 -0
- package/dist/components/primitives/baht-tabs.d.ts +54 -0
- package/dist/components/primitives/baht-tabs.js +128 -0
- package/dist/components/primitives/baht-tags.d.ts +96 -0
- package/dist/components/primitives/baht-tags.js +323 -0
- package/dist/components/primitives/baht-text.d.ts +10 -0
- package/dist/components/primitives/baht-text.js +29 -0
- package/dist/components/primitives/baht-textarea.d.ts +5 -0
- package/dist/components/primitives/baht-textarea.js +40 -0
- package/dist/components/primitives/baht-theme-toggle.d.ts +44 -0
- package/dist/components/primitives/baht-theme-toggle.js +101 -0
- package/dist/components/primitives/baht-timeline.d.ts +21 -0
- package/dist/components/primitives/baht-timeline.js +42 -0
- package/dist/components/primitives/baht-toast.d.ts +29 -0
- package/dist/components/primitives/baht-toast.js +83 -0
- package/dist/components/primitives/baht-toggle.d.ts +6 -0
- package/dist/components/primitives/baht-toggle.js +42 -0
- package/dist/components/primitives/baht-tooltip.d.ts +34 -0
- package/dist/components/primitives/baht-tooltip.js +85 -0
- package/dist/components/primitives/baht-tree.d.ts +58 -0
- package/dist/components/primitives/baht-tree.js +159 -0
- package/dist/components/primitives/baht-typeahead.d.ts +92 -0
- package/dist/components/primitives/baht-typeahead.js +258 -0
- package/dist/components/primitives/baht-upload.d.ts +108 -0
- package/dist/components/primitives/baht-upload.js +325 -0
- package/dist/components/primitives/baht-wizard.d.ts +57 -0
- package/dist/components/primitives/baht-wizard.js +147 -0
- package/dist/components/primitives/charts.d.ts +134 -0
- package/dist/components/primitives/charts.js +184 -0
- package/dist/components/primitives/column-map.d.ts +56 -0
- package/dist/components/primitives/column-map.js +70 -0
- package/dist/components/primitives/control-icons.d.ts +2 -0
- package/dist/components/primitives/control-icons.js +40 -0
- package/dist/components/primitives/icons.d.ts +24 -0
- package/dist/components/primitives/icons.js +86 -0
- package/dist/components/primitives/illustrations.d.ts +21 -0
- package/dist/components/primitives/illustrations.js +78 -0
- package/dist/components/primitives/index.d.ts +89 -0
- package/dist/components/primitives/kbd.d.ts +6 -0
- package/dist/components/primitives/kbd.js +9 -0
- package/dist/components/primitives/listbox.d.ts +2 -0
- package/dist/components/primitives/listbox.js +7 -0
- package/dist/components/primitives/markdown-render.d.ts +9 -0
- package/dist/components/primitives/markdown-render.js +77 -0
- package/dist/components/primitives/rule-rows.d.ts +55 -0
- package/dist/components/primitives/rule-rows.js +75 -0
- package/dist/components/primitives/tag-map.d.ts +6 -0
- package/dist/components/primitives/tag-map.js +39 -0
- package/dist/components/reference-labels.d.ts +22 -0
- package/dist/components/reference-labels.js +29 -0
- package/dist/components/shortcuts.d.ts +7 -0
- package/dist/components/shortcuts.js +43 -0
- package/dist/css/components.css +7517 -0
- package/dist/css/datepicker.css +346 -0
- package/dist/css/tokens.css +679 -0
- package/dist/custom-elements.json +45172 -0
- package/dist/engine.d.ts +1 -0
- package/dist/engine.js +1 -0
- package/dist/hydrate.d.ts +9 -0
- package/dist/hydrate.js +46 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +210 -0
- package/dist/overlay.d.ts +50 -0
- package/dist/overlay.js +140 -0
- package/dist/react.d.ts +557 -0
- package/dist/react.js +1 -0
- package/dist/register.d.ts +106 -0
- package/dist/register.js +99 -0
- package/dist/ssr.d.ts +16 -0
- package/dist/ssr.js +125 -0
- package/dist/tokens.css +8197 -0
- package/dist/vscode.css-custom-data.json +6 -0
- package/dist/vscode.html-custom-data.json +2261 -0
- package/dist/web-types.json +6523 -0
- package/package.json +157 -4
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { nothing as h, html as p } from "lit";
|
|
2
|
+
import { property as o, state as b, query as u } from "lit/decorators.js";
|
|
3
|
+
import { BahtElement as f, arr as y, adoptLightChildren as v } from "../base.js";
|
|
4
|
+
import { customElement as m } from "../define.js";
|
|
5
|
+
var k = Object.defineProperty, $ = Object.getOwnPropertyDescriptor, n = (e, t, s, a) => {
|
|
6
|
+
for (var i = a > 1 ? void 0 : a ? $(t, s) : t, r = e.length - 1, d; r >= 0; r--)
|
|
7
|
+
(d = e[r]) && (i = (a ? d(t, s, i) : d(i)) || i);
|
|
8
|
+
return a && i && k(t, s, i), i;
|
|
9
|
+
};
|
|
10
|
+
const c = /* @__PURE__ */ new WeakMap();
|
|
11
|
+
function g(e, t) {
|
|
12
|
+
const s = e.style, a = c.get(e);
|
|
13
|
+
if (t) {
|
|
14
|
+
if (a) return;
|
|
15
|
+
c.set(e, {
|
|
16
|
+
value: s.getPropertyValue("display"),
|
|
17
|
+
priority: s.getPropertyPriority("display")
|
|
18
|
+
}), s.setProperty("display", "none", "important");
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
a && (c.delete(e), a.value ? s.setProperty("display", a.value, a.priority) : s.removeProperty("display"));
|
|
22
|
+
}
|
|
23
|
+
let l = class extends f {
|
|
24
|
+
constructor() {
|
|
25
|
+
super(...arguments), this.tabs = [], this.value = "", this.label = "", this.activation = "automatic", this.variant = "line", this.panelKeys = [], this.onKeydown = (e) => {
|
|
26
|
+
const t = y(this.tabs).filter((r) => !r.disabled), s = e.target instanceof HTMLElement ? e.target.dataset.key : void 0, a = t.findIndex((r) => r.key === s);
|
|
27
|
+
let i;
|
|
28
|
+
if (e.key === "ArrowRight") i = t[(a + 1) % t.length];
|
|
29
|
+
else if (e.key === "ArrowLeft") i = t[(a - 1 + t.length) % t.length];
|
|
30
|
+
else if (e.key === "Home") i = t[0];
|
|
31
|
+
else if (e.key === "End") i = t.at(-1);
|
|
32
|
+
else if ((e.key === "Enter" || e.key === " ") && s) {
|
|
33
|
+
e.preventDefault(), this.select(s);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
i && (e.preventDefault(), this.focusTab(i.key), this.activation !== "manual" && this.select(i.key));
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
tabId(e) {
|
|
40
|
+
return `baht-tab-${this.uid}-${e}`;
|
|
41
|
+
}
|
|
42
|
+
panelId(e) {
|
|
43
|
+
return `baht-tabpanel-${this.uid}-${e}`;
|
|
44
|
+
}
|
|
45
|
+
/** The tab actually shown: `value` when it names an enabled tab, else the first enabled one. */
|
|
46
|
+
get selected() {
|
|
47
|
+
var s;
|
|
48
|
+
const e = y(this.tabs), t = e.find((a) => a.key === this.value && !a.disabled);
|
|
49
|
+
return (t == null ? void 0 : t.key) ?? ((s = e.find((a) => !a.disabled)) == null ? void 0 : s.key) ?? "";
|
|
50
|
+
}
|
|
51
|
+
firstUpdated() {
|
|
52
|
+
this.value || (this.value = this.selected);
|
|
53
|
+
}
|
|
54
|
+
// After every render and whenever a framework host adds a panel (base.ts).
|
|
55
|
+
adoptChildren() {
|
|
56
|
+
v(this, this.panelsEl), this.syncPanels();
|
|
57
|
+
}
|
|
58
|
+
syncPanels() {
|
|
59
|
+
const e = this.selected, t = [];
|
|
60
|
+
for (const s of Array.from(this.panelsEl.children)) {
|
|
61
|
+
if (!(s instanceof HTMLElement)) continue;
|
|
62
|
+
const a = s.dataset.tab;
|
|
63
|
+
a !== void 0 && (t.push(a), s.id = this.panelId(a), s.setAttribute("role", "tabpanel"), s.setAttribute("aria-labelledby", this.tabId(a)), s.tabIndex = 0, s.hidden = a !== e, g(s, a !== e));
|
|
64
|
+
}
|
|
65
|
+
this.panelsEl.hidden = t.length === 0, t.join("\0") !== this.panelKeys.join("\0") && (this.panelKeys = t);
|
|
66
|
+
}
|
|
67
|
+
select(e) {
|
|
68
|
+
e !== this.selected && (this.value = e, this.emit("baht-change", { value: e }));
|
|
69
|
+
}
|
|
70
|
+
focusTab(e) {
|
|
71
|
+
var t;
|
|
72
|
+
(t = this.querySelector(`#${CSS.escape(this.tabId(e))}`)) == null || t.focus();
|
|
73
|
+
}
|
|
74
|
+
render() {
|
|
75
|
+
const e = this.selected;
|
|
76
|
+
return p`<div class="baht-tabs${this.variant === "pill" ? " baht-tabs--pill" : ""}">
|
|
77
|
+
<div class="baht-tabs-list" role="tablist" aria-label=${this.label || h} @keydown=${this.onKeydown}>
|
|
78
|
+
${y(this.tabs).map(
|
|
79
|
+
(t) => p`<button
|
|
80
|
+
type="button"
|
|
81
|
+
role="tab"
|
|
82
|
+
class="baht-tabs-tab${t.key === e ? " baht-tabs-tab--on" : ""}"
|
|
83
|
+
id=${this.tabId(t.key)}
|
|
84
|
+
data-key=${t.key}
|
|
85
|
+
aria-selected=${t.key === e ? "true" : "false"}
|
|
86
|
+
aria-controls=${this.panelKeys.includes(t.key) ? this.panelId(t.key) : h}
|
|
87
|
+
tabindex=${t.key === e ? "0" : "-1"}
|
|
88
|
+
?disabled=${t.disabled}
|
|
89
|
+
@click=${() => {
|
|
90
|
+
this.select(t.key);
|
|
91
|
+
}}
|
|
92
|
+
>
|
|
93
|
+
<span>${t.label}</span>
|
|
94
|
+
${t.badge ? p`<span class="baht-tabs-badge">${t.badge}</span>` : h}
|
|
95
|
+
</button>`
|
|
96
|
+
)}
|
|
97
|
+
</div>
|
|
98
|
+
<div class="baht-tabs-panels"></div>
|
|
99
|
+
</div>`;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
n([
|
|
103
|
+
o({ attribute: !1 })
|
|
104
|
+
], l.prototype, "tabs", 2);
|
|
105
|
+
n([
|
|
106
|
+
o({ reflect: !0 })
|
|
107
|
+
], l.prototype, "value", 2);
|
|
108
|
+
n([
|
|
109
|
+
o()
|
|
110
|
+
], l.prototype, "label", 2);
|
|
111
|
+
n([
|
|
112
|
+
o()
|
|
113
|
+
], l.prototype, "activation", 2);
|
|
114
|
+
n([
|
|
115
|
+
o()
|
|
116
|
+
], l.prototype, "variant", 2);
|
|
117
|
+
n([
|
|
118
|
+
b()
|
|
119
|
+
], l.prototype, "panelKeys", 2);
|
|
120
|
+
n([
|
|
121
|
+
u(".baht-tabs-panels")
|
|
122
|
+
], l.prototype, "panelsEl", 2);
|
|
123
|
+
l = n([
|
|
124
|
+
m("baht-tabs")
|
|
125
|
+
], l);
|
|
126
|
+
export {
|
|
127
|
+
l as BahtTabs
|
|
128
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { PropertyValues, TemplateResult } from 'lit';
|
|
2
|
+
import { BahtFieldBase } from '../field-base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creatable chip input: value is `string[]` (unique, trimmed, in entry
|
|
5
|
+
* order). Type text + Enter or comma to add a chip; Backspace on an empty
|
|
6
|
+
* input removes the last chip; pasting "a, b, c" adds three at once.
|
|
7
|
+
*
|
|
8
|
+
* Suggestions come from `field.options` — the SAME list every other
|
|
9
|
+
* option-bearing field reads, already resolved by `<baht-form>` when the
|
|
10
|
+
* descriptor uses `options_from` (spec 01 §1: dynamic options are merged
|
|
11
|
+
* into `field.options` before the primitive ever sees them, so this
|
|
12
|
+
* component needs no fetcher of its own). They filter as you type
|
|
13
|
+
* (case-insensitive, prefix matches first) and exclude tags already chosen.
|
|
14
|
+
* Free text becomes a chip unless `field.allow_new === false`, in which case
|
|
15
|
+
* only a suggestion's `key` (matched case-insensitively) can become one.
|
|
16
|
+
*
|
|
17
|
+
* el.field = { type: 'tags', key: 'labels', options: [...], max_items: 5 };
|
|
18
|
+
* el.addEventListener('baht-input', (e) => (draft.labels = e.detail.value));
|
|
19
|
+
*
|
|
20
|
+
* ARIA: APG editable combobox with list autocomplete, same pattern as
|
|
21
|
+
* <baht-typeahead> — the input is the combobox, the chips sit before it in
|
|
22
|
+
* the same control, `aria-activedescendant` walks the listbox.
|
|
23
|
+
*/
|
|
24
|
+
export declare class BahtTags extends BahtFieldBase {
|
|
25
|
+
constructor();
|
|
26
|
+
private inputText;
|
|
27
|
+
private open;
|
|
28
|
+
private activeIndex;
|
|
29
|
+
/** Transient reason the last chip attempt was refused (max_length /
|
|
30
|
+
* max_items / allow_new / duplicate) — cleared on the next successful
|
|
31
|
+
* add or edit, never persisted, never blocks anything by itself. */
|
|
32
|
+
private hint;
|
|
33
|
+
private inputEl;
|
|
34
|
+
private readonly combo;
|
|
35
|
+
protected willUpdate(changed: PropertyValues<this>): void;
|
|
36
|
+
/** The host value as canonical tags — a store/host can hand in anything
|
|
37
|
+
* (`[1, null]`), and a non-string entry must not crash the render. */
|
|
38
|
+
private get tags();
|
|
39
|
+
/** A chip shows the matching option's label when the tag happens to be one
|
|
40
|
+
* (case-insensitive) — same fallback the readonly display (`displayValue`)
|
|
41
|
+
* already applies; free text with no match shows as typed. */
|
|
42
|
+
private chipLabel;
|
|
43
|
+
private get maxLength();
|
|
44
|
+
private get allowNew();
|
|
45
|
+
private get suggestions();
|
|
46
|
+
/** Same id the base label's `for` points at — clicking the field label
|
|
47
|
+
* focuses the input natively, no click handler of our own needed. */
|
|
48
|
+
private get inputId();
|
|
49
|
+
private get listboxId();
|
|
50
|
+
private get hintId();
|
|
51
|
+
/** Base `describedBy` (error/help) plus the transient refusal hint, when
|
|
52
|
+
* one is showing. */
|
|
53
|
+
private get controlDescribedBy();
|
|
54
|
+
private optionId;
|
|
55
|
+
/** Why `trimmed` can't join `current` right now, or null when it can —
|
|
56
|
+
* same rules @20baht/validator re-checks server-side. */
|
|
57
|
+
private rejectionFor;
|
|
58
|
+
/**
|
|
59
|
+
* `current` + one more chip, or the reason it was refused — null only for
|
|
60
|
+
* blank input (nothing worth reporting). Pure (no emit) so `addMany` can
|
|
61
|
+
* fold several candidates into ONE next array before telling the host,
|
|
62
|
+
* instead of racing `this.value` across several back-to-back emits.
|
|
63
|
+
*/
|
|
64
|
+
private nextWithTag;
|
|
65
|
+
private hintFor;
|
|
66
|
+
/** Attempt to add one chip; returns whether it landed. A refusal shows a
|
|
67
|
+
* brief inline hint instead of failing silently. */
|
|
68
|
+
private addTag;
|
|
69
|
+
private removeTag;
|
|
70
|
+
/** Split pasted / bulk text on commas (and newlines) into separate chips,
|
|
71
|
+
* emitted as ONE array (see `nextWithTag`). Reports the last refusal only
|
|
72
|
+
* when NOTHING from the paste landed. */
|
|
73
|
+
private addMany;
|
|
74
|
+
private listen;
|
|
75
|
+
private close;
|
|
76
|
+
private highlight;
|
|
77
|
+
private commitTyped;
|
|
78
|
+
private pick;
|
|
79
|
+
private onInput;
|
|
80
|
+
private onEnter;
|
|
81
|
+
private onBackspace;
|
|
82
|
+
private moveActive;
|
|
83
|
+
private onArrowDown;
|
|
84
|
+
private onArrowUp;
|
|
85
|
+
private onEscape;
|
|
86
|
+
private onKeydown;
|
|
87
|
+
private onPaste;
|
|
88
|
+
private onBlur;
|
|
89
|
+
protected updated(): void;
|
|
90
|
+
protected renderControl(): TemplateResult;
|
|
91
|
+
}
|
|
92
|
+
declare global {
|
|
93
|
+
interface HTMLElementTagNameMap {
|
|
94
|
+
'baht-tags': BahtTags;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { nothing as r, html as p } from "lit";
|
|
2
|
+
import { state as d, query as f } from "lit/decorators.js";
|
|
3
|
+
import { live as g } from "lit/directives/live.js";
|
|
4
|
+
import { BahtFieldBase as m } from "../field-base.js";
|
|
5
|
+
import { scrollOptionIntoView as b } from "./listbox.js";
|
|
6
|
+
import { ComboboxController as v } from "../combobox-controller.js";
|
|
7
|
+
import { normalizeTagsValue as u, optionKeyLookup as x, t as l } from "@20baht/engine";
|
|
8
|
+
import { customElement as w } from "../define.js";
|
|
9
|
+
import { floatPanel as I } from "../floating.js";
|
|
10
|
+
var y = Object.defineProperty, $ = Object.getOwnPropertyDescriptor, c = (t, e, i, s) => {
|
|
11
|
+
for (var n = s > 1 ? void 0 : s ? $(e, i) : e, o = t.length - 1, a; o >= 0; o--)
|
|
12
|
+
(a = t[o]) && (n = (s ? a(e, i, n) : a(n)) || n);
|
|
13
|
+
return s && n && y(e, i, n), n;
|
|
14
|
+
};
|
|
15
|
+
const T = 8;
|
|
16
|
+
let h = class extends m {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(), this.inputText = "", this.open = !1, this.activeIndex = -1, this.hint = null, this.combo = new v(this, {
|
|
19
|
+
onOutside: () => {
|
|
20
|
+
this.close();
|
|
21
|
+
}
|
|
22
|
+
}), I(this, { panel: ".baht-tags-list", fit: !0, gap: 2 });
|
|
23
|
+
}
|
|
24
|
+
willUpdate(t) {
|
|
25
|
+
super.willUpdate(t);
|
|
26
|
+
const e = t.get("field");
|
|
27
|
+
t.has("field") && e !== void 0 && e.key !== this.field.key && (this.inputText = "", this.close());
|
|
28
|
+
}
|
|
29
|
+
/** The host value as canonical tags — a store/host can hand in anything
|
|
30
|
+
* (`[1, null]`), and a non-string entry must not crash the render. */
|
|
31
|
+
get tags() {
|
|
32
|
+
return u(this.value);
|
|
33
|
+
}
|
|
34
|
+
/** A chip shows the matching option's label when the tag happens to be one
|
|
35
|
+
* (case-insensitive) — same fallback the readonly display (`displayValue`)
|
|
36
|
+
* already applies; free text with no match shows as typed. */
|
|
37
|
+
chipLabel(t) {
|
|
38
|
+
const e = t.toLowerCase(), i = (this.field.options ?? []).find((s) => s.key.toLowerCase() === e);
|
|
39
|
+
return (i == null ? void 0 : i.label) ?? t;
|
|
40
|
+
}
|
|
41
|
+
get maxLength() {
|
|
42
|
+
return this.field.max_length ?? 32;
|
|
43
|
+
}
|
|
44
|
+
get allowNew() {
|
|
45
|
+
return this.field.allow_new !== !1;
|
|
46
|
+
}
|
|
47
|
+
get suggestions() {
|
|
48
|
+
const t = this.field.options ?? [], e = new Set(this.tags.map((o) => o.toLowerCase())), i = this.inputText.trim().toLowerCase(), s = [], n = [];
|
|
49
|
+
for (const o of t) {
|
|
50
|
+
if (e.has(o.key.toLowerCase())) continue;
|
|
51
|
+
if (!i) {
|
|
52
|
+
s.push(o);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const a = o.label.toLowerCase();
|
|
56
|
+
a.startsWith(i) || o.key.toLowerCase().startsWith(i) ? s.push(o) : (a.includes(i) || o.key.toLowerCase().includes(i)) && n.push(o);
|
|
57
|
+
}
|
|
58
|
+
return [...s, ...n].slice(0, T);
|
|
59
|
+
}
|
|
60
|
+
/** Same id the base label's `for` points at — clicking the field label
|
|
61
|
+
* focuses the input natively, no click handler of our own needed. */
|
|
62
|
+
get inputId() {
|
|
63
|
+
return this.controlId;
|
|
64
|
+
}
|
|
65
|
+
get listboxId() {
|
|
66
|
+
return `${this.inputId}-list`;
|
|
67
|
+
}
|
|
68
|
+
get hintId() {
|
|
69
|
+
return `${this.inputId}-hint`;
|
|
70
|
+
}
|
|
71
|
+
/** Base `describedBy` (error/help) plus the transient refusal hint, when
|
|
72
|
+
* one is showing. */
|
|
73
|
+
get controlDescribedBy() {
|
|
74
|
+
const t = this.describedBy, e = [t === r ? "" : t, this.hint ? this.hintId : ""].filter(Boolean);
|
|
75
|
+
return e.length > 0 ? e.join(" ") : r;
|
|
76
|
+
}
|
|
77
|
+
optionId(t) {
|
|
78
|
+
return `${this.listboxId}-${t}`;
|
|
79
|
+
}
|
|
80
|
+
/** Why `trimmed` can't join `current` right now, or null when it can —
|
|
81
|
+
* same rules @20baht/validator re-checks server-side. */
|
|
82
|
+
rejectionFor(t, e, i) {
|
|
83
|
+
return e.length > this.maxLength ? "tooLong" : t.some((s) => s.toLowerCase() === i) ? "duplicate" : !this.allowNew && !new Set((this.field.options ?? []).map((n) => n.key.toLowerCase())).has(i) ? "notAllowed" : this.field.max_items !== void 0 && t.length >= this.field.max_items ? "maxItems" : null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* `current` + one more chip, or the reason it was refused — null only for
|
|
87
|
+
* blank input (nothing worth reporting). Pure (no emit) so `addMany` can
|
|
88
|
+
* fold several candidates into ONE next array before telling the host,
|
|
89
|
+
* instead of racing `this.value` across several back-to-back emits.
|
|
90
|
+
*/
|
|
91
|
+
nextWithTag(t, e) {
|
|
92
|
+
const i = e.trim();
|
|
93
|
+
if (!i) return null;
|
|
94
|
+
const s = i.toLowerCase(), n = this.field.options ?? [], o = x(n).get(s) ?? i, a = this.rejectionFor(t, o, s);
|
|
95
|
+
return a ? { reason: a } : { tags: u([...t, o], n) };
|
|
96
|
+
}
|
|
97
|
+
hintFor(t) {
|
|
98
|
+
switch (t) {
|
|
99
|
+
case "tooLong":
|
|
100
|
+
return l("tagTooLong", { n: this.maxLength });
|
|
101
|
+
case "duplicate":
|
|
102
|
+
return l("tagDuplicate");
|
|
103
|
+
case "notAllowed":
|
|
104
|
+
return l("tagNotAllowed");
|
|
105
|
+
case "maxItems":
|
|
106
|
+
return l("maxItems", { n: this.field.max_items });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** Attempt to add one chip; returns whether it landed. A refusal shows a
|
|
110
|
+
* brief inline hint instead of failing silently. */
|
|
111
|
+
addTag(t) {
|
|
112
|
+
const e = this.nextWithTag(this.tags, t);
|
|
113
|
+
return e ? "reason" in e ? (this.hint = this.hintFor(e.reason), !1) : (this.hint = null, this.emitInput(e.tags), !0) : !1;
|
|
114
|
+
}
|
|
115
|
+
removeTag(t) {
|
|
116
|
+
var e;
|
|
117
|
+
this.emitInput(this.tags.filter((i) => i !== t)), (e = this.inputEl) == null || e.focus();
|
|
118
|
+
}
|
|
119
|
+
/** Split pasted / bulk text on commas (and newlines) into separate chips,
|
|
120
|
+
* emitted as ONE array (see `nextWithTag`). Reports the last refusal only
|
|
121
|
+
* when NOTHING from the paste landed. */
|
|
122
|
+
addMany(t) {
|
|
123
|
+
let e = this.tags, i = !1, s = null;
|
|
124
|
+
for (const n of t.split(/[,\n]/)) {
|
|
125
|
+
const o = this.nextWithTag(e, n);
|
|
126
|
+
if (o) {
|
|
127
|
+
if ("reason" in o) {
|
|
128
|
+
s = o.reason;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
e = o.tags, i = !0;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
i ? (this.hint = null, this.emitInput(e)) : s && (this.hint = this.hintFor(s));
|
|
135
|
+
}
|
|
136
|
+
listen() {
|
|
137
|
+
this.combo.watchOutside();
|
|
138
|
+
}
|
|
139
|
+
close() {
|
|
140
|
+
this.combo.unwatchOutside(), this.open = !1, this.activeIndex = -1;
|
|
141
|
+
}
|
|
142
|
+
highlight(t) {
|
|
143
|
+
this.activeIndex !== t && (this.activeIndex = t);
|
|
144
|
+
}
|
|
145
|
+
commitTyped() {
|
|
146
|
+
this.addTag(this.inputText) && (this.inputText = ""), this.close();
|
|
147
|
+
}
|
|
148
|
+
pick(t) {
|
|
149
|
+
var e;
|
|
150
|
+
this.addTag(t.key), this.inputText = "", this.close(), (e = this.inputEl) == null || e.focus();
|
|
151
|
+
}
|
|
152
|
+
onInput(t) {
|
|
153
|
+
this.inputText = t.target.value, this.activeIndex = -1, this.open = !0, this.hint = null, this.listen();
|
|
154
|
+
}
|
|
155
|
+
onEnter(t) {
|
|
156
|
+
t.preventDefault();
|
|
157
|
+
const e = this.open && this.activeIndex >= 0 ? this.suggestions[this.activeIndex] : void 0;
|
|
158
|
+
e ? this.pick(e) : this.commitTyped();
|
|
159
|
+
}
|
|
160
|
+
onBackspace(t) {
|
|
161
|
+
this.inputText !== "" || this.tags.length === 0 || (t.preventDefault(), this.removeTag(this.tags[this.tags.length - 1]));
|
|
162
|
+
}
|
|
163
|
+
moveActive(t) {
|
|
164
|
+
const e = this.combo.nextActive(t, this.activeIndex, this.suggestions.length, {
|
|
165
|
+
wrap: !0
|
|
166
|
+
});
|
|
167
|
+
e !== void 0 && (this.activeIndex = e);
|
|
168
|
+
}
|
|
169
|
+
onArrowDown(t) {
|
|
170
|
+
if (t.preventDefault(), !this.open) {
|
|
171
|
+
this.open = !0, this.listen();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
this.moveActive(t.key);
|
|
175
|
+
}
|
|
176
|
+
onArrowUp(t) {
|
|
177
|
+
t.preventDefault(), this.open && this.moveActive(t.key);
|
|
178
|
+
}
|
|
179
|
+
onEscape(t) {
|
|
180
|
+
this.open && (t.preventDefault(), this.close());
|
|
181
|
+
}
|
|
182
|
+
onKeydown(t) {
|
|
183
|
+
if (!(t.isComposing || t.keyCode === 229))
|
|
184
|
+
switch (t.key) {
|
|
185
|
+
case ",":
|
|
186
|
+
t.preventDefault(), this.commitTyped();
|
|
187
|
+
break;
|
|
188
|
+
case "Enter":
|
|
189
|
+
this.onEnter(t);
|
|
190
|
+
break;
|
|
191
|
+
case "Backspace":
|
|
192
|
+
this.onBackspace(t);
|
|
193
|
+
break;
|
|
194
|
+
case "ArrowDown":
|
|
195
|
+
this.onArrowDown(t);
|
|
196
|
+
break;
|
|
197
|
+
case "ArrowUp":
|
|
198
|
+
this.onArrowUp(t);
|
|
199
|
+
break;
|
|
200
|
+
case "Escape":
|
|
201
|
+
this.onEscape(t);
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
onPaste(t) {
|
|
206
|
+
var a;
|
|
207
|
+
const e = ((a = t.clipboardData) == null ? void 0 : a.getData("text")) ?? "";
|
|
208
|
+
if (!e.includes(",") && !e.includes(`
|
|
209
|
+
`)) return;
|
|
210
|
+
t.preventDefault();
|
|
211
|
+
const i = t.target, s = i.value, n = i.selectionStart ?? s.length, o = i.selectionEnd ?? n;
|
|
212
|
+
this.addMany(s.slice(0, n) + e + s.slice(o)), this.inputText = "";
|
|
213
|
+
}
|
|
214
|
+
onBlur() {
|
|
215
|
+
this.commitTyped();
|
|
216
|
+
}
|
|
217
|
+
updated() {
|
|
218
|
+
b(this, this.open, this.activeIndex, this.optionId(this.activeIndex));
|
|
219
|
+
}
|
|
220
|
+
renderControl() {
|
|
221
|
+
const t = this.open && this.suggestions.length > 0, e = this.disabled || this.readonly;
|
|
222
|
+
return p`<div class="baht-tags${this.open ? " baht-tags--open" : ""}">
|
|
223
|
+
<div class="baht-control baht-tags-control">
|
|
224
|
+
${this.tags.map(
|
|
225
|
+
(i) => p`<span class="baht-tag-chip">
|
|
226
|
+
<span class="baht-tag-chip-label">${this.chipLabel(i)}</span>
|
|
227
|
+
${e ? r : p`<button
|
|
228
|
+
type="button"
|
|
229
|
+
class="baht-tag-chip-remove"
|
|
230
|
+
aria-label=${l("removeTag", { tag: this.chipLabel(i) })}
|
|
231
|
+
title=${l("removeTag", { tag: this.chipLabel(i) })}
|
|
232
|
+
@click=${() => {
|
|
233
|
+
this.removeTag(i);
|
|
234
|
+
}}
|
|
235
|
+
>
|
|
236
|
+
×
|
|
237
|
+
</button>`}
|
|
238
|
+
</span>`
|
|
239
|
+
)}
|
|
240
|
+
<input
|
|
241
|
+
class="baht-tags-input"
|
|
242
|
+
id=${this.inputId}
|
|
243
|
+
type="text"
|
|
244
|
+
autocomplete="off"
|
|
245
|
+
role="combobox"
|
|
246
|
+
aria-labelledby=${this.field.label ? this.labelId : r}
|
|
247
|
+
aria-expanded=${t ? "true" : "false"}
|
|
248
|
+
aria-controls=${this.listboxId}
|
|
249
|
+
aria-autocomplete="list"
|
|
250
|
+
aria-activedescendant=${t && this.activeIndex >= 0 ? this.optionId(this.activeIndex) : r}
|
|
251
|
+
aria-invalid=${this.invalidAttr}
|
|
252
|
+
aria-describedby=${this.controlDescribedBy}
|
|
253
|
+
placeholder=${this.tags.length === 0 ? this.field.placeholder ?? "" : ""}
|
|
254
|
+
.value=${g(this.inputText)}
|
|
255
|
+
?disabled=${e}
|
|
256
|
+
@input=${(i) => {
|
|
257
|
+
this.onInput(i);
|
|
258
|
+
}}
|
|
259
|
+
@keydown=${(i) => {
|
|
260
|
+
this.onKeydown(i);
|
|
261
|
+
}}
|
|
262
|
+
@paste=${(i) => {
|
|
263
|
+
this.onPaste(i);
|
|
264
|
+
}}
|
|
265
|
+
@blur=${() => {
|
|
266
|
+
this.onBlur();
|
|
267
|
+
}}
|
|
268
|
+
/>
|
|
269
|
+
</div>
|
|
270
|
+
${this.hint ? p`<div class="baht-tags-hint" id=${this.hintId} role="status">${this.hint}</div>` : r}
|
|
271
|
+
<div
|
|
272
|
+
class="baht-listbox baht-tags-list"
|
|
273
|
+
id=${this.listboxId}
|
|
274
|
+
role="listbox"
|
|
275
|
+
aria-label=${this.field.label ?? ""}
|
|
276
|
+
?hidden=${!t}
|
|
277
|
+
>
|
|
278
|
+
${this.suggestions.map(
|
|
279
|
+
// eslint-disable-next-line lit-a11y/click-events-have-key-events -- keyboard lives on the combobox input (aria-activedescendant pattern)
|
|
280
|
+
(i, s) => p`<div
|
|
281
|
+
class="baht-listbox-option${s === this.activeIndex ? " baht-listbox-option--active" : ""}"
|
|
282
|
+
id=${this.optionId(s)}
|
|
283
|
+
role="option"
|
|
284
|
+
aria-selected=${s === this.activeIndex ? "true" : "false"}
|
|
285
|
+
data-key=${i.key}
|
|
286
|
+
@mousedown=${(n) => {
|
|
287
|
+
n.preventDefault();
|
|
288
|
+
}}
|
|
289
|
+
@mousemove=${() => {
|
|
290
|
+
this.highlight(s);
|
|
291
|
+
}}
|
|
292
|
+
@click=${() => {
|
|
293
|
+
this.pick(i);
|
|
294
|
+
}}
|
|
295
|
+
>
|
|
296
|
+
${i.label}
|
|
297
|
+
</div>`
|
|
298
|
+
)}
|
|
299
|
+
</div>
|
|
300
|
+
</div>`;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
c([
|
|
304
|
+
d()
|
|
305
|
+
], h.prototype, "inputText", 2);
|
|
306
|
+
c([
|
|
307
|
+
d()
|
|
308
|
+
], h.prototype, "open", 2);
|
|
309
|
+
c([
|
|
310
|
+
d()
|
|
311
|
+
], h.prototype, "activeIndex", 2);
|
|
312
|
+
c([
|
|
313
|
+
d()
|
|
314
|
+
], h.prototype, "hint", 2);
|
|
315
|
+
c([
|
|
316
|
+
f("input")
|
|
317
|
+
], h.prototype, "inputEl", 2);
|
|
318
|
+
h = c([
|
|
319
|
+
w("baht-tags")
|
|
320
|
+
], h);
|
|
321
|
+
export {
|
|
322
|
+
h as BahtTags
|
|
323
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { nothing, TemplateResult } from 'lit';
|
|
2
|
+
import { BahtElement } from '../base.js';
|
|
3
|
+
import { FieldDescriptor } from '@20baht/engine';
|
|
4
|
+
/** Static text block (`type: "label"`): no value, no emits. */
|
|
5
|
+
export declare class BahtText extends BahtElement {
|
|
6
|
+
field: FieldDescriptor;
|
|
7
|
+
/** `field` as the host may actually have left it: a framework can bind it after connecting. */
|
|
8
|
+
private get assignedField();
|
|
9
|
+
protected render(): TemplateResult | typeof nothing;
|
|
10
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { nothing as n, html as p } from "lit";
|
|
2
|
+
import { property as h } from "lit/decorators.js";
|
|
3
|
+
import { BahtElement as d } from "../base.js";
|
|
4
|
+
import { customElement as m } from "../define.js";
|
|
5
|
+
var v = Object.defineProperty, b = Object.getOwnPropertyDescriptor, f = (e, r, s, i) => {
|
|
6
|
+
for (var t = i > 1 ? void 0 : i ? b(r, s) : r, l = e.length - 1, o; l >= 0; l--)
|
|
7
|
+
(o = e[l]) && (t = (i ? o(r, s, t) : o(t)) || t);
|
|
8
|
+
return i && t && v(r, s, t), t;
|
|
9
|
+
};
|
|
10
|
+
let a = class extends d {
|
|
11
|
+
/** `field` as the host may actually have left it: a framework can bind it after connecting. */
|
|
12
|
+
get assignedField() {
|
|
13
|
+
return this.field;
|
|
14
|
+
}
|
|
15
|
+
render() {
|
|
16
|
+
if (!this.assignedField) return n;
|
|
17
|
+
const e = this.field.variant ?? "body";
|
|
18
|
+
return p`<div class="baht-text baht-text--${e}">${this.field.text ?? this.field.label ?? ""}</div>`;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
f([
|
|
22
|
+
h({ attribute: !1 })
|
|
23
|
+
], a.prototype, "field", 2);
|
|
24
|
+
a = f([
|
|
25
|
+
m("baht-text")
|
|
26
|
+
], a);
|
|
27
|
+
export {
|
|
28
|
+
a as BahtText
|
|
29
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { html as h } from "lit";
|
|
2
|
+
import { ifDefined as a } from "lit/directives/if-defined.js";
|
|
3
|
+
import { live as n } from "lit/directives/live.js";
|
|
4
|
+
import { BahtFieldBase as c } from "../field-base.js";
|
|
5
|
+
import { customElement as m } from "../define.js";
|
|
6
|
+
var p = Object.getOwnPropertyDescriptor, f = (e, i, d, l) => {
|
|
7
|
+
for (var t = l > 1 ? void 0 : l ? p(i, d) : i, r = e.length - 1, o; r >= 0; r--)
|
|
8
|
+
(o = e[r]) && (t = o(t) || t);
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
let s = class extends c {
|
|
12
|
+
renderControl() {
|
|
13
|
+
return h`<span class="baht-field-icon-wrap">
|
|
14
|
+
${this.renderFieldIcon()}
|
|
15
|
+
<textarea
|
|
16
|
+
class="baht-control baht-control--textarea${this.hasFieldIcon ? " baht-control--has-icon" : ""}"
|
|
17
|
+
id=${this.controlId}
|
|
18
|
+
.value=${n(this.shownText)}
|
|
19
|
+
placeholder=${a(this.field.placeholder)}
|
|
20
|
+
maxlength=${a(this.field.max_length)}
|
|
21
|
+
rows=${this.field.rows ?? 3}
|
|
22
|
+
autocomplete=${a(this.field.autocomplete)}
|
|
23
|
+
?disabled=${this.disabled}
|
|
24
|
+
?readonly=${this.readonly}
|
|
25
|
+
?required=${this.required}
|
|
26
|
+
aria-invalid=${this.invalidAttr}
|
|
27
|
+
aria-describedby=${this.describedBy}
|
|
28
|
+
@input=${(e) => {
|
|
29
|
+
this.emitTyped(e.target.value);
|
|
30
|
+
}}
|
|
31
|
+
></textarea>
|
|
32
|
+
</span>`;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
s = f([
|
|
36
|
+
m("baht-textarea")
|
|
37
|
+
], s);
|
|
38
|
+
export {
|
|
39
|
+
s as BahtTextarea
|
|
40
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { PropertyValues, TemplateResult } from 'lit';
|
|
2
|
+
import { BahtElement } from '../base.js';
|
|
3
|
+
export type ThemeName = 'light' | 'dark';
|
|
4
|
+
/**
|
|
5
|
+
* Light / dark switch for the 20baht themes. Sets `data-baht-theme` on `<html>` (or on the
|
|
6
|
+
* `target` element), so every `--baht-*` token follows.
|
|
7
|
+
*
|
|
8
|
+
* <baht-theme-toggle></baht-theme-toggle>
|
|
9
|
+
* <baht-theme-toggle default="system"></baht-theme-toggle> <!-- first visit follows the OS -->
|
|
10
|
+
* <baht-theme-toggle target="#preview" storage-key=""></baht-theme-toggle>
|
|
11
|
+
*
|
|
12
|
+
* Starting theme: the one saved in `localStorage[storage-key]`, else the theme already on the
|
|
13
|
+
* target, else `default`. Clicking flips it, saves it and fires `baht-theme-change`. Every
|
|
14
|
+
* toggle watches its target's attribute, so several toggles (or the app's own settings page)
|
|
15
|
+
* stay in sync. To avoid a flash of the wrong theme on load, apply the saved theme before
|
|
16
|
+
* paint with an inline script (see the docs page).
|
|
17
|
+
*
|
|
18
|
+
* A11y: an APG toggle button — fixed localized name ("Dark theme"), `aria-pressed` = dark.
|
|
19
|
+
*
|
|
20
|
+
* @fires {CustomEvent<{ theme: ThemeName }>} baht-theme-change - The user switched theme. `detail: { theme: 'light' | 'dark' }`.
|
|
21
|
+
*/
|
|
22
|
+
export declare class BahtThemeToggle extends BahtElement {
|
|
23
|
+
/** Current theme. Setting it applies it to the target (not saved, no event). */
|
|
24
|
+
theme: ThemeName;
|
|
25
|
+
/** Theme when nothing is saved and the target has none: `light`, `dark`, or `system`. */
|
|
26
|
+
default: ThemeName | 'system';
|
|
27
|
+
/** CSS selector of the element that carries `data-baht-theme`. Default: `<html>`. */
|
|
28
|
+
target: string;
|
|
29
|
+
/** localStorage key for the user's choice; `""` turns persistence off. */
|
|
30
|
+
storageKey: string;
|
|
31
|
+
private targetEl;
|
|
32
|
+
private observer;
|
|
33
|
+
connectedCallback(): void;
|
|
34
|
+
disconnectedCallback(): void;
|
|
35
|
+
protected willUpdate(changed: PropertyValues<this>): void;
|
|
36
|
+
protected updated(changed: PropertyValues<this>): void;
|
|
37
|
+
private attachTarget;
|
|
38
|
+
private initialTheme;
|
|
39
|
+
private read;
|
|
40
|
+
private save;
|
|
41
|
+
/** Flip light ↔ dark, save it and fire `baht-theme-change` (what a click does). */
|
|
42
|
+
toggle(): void;
|
|
43
|
+
protected render(): TemplateResult;
|
|
44
|
+
}
|