@marianmeres/stuic 3.2.0 → 3.3.1

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.
@@ -57,6 +57,9 @@
57
57
  /** Show scrollbar on hover (default: true). Set to false when using navigation buttons */
58
58
  scrollbar?: boolean;
59
59
 
60
+ /** Enable horizontal scrolling via mouse wheel (default: true) */
61
+ wheelScroll?: boolean;
62
+
60
63
  /** Custom class for container */
61
64
  class?: string;
62
65
 
@@ -103,6 +106,7 @@
103
106
  loop = false,
104
107
  scrollBehavior = "smooth",
105
108
  scrollbar = true,
109
+ wheelScroll = true,
106
110
  class: classProp,
107
111
  classTrack,
108
112
  classItem,
@@ -214,14 +218,18 @@
214
218
  itemEls[activeItem.id]?.scrollIntoView({
215
219
  behavior: scrollBehavior,
216
220
  block: "nearest",
217
- inline: snapAlign === "center" ? "center" : snapAlign === "end" ? "end" : "start",
221
+ inline:
222
+ snapAlign === "center" ? "center" : snapAlign === "end" ? "end" : "start",
218
223
  });
219
224
  }
220
225
 
221
226
  // Reset flag after scroll animation completes
222
- setTimeout(() => {
223
- isScrollingProgrammatically = false;
224
- }, scrollBehavior === "instant" ? 0 : 300);
227
+ setTimeout(
228
+ () => {
229
+ isScrollingProgrammatically = false;
230
+ },
231
+ scrollBehavior === "instant" ? 0 : 300
232
+ );
225
233
  }, 0);
226
234
  }
227
235
 
@@ -248,6 +256,24 @@
248
256
  }
249
257
  }
250
258
 
259
+ // Mouse wheel horizontal scroll handler
260
+ function handleWheel(e: WheelEvent) {
261
+ if (!wheelScroll || e.deltaY === 0) return;
262
+ e.preventDefault();
263
+
264
+ // With snap enabled, navigate by item; otherwise scroll by pixels
265
+ if (snap) {
266
+ if (e.deltaY > 0) {
267
+ coll.setActiveNext();
268
+ } else {
269
+ coll.setActivePrevious();
270
+ }
271
+ scrollActiveIntoView();
272
+ } else {
273
+ trackEl!.scrollLeft += e.deltaY;
274
+ }
275
+ }
276
+
251
277
  // Public API methods
252
278
  export function goTo(index: number) {
253
279
  coll.setActiveIndex(index);
@@ -315,6 +341,7 @@
315
341
  data-snap-align={!unstyled && snap ? snapAlign : undefined}
316
342
  data-scrollbar={!unstyled && scrollbar ? "true" : undefined}
317
343
  onkeydown={handleKeydown}
344
+ onwheel={handleWheel}
318
345
  >
319
346
  {#each coll.items as item, i (item.id)}
320
347
  {@const active = isItemActive(i)}
@@ -41,6 +41,8 @@ export interface Props extends Omit<HTMLAttributes<HTMLDivElement>, "children">
41
41
  scrollBehavior?: ScrollBehavior;
42
42
  /** Show scrollbar on hover (default: true). Set to false when using navigation buttons */
43
43
  scrollbar?: boolean;
44
+ /** Enable horizontal scrolling via mouse wheel (default: true) */
45
+ wheelScroll?: boolean;
44
46
  /** Custom class for container */
45
47
  class?: string;
46
48
  /** Custom class for the scrollable track */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/stuic",
3
- "version": "3.2.0",
3
+ "version": "3.3.1",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",