bank20baht-ui 0.2.8 → 0.2.9

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.
@@ -0,0 +1,92 @@
1
+ import { PropertyValues, TemplateResult } from 'lit';
2
+ import { BahtElement } from '../base.js';
3
+ export interface TypeaheadOption {
4
+ key: string;
5
+ label: string;
6
+ /** Secondary text shown right-aligned (e.g. an email under a name). */
7
+ sub?: string;
8
+ }
9
+ /**
10
+ * Text input with suggestions (autocomplete). The value IS the text — pick a
11
+ * suggestion and the input shows its label; keep typing and the text stands
12
+ * on its own (`free-text`, default) or is only a filter (`free-text="false"`,
13
+ * blur then reverts to the last picked option).
14
+ *
15
+ * Suggestions come from a static `options` list (filtered here — labels that
16
+ * start with the term rank first, then labels that contain it) or from an
17
+ * async `fetcher(term)`. Typing is debounced (`debounce`, 150 ms) before the
18
+ * host hears `baht-change` and before a fetcher runs.
19
+ *
20
+ * const el = document.createElement('baht-typeahead');
21
+ * el.options = [{ key: 'th', label: 'Thailand' }, { key: 'tw', label: 'Taiwan' }];
22
+ * el.addEventListener('baht-change', (e) => (draft.country = e.detail.value));
23
+ * el.addEventListener('baht-select', (e) => (draft.countryCode = e.detail.option.key));
24
+ *
25
+ * ARIA: APG editable combobox with list autocomplete — the input is the
26
+ * combobox, `aria-activedescendant` walks the listbox, Escape closes, Enter
27
+ * picks. Unlike <baht-reference-picker> the input is always editable and the
28
+ * text itself is a valid value; unlike <baht-select> the list is a filter of
29
+ * what was typed, not a fixed menu.
30
+ */
31
+ export declare class BahtTypeahead extends BahtElement {
32
+ /** Accessible name (also the listbox name). */
33
+ label: string;
34
+ /** The text. Controlled: re-feed after `baht-change` (or don't — the input keeps what was typed). */
35
+ value: string;
36
+ placeholder: string;
37
+ disabled: boolean;
38
+ /** Marks the control invalid (styles + aria-invalid). */
39
+ invalid: boolean;
40
+ /** Static suggestion list, filtered client-side. Ignored when `fetcher` is set. */
41
+ options: TypeaheadOption[];
42
+ /** Async suggestions: term in, options out. Errors show as "no matches". */
43
+ fetcher: ((term: string) => Promise<TypeaheadOption[]>) | null;
44
+ /** Quiet time (ms) before the host hears the text and suggestions are (re)computed. */
45
+ debounce: number;
46
+ /** Characters typed before suggestions appear (0 = suggest on focus/arrow too). */
47
+ minChars: number;
48
+ /** Cap on suggestions shown. */
49
+ maxItems: number;
50
+ /** false = the text must be a picked option; blur reverts otherwise. */
51
+ freeText: boolean;
52
+ /** HTML autocomplete token forwarded to the input ('off' keeps the browser's own list away). */
53
+ autocomplete: string;
54
+ private term;
55
+ private open;
56
+ private results;
57
+ private loading;
58
+ private activeIndex;
59
+ private inputEl;
60
+ private readonly uid;
61
+ private timer;
62
+ private fetchSeq;
63
+ /** The text currently IS this picked option (null once the user types again). */
64
+ private picked;
65
+ /** Most recent pick ever — what `free-text="false"` reverts to on blur. */
66
+ private lastPicked;
67
+ private readonly onDocMousedown;
68
+ private get inputId();
69
+ private get listboxId();
70
+ private optionId;
71
+ disconnectedCallback(): void;
72
+ protected willUpdate(changed: PropertyValues<this>): void;
73
+ protected updated(): void;
74
+ private filterStatic;
75
+ private suggest;
76
+ private highlight;
77
+ private listen;
78
+ private close;
79
+ private emitChange;
80
+ private onInput;
81
+ /** Hand pending text to the host now (blur, Enter). */
82
+ private flush;
83
+ private pick;
84
+ private onBlur;
85
+ private onKeydown;
86
+ protected render(): TemplateResult;
87
+ }
88
+ declare global {
89
+ interface HTMLElementTagNameMap {
90
+ 'baht-typeahead': BahtTypeahead;
91
+ }
92
+ }
@@ -42,6 +42,7 @@ export { BahtEmptyState } from './baht-empty-state.js';
42
42
  export { BahtErrorState } from './baht-error-state.js';
43
43
  export { BahtKeyvalueEditor } from './baht-keyvalue-editor.js';
44
44
  export { BahtReferencePicker, type ReferenceOption } from './baht-reference-picker.js';
45
+ export { BahtTypeahead, type TypeaheadOption } from './baht-typeahead.js';
45
46
  export { BahtRepeater } from './baht-repeater.js';
46
47
  export { BahtSteps } from './baht-steps.js';
47
48
  export { TAG_FOR_TYPE } from './tag-map.js';
@@ -41,6 +41,16 @@ export interface MessageCatalog {
41
41
  /** Placeholder option of a dropdown. */
42
42
  choose: string;
43
43
  rowCount: string;
44
+ close: string;
45
+ dismiss: string;
46
+ opensInNewTab: string;
47
+ otpCharacter: string;
48
+ row: string;
49
+ removeRowN: string;
50
+ stepDone: string;
51
+ stepCurrent: string;
52
+ today: string;
53
+ clear: string;
44
54
  }
45
55
  export type MessageKey = keyof MessageCatalog;
46
56
  export type Locale = 'en' | 'th';