medusa-storefront-hooks 1.0.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.
@@ -0,0 +1,3 @@
1
+ export { useToggleState, default } from './use-toggle-state';
2
+ export type { StateType } from './use-toggle-state';
3
+ export { useIntersection } from './use-in-view';
@@ -0,0 +1,21 @@
1
+ import { useState as u, useEffect as f } from "react";
2
+ function l(t = !1) {
3
+ const [s, n] = u(t), c = () => n(!1), o = () => n(!0), r = () => n((a) => !a), e = [s, o, c, r];
4
+ return e.state = s, e.open = o, e.close = c, e.toggle = r, e;
5
+ }
6
+ function g(t, s) {
7
+ const [n, c] = u(!1);
8
+ return f(() => {
9
+ if (!t.current) return;
10
+ const o = t.current, r = new IntersectionObserver(
11
+ ([e]) => c(e.isIntersecting),
12
+ { rootMargin: s }
13
+ );
14
+ return r.observe(o), () => r.unobserve(o);
15
+ }, [t, s]), n;
16
+ }
17
+ export {
18
+ l as default,
19
+ g as useIntersection,
20
+ l as useToggleState
21
+ };
@@ -0,0 +1 @@
1
+ (function(e,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],t):(e=typeof globalThis<"u"?globalThis:e||self,t(e.MedusaStorefrontHooks={},e.React))})(this,function(e,t){"use strict";function f(n=!1){const[o,u]=t.useState(n),c=()=>u(!1),r=()=>u(!0),i=()=>u(l=>!l),s=[o,r,c,i];return s.state=o,s.open=r,s.close=c,s.toggle=i,s}function a(n,o){const[u,c]=t.useState(!1);return t.useEffect(()=>{if(!n.current)return;const r=n.current,i=new IntersectionObserver(([s])=>c(s.isIntersecting),{rootMargin:o});return i.observe(r),()=>i.unobserve(r)},[n,o]),u}e.default=f,e.useIntersection=a,e.useToggleState=f,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -0,0 +1,3 @@
1
+ import { RefObject } from 'react';
2
+
3
+ export declare function useIntersection(element: RefObject<HTMLDivElement | null>, rootMargin: string): boolean;
@@ -0,0 +1,8 @@
1
+ export type StateType = [boolean, () => void, () => void, () => void] & {
2
+ state: boolean;
3
+ open: () => void;
4
+ close: () => void;
5
+ toggle: () => void;
6
+ };
7
+ export declare function useToggleState(initialState?: boolean): StateType;
8
+ export default useToggleState;
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "medusa-storefront-hooks",
3
+ "version": "1.0.0",
4
+ "description": "Reusable React hooks for Medusa storefronts.",
5
+ "author": "SmartByte Labs",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "sideEffects": false,
9
+ "main": "./dist/ui-library.umd.cjs",
10
+ "module": "./dist/ui-library.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/ui-library.js",
16
+ "require": "./dist/ui-library.umd.cjs",
17
+ "default": "./dist/ui-library.js"
18
+ }
19
+ },
20
+ "files": ["dist"],
21
+ "scripts": {
22
+ "build": "tsc && vite build"
23
+ },
24
+ "peerDependencies": {
25
+ "react": "^18.0.0 || ^19.0.0",
26
+ "react-dom": "^18.0.0 || ^19.0.0"
27
+ },
28
+ "devDependencies": {
29
+ "@types/react": "^18.0.0 || ^19.0.0",
30
+ "@types/react-dom": "^18.0.0 || ^19.0.0",
31
+ "@vitejs/plugin-react": "^4.0.0",
32
+ "react": "^19.0.0",
33
+ "react-dom": "^19.0.0",
34
+ "typescript": "^5.0.0",
35
+ "vite": "^5.0.0",
36
+ "vite-plugin-dts": "^3.0.0"
37
+ }
38
+ }