@hashrytech/quick-components-kit 0.10.0 → 0.11.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @hashrytech/quick-components-kit
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - feat: Adding scroll to action
8
+
3
9
  ## 0.10.0
4
10
 
5
11
  ### Minor Changes
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Svelte action to scroll smoothly to the top, a specific Y position, or a DOM element on click.
3
+ *
4
+ * @param node - The element the action is applied to
5
+ * @param target - Can be:
6
+ * - `undefined` → scroll to top
7
+ * - `number` → scroll to Y position
8
+ * - `string` → interpreted as element ID to scroll to
9
+ * - `HTMLElement` → scroll directly to that element
10
+ */
11
+ export declare function scrollTo(node: HTMLElement, target?: number | string | HTMLElement): {
12
+ update(newTarget?: number | string | HTMLElement): void;
13
+ destroy(): void;
14
+ };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Svelte action to scroll smoothly to the top, a specific Y position, or a DOM element on click.
3
+ *
4
+ * @param node - The element the action is applied to
5
+ * @param target - Can be:
6
+ * - `undefined` → scroll to top
7
+ * - `number` → scroll to Y position
8
+ * - `string` → interpreted as element ID to scroll to
9
+ * - `HTMLElement` → scroll directly to that element
10
+ */
11
+ export function scrollTo(node, target) {
12
+ function handleClick(e) {
13
+ e.preventDefault();
14
+ if (typeof target === 'number') {
15
+ window.scrollTo({ top: target, behavior: 'smooth' });
16
+ }
17
+ else if (typeof target === 'string') {
18
+ const el = document.getElementById(target);
19
+ if (el)
20
+ el.scrollIntoView({ behavior: 'smooth' });
21
+ }
22
+ else if (target instanceof HTMLElement) {
23
+ target.scrollIntoView({ behavior: 'smooth' });
24
+ }
25
+ else {
26
+ // Default: scroll to top
27
+ window.scrollTo({ top: 0, behavior: 'smooth' });
28
+ }
29
+ }
30
+ node.addEventListener('click', handleClick);
31
+ return {
32
+ update(newTarget) {
33
+ target = newTarget;
34
+ },
35
+ destroy() {
36
+ node.removeEventListener('click', handleClick);
37
+ }
38
+ };
39
+ }
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/hashrytech/quick-components-kit.git"
7
7
  },
8
- "version": "0.10.0",
8
+ "version": "0.11.0",
9
9
  "license": "MIT",
10
10
  "author": "Hashry Tech",
11
11
  "files": [