|
8 | 8 | /** @type {string} */ |
9 | 9 | export let tag; |
10 | 10 |
|
11 | | - /** @type {{key: string, value: string}[]} */ |
| 11 | + /** @type {import('$commonTypes').LabelValuePair[]} */ |
12 | 12 | export let options = []; |
13 | 13 |
|
14 | 14 | /** @type {boolean} */ |
|
24 | 24 | export let selectedText = ''; |
25 | 25 |
|
26 | 26 | /** @type {string[]} */ |
27 | | - export let selectedKeys; |
| 27 | + export let selectedLabels; |
28 | 28 |
|
29 | 29 | /** @type {string} */ |
30 | 30 | export let containerClasses = ""; |
|
51 | 51 | /** @type {boolean} */ |
52 | 52 | let showOptionList = false; |
53 | 53 |
|
54 | | - /** @type {{key: string, value: string, checked: boolean}[]} */ |
| 54 | + /** @type {{label: string, value: string, checked: boolean}[]} */ |
55 | 55 | let innerOptions = []; |
56 | 56 |
|
57 | | - /** @type {{key: string, value: string, checked: boolean}[]} */ |
| 57 | + /** @type {{label: string, value: string, checked: boolean}[]} */ |
58 | 58 | let refOptions = []; |
59 | 59 |
|
60 | 60 | /** @type {string} */ |
|
66 | 66 | onMount(() => { |
67 | 67 | innerOptions = options.map(x => { |
68 | 68 | return { |
69 | | - key: x.key, |
| 69 | + label: x.label, |
70 | 70 | value: x.value, |
71 | 71 | checked: false |
72 | 72 | } |
73 | 73 | }); |
74 | 74 |
|
75 | 75 | refOptions = options.map(x => { |
76 | 76 | return { |
77 | | - key: x.key, |
| 77 | + label: x.label, |
78 | 78 | value: x.value, |
79 | 79 | checked: false |
80 | 80 | } |
|
83 | 83 |
|
84 | 84 | $: { |
85 | 85 | innerOptions = innerOptions.map(x => { |
86 | | - x.checked = !!selectedKeys?.includes(x.key); |
| 86 | + x.checked = !!selectedLabels?.includes(x.label); |
87 | 87 | return {...x}; |
88 | 88 | }); |
89 | 89 | refOptions = refOptions.map(x => { |
90 | | - x.checked = !!selectedKeys?.includes(x.key); |
| 90 | + x.checked = !!selectedLabels?.includes(x.label); |
91 | 91 | return {...x}; |
92 | 92 | }); |
93 | 93 | changeDisplayText(); |
94 | 94 | } |
95 | 95 |
|
96 | 96 | $: { |
97 | 97 | if (options.length > refOptions.length) { |
98 | | - const curKeys = refOptions.map(x => x.key); |
99 | | - const newOptions = options.filter(x => !curKeys.includes(x.key)).map(x => { |
| 98 | + const curKeys = refOptions.map(x => x.label); |
| 99 | + const newOptions = options.filter(x => !curKeys.includes(x.label)).map(x => { |
100 | 100 | return { |
101 | | - key: x.key, |
| 101 | + label: x.label, |
102 | 102 | value: x.value, |
103 | 103 | checked: false |
104 | 104 | }; |
|
147 | 147 | */ |
148 | 148 | function checkOption(e, option) { |
149 | 149 | innerOptions = innerOptions.map(x => { |
150 | | - if (x.key == option.key) { |
| 150 | + if (x.label == option.label) { |
151 | 151 | x.checked = e == null ? !x.checked : e.target.checked; |
152 | 152 | } |
153 | 153 | return { ...x }; |
154 | 154 | }); |
155 | 155 |
|
156 | 156 | refOptions = refOptions.map(x => { |
157 | | - if (x.key == option.key) { |
| 157 | + if (x.label == option.label) { |
158 | 158 | x.checked = e == null ? !x.checked : e.target.checked; |
159 | 159 | } |
160 | 160 | return { ...x }; |
|
178 | 178 |
|
179 | 179 | /** @param {boolean} checked */ |
180 | 180 | function syncChangesToRef(checked) { |
181 | | - const keys = innerOptions.map(x => x.key); |
| 181 | + const keys = innerOptions.map(x => x.label); |
182 | 182 | refOptions = refOptions.map(x => { |
183 | | - if (keys.includes(x.key)) { |
| 183 | + if (keys.includes(x.label)) { |
184 | 184 | return { |
185 | 185 | ...x, |
186 | 186 | checked: checked |
|
229 | 229 |
|
230 | 230 | function sendEvent() { |
231 | 231 | svelteDispatch("select", { |
232 | | - selecteds: refOptions.filter(x => !!x.checked).map(x => ({ key: x.key, value: x.value })) |
| 232 | + selecteds: refOptions.filter(x => !!x.checked).map(x => ({ label: x.label, value: x.value })) |
233 | 233 | }); |
234 | 234 | } |
235 | 235 |
|
|
343 | 343 | /> |
344 | 344 | </div> |
345 | 345 | <div class="line-align-center select-name"> |
346 | | - {option.value} |
| 346 | + {option.label} |
347 | 347 | </div> |
348 | 348 | </li> |
349 | 349 | {/each} |
|
0 commit comments