@shival99/z-ui-svelte 0.1.11 → 0.1.13

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.
@@ -4,6 +4,7 @@
4
4
  import type { ClassValue } from 'clsx';
5
5
  import { zTranslate } from '../../i18n/translate.svelte';
6
6
  import { zHoverGlide } from '../../interactions/z-hover-glide';
7
+ import { zScrollEdges, type ZScrollEdges } from '../../interactions/z-scroll-edges';
7
8
  import {
8
9
  Z_ASYNC_OPTIONS_DEFAULT_PAGE_SIZE,
9
10
  zMergeAsyncOptions,
@@ -161,6 +162,8 @@
161
162
  let inputEl = $state<HTMLInputElement | null>(null);
162
163
  let dropdownEl = $state<HTMLDivElement | null>(null);
163
164
  let optionsEl = $state<HTMLDivElement | null>(null);
165
+ // Which edges of the option list have more to show: they fade while it is scrolled (see `fades`).
166
+ let listEdges = $state<ZScrollEdges>({ atTop: true, atEnd: true });
164
167
  let sentinel = $state<HTMLDivElement | null>(null);
165
168
 
166
169
  let isFocused = $state(false);
@@ -1078,6 +1081,22 @@
1078
1081
  </div>
1079
1082
  {/snippet}
1080
1083
 
1084
+ {#snippet fades(edges: ZScrollEdges)}
1085
+ <!-- Soft edges while a list is scrolled: the top once it left the start, the bottom while there is more below. -->
1086
+ {#if !edges.atTop}
1087
+ <div
1088
+ class="from-popover pointer-events-none absolute inset-x-0 top-0 h-6 bg-gradient-to-b to-transparent"
1089
+ aria-hidden="true"
1090
+ ></div>
1091
+ {/if}
1092
+ {#if !edges.atTop && !edges.atEnd}
1093
+ <div
1094
+ class="from-popover pointer-events-none absolute inset-x-0 bottom-0 h-6 bg-gradient-to-t to-transparent"
1095
+ aria-hidden="true"
1096
+ ></div>
1097
+ {/if}
1098
+ {/snippet}
1099
+
1081
1100
  {#snippet loadingMore()}
1082
1101
  <div
1083
1102
  class="z-autocomplete-loading-more z-autocomplete-loading-enter from-popover via-popover/95 sticky bottom-0 -mx-1 -mb-1 flex items-center justify-center bg-gradient-to-t to-transparent pt-6 pb-2"
@@ -1221,70 +1240,78 @@
1221
1240
  {/if}
1222
1241
  </div>
1223
1242
  {:else if useVirtual}
1224
- <div
1225
- bind:this={optionsEl}
1226
- {@attach zHoverGlide({ class: 'bg-primary/15 rounded-(--radius-sm)' })}
1227
- class="z-autocomplete-content-state z-autocomplete-options z-autocomplete-virtual-scroll relative overflow-x-hidden overflow-y-auto overscroll-y-contain p-1"
1228
- style:height={`${heightExpand}px`}
1229
- onscroll={onOptionsScroll}
1230
- >
1231
- <div class="z-autocomplete-virtual-inner relative" style:height={`${$virtualizer.getTotalSize()}px`}>
1232
- {#each $virtualizer.getVirtualItems() as item (item.key)}
1233
- {@const option = filteredOptions[item.index]}
1234
- {#if option}
1235
- <!-- svelte-ignore a11y_click_events_have_key_events (keyboard is handled by the input) -->
1236
- <div
1237
- data-glide-item
1238
- data-index={item.index}
1239
- role="option"
1240
- tabindex="-1"
1241
- aria-selected={activeIndex === item.index}
1242
- aria-disabled={option.disabled || undefined}
1243
- class={['z-autocomplete-option absolute right-0 left-0 min-w-0', optionClass(option, item.index)]}
1244
- style:display={hasTemplate ? 'block' : null}
1245
- style:height={zDynamicSize ? null : `${optionHeight}px`}
1246
- style:min-height={zDynamicSize ? `${optionHeight}px` : null}
1247
- style:overflow={hasTemplate ? 'visible' : null}
1248
- style:transform={`translateY(${item.start}px) translateZ(0)`}
1249
- onmouseenter={() => (activeIndex = item.index)}
1250
- onclick={() => selectOption(option)}
1251
- {@attach zDynamicSize ? (node: HTMLDivElement) => $virtualizer.measureElement(node) : null}
1252
- >
1253
- {@render optionBody(option, item.index)}
1254
- </div>
1255
- {/if}
1256
- {/each}
1243
+ <div class="relative">
1244
+ <div
1245
+ bind:this={optionsEl}
1246
+ {@attach zHoverGlide({ class: 'bg-primary/15 rounded-(--radius-sm)' })}
1247
+ {@attach zScrollEdges(edges => (listEdges = edges))}
1248
+ class="z-autocomplete-content-state z-autocomplete-options z-autocomplete-virtual-scroll relative overflow-x-hidden overflow-y-auto overscroll-y-contain p-1"
1249
+ style:height={`${heightExpand}px`}
1250
+ onscroll={onOptionsScroll}
1251
+ >
1252
+ <div class="z-autocomplete-virtual-inner relative" style:height={`${$virtualizer.getTotalSize()}px`}>
1253
+ {#each $virtualizer.getVirtualItems() as item (item.key)}
1254
+ {@const option = filteredOptions[item.index]}
1255
+ {#if option}
1256
+ <!-- svelte-ignore a11y_click_events_have_key_events (keyboard is handled by the input) -->
1257
+ <div
1258
+ data-glide-item
1259
+ data-index={item.index}
1260
+ role="option"
1261
+ tabindex="-1"
1262
+ aria-selected={activeIndex === item.index}
1263
+ aria-disabled={option.disabled || undefined}
1264
+ class={['z-autocomplete-option absolute right-0 left-0 min-w-0', optionClass(option, item.index)]}
1265
+ style:display={hasTemplate ? 'block' : null}
1266
+ style:height={zDynamicSize ? null : `${optionHeight}px`}
1267
+ style:min-height={zDynamicSize ? `${optionHeight}px` : null}
1268
+ style:overflow={hasTemplate ? 'visible' : null}
1269
+ style:transform={`translateY(${item.start}px) translateZ(0)`}
1270
+ onmouseenter={() => (activeIndex = item.index)}
1271
+ onclick={() => selectOption(option)}
1272
+ {@attach zDynamicSize ? (node: HTMLDivElement) => $virtualizer.measureElement(node) : null}
1273
+ >
1274
+ {@render optionBody(option, item.index)}
1275
+ </div>
1276
+ {/if}
1277
+ {/each}
1278
+ </div>
1279
+ {#if isLoadingMore}{@render loadingMore()}{/if}
1257
1280
  </div>
1258
- {#if isLoadingMore}{@render loadingMore()}{/if}
1281
+ {@render fades(listEdges)}
1259
1282
  </div>
1260
1283
  {:else}
1261
- <div
1262
- bind:this={optionsEl}
1263
- {@attach zHoverGlide({ class: 'bg-primary/15 rounded-(--radius-sm)' })}
1264
- class="z-autocomplete-content-state z-autocomplete-options flex flex-col gap-0.75 overflow-x-hidden overflow-y-auto overscroll-y-contain p-1"
1265
- style:min-height={`${heightExpand}px`}
1266
- style:max-height={`${heightExpand}px`}
1267
- >
1268
- {#each filteredOptions as option, index (trackKey(option, index))}
1269
- <!-- svelte-ignore a11y_click_events_have_key_events (keyboard is handled by the input) -->
1270
- <div
1271
- data-glide-item
1272
- role="option"
1273
- tabindex="-1"
1274
- aria-selected={activeIndex === index}
1275
- aria-disabled={option.disabled || undefined}
1276
- class={['z-autocomplete-option relative min-w-0', optionClass(option, index)]}
1277
- style:display={hasTemplate ? 'block' : null}
1278
- style:min-height={hasTemplate ? null : `${optionHeight}px`}
1279
- style:overflow={hasTemplate ? 'visible' : null}
1280
- onmouseenter={() => (activeIndex = index)}
1281
- onclick={() => selectOption(option)}
1282
- >
1283
- {@render optionBody(option, index)}
1284
- </div>
1285
- {/each}
1286
- {#if canLoadMore}<div bind:this={sentinel} class="h-px w-full shrink-0"></div>{/if}
1287
- {#if isLoadingMore}{@render loadingMore()}{/if}
1284
+ <div class="relative">
1285
+ <div
1286
+ bind:this={optionsEl}
1287
+ {@attach zHoverGlide({ class: 'bg-primary/15 rounded-(--radius-sm)' })}
1288
+ {@attach zScrollEdges(edges => (listEdges = edges))}
1289
+ class="z-autocomplete-content-state z-autocomplete-options flex flex-col gap-0.75 overflow-x-hidden overflow-y-auto overscroll-y-contain p-1"
1290
+ style:min-height={`${heightExpand}px`}
1291
+ style:max-height={`${heightExpand}px`}
1292
+ >
1293
+ {#each filteredOptions as option, index (trackKey(option, index))}
1294
+ <!-- svelte-ignore a11y_click_events_have_key_events (keyboard is handled by the input) -->
1295
+ <div
1296
+ data-glide-item
1297
+ role="option"
1298
+ tabindex="-1"
1299
+ aria-selected={activeIndex === index}
1300
+ aria-disabled={option.disabled || undefined}
1301
+ class={['z-autocomplete-option relative min-w-0', optionClass(option, index)]}
1302
+ style:display={hasTemplate ? 'block' : null}
1303
+ style:min-height={hasTemplate ? null : `${optionHeight}px`}
1304
+ style:overflow={hasTemplate ? 'visible' : null}
1305
+ onmouseenter={() => (activeIndex = index)}
1306
+ onclick={() => selectOption(option)}
1307
+ >
1308
+ {@render optionBody(option, index)}
1309
+ </div>
1310
+ {/each}
1311
+ {#if canLoadMore}<div bind:this={sentinel} class="h-px w-full shrink-0"></div>{/if}
1312
+ {#if isLoadingMore}{@render loadingMore()}{/if}
1313
+ </div>
1314
+ {@render fades(listEdges)}
1288
1315
  </div>
1289
1316
  {/if}
1290
1317
  </div>
@@ -4,6 +4,7 @@
4
4
  import type { ClassValue } from 'clsx';
5
5
  import { zTranslate } from '../../i18n/translate.svelte';
6
6
  import { zHoverGlide } from '../../interactions/z-hover-glide';
7
+ import { zScrollEdges, type ZScrollEdges } from '../../interactions/z-scroll-edges';
7
8
  import {
8
9
  Z_ASYNC_OPTIONS_DEFAULT_PAGE_SIZE,
9
10
  zMergeAsyncOptions,
@@ -776,6 +777,9 @@
776
777
  let treeStack = $state.raw<ZSelectTreeLevel<O>[]>([]);
777
778
  let treeIndex = $state(0);
778
779
  let treeQuery = $state('');
780
+ // Which edges of the option lists have more to show: they fade while scrolled (see `fades`).
781
+ let listEdges = $state<ZScrollEdges>({ atTop: true, atEnd: true });
782
+ let treeEdges = $state<ZScrollEdges>({ atTop: true, atEnd: true });
779
783
  let treeDirection = $state<'none' | 'forward' | 'back'>('none');
780
784
 
781
785
  const treeLevel = $derived(treeStack[treeIndex] ?? { label: '', options: [] });
@@ -784,9 +788,17 @@
784
788
  .slice(0, treeIndex + 1)
785
789
  .map((level, index) => (index === 0 ? zTreeRootLabel || zTranslate('i18n_z_ui_select_tree_root') : level.label))
786
790
  );
787
- const treeOptions = $derived(
788
- filterOptions(zTranslateLabels ? treeLevel.options.map(translate) : treeLevel.options, treeQuery)
789
- );
791
+ /** Every option without children below `options`, in order: what a search in a tree looks through. */
792
+ function collectLeaves(options: O[]): O[] {
793
+ return options.flatMap(option => (option.children?.length ? collectLeaves(option.children as O[]) : [option]));
794
+ }
795
+ // A search looks through everything under the level being shown, not only its own rows.
796
+ const treeOptions = $derived.by(() => {
797
+ const searching = treeQuery.trim() !== '';
798
+ const options = searching ? collectLeaves(treeLevel.options) : treeLevel.options;
799
+ const shown = zTranslateLabels ? options.map(translate) : options;
800
+ return searching ? filterOptions(shown, treeQuery) : shown;
801
+ });
790
802
 
791
803
  function findTreePath(options: O[], target: unknown): O[] | null {
792
804
  for (const option of options) {
@@ -1216,6 +1228,33 @@
1216
1228
  {/if}
1217
1229
  {/snippet}
1218
1230
 
1231
+ {#snippet groupHeading(label: string)}
1232
+ <!-- A divider with the group's name, above its first option (`option.group`). A virtual list does not draw groups. -->
1233
+ <div
1234
+ role="presentation"
1235
+ class="text-muted-foreground z-select-group mt-1 flex shrink-0 items-center gap-2 px-2 pt-1 pb-0.5 text-[10px] font-medium tracking-wide uppercase first:mt-0"
1236
+ >
1237
+ <span class="truncate">{label}</span>
1238
+ <span class="bg-border h-px flex-1"></span>
1239
+ </div>
1240
+ {/snippet}
1241
+
1242
+ {#snippet fades(edges: ZScrollEdges)}
1243
+ <!-- Soft edges while a list is scrolled: the top once it left the start, the bottom while there is more below. -->
1244
+ {#if !edges.atTop}
1245
+ <div
1246
+ class="from-popover pointer-events-none absolute inset-x-0 top-0 h-6 bg-gradient-to-b to-transparent"
1247
+ aria-hidden="true"
1248
+ ></div>
1249
+ {/if}
1250
+ {#if !edges.atTop && !edges.atEnd}
1251
+ <div
1252
+ class="from-popover pointer-events-none absolute inset-x-0 bottom-0 h-6 bg-gradient-to-t to-transparent"
1253
+ aria-hidden="true"
1254
+ ></div>
1255
+ {/if}
1256
+ {/snippet}
1257
+
1219
1258
  {#snippet loadingMore()}
1220
1259
  <div
1221
1260
  class="z-select-loading-more from-popover via-popover/95 sticky bottom-0 -mx-1 -mb-1 flex items-center justify-center bg-gradient-to-t to-transparent pt-6 pb-2"
@@ -1452,6 +1491,7 @@
1452
1491
  {#key treeIndex}
1453
1492
  <div
1454
1493
  {@attach zHoverGlide()}
1494
+ {@attach zScrollEdges(edges => (treeEdges = edges))}
1455
1495
  id={`${dropdownId}-list`}
1456
1496
  role="listbox"
1457
1497
  class={[
@@ -1461,6 +1501,9 @@
1461
1501
  ]}
1462
1502
  >
1463
1503
  {#each treeOptions as option, index (key(option))}
1504
+ {#if option.group && option.group !== treeOptions[index - 1]?.group}{@render groupHeading(
1505
+ option.group
1506
+ )}{/if}
1464
1507
  <!-- svelte-ignore a11y_click_events_have_key_events (keyboard is handled by the combobox input) -->
1465
1508
  <div
1466
1509
  id={optionId(index)}
@@ -1470,14 +1513,12 @@
1470
1513
  tabindex="-1"
1471
1514
  aria-selected={isSelected(option)}
1472
1515
  aria-disabled={option.disabled || undefined}
1473
- class={['z-select-option relative flex min-w-0 items-center gap-2', optionClass(option, false)]}
1474
- style:min-height={`${zOptionHeight}px`}
1516
+ class={['z-select-option relative flex min-w-0 items-center gap-2', optionClass(option, !!optionSnippet)]}
1517
+ style:min-height={optionSnippet ? null : `${zOptionHeight}px`}
1475
1518
  onclick={() => onTreeOptionClick(option)}
1476
1519
  >
1477
- <span class="min-w-0 flex-1 truncate" {@attach zTooltip(optionTip(option.label))}>
1478
- {@render highlighted(option.label, treeQuery)}
1479
- </span>
1480
- {#if zShowCheck && isSelected(option)}{@render check()}{/if}
1520
+ <!-- The same template as a flat list, for a branch and for a leaf: the snippet tells them apart by `option.children`. -->
1521
+ <div class="flex min-w-0 flex-1 items-center gap-2">{@render optionBody(option, treeQuery)}</div>
1481
1522
  {#if option.children?.length}
1482
1523
  <ZIcon zType="lucideChevronRight" zSize="16" class="text-muted-foreground shrink-0" />
1483
1524
  {/if}
@@ -1487,6 +1528,7 @@
1487
1528
  {/each}
1488
1529
  </div>
1489
1530
  {/key}
1531
+ {@render fades(treeEdges)}
1490
1532
  </div>
1491
1533
  {:else}
1492
1534
  {#if zShowSearch}{@render searchBox(query, onSearchInput)}{/if}
@@ -1496,68 +1538,75 @@
1496
1538
  <ZIcon zType="lucideLoaderCircle" zSize="24" class="text-primary animate-spin" />
1497
1539
  </div>
1498
1540
  {:else if filteredOptions.length > 0}
1499
- <div
1500
- bind:this={optionsEl}
1501
- {@attach zHoverGlide()}
1502
- id={`${dropdownId}-list`}
1503
- role="listbox"
1504
- aria-multiselectable={isMultiple || undefined}
1505
- class={[
1506
- 'z-select-options overflow-x-hidden overflow-y-auto overscroll-y-contain p-1',
1507
- useVirtual ? 'z-select-virtual-scroll' : 'flex flex-col gap-0.75',
1508
- ]}
1509
- style:height={useVirtual || hasPaginated ? `${optionsMaxHeight}px` : null}
1510
- style:max-height={`${optionsMaxHeight}px`}
1511
- onscroll={onOptionsScroll}
1512
- >
1513
- {#if useVirtual}
1514
- <div class="z-select-virtual-inner relative" style:height={`${$virtualizer.getTotalSize()}px`}>
1515
- {#each $virtualizer.getVirtualItems() as item (item.key)}
1516
- {@const option = filteredOptions[item.index]}
1517
- {#if option}
1518
- <!-- svelte-ignore a11y_click_events_have_key_events (keyboard is handled by the combobox input) -->
1519
- <div
1520
- id={optionId(item.index)}
1521
- data-glide-item
1522
- data-active={keyboardNav && item.index === activeIndex}
1523
- data-index={item.index}
1524
- role="option"
1525
- tabindex="-1"
1526
- aria-selected={isSelected(option)}
1527
- aria-disabled={option.disabled || undefined}
1528
- class={['z-select-option absolute right-0 left-0 min-w-0', optionClass(option, !!optionSnippet)]}
1529
- style:height={zDynamicSize ? null : `${zOptionHeight}px`}
1530
- style:min-height={zDynamicSize ? `${zOptionHeight}px` : null}
1531
- style:transform={`translateY(${item.start}px)`}
1532
- onclick={() => selectOption(option)}
1533
- {@attach zDynamicSize ? (node: HTMLDivElement) => $virtualizer.measureElement(node) : null}
1534
- >
1535
- {@render optionBody(option, searchText)}
1536
- </div>
1537
- {/if}
1538
- {/each}
1539
- </div>
1540
- {:else}
1541
- {#each filteredOptions as option, index (key(option))}
1542
- <!-- svelte-ignore a11y_click_events_have_key_events (keyboard is handled by the combobox input) -->
1543
- <div
1544
- id={optionId(index)}
1545
- data-glide-item
1546
- data-active={keyboardNav && index === activeIndex}
1547
- role="option"
1548
- tabindex="-1"
1549
- aria-selected={isSelected(option)}
1550
- aria-disabled={option.disabled || undefined}
1551
- class={['z-select-option relative min-w-0', optionClass(option, !!optionSnippet)]}
1552
- style:min-height={optionSnippet ? null : `${zOptionHeight}px`}
1553
- onclick={() => selectOption(option)}
1554
- >
1555
- {@render optionBody(option, searchText)}
1541
+ <div class="relative">
1542
+ <div
1543
+ bind:this={optionsEl}
1544
+ {@attach zHoverGlide()}
1545
+ {@attach zScrollEdges(edges => (listEdges = edges))}
1546
+ id={`${dropdownId}-list`}
1547
+ role="listbox"
1548
+ aria-multiselectable={isMultiple || undefined}
1549
+ class={[
1550
+ 'z-select-options overflow-x-hidden overflow-y-auto overscroll-y-contain p-1',
1551
+ useVirtual ? 'z-select-virtual-scroll' : 'flex flex-col gap-0.75',
1552
+ ]}
1553
+ style:height={useVirtual || hasPaginated ? `${optionsMaxHeight}px` : null}
1554
+ style:max-height={`${optionsMaxHeight}px`}
1555
+ onscroll={onOptionsScroll}
1556
+ >
1557
+ {#if useVirtual}
1558
+ <div class="z-select-virtual-inner relative" style:height={`${$virtualizer.getTotalSize()}px`}>
1559
+ {#each $virtualizer.getVirtualItems() as item (item.key)}
1560
+ {@const option = filteredOptions[item.index]}
1561
+ {#if option}
1562
+ <!-- svelte-ignore a11y_click_events_have_key_events (keyboard is handled by the combobox input) -->
1563
+ <div
1564
+ id={optionId(item.index)}
1565
+ data-glide-item
1566
+ data-active={keyboardNav && item.index === activeIndex}
1567
+ data-index={item.index}
1568
+ role="option"
1569
+ tabindex="-1"
1570
+ aria-selected={isSelected(option)}
1571
+ aria-disabled={option.disabled || undefined}
1572
+ class={['z-select-option absolute right-0 left-0 min-w-0', optionClass(option, !!optionSnippet)]}
1573
+ style:height={zDynamicSize ? null : `${zOptionHeight}px`}
1574
+ style:min-height={zDynamicSize ? `${zOptionHeight}px` : null}
1575
+ style:transform={`translateY(${item.start}px)`}
1576
+ onclick={() => selectOption(option)}
1577
+ {@attach zDynamicSize ? (node: HTMLDivElement) => $virtualizer.measureElement(node) : null}
1578
+ >
1579
+ {@render optionBody(option, searchText)}
1580
+ </div>
1581
+ {/if}
1582
+ {/each}
1556
1583
  </div>
1557
- {/each}
1558
- {#if canLoadMore}<div bind:this={sentinel} class="h-px w-full shrink-0"></div>{/if}
1559
- {/if}
1560
- {#if isLoadingMore}{@render loadingMore()}{/if}
1584
+ {:else}
1585
+ {#each filteredOptions as option, index (key(option))}
1586
+ {#if option.group && option.group !== filteredOptions[index - 1]?.group}{@render groupHeading(
1587
+ option.group
1588
+ )}{/if}
1589
+ <!-- svelte-ignore a11y_click_events_have_key_events (keyboard is handled by the combobox input) -->
1590
+ <div
1591
+ id={optionId(index)}
1592
+ data-glide-item
1593
+ data-active={keyboardNav && index === activeIndex}
1594
+ role="option"
1595
+ tabindex="-1"
1596
+ aria-selected={isSelected(option)}
1597
+ aria-disabled={option.disabled || undefined}
1598
+ class={['z-select-option relative min-w-0', optionClass(option, !!optionSnippet)]}
1599
+ style:min-height={optionSnippet ? null : `${zOptionHeight}px`}
1600
+ onclick={() => selectOption(option)}
1601
+ >
1602
+ {@render optionBody(option, searchText)}
1603
+ </div>
1604
+ {/each}
1605
+ {#if canLoadMore}<div bind:this={sentinel} class="h-px w-full shrink-0"></div>{/if}
1606
+ {/if}
1607
+ {#if isLoadingMore}{@render loadingMore()}{/if}
1608
+ </div>
1609
+ {@render fades(listEdges)}
1561
1610
  </div>
1562
1611
  {:else}
1563
1612
  <div class="flex items-center justify-center p-1" style:height={`${optionsMaxHeight}px`}>
@@ -10,6 +10,7 @@ export interface ZSelectOption<T = unknown> {
10
10
  label: string;
11
11
  value: T;
12
12
  disabled?: boolean;
13
+ /** Divider with this name above the first option of each run of equal groups. Not drawn in a virtual list. */
13
14
  group?: string;
14
15
  icon?: ZIcon;
15
16
  /** Nested options. With `zTree`, clicking this option drills into them instead of selecting it. */
@@ -9,3 +9,4 @@ export { zSpotlight, type ZSpotlightOptions } from './z-spotlight';
9
9
  export { zTilt, type ZTiltOptions } from './z-tilt';
10
10
  export { zMagnetic, type ZMagneticOptions } from './z-magnetic';
11
11
  export { zScrollReveal, type ZScrollRevealOptions } from './z-scroll-reveal';
12
+ export { zScrollEdges, type ZScrollEdges } from './z-scroll-edges';
@@ -9,3 +9,4 @@ export { zSpotlight } from './z-spotlight';
9
9
  export { zTilt } from './z-tilt';
10
10
  export { zMagnetic } from './z-magnetic';
11
11
  export { zScrollReveal } from './z-scroll-reveal';
12
+ export { zScrollEdges } from './z-scroll-edges';
@@ -0,0 +1,14 @@
1
+ import type { Attachment } from 'svelte/attachments';
2
+ /** Whether a scroller sits at its first or its last pixel. */
3
+ export interface ZScrollEdges {
4
+ atTop: boolean;
5
+ atEnd: boolean;
6
+ }
7
+ /**
8
+ * Reports when the host scroller reaches or leaves its start and its end (scrolling, resizing, rows added or removed),
9
+ * so a list can fade the edge that has more to show: a fade at the top once it is scrolled, one at the bottom while
10
+ * there is more below. `onChange` runs only when an edge flips, and once on attach.
11
+ *
12
+ * `<div {@attach zScrollEdges(edges => (state = edges))}>…</div>`
13
+ */
14
+ export declare function zScrollEdges(onChange: (edges: ZScrollEdges) => void): Attachment<HTMLElement>;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Reports when the host scroller reaches or leaves its start and its end (scrolling, resizing, rows added or removed),
3
+ * so a list can fade the edge that has more to show: a fade at the top once it is scrolled, one at the bottom while
4
+ * there is more below. `onChange` runs only when an edge flips, and once on attach.
5
+ *
6
+ * `<div {@attach zScrollEdges(edges => (state = edges))}>…</div>`
7
+ */
8
+ export function zScrollEdges(onChange) {
9
+ return host => {
10
+ let last = '';
11
+ const measure = () => {
12
+ const atTop = host.scrollTop <= 0;
13
+ const atEnd = host.scrollTop + host.clientHeight >= host.scrollHeight - 2;
14
+ const key = `${atTop}|${atEnd}`;
15
+ if (key === last) {
16
+ return;
17
+ }
18
+ last = key;
19
+ onChange({ atTop, atEnd });
20
+ };
21
+ const resize = new ResizeObserver(measure);
22
+ const watch = () => {
23
+ resize.disconnect();
24
+ resize.observe(host);
25
+ for (const child of host.children) {
26
+ resize.observe(child);
27
+ }
28
+ };
29
+ const mutation = new MutationObserver(() => {
30
+ watch();
31
+ measure();
32
+ });
33
+ host.addEventListener('scroll', measure, { passive: true });
34
+ mutation.observe(host, { childList: true });
35
+ watch();
36
+ measure();
37
+ return () => {
38
+ host.removeEventListener('scroll', measure);
39
+ mutation.disconnect();
40
+ resize.disconnect();
41
+ };
42
+ };
43
+ }
@@ -188,6 +188,12 @@
188
188
  min-height: 0;
189
189
  }
190
190
 
191
+ /* A bar strip inside the wrapper: the strip's 2.5rem floor leaves 2px above and below its 36px tabs, but nothing at the
192
+ sides, so the first and last tab touched the wrapper's edge. Give the sides the same 2px. */
193
+ .z-tabs-container[data-type='bar'][data-orientation='horizontal'] > .z-tabs-nav-surface {
194
+ padding-inline: 0.125rem;
195
+ }
196
+
191
197
  /* Round arrow and menu buttons for the pill family, matching the pill shape. */
192
198
  .z-tabs-container:is(
193
199
  [data-type='pill-primary'],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shival99/z-ui-svelte",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "Z-UI component library for Svelte 5 (runes, no CDK).",
5
5
  "license": "MIT",
6
6
  "type": "module",