vira 33.1.0 → 33.2.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.
|
@@ -50,6 +50,24 @@ export const ViraDropdown = defineViraElement()({
|
|
|
50
50
|
white-space: nowrap;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
.option-label {
|
|
54
|
+
display: inline-flex;
|
|
55
|
+
align-items: center;
|
|
56
|
+
gap: 8px;
|
|
57
|
+
max-width: 100%;
|
|
58
|
+
vertical-align: bottom;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.option-icon {
|
|
62
|
+
flex-shrink: 0;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.option-label-text {
|
|
66
|
+
overflow: hidden;
|
|
67
|
+
text-overflow: ellipsis;
|
|
68
|
+
white-space: nowrap;
|
|
69
|
+
}
|
|
70
|
+
|
|
53
71
|
.search-input {
|
|
54
72
|
${noNativeFormStyles};
|
|
55
73
|
flex-grow: 1;
|
|
@@ -224,6 +242,29 @@ export const ViraDropdown = defineViraElement()({
|
|
|
224
242
|
: inputs.isMultiSelect && selectedOptions.length > 1
|
|
225
243
|
? `${selectedOptions.length} Selected`
|
|
226
244
|
: selectedOptions[0]?.label || '';
|
|
245
|
+
function renderOptionLabel(option) {
|
|
246
|
+
return option.icon || option.labelTemplate
|
|
247
|
+
? html `
|
|
248
|
+
<span class="option-label">
|
|
249
|
+
${option.icon
|
|
250
|
+
? html `
|
|
251
|
+
<${ViraIcon.assign({
|
|
252
|
+
icon: option.icon,
|
|
253
|
+
})}
|
|
254
|
+
class="option-icon"
|
|
255
|
+
></${ViraIcon}>
|
|
256
|
+
`
|
|
257
|
+
: nothing}
|
|
258
|
+
<span class="option-label-text">
|
|
259
|
+
${option.labelTemplate ?? option.label}
|
|
260
|
+
</span>
|
|
261
|
+
</span>
|
|
262
|
+
`
|
|
263
|
+
: option.label;
|
|
264
|
+
}
|
|
265
|
+
const selectionTemplate = check.isLengthExactly(selectedOptions, 1)
|
|
266
|
+
? renderOptionLabel(selectedOptions[0])
|
|
267
|
+
: selectionDisplay;
|
|
227
268
|
function selectOption(option) {
|
|
228
269
|
const newSelectedValues = inputs.isMultiSelect
|
|
229
270
|
? selectedOptions.includes(option)
|
|
@@ -330,7 +371,7 @@ export const ViraDropdown = defineViraElement()({
|
|
|
330
371
|
function renderOptionEntries(options) {
|
|
331
372
|
return renderMenuItemEntries(options.map((option) => {
|
|
332
373
|
return {
|
|
333
|
-
content: option
|
|
374
|
+
content: renderOptionLabel(option),
|
|
334
375
|
onClick() {
|
|
335
376
|
selectOption(option);
|
|
336
377
|
},
|
|
@@ -540,7 +581,7 @@ export const ViraDropdown = defineViraElement()({
|
|
|
540
581
|
})}"
|
|
541
582
|
title=${ifDefined(shouldUsePlaceholder ? undefined : selectionDisplay)}
|
|
542
583
|
>
|
|
543
|
-
${prefixTemplate} ${
|
|
584
|
+
${prefixTemplate} ${selectionTemplate}
|
|
544
585
|
</span>
|
|
545
586
|
`}
|
|
546
587
|
|
|
@@ -557,7 +598,7 @@ export const ViraDropdown = defineViraElement()({
|
|
|
557
598
|
`;
|
|
558
599
|
const contentTemplate = inputs.isReadonly
|
|
559
600
|
? html `
|
|
560
|
-
<span class="readonly-value">${
|
|
601
|
+
<span class="readonly-value">${selectionTemplate}</span>
|
|
561
602
|
`
|
|
562
603
|
: triggerTemplate;
|
|
563
604
|
if (inputs.label) {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { type PartialWithUndefined } from '@augment-vir/common';
|
|
2
|
+
import { type HtmlInterpolation } from 'element-vir';
|
|
3
|
+
import { type ViraIconSvg } from '../icons/icon-svg.js';
|
|
2
4
|
/**
|
|
3
5
|
* Options for `ViraDropdown`.
|
|
4
6
|
*
|
|
@@ -8,9 +10,17 @@ import { type PartialWithUndefined } from '@augment-vir/common';
|
|
|
8
10
|
export type ViraDropdownOption = {
|
|
9
11
|
/** A value or id, used to keep track of which option is selected. */
|
|
10
12
|
value: string;
|
|
13
|
+
/**
|
|
14
|
+
* Plain text for the option. Still used for search filtering, tooltips, and the search input's
|
|
15
|
+
* text when `labelTemplate` is set.
|
|
16
|
+
*/
|
|
11
17
|
label: string;
|
|
12
18
|
} & PartialWithUndefined<{
|
|
13
19
|
disabled: boolean;
|
|
20
|
+
/** Drawn before the label. Not drawn inside a searchable dropdown's text input. */
|
|
21
|
+
icon: ViraIconSvg;
|
|
22
|
+
/** Rendered instead of `label`. Not rendered inside a searchable dropdown's text input. */
|
|
23
|
+
labelTemplate: HtmlInterpolation;
|
|
14
24
|
}>;
|
|
15
25
|
/**
|
|
16
26
|
* A group of options for `ViraDropdown`, rendered under a group label.
|