@kodaris/krubble-components 1.0.53 → 1.0.54
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/custom-elements.json +836 -239
- package/dist/form/auto-suggest/auto-suggest.d.ts +20 -42
- package/dist/form/auto-suggest/auto-suggest.d.ts.map +1 -1
- package/dist/form/auto-suggest/auto-suggest.js +193 -426
- package/dist/form/auto-suggest/auto-suggest.js.map +1 -1
- package/dist/form/combo-box/combo-box.d.ts +92 -0
- package/dist/form/combo-box/combo-box.d.ts.map +1 -0
- package/dist/form/combo-box/combo-box.js +714 -0
- package/dist/form/combo-box/combo-box.js.map +1 -0
- package/dist/form/index.d.ts +1 -0
- package/dist/form/index.d.ts.map +1 -1
- package/dist/form/index.js +1 -0
- package/dist/form/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/krubble-components.bundled.js +1070 -585
- package/dist/krubble-components.bundled.js.map +1 -1
- package/dist/krubble-components.bundled.min.js +394 -264
- package/dist/krubble-components.bundled.min.js.map +1 -1
- package/dist/krubble-components.umd.js +1071 -586
- package/dist/krubble-components.umd.js.map +1 -1
- package/dist/krubble-components.umd.min.js +462 -332
- package/dist/krubble-components.umd.min.js.map +1 -1
- package/dist/table/table.d.ts.map +1 -1
- package/dist/table/table.js +8 -1
- package/dist/table/table.js.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,714 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { LitElement, html, css, nothing } from 'lit';
|
|
8
|
+
import { customElement, property, state, query } from 'lit/decorators.js';
|
|
9
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
10
|
+
/**
|
|
11
|
+
* @element kr-combo-box
|
|
12
|
+
*
|
|
13
|
+
* A searchable select field. Looks like a select dropdown but when opened
|
|
14
|
+
* shows a search input at the top of the panel for filtering options via
|
|
15
|
+
* a fetch function. Works with any object shape — use optionValue and
|
|
16
|
+
* optionLabel to tell the component how to extract the value and display text.
|
|
17
|
+
*
|
|
18
|
+
* @property {string} label - Label text
|
|
19
|
+
* @property {string} name - Name for form submission
|
|
20
|
+
* @property {string} value - Currently selected value
|
|
21
|
+
* @property {string} placeholder - Placeholder text when nothing is selected
|
|
22
|
+
* @property {boolean} disabled - Whether the field is disabled
|
|
23
|
+
* @property {boolean} readonly - Whether the field is readonly
|
|
24
|
+
* @property {boolean} required - Whether the field is required
|
|
25
|
+
* @property {string} hint - Helper text displayed below the field
|
|
26
|
+
* @property {string|Function} optionValue - Field name or function to extract the value from an option
|
|
27
|
+
* @property {string|Function} optionLabel - Field name or function to extract the label from an option
|
|
28
|
+
* @property {any[]} options - Array of options
|
|
29
|
+
* @property {Function} fetch - Function that returns a promise of options
|
|
30
|
+
* @property {Function} fetchSelection - Function that resolves a single option by its value
|
|
31
|
+
*
|
|
32
|
+
* @fires change - Fired when the selected value changes
|
|
33
|
+
* @fires select - Fired when an option is selected
|
|
34
|
+
*/
|
|
35
|
+
let KRComboBox = class KRComboBox extends LitElement {
|
|
36
|
+
constructor() {
|
|
37
|
+
super();
|
|
38
|
+
this._requestId = 0;
|
|
39
|
+
this._selectedOption = null;
|
|
40
|
+
this._handleDocumentClick = (e) => {
|
|
41
|
+
if (!e.composedPath().includes(this)) {
|
|
42
|
+
this._close();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
this.label = '';
|
|
46
|
+
this.name = '';
|
|
47
|
+
this.value = '';
|
|
48
|
+
this.placeholder = 'Select an option';
|
|
49
|
+
this.disabled = false;
|
|
50
|
+
this.readonly = false;
|
|
51
|
+
this.required = false;
|
|
52
|
+
this.hint = '';
|
|
53
|
+
this.optionValue = 'value';
|
|
54
|
+
this.optionLabel = 'label';
|
|
55
|
+
this.options = [];
|
|
56
|
+
this.fetch = null;
|
|
57
|
+
this.fetchSelection = null;
|
|
58
|
+
this._isOpen = false;
|
|
59
|
+
this._highlightedIndex = -1;
|
|
60
|
+
this._touched = false;
|
|
61
|
+
this._searchQuery = '';
|
|
62
|
+
this._handleInvalid = (e) => {
|
|
63
|
+
e.preventDefault();
|
|
64
|
+
this._touched = true;
|
|
65
|
+
};
|
|
66
|
+
this._internals = this.attachInternals();
|
|
67
|
+
}
|
|
68
|
+
connectedCallback() {
|
|
69
|
+
super.connectedCallback();
|
|
70
|
+
document.addEventListener('click', this._handleDocumentClick);
|
|
71
|
+
this.addEventListener('invalid', this._handleInvalid);
|
|
72
|
+
}
|
|
73
|
+
disconnectedCallback() {
|
|
74
|
+
super.disconnectedCallback();
|
|
75
|
+
document.removeEventListener('click', this._handleDocumentClick);
|
|
76
|
+
this.removeEventListener('invalid', this._handleInvalid);
|
|
77
|
+
}
|
|
78
|
+
firstUpdated() {
|
|
79
|
+
this._updateValidity();
|
|
80
|
+
if (this.value && this.fetchSelection) {
|
|
81
|
+
this._resolveSelection();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
updated(changedProperties) {
|
|
85
|
+
if (changedProperties.has('required') || changedProperties.has('value')) {
|
|
86
|
+
this._updateValidity();
|
|
87
|
+
}
|
|
88
|
+
if (changedProperties.has('value')) {
|
|
89
|
+
if (this.value) {
|
|
90
|
+
// Only resolve if the selected option doesn't match the current value
|
|
91
|
+
if (!this._selectedOption || this._getOptionValue(this._selectedOption) !== this.value) {
|
|
92
|
+
this._resolveSelection();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
this._selectedOption = null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (changedProperties.has('options') && this._isOpen) {
|
|
100
|
+
this._positionDropdown();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
get form() {
|
|
104
|
+
return this._internals.form;
|
|
105
|
+
}
|
|
106
|
+
get validity() {
|
|
107
|
+
return this._internals.validity;
|
|
108
|
+
}
|
|
109
|
+
get validationMessage() {
|
|
110
|
+
return this._internals.validationMessage;
|
|
111
|
+
}
|
|
112
|
+
checkValidity() {
|
|
113
|
+
return this._internals.checkValidity();
|
|
114
|
+
}
|
|
115
|
+
reportValidity() {
|
|
116
|
+
return this._internals.reportValidity();
|
|
117
|
+
}
|
|
118
|
+
formResetCallback() {
|
|
119
|
+
this.value = '';
|
|
120
|
+
this._selectedOption = null;
|
|
121
|
+
this._touched = false;
|
|
122
|
+
this._isOpen = false;
|
|
123
|
+
this._highlightedIndex = -1;
|
|
124
|
+
this._searchQuery = '';
|
|
125
|
+
this._internals.setFormValue('');
|
|
126
|
+
this._internals.setValidity({});
|
|
127
|
+
}
|
|
128
|
+
formStateRestoreCallback(state) {
|
|
129
|
+
this.value = state;
|
|
130
|
+
}
|
|
131
|
+
focus() {
|
|
132
|
+
this._triggerElement?.focus();
|
|
133
|
+
}
|
|
134
|
+
blur() {
|
|
135
|
+
this._triggerElement?.blur();
|
|
136
|
+
}
|
|
137
|
+
_updateValidity() {
|
|
138
|
+
if (this.required && !this.value) {
|
|
139
|
+
this._internals.setValidity({ valueMissing: true }, 'Please select an option', this._triggerElement);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
this._internals.setValidity({});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
_handleTriggerClick() {
|
|
146
|
+
if (this.disabled || this.readonly) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (this._isOpen) {
|
|
150
|
+
this._close();
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
this._open();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
_open() {
|
|
157
|
+
this._isOpen = true;
|
|
158
|
+
this._searchQuery = '';
|
|
159
|
+
this._highlightedIndex = -1;
|
|
160
|
+
this._fetch();
|
|
161
|
+
this.updateComplete.then(() => {
|
|
162
|
+
this._positionDropdown();
|
|
163
|
+
if (this._searchInput) {
|
|
164
|
+
this._searchInput.focus();
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
_close() {
|
|
169
|
+
this._isOpen = false;
|
|
170
|
+
this._highlightedIndex = -1;
|
|
171
|
+
this._searchQuery = '';
|
|
172
|
+
}
|
|
173
|
+
_positionDropdown() {
|
|
174
|
+
requestAnimationFrame(() => {
|
|
175
|
+
const dropdown = this.shadowRoot?.querySelector('.dropdown');
|
|
176
|
+
if (!dropdown) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const triggerRect = this._triggerElement.getBoundingClientRect();
|
|
180
|
+
const spaceBelow = window.innerHeight - triggerRect.bottom - 4 - 8;
|
|
181
|
+
const spaceAbove = triggerRect.top - 4 - 8;
|
|
182
|
+
dropdown.style.left = triggerRect.left + 'px';
|
|
183
|
+
dropdown.style.width = triggerRect.width + 'px';
|
|
184
|
+
// Prefer opening below; only flip above when space below is tight
|
|
185
|
+
if (spaceBelow < 200 && spaceAbove > spaceBelow) {
|
|
186
|
+
dropdown.style.top = '';
|
|
187
|
+
dropdown.style.bottom = (window.innerHeight - triggerRect.top + 4) + 'px';
|
|
188
|
+
dropdown.style.maxHeight = spaceAbove + 'px';
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
dropdown.style.bottom = '';
|
|
192
|
+
dropdown.style.top = triggerRect.bottom + 4 + 'px';
|
|
193
|
+
dropdown.style.maxHeight = spaceBelow + 'px';
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
_fetch() {
|
|
198
|
+
if (!this.fetch) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
this._requestId++;
|
|
202
|
+
const requestId = this._requestId;
|
|
203
|
+
this.fetch(this._searchQuery).then((options) => {
|
|
204
|
+
if (requestId === this._requestId) {
|
|
205
|
+
this.options = options;
|
|
206
|
+
}
|
|
207
|
+
}).catch((error) => {
|
|
208
|
+
console.error('kr-combo-box: fetch failed', error);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
_handleSearchInput(e) {
|
|
212
|
+
this._searchQuery = e.target.value;
|
|
213
|
+
this._highlightedIndex = -1;
|
|
214
|
+
this._fetch();
|
|
215
|
+
}
|
|
216
|
+
_handleSearchKeyDown(e) {
|
|
217
|
+
switch (e.key) {
|
|
218
|
+
case 'ArrowDown':
|
|
219
|
+
e.preventDefault();
|
|
220
|
+
this._highlightedIndex = Math.min(this._highlightedIndex + 1, this.options.length - 1);
|
|
221
|
+
this._scrollToHighlighted();
|
|
222
|
+
break;
|
|
223
|
+
case 'ArrowUp':
|
|
224
|
+
e.preventDefault();
|
|
225
|
+
if (this._highlightedIndex === -1) {
|
|
226
|
+
this._highlightedIndex = this.options.length - 1;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
this._highlightedIndex = Math.max(this._highlightedIndex - 1, 0);
|
|
230
|
+
}
|
|
231
|
+
this._scrollToHighlighted();
|
|
232
|
+
break;
|
|
233
|
+
case 'Enter':
|
|
234
|
+
e.preventDefault();
|
|
235
|
+
if (this._highlightedIndex >= 0 && this.options[this._highlightedIndex]) {
|
|
236
|
+
this._selectOption(this.options[this._highlightedIndex]);
|
|
237
|
+
}
|
|
238
|
+
break;
|
|
239
|
+
case 'Escape':
|
|
240
|
+
e.preventDefault();
|
|
241
|
+
this._close();
|
|
242
|
+
this._triggerElement?.focus();
|
|
243
|
+
break;
|
|
244
|
+
case 'Tab':
|
|
245
|
+
this._close();
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
_handleTriggerKeyDown(e) {
|
|
250
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp' || e.key === 'Enter' || e.key === ' ') {
|
|
251
|
+
e.preventDefault();
|
|
252
|
+
if (!this._isOpen) {
|
|
253
|
+
this._open();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
_handleTriggerBlur() {
|
|
258
|
+
this._touched = true;
|
|
259
|
+
this._updateValidity();
|
|
260
|
+
}
|
|
261
|
+
_scrollToHighlighted() {
|
|
262
|
+
this.updateComplete.then(() => {
|
|
263
|
+
const container = this.shadowRoot?.querySelector('.options');
|
|
264
|
+
const highlighted = this.shadowRoot?.querySelector('.option--highlighted');
|
|
265
|
+
if (container && highlighted) {
|
|
266
|
+
const containerRect = container.getBoundingClientRect();
|
|
267
|
+
const highlightedRect = highlighted.getBoundingClientRect();
|
|
268
|
+
if (highlightedRect.bottom > containerRect.bottom) {
|
|
269
|
+
highlighted.scrollIntoView({ block: 'nearest' });
|
|
270
|
+
}
|
|
271
|
+
else if (highlightedRect.top < containerRect.top) {
|
|
272
|
+
highlighted.scrollIntoView({ block: 'nearest' });
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
_getOptionValue(option) {
|
|
278
|
+
if (typeof this.optionValue === 'function') {
|
|
279
|
+
return this.optionValue(option);
|
|
280
|
+
}
|
|
281
|
+
return option[this.optionValue];
|
|
282
|
+
}
|
|
283
|
+
_getOptionLabel(option) {
|
|
284
|
+
let label;
|
|
285
|
+
if (typeof this.optionLabel === 'function') {
|
|
286
|
+
label = this.optionLabel(option);
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
label = option[this.optionLabel];
|
|
290
|
+
}
|
|
291
|
+
if (!label) {
|
|
292
|
+
return this._getOptionValue(option);
|
|
293
|
+
}
|
|
294
|
+
return label;
|
|
295
|
+
}
|
|
296
|
+
_resolveSelection() {
|
|
297
|
+
if (!this.fetchSelection) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const fetchedValue = this.value;
|
|
301
|
+
this.fetchSelection(this.value).then((option) => {
|
|
302
|
+
if (this.value !== fetchedValue) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
if (!option) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
this._selectedOption = option;
|
|
309
|
+
this.requestUpdate();
|
|
310
|
+
}).catch((error) => {
|
|
311
|
+
console.error('kr-combo-box: fetchSelection failed', error);
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
_selectOption(option) {
|
|
315
|
+
if (option.disabled) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
this.value = this._getOptionValue(option);
|
|
319
|
+
this._selectedOption = option;
|
|
320
|
+
this._close();
|
|
321
|
+
this._internals.setFormValue(this.value);
|
|
322
|
+
this._updateValidity();
|
|
323
|
+
this.dispatchEvent(new CustomEvent('select', {
|
|
324
|
+
detail: { option: option },
|
|
325
|
+
bubbles: true,
|
|
326
|
+
composed: true,
|
|
327
|
+
}));
|
|
328
|
+
this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
|
|
329
|
+
this._triggerElement?.focus();
|
|
330
|
+
}
|
|
331
|
+
_handleOptionMouseEnter(e, index) {
|
|
332
|
+
this._highlightedIndex = index;
|
|
333
|
+
}
|
|
334
|
+
_renderOption(option, index) {
|
|
335
|
+
const optionValue = this._getOptionValue(option);
|
|
336
|
+
return html `
|
|
337
|
+
<button
|
|
338
|
+
class=${classMap({
|
|
339
|
+
option: true,
|
|
340
|
+
'option--highlighted': index === this._highlightedIndex,
|
|
341
|
+
'option--selected': optionValue === this.value,
|
|
342
|
+
})}
|
|
343
|
+
type="button"
|
|
344
|
+
role="option"
|
|
345
|
+
aria-selected=${optionValue === this.value}
|
|
346
|
+
?disabled=${option.disabled}
|
|
347
|
+
@click=${(e) => this._selectOption(option)}
|
|
348
|
+
@mouseenter=${(e) => this._handleOptionMouseEnter(e, index)}
|
|
349
|
+
>
|
|
350
|
+
${this._getOptionLabel(option)}
|
|
351
|
+
</button>
|
|
352
|
+
`;
|
|
353
|
+
}
|
|
354
|
+
render() {
|
|
355
|
+
let footer = nothing;
|
|
356
|
+
if (this._touched && this.required && !this.value) {
|
|
357
|
+
footer = html `<div class="validation-message">Please select an option</div>`;
|
|
358
|
+
}
|
|
359
|
+
else if (this.hint) {
|
|
360
|
+
footer = html `<div class="hint">${this.hint}</div>`;
|
|
361
|
+
}
|
|
362
|
+
return html `
|
|
363
|
+
<div class="wrapper">
|
|
364
|
+
${this.label
|
|
365
|
+
? html `
|
|
366
|
+
<label>
|
|
367
|
+
${this.label}
|
|
368
|
+
${this.required ? html `<span class="required">*</span>` : nothing}
|
|
369
|
+
</label>
|
|
370
|
+
`
|
|
371
|
+
: nothing}
|
|
372
|
+
|
|
373
|
+
<button
|
|
374
|
+
class=${classMap({
|
|
375
|
+
trigger: true,
|
|
376
|
+
'trigger--open': this._isOpen,
|
|
377
|
+
'trigger--invalid': this._touched && this.required && !this.value,
|
|
378
|
+
})}
|
|
379
|
+
type="button"
|
|
380
|
+
?disabled=${this.disabled}
|
|
381
|
+
aria-haspopup="listbox"
|
|
382
|
+
aria-expanded=${this._isOpen}
|
|
383
|
+
@click=${this._handleTriggerClick}
|
|
384
|
+
@keydown=${this._handleTriggerKeyDown}
|
|
385
|
+
@blur=${this._handleTriggerBlur}
|
|
386
|
+
>
|
|
387
|
+
<span class=${classMap({
|
|
388
|
+
trigger__value: true,
|
|
389
|
+
trigger__placeholder: !this._selectedOption,
|
|
390
|
+
})}>
|
|
391
|
+
${this._selectedOption ? this._getOptionLabel(this._selectedOption) : this.placeholder}
|
|
392
|
+
</span>
|
|
393
|
+
<svg
|
|
394
|
+
class=${classMap({
|
|
395
|
+
trigger__icon: true,
|
|
396
|
+
'trigger__icon--open': this._isOpen,
|
|
397
|
+
})}
|
|
398
|
+
viewBox="0 0 24 24"
|
|
399
|
+
fill="currentColor"
|
|
400
|
+
>
|
|
401
|
+
<path d="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6z"/>
|
|
402
|
+
</svg>
|
|
403
|
+
</button>
|
|
404
|
+
|
|
405
|
+
<div
|
|
406
|
+
role="listbox"
|
|
407
|
+
class=${classMap({
|
|
408
|
+
dropdown: true,
|
|
409
|
+
'dropdown--open': this._isOpen,
|
|
410
|
+
})}
|
|
411
|
+
>
|
|
412
|
+
<div class="search">
|
|
413
|
+
<div class="search__field">
|
|
414
|
+
<input
|
|
415
|
+
class="search__input"
|
|
416
|
+
type="text"
|
|
417
|
+
placeholder="Search..."
|
|
418
|
+
.value=${this._searchQuery}
|
|
419
|
+
@input=${this._handleSearchInput}
|
|
420
|
+
@keydown=${this._handleSearchKeyDown}
|
|
421
|
+
/>
|
|
422
|
+
<svg class="search__icon" viewBox="0 0 24 24" fill="currentColor">
|
|
423
|
+
<path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/>
|
|
424
|
+
</svg>
|
|
425
|
+
</div>
|
|
426
|
+
</div>
|
|
427
|
+
|
|
428
|
+
<div class="options">
|
|
429
|
+
${this.options.length === 0
|
|
430
|
+
? html `<div class="empty">No options found</div>`
|
|
431
|
+
: this.options.map((option, index) => this._renderOption(option, index))}
|
|
432
|
+
</div>
|
|
433
|
+
</div>
|
|
434
|
+
|
|
435
|
+
${footer}
|
|
436
|
+
</div>
|
|
437
|
+
`;
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
KRComboBox.styles = css `
|
|
441
|
+
:host {
|
|
442
|
+
display: block;
|
|
443
|
+
font-family: inherit;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
.wrapper {
|
|
447
|
+
display: flex;
|
|
448
|
+
flex-direction: column;
|
|
449
|
+
gap: 6px;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
label {
|
|
453
|
+
font-size: 14px;
|
|
454
|
+
font-weight: 500;
|
|
455
|
+
color: black;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
.required {
|
|
459
|
+
color: var(--kr-text-field-required-color, #ef4444);
|
|
460
|
+
margin-left: 0.125rem;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/* Trigger button */
|
|
464
|
+
.trigger {
|
|
465
|
+
display: flex;
|
|
466
|
+
align-items: center;
|
|
467
|
+
justify-content: space-between;
|
|
468
|
+
width: 100%;
|
|
469
|
+
padding: 10px 12px;
|
|
470
|
+
font-family: inherit;
|
|
471
|
+
font-size: 14px;
|
|
472
|
+
line-height: 1.5;
|
|
473
|
+
color: var(--kr-text-field-color, #111827);
|
|
474
|
+
background-color: var(--kr-text-field-bg, #fff);
|
|
475
|
+
border: 1px solid var(--kr-text-field-border-color, #0000003d);
|
|
476
|
+
border-radius: 8px;
|
|
477
|
+
cursor: pointer;
|
|
478
|
+
transition: border-color 0.2s, box-shadow 0.2s;
|
|
479
|
+
text-align: left;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
.trigger:hover:not(:disabled) {
|
|
483
|
+
border-color: #9ca3af;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
.trigger:focus {
|
|
487
|
+
outline: none;
|
|
488
|
+
border-color: var(--kr-text-field-focus-border-color, #163052);
|
|
489
|
+
box-shadow: 0 0 0 3px var(--kr-text-field-focus-ring-color, rgba(22, 48, 82, 0.1));
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
.trigger:disabled {
|
|
493
|
+
background-color: var(--kr-text-field-disabled-bg, #f3f4f6);
|
|
494
|
+
color: var(--kr-text-field-disabled-color, #9ca3af);
|
|
495
|
+
cursor: not-allowed;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
.trigger--open {
|
|
499
|
+
border-color: var(--kr-text-field-focus-border-color, #163052);
|
|
500
|
+
box-shadow: 0 0 0 3px var(--kr-text-field-focus-ring-color, rgba(22, 48, 82, 0.1));
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
.trigger--invalid {
|
|
504
|
+
border-color: var(--kr-text-field-error-border-color, #ef4444);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
.trigger--invalid:focus {
|
|
508
|
+
box-shadow: 0 0 0 3px var(--kr-text-field-error-ring-color, rgba(239, 68, 68, 0.1));
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
.trigger__value {
|
|
512
|
+
flex: 1;
|
|
513
|
+
overflow: hidden;
|
|
514
|
+
text-overflow: ellipsis;
|
|
515
|
+
white-space: nowrap;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
.trigger__placeholder {
|
|
519
|
+
color: var(--kr-text-field-placeholder-color, #9ca3af);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
.trigger__icon {
|
|
523
|
+
flex-shrink: 0;
|
|
524
|
+
margin-left: 0.5rem;
|
|
525
|
+
width: 20px;
|
|
526
|
+
height: 20px;
|
|
527
|
+
color: var(--kr-text-muted, #6b7280);
|
|
528
|
+
transition: transform 0.2s;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
.trigger__icon--open {
|
|
532
|
+
transform: rotate(180deg);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/* Dropdown */
|
|
536
|
+
.dropdown {
|
|
537
|
+
position: fixed;
|
|
538
|
+
z-index: 10000;
|
|
539
|
+
background: white;
|
|
540
|
+
border: 1px solid #9ba7b6;
|
|
541
|
+
border-radius: 8px;
|
|
542
|
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
|
|
543
|
+
box-sizing: border-box;
|
|
544
|
+
display: none;
|
|
545
|
+
overflow: hidden;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
.dropdown--open {
|
|
549
|
+
display: flex;
|
|
550
|
+
flex-direction: column;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/* Search input inside dropdown */
|
|
554
|
+
.search {
|
|
555
|
+
padding: 12px 12px 2px 12px;
|
|
556
|
+
flex-shrink: 0;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
.search__field {
|
|
560
|
+
display: flex;
|
|
561
|
+
align-items: center;
|
|
562
|
+
padding: 8px 12px;
|
|
563
|
+
border: 1px solid var(--kr-text-field-border-color, #0000003d);
|
|
564
|
+
border-radius: 8px;
|
|
565
|
+
background-color: var(--kr-text-field-bg, #fff);
|
|
566
|
+
transition: border-color 0.2s, box-shadow 0.2s;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
.search__field:focus-within {
|
|
570
|
+
border-color: var(--kr-text-field-focus-border-color, #163052);
|
|
571
|
+
box-shadow: 0 0 0 3px var(--kr-text-field-focus-ring-color, rgba(22, 48, 82, 0.1));
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
.search__icon {
|
|
575
|
+
width: 20px;
|
|
576
|
+
height: 20px;
|
|
577
|
+
color: var(--kr-text-muted, #6b7280);
|
|
578
|
+
flex-shrink: 0;
|
|
579
|
+
margin-left: 8px;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
.search__input {
|
|
583
|
+
flex: 1;
|
|
584
|
+
border: none;
|
|
585
|
+
outline: none;
|
|
586
|
+
font-size: 14px;
|
|
587
|
+
font-family: inherit;
|
|
588
|
+
color: var(--kr-text-field-color, #111827);
|
|
589
|
+
background: transparent;
|
|
590
|
+
padding: 0;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
.search__input::placeholder {
|
|
594
|
+
color: var(--kr-text-field-placeholder-color, #9ca3af);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/* Options list */
|
|
598
|
+
.options {
|
|
599
|
+
overflow-y: auto;
|
|
600
|
+
padding: 4px 0;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
.option {
|
|
604
|
+
display: flex;
|
|
605
|
+
align-items: center;
|
|
606
|
+
width: 100%;
|
|
607
|
+
padding: 12px 18px;
|
|
608
|
+
background: none;
|
|
609
|
+
border: none;
|
|
610
|
+
font-size: 14px;
|
|
611
|
+
font-family: inherit;
|
|
612
|
+
color: var(--kr-text, #000000);
|
|
613
|
+
text-align: left;
|
|
614
|
+
cursor: pointer;
|
|
615
|
+
transition: background 0.15s ease;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
.option:hover:not(:disabled) {
|
|
619
|
+
background: var(--kr-select-option-hover-bg, #f3f4f6);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
.option--highlighted {
|
|
623
|
+
background-color: var(--kr-select-option-hover-bg, #f3f4f6);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
.option--selected {
|
|
627
|
+
color: var(--kr-text-field-focus-border-color, #163052);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
.option:disabled {
|
|
631
|
+
opacity: 0.5;
|
|
632
|
+
cursor: not-allowed;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
.empty {
|
|
636
|
+
padding: 12px 18px;
|
|
637
|
+
text-align: left;
|
|
638
|
+
color: var(--kr-text-muted, #6b7280);
|
|
639
|
+
font-size: 14px;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
.hint {
|
|
643
|
+
font-size: 0.75rem;
|
|
644
|
+
color: var(--kr-text-field-helper-color, #6b7280);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
.validation-message {
|
|
648
|
+
font-size: 0.75rem;
|
|
649
|
+
color: var(--kr-text-field-error-color, #ef4444);
|
|
650
|
+
}
|
|
651
|
+
`;
|
|
652
|
+
KRComboBox.formAssociated = true;
|
|
653
|
+
__decorate([
|
|
654
|
+
property({ type: String })
|
|
655
|
+
], KRComboBox.prototype, "label", void 0);
|
|
656
|
+
__decorate([
|
|
657
|
+
property({ type: String })
|
|
658
|
+
], KRComboBox.prototype, "name", void 0);
|
|
659
|
+
__decorate([
|
|
660
|
+
property({ type: String })
|
|
661
|
+
], KRComboBox.prototype, "value", void 0);
|
|
662
|
+
__decorate([
|
|
663
|
+
property({ type: String })
|
|
664
|
+
], KRComboBox.prototype, "placeholder", void 0);
|
|
665
|
+
__decorate([
|
|
666
|
+
property({ type: Boolean })
|
|
667
|
+
], KRComboBox.prototype, "disabled", void 0);
|
|
668
|
+
__decorate([
|
|
669
|
+
property({ type: Boolean })
|
|
670
|
+
], KRComboBox.prototype, "readonly", void 0);
|
|
671
|
+
__decorate([
|
|
672
|
+
property({ type: Boolean })
|
|
673
|
+
], KRComboBox.prototype, "required", void 0);
|
|
674
|
+
__decorate([
|
|
675
|
+
property({ type: String })
|
|
676
|
+
], KRComboBox.prototype, "hint", void 0);
|
|
677
|
+
__decorate([
|
|
678
|
+
property({ attribute: 'option-value' })
|
|
679
|
+
], KRComboBox.prototype, "optionValue", void 0);
|
|
680
|
+
__decorate([
|
|
681
|
+
property({ attribute: 'option-label' })
|
|
682
|
+
], KRComboBox.prototype, "optionLabel", void 0);
|
|
683
|
+
__decorate([
|
|
684
|
+
property({ type: Array })
|
|
685
|
+
], KRComboBox.prototype, "options", void 0);
|
|
686
|
+
__decorate([
|
|
687
|
+
property({ attribute: false })
|
|
688
|
+
], KRComboBox.prototype, "fetch", void 0);
|
|
689
|
+
__decorate([
|
|
690
|
+
property({ attribute: false })
|
|
691
|
+
], KRComboBox.prototype, "fetchSelection", void 0);
|
|
692
|
+
__decorate([
|
|
693
|
+
state()
|
|
694
|
+
], KRComboBox.prototype, "_isOpen", void 0);
|
|
695
|
+
__decorate([
|
|
696
|
+
state()
|
|
697
|
+
], KRComboBox.prototype, "_highlightedIndex", void 0);
|
|
698
|
+
__decorate([
|
|
699
|
+
state()
|
|
700
|
+
], KRComboBox.prototype, "_touched", void 0);
|
|
701
|
+
__decorate([
|
|
702
|
+
state()
|
|
703
|
+
], KRComboBox.prototype, "_searchQuery", void 0);
|
|
704
|
+
__decorate([
|
|
705
|
+
query('.trigger')
|
|
706
|
+
], KRComboBox.prototype, "_triggerElement", void 0);
|
|
707
|
+
__decorate([
|
|
708
|
+
query('.search__input')
|
|
709
|
+
], KRComboBox.prototype, "_searchInput", void 0);
|
|
710
|
+
KRComboBox = __decorate([
|
|
711
|
+
customElement('kr-combo-box')
|
|
712
|
+
], KRComboBox);
|
|
713
|
+
export { KRComboBox };
|
|
714
|
+
//# sourceMappingURL=combo-box.js.map
|