File size: 627 Bytes
bc20498
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { derived } from 'svelte/store';
import { createListbox } from '../listbox/create.js';
export function createSelect(props) {
    const listbox = createListbox({ ...props, builder: 'select' });
    const selectedLabel = derived(listbox.states.selected, ($selected) => {
        if (Array.isArray($selected)) {
            return $selected.map((o) => o.label).join(', ');
        }
        return $selected?.label ?? '';
    });
    return {
        ...listbox,
        elements: {
            ...listbox.elements,
        },
        states: {
            ...listbox.states,
            selectedLabel,
        },
    };
}