noph-ui 0.16.1 → 0.16.2
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.
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
onchange,
|
|
31
31
|
oninput,
|
|
32
32
|
multiple,
|
|
33
|
+
clampMenuWidth = false,
|
|
33
34
|
...attributes
|
|
34
35
|
}: SelectProps = $props()
|
|
35
36
|
|
|
@@ -43,6 +44,8 @@
|
|
|
43
44
|
}
|
|
44
45
|
let selectedOption = $state(options.filter((option) => option.selected))
|
|
45
46
|
|
|
47
|
+
let useVirtualList = $derived(options.length > 500)
|
|
48
|
+
|
|
46
49
|
let errorTextRaw: string = $state(errorText)
|
|
47
50
|
let errorRaw = $state(error)
|
|
48
51
|
let selectElement: HTMLSelectElement | undefined = $state()
|
|
@@ -288,7 +291,7 @@
|
|
|
288
291
|
</div>
|
|
289
292
|
</div>
|
|
290
293
|
|
|
291
|
-
{#snippet item(option: SelectOption
|
|
294
|
+
{#snippet item(option: SelectOption)}
|
|
292
295
|
<Item
|
|
293
296
|
onclick={(event) => {
|
|
294
297
|
handleOptionSelect(event, option)
|
|
@@ -312,7 +315,6 @@
|
|
|
312
315
|
}
|
|
313
316
|
}}
|
|
314
317
|
variant="button"
|
|
315
|
-
style={width ? `width:${width}px` : ''}
|
|
316
318
|
selected={Array.isArray(value) ? value.includes(option.value) : value === option.value}
|
|
317
319
|
>{option.label}
|
|
318
320
|
{#snippet start()}
|
|
@@ -324,7 +326,9 @@
|
|
|
324
326
|
{/snippet}
|
|
325
327
|
|
|
326
328
|
<Menu
|
|
327
|
-
style="position-anchor:--{uid};
|
|
329
|
+
style="position-anchor:--{uid};{clampMenuWidth || useVirtualList
|
|
330
|
+
? 'width'
|
|
331
|
+
: 'min-width'}:{clientWidth}px"
|
|
328
332
|
popover="manual"
|
|
329
333
|
role="listbox"
|
|
330
334
|
--np-menu-justify-self="none"
|
|
@@ -343,10 +347,10 @@
|
|
|
343
347
|
}}
|
|
344
348
|
bind:element={menuElement}
|
|
345
349
|
>
|
|
346
|
-
{#if
|
|
347
|
-
<VirtualList
|
|
350
|
+
{#if useVirtualList}
|
|
351
|
+
<VirtualList height="250px" itemHeight={56} items={options}>
|
|
348
352
|
{#snippet row(option)}
|
|
349
|
-
{@render item(option
|
|
353
|
+
{@render item(option)}
|
|
350
354
|
{/snippet}
|
|
351
355
|
</VirtualList>
|
|
352
356
|
{:else}
|
|
@@ -5,24 +5,21 @@
|
|
|
5
5
|
interface VitualListProps extends HTMLAttributes<HTMLDivElement> {
|
|
6
6
|
items: T[]
|
|
7
7
|
height?: string
|
|
8
|
-
width?: string
|
|
9
8
|
itemHeight?: number
|
|
10
9
|
start?: number
|
|
11
10
|
end?: number
|
|
12
11
|
row: Snippet<[T]>
|
|
13
12
|
}
|
|
14
|
-
|
|
13
|
+
|
|
15
14
|
let {
|
|
16
15
|
items,
|
|
17
16
|
height = '100%',
|
|
18
|
-
width,
|
|
19
17
|
itemHeight,
|
|
20
18
|
start = $bindable(0),
|
|
21
19
|
end = $bindable(0),
|
|
22
20
|
row,
|
|
23
21
|
}: VitualListProps = $props()
|
|
24
22
|
|
|
25
|
-
// local state
|
|
26
23
|
let height_map: number[] = []
|
|
27
24
|
// eslint-disable-next-line no-undef
|
|
28
25
|
let rows: HTMLCollectionOf<HTMLElement> | undefined = $state()
|
|
@@ -52,7 +49,7 @@
|
|
|
52
49
|
}
|
|
53
50
|
const { scrollTop } = viewport
|
|
54
51
|
|
|
55
|
-
await tick()
|
|
52
|
+
await tick()
|
|
56
53
|
|
|
57
54
|
let content_height = top - scrollTop
|
|
58
55
|
let i = start
|
|
@@ -62,7 +59,7 @@
|
|
|
62
59
|
|
|
63
60
|
if (!row) {
|
|
64
61
|
end = i + 1
|
|
65
|
-
await tick()
|
|
62
|
+
await tick()
|
|
66
63
|
row = rows[i - start]
|
|
67
64
|
}
|
|
68
65
|
|
|
@@ -124,7 +121,6 @@
|
|
|
124
121
|
height_map.fill(average_height, i, items.length)
|
|
125
122
|
bottom = remaining * average_height
|
|
126
123
|
|
|
127
|
-
// prevent jumping if we scrolled up into unknown territory
|
|
128
124
|
if (start < old_start) {
|
|
129
125
|
await tick()
|
|
130
126
|
|
|
@@ -159,12 +155,9 @@
|
|
|
159
155
|
bind:this={viewport}
|
|
160
156
|
bind:offsetHeight={viewport_height}
|
|
161
157
|
onscroll={handle_scroll}
|
|
162
|
-
style="
|
|
158
|
+
style="height: {height};"
|
|
163
159
|
>
|
|
164
|
-
<div
|
|
165
|
-
bind:this={contents}
|
|
166
|
-
style="flex:1;display:block;padding-top: {top}px; padding-bottom: {bottom}px;"
|
|
167
|
-
>
|
|
160
|
+
<div bind:this={contents} style="padding-top: {top}px; padding-bottom: {bottom}px;">
|
|
168
161
|
{#each visible as entry (entry.index)}
|
|
169
162
|
{@render row(entry.data)}
|
|
170
163
|
{/each}
|
package/dist/select/types.d.ts
CHANGED