@vitus-labs/hooks 0.24.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/LICENSE +21 -0
- package/lib/analysis/vitus-labs-hooks.browser.js.html +6444 -0
- package/lib/analysis/vitus-labs-hooks.js.html +6444 -0
- package/lib/analysis/vitus-labs-hooks.module.js.html +6444 -0
- package/lib/analysis/vitus-labs-hooks.native.js.html +6444 -0
- package/lib/analysis/vitus-labs-hooks.umd.js.html +6444 -0
- package/lib/analysis/vitus-labs-hooks.umd.min.js.html +6444 -0
- package/lib/index.d.ts +17 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/useHover.d.ts +7 -0
- package/lib/types/useWindowResize.d.ts +9 -0
- package/lib/vitus-labs-hooks.browser.js +32 -0
- package/lib/vitus-labs-hooks.browser.js.map +1 -0
- package/lib/vitus-labs-hooks.js +36 -0
- package/lib/vitus-labs-hooks.js.map +1 -0
- package/lib/vitus-labs-hooks.module.js +32 -0
- package/lib/vitus-labs-hooks.module.js.map +1 -0
- package/lib/vitus-labs-hooks.native.js +32 -0
- package/lib/vitus-labs-hooks.native.js.map +1 -0
- package/lib/vitus-labs-hooks.umd.js +39 -0
- package/lib/vitus-labs-hooks.umd.js.map +1 -0
- package/lib/vitus-labs-hooks.umd.min.js +2 -0
- package/lib/vitus-labs-hooks.umd.min.js.map +1 -0
- package/package.json +58 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare type UseHover = (initialValue?: boolean) => {
|
|
2
|
+
hover: boolean;
|
|
3
|
+
onMouseEnter: () => void;
|
|
4
|
+
onMouseLeave: () => void;
|
|
5
|
+
};
|
|
6
|
+
declare const useHover: UseHover;
|
|
7
|
+
|
|
8
|
+
declare type UseWindowResize = (throttleDelay?: number, defaultValues?: Partial<{
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}>) => {
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
};
|
|
15
|
+
declare const useWindowResize: UseWindowResize;
|
|
16
|
+
|
|
17
|
+
export { UseHover, UseWindowResize, useHover, useWindowResize };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
2
|
+
import { throttle } from '@vitus-labs/core';
|
|
3
|
+
|
|
4
|
+
const useHover = (initial = false) => {
|
|
5
|
+
const [hover, handleHover] = useState(initial);
|
|
6
|
+
const setHover = useCallback(() => handleHover(true), []);
|
|
7
|
+
const unsetHover = useCallback(() => handleHover(false), []);
|
|
8
|
+
return {
|
|
9
|
+
hover,
|
|
10
|
+
onMouseEnter: setHover,
|
|
11
|
+
onMouseLeave: unsetHover,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const useWindowResize = (throttleDelay = 200, { width = 0, height = 0 } = {}) => {
|
|
16
|
+
const getSize = () => ({
|
|
17
|
+
width: window.innerWidth ,
|
|
18
|
+
height: window.innerHeight ,
|
|
19
|
+
});
|
|
20
|
+
const [windowSize, setWindowSize] = useState(getSize);
|
|
21
|
+
const handleResize = throttle(() => {
|
|
22
|
+
setWindowSize(getSize());
|
|
23
|
+
}, throttleDelay);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
window.addEventListener('resize', handleResize, false);
|
|
26
|
+
return () => window.removeEventListener('resize', handleResize, false);
|
|
27
|
+
}, []); // Empty array ensures that effect is only run on mount and unmount
|
|
28
|
+
return windowSize;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { useHover, useWindowResize };
|
|
32
|
+
//# sourceMappingURL=vitus-labs-hooks.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitus-labs-hooks.browser.js","sources":["../src/useHover.ts","../src/useWindowResize.ts"],"sourcesContent":["import { useState, useCallback } from 'react'\n\nexport type UseHover = (initialValue?: boolean) => {\n hover: boolean\n onMouseEnter: () => void\n onMouseLeave: () => void\n}\n\nconst useHover: UseHover = (initial = false) => {\n const [hover, handleHover] = useState(initial)\n\n const setHover = useCallback(() => handleHover(true), [])\n const unsetHover = useCallback(() => handleHover(false), [])\n\n return {\n hover,\n onMouseEnter: setHover,\n onMouseLeave: unsetHover,\n }\n}\n\nexport default useHover\n","import { useState, useEffect } from 'react'\nimport { throttle } from '@vitus-labs/core'\n\nexport type UseWindowResize = (\n throttleDelay?: number,\n defaultValues?: Partial<{\n width: number\n height: number\n }>\n) => {\n width: number\n height: number\n}\n\nconst useWindowResize: UseWindowResize = (\n throttleDelay = 200,\n { width = 0, height = 0 } = {}\n) => {\n const getSize = () => ({\n width: __CLIENT__ ? window.innerWidth : width,\n height: __CLIENT__ ? window.innerHeight : height,\n })\n\n const [windowSize, setWindowSize] = useState(getSize)\n\n const handleResize = throttle(() => {\n setWindowSize(getSize())\n }, throttleDelay)\n\n useEffect(() => {\n if (__SERVER__) return undefined\n\n window.addEventListener('resize', handleResize, false)\n\n return () => window.removeEventListener('resize', handleResize, false)\n }, []) // Empty array ensures that effect is only run on mount and unmount\n\n return windowSize\n}\n\nexport default useWindowResize\n"],"names":[],"mappings":";;;MAQM,QAAQ,GAAa,CAAC,OAAO,GAAG,KAAK;IACzC,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAA;IAE9C,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAA;IACzD,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAA;IAE5D,OAAO;QACL,KAAK;QACL,YAAY,EAAE,QAAQ;QACtB,YAAY,EAAE,UAAU;KACzB,CAAA;AACH;;MCLM,eAAe,GAAoB,CACvC,aAAa,GAAG,GAAG,EACnB,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,EAAE;IAE9B,MAAM,OAAO,GAAG,OAAO;QACrB,KAAK,EAAe,MAAM,CAAC,UAAU,CAAQ;QAC7C,MAAM,EAAe,MAAM,CAAC,WAAW,CAAS;KACjD,CAAC,CAAA;IAEF,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAA;IAErD,MAAM,YAAY,GAAG,QAAQ,CAAC;QAC5B,aAAa,CAAC,OAAO,EAAE,CAAC,CAAA;KACzB,EAAE,aAAa,CAAC,CAAA;IAEjB,SAAS,CAAC;QAGR,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,CAAC,CAAA;QAEtD,OAAO,MAAM,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,CAAC,CAAA;KACvE,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,UAAU,CAAA;AACnB;;;;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var core = require('@vitus-labs/core');
|
|
7
|
+
|
|
8
|
+
const useHover = (initial = false) => {
|
|
9
|
+
const [hover, handleHover] = react.useState(initial);
|
|
10
|
+
const setHover = react.useCallback(() => handleHover(true), []);
|
|
11
|
+
const unsetHover = react.useCallback(() => handleHover(false), []);
|
|
12
|
+
return {
|
|
13
|
+
hover,
|
|
14
|
+
onMouseEnter: setHover,
|
|
15
|
+
onMouseLeave: unsetHover,
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const useWindowResize = (throttleDelay = 200, { width = 0, height = 0 } = {}) => {
|
|
20
|
+
const getSize = () => ({
|
|
21
|
+
width: width,
|
|
22
|
+
height: height,
|
|
23
|
+
});
|
|
24
|
+
const [windowSize, setWindowSize] = react.useState(getSize);
|
|
25
|
+
core.throttle(() => {
|
|
26
|
+
setWindowSize(getSize());
|
|
27
|
+
}, throttleDelay);
|
|
28
|
+
react.useEffect(() => {
|
|
29
|
+
return undefined;
|
|
30
|
+
}, []); // Empty array ensures that effect is only run on mount and unmount
|
|
31
|
+
return windowSize;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.useHover = useHover;
|
|
35
|
+
exports.useWindowResize = useWindowResize;
|
|
36
|
+
//# sourceMappingURL=vitus-labs-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitus-labs-hooks.js","sources":["../src/useHover.ts","../src/useWindowResize.ts"],"sourcesContent":["import { useState, useCallback } from 'react'\n\nexport type UseHover = (initialValue?: boolean) => {\n hover: boolean\n onMouseEnter: () => void\n onMouseLeave: () => void\n}\n\nconst useHover: UseHover = (initial = false) => {\n const [hover, handleHover] = useState(initial)\n\n const setHover = useCallback(() => handleHover(true), [])\n const unsetHover = useCallback(() => handleHover(false), [])\n\n return {\n hover,\n onMouseEnter: setHover,\n onMouseLeave: unsetHover,\n }\n}\n\nexport default useHover\n","import { useState, useEffect } from 'react'\nimport { throttle } from '@vitus-labs/core'\n\nexport type UseWindowResize = (\n throttleDelay?: number,\n defaultValues?: Partial<{\n width: number\n height: number\n }>\n) => {\n width: number\n height: number\n}\n\nconst useWindowResize: UseWindowResize = (\n throttleDelay = 200,\n { width = 0, height = 0 } = {}\n) => {\n const getSize = () => ({\n width: __CLIENT__ ? window.innerWidth : width,\n height: __CLIENT__ ? window.innerHeight : height,\n })\n\n const [windowSize, setWindowSize] = useState(getSize)\n\n const handleResize = throttle(() => {\n setWindowSize(getSize())\n }, throttleDelay)\n\n useEffect(() => {\n if (__SERVER__) return undefined\n\n window.addEventListener('resize', handleResize, false)\n\n return () => window.removeEventListener('resize', handleResize, false)\n }, []) // Empty array ensures that effect is only run on mount and unmount\n\n return windowSize\n}\n\nexport default useWindowResize\n"],"names":["useState","useCallback","throttle","useEffect"],"mappings":";;;;;;;MAQM,QAAQ,GAAa,CAAC,OAAO,GAAG,KAAK;IACzC,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,GAAGA,cAAQ,CAAC,OAAO,CAAC,CAAA;IAE9C,MAAM,QAAQ,GAAGC,iBAAW,CAAC,MAAM,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAA;IACzD,MAAM,UAAU,GAAGA,iBAAW,CAAC,MAAM,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAA;IAE5D,OAAO;QACL,KAAK;QACL,YAAY,EAAE,QAAQ;QACtB,YAAY,EAAE,UAAU;KACzB,CAAA;AACH;;MCLM,eAAe,GAAoB,CACvC,aAAa,GAAG,GAAG,EACnB,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,EAAE;IAE9B,MAAM,OAAO,GAAG,OAAO;QACrB,KAAK,EAAmC,KAAK;QAC7C,MAAM,EAAoC,MAAM;KACjD,CAAC,CAAA;IAEF,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAGD,cAAQ,CAAC,OAAO,CAAC,CAAA;IAEhCE,aAAQ,CAAC;QAC5B,aAAa,CAAC,OAAO,EAAE,CAAC,CAAA;KACzB,EAAE,aAAa,EAAC;IAEjBC,eAAS,CAAC;QACQ,OAAO,SAAS,CAAA;KAKjC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,UAAU,CAAA;AACnB;;;;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
2
|
+
import { throttle } from '@vitus-labs/core';
|
|
3
|
+
|
|
4
|
+
const useHover = (initial = false) => {
|
|
5
|
+
const [hover, handleHover] = useState(initial);
|
|
6
|
+
const setHover = useCallback(() => handleHover(true), []);
|
|
7
|
+
const unsetHover = useCallback(() => handleHover(false), []);
|
|
8
|
+
return {
|
|
9
|
+
hover,
|
|
10
|
+
onMouseEnter: setHover,
|
|
11
|
+
onMouseLeave: unsetHover,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const useWindowResize = (throttleDelay = 200, { width = 0, height = 0 } = {}) => {
|
|
16
|
+
const getSize = () => ({
|
|
17
|
+
width: width,
|
|
18
|
+
height: height,
|
|
19
|
+
});
|
|
20
|
+
const [windowSize, setWindowSize] = useState(getSize);
|
|
21
|
+
const handleResize = throttle(() => {
|
|
22
|
+
setWindowSize(getSize());
|
|
23
|
+
}, throttleDelay);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
window.addEventListener('resize', handleResize, false);
|
|
26
|
+
return () => window.removeEventListener('resize', handleResize, false);
|
|
27
|
+
}, []); // Empty array ensures that effect is only run on mount and unmount
|
|
28
|
+
return windowSize;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { useHover, useWindowResize };
|
|
32
|
+
//# sourceMappingURL=vitus-labs-hooks.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitus-labs-hooks.module.js","sources":["../src/useHover.ts","../src/useWindowResize.ts"],"sourcesContent":["import { useState, useCallback } from 'react'\n\nexport type UseHover = (initialValue?: boolean) => {\n hover: boolean\n onMouseEnter: () => void\n onMouseLeave: () => void\n}\n\nconst useHover: UseHover = (initial = false) => {\n const [hover, handleHover] = useState(initial)\n\n const setHover = useCallback(() => handleHover(true), [])\n const unsetHover = useCallback(() => handleHover(false), [])\n\n return {\n hover,\n onMouseEnter: setHover,\n onMouseLeave: unsetHover,\n }\n}\n\nexport default useHover\n","import { useState, useEffect } from 'react'\nimport { throttle } from '@vitus-labs/core'\n\nexport type UseWindowResize = (\n throttleDelay?: number,\n defaultValues?: Partial<{\n width: number\n height: number\n }>\n) => {\n width: number\n height: number\n}\n\nconst useWindowResize: UseWindowResize = (\n throttleDelay = 200,\n { width = 0, height = 0 } = {}\n) => {\n const getSize = () => ({\n width: __CLIENT__ ? window.innerWidth : width,\n height: __CLIENT__ ? window.innerHeight : height,\n })\n\n const [windowSize, setWindowSize] = useState(getSize)\n\n const handleResize = throttle(() => {\n setWindowSize(getSize())\n }, throttleDelay)\n\n useEffect(() => {\n if (__SERVER__) return undefined\n\n window.addEventListener('resize', handleResize, false)\n\n return () => window.removeEventListener('resize', handleResize, false)\n }, []) // Empty array ensures that effect is only run on mount and unmount\n\n return windowSize\n}\n\nexport default useWindowResize\n"],"names":[],"mappings":";;;MAQM,QAAQ,GAAa,CAAC,OAAO,GAAG,KAAK;IACzC,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAA;IAE9C,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAA;IACzD,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAA;IAE5D,OAAO;QACL,KAAK;QACL,YAAY,EAAE,QAAQ;QACtB,YAAY,EAAE,UAAU;KACzB,CAAA;AACH;;MCLM,eAAe,GAAoB,CACvC,aAAa,GAAG,GAAG,EACnB,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,EAAE;IAE9B,MAAM,OAAO,GAAG,OAAO;QACrB,KAAK,EAAmC,KAAK;QAC7C,MAAM,EAAoC,MAAM;KACjD,CAAC,CAAA;IAEF,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAA;IAErD,MAAM,YAAY,GAAG,QAAQ,CAAC;QAC5B,aAAa,CAAC,OAAO,EAAE,CAAC,CAAA;KACzB,EAAE,aAAa,CAAC,CAAA;IAEjB,SAAS,CAAC;QAGR,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,CAAC,CAAA;QAEtD,OAAO,MAAM,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,CAAC,CAAA;KACvE,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,UAAU,CAAA;AACnB;;;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
2
|
+
import { throttle } from '@vitus-labs/core';
|
|
3
|
+
|
|
4
|
+
const useHover = (initial = false) => {
|
|
5
|
+
const [hover, handleHover] = useState(initial);
|
|
6
|
+
const setHover = useCallback(() => handleHover(true), []);
|
|
7
|
+
const unsetHover = useCallback(() => handleHover(false), []);
|
|
8
|
+
return {
|
|
9
|
+
hover,
|
|
10
|
+
onMouseEnter: setHover,
|
|
11
|
+
onMouseLeave: unsetHover,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const useWindowResize = (throttleDelay = 200, { width = 0, height = 0 } = {}) => {
|
|
16
|
+
const getSize = () => ({
|
|
17
|
+
width: window.innerWidth ,
|
|
18
|
+
height: window.innerHeight ,
|
|
19
|
+
});
|
|
20
|
+
const [windowSize, setWindowSize] = useState(getSize);
|
|
21
|
+
const handleResize = throttle(() => {
|
|
22
|
+
setWindowSize(getSize());
|
|
23
|
+
}, throttleDelay);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
window.addEventListener('resize', handleResize, false);
|
|
26
|
+
return () => window.removeEventListener('resize', handleResize, false);
|
|
27
|
+
}, []); // Empty array ensures that effect is only run on mount and unmount
|
|
28
|
+
return windowSize;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { useHover, useWindowResize };
|
|
32
|
+
//# sourceMappingURL=vitus-labs-hooks.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitus-labs-hooks.native.js","sources":["../src/useHover.ts","../src/useWindowResize.ts"],"sourcesContent":["import { useState, useCallback } from 'react'\n\nexport type UseHover = (initialValue?: boolean) => {\n hover: boolean\n onMouseEnter: () => void\n onMouseLeave: () => void\n}\n\nconst useHover: UseHover = (initial = false) => {\n const [hover, handleHover] = useState(initial)\n\n const setHover = useCallback(() => handleHover(true), [])\n const unsetHover = useCallback(() => handleHover(false), [])\n\n return {\n hover,\n onMouseEnter: setHover,\n onMouseLeave: unsetHover,\n }\n}\n\nexport default useHover\n","import { useState, useEffect } from 'react'\nimport { throttle } from '@vitus-labs/core'\n\nexport type UseWindowResize = (\n throttleDelay?: number,\n defaultValues?: Partial<{\n width: number\n height: number\n }>\n) => {\n width: number\n height: number\n}\n\nconst useWindowResize: UseWindowResize = (\n throttleDelay = 200,\n { width = 0, height = 0 } = {}\n) => {\n const getSize = () => ({\n width: __CLIENT__ ? window.innerWidth : width,\n height: __CLIENT__ ? window.innerHeight : height,\n })\n\n const [windowSize, setWindowSize] = useState(getSize)\n\n const handleResize = throttle(() => {\n setWindowSize(getSize())\n }, throttleDelay)\n\n useEffect(() => {\n if (__SERVER__) return undefined\n\n window.addEventListener('resize', handleResize, false)\n\n return () => window.removeEventListener('resize', handleResize, false)\n }, []) // Empty array ensures that effect is only run on mount and unmount\n\n return windowSize\n}\n\nexport default useWindowResize\n"],"names":[],"mappings":";;;MAQM,QAAQ,GAAa,CAAC,OAAO,GAAG,KAAK;IACzC,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAA;IAE9C,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAA;IACzD,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAA;IAE5D,OAAO;QACL,KAAK;QACL,YAAY,EAAE,QAAQ;QACtB,YAAY,EAAE,UAAU;KACzB,CAAA;AACH;;MCLM,eAAe,GAAoB,CACvC,aAAa,GAAG,GAAG,EACnB,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,EAAE;IAE9B,MAAM,OAAO,GAAG,OAAO;QACrB,KAAK,EAAe,MAAM,CAAC,UAAU,CAAQ;QAC7C,MAAM,EAAe,MAAM,CAAC,WAAW,CAAS;KACjD,CAAC,CAAA;IAEF,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAA;IAErD,MAAM,YAAY,GAAG,QAAQ,CAAC;QAC5B,aAAa,CAAC,OAAO,EAAE,CAAC,CAAA;KACzB,EAAE,aAAa,CAAC,CAAA;IAEjB,SAAS,CAAC;QAGR,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,CAAC,CAAA;QAEtD,OAAO,MAAM,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,CAAC,CAAA;KACvE,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,UAAU,CAAA;AACnB;;;;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@vitus-labs/core')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'react', '@vitus-labs/core'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.vitusLabsHooks = {}, global.React, global.core));
|
|
5
|
+
})(this, (function (exports, react, core) { 'use strict';
|
|
6
|
+
|
|
7
|
+
const useHover = (initial = false) => {
|
|
8
|
+
const [hover, handleHover] = react.useState(initial);
|
|
9
|
+
const setHover = react.useCallback(() => handleHover(true), []);
|
|
10
|
+
const unsetHover = react.useCallback(() => handleHover(false), []);
|
|
11
|
+
return {
|
|
12
|
+
hover,
|
|
13
|
+
onMouseEnter: setHover,
|
|
14
|
+
onMouseLeave: unsetHover,
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const useWindowResize = (throttleDelay = 200, { width = 0, height = 0 } = {}) => {
|
|
19
|
+
const getSize = () => ({
|
|
20
|
+
width: width,
|
|
21
|
+
height: height,
|
|
22
|
+
});
|
|
23
|
+
const [windowSize, setWindowSize] = react.useState(getSize);
|
|
24
|
+
core.throttle(() => {
|
|
25
|
+
setWindowSize(getSize());
|
|
26
|
+
}, throttleDelay);
|
|
27
|
+
react.useEffect(() => {
|
|
28
|
+
return undefined;
|
|
29
|
+
}, []); // Empty array ensures that effect is only run on mount and unmount
|
|
30
|
+
return windowSize;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
exports.useHover = useHover;
|
|
34
|
+
exports.useWindowResize = useWindowResize;
|
|
35
|
+
|
|
36
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
37
|
+
|
|
38
|
+
}));
|
|
39
|
+
//# sourceMappingURL=vitus-labs-hooks.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitus-labs-hooks.umd.js","sources":["../src/useHover.ts","../src/useWindowResize.ts"],"sourcesContent":["import { useState, useCallback } from 'react'\n\nexport type UseHover = (initialValue?: boolean) => {\n hover: boolean\n onMouseEnter: () => void\n onMouseLeave: () => void\n}\n\nconst useHover: UseHover = (initial = false) => {\n const [hover, handleHover] = useState(initial)\n\n const setHover = useCallback(() => handleHover(true), [])\n const unsetHover = useCallback(() => handleHover(false), [])\n\n return {\n hover,\n onMouseEnter: setHover,\n onMouseLeave: unsetHover,\n }\n}\n\nexport default useHover\n","import { useState, useEffect } from 'react'\nimport { throttle } from '@vitus-labs/core'\n\nexport type UseWindowResize = (\n throttleDelay?: number,\n defaultValues?: Partial<{\n width: number\n height: number\n }>\n) => {\n width: number\n height: number\n}\n\nconst useWindowResize: UseWindowResize = (\n throttleDelay = 200,\n { width = 0, height = 0 } = {}\n) => {\n const getSize = () => ({\n width: __CLIENT__ ? window.innerWidth : width,\n height: __CLIENT__ ? window.innerHeight : height,\n })\n\n const [windowSize, setWindowSize] = useState(getSize)\n\n const handleResize = throttle(() => {\n setWindowSize(getSize())\n }, throttleDelay)\n\n useEffect(() => {\n if (__SERVER__) return undefined\n\n window.addEventListener('resize', handleResize, false)\n\n return () => window.removeEventListener('resize', handleResize, false)\n }, []) // Empty array ensures that effect is only run on mount and unmount\n\n return windowSize\n}\n\nexport default useWindowResize\n"],"names":["useState","useCallback","throttle","useEffect"],"mappings":";;;;;;QAQM,QAAQ,GAAa,CAAC,OAAO,GAAG,KAAK;MACzC,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,GAAGA,cAAQ,CAAC,OAAO,CAAC,CAAA;MAE9C,MAAM,QAAQ,GAAGC,iBAAW,CAAC,MAAM,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAA;MACzD,MAAM,UAAU,GAAGA,iBAAW,CAAC,MAAM,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAA;MAE5D,OAAO;UACL,KAAK;UACL,YAAY,EAAE,QAAQ;UACtB,YAAY,EAAE,UAAU;OACzB,CAAA;EACH;;QCLM,eAAe,GAAoB,CACvC,aAAa,GAAG,GAAG,EACnB,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,EAAE;MAE9B,MAAM,OAAO,GAAG,OAAO;UACrB,KAAK,EAAmC,KAAK;UAC7C,MAAM,EAAoC,MAAM;OACjD,CAAC,CAAA;MAEF,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAGD,cAAQ,CAAC,OAAO,CAAC,CAAA;MAEhCE,aAAQ,CAAC;UAC5B,aAAa,CAAC,OAAO,EAAE,CAAC,CAAA;OACzB,EAAE,aAAa,EAAC;MAEjBC,eAAS,CAAC;UACQ,OAAO,SAAS,CAAA;OAKjC,EAAE,EAAE,CAAC,CAAA;MAEN,OAAO,UAAU,CAAA;EACnB;;;;;;;;;;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("@vitus-labs/core")):"function"==typeof define&&define.amd?define(["exports","react","@vitus-labs/core"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).vitusLabsHooks={},e.React,e.core)}(this,(function(e,t,o){"use strict";e.useHover=(e=!1)=>{const[o,s]=t.useState(e);return{hover:o,onMouseEnter:t.useCallback((()=>s(!0)),[]),onMouseLeave:t.useCallback((()=>s(!1)),[])}},e.useWindowResize=(e=200,{width:s=0,height:u=0}={})=>{const i=()=>({width:s,height:u}),[r,n]=t.useState(i);return o.throttle((()=>{n(i())}),e),t.useEffect((()=>{}),[]),r},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
2
|
+
//# sourceMappingURL=vitus-labs-hooks.umd.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitus-labs-hooks.umd.min.js","sources":["../src/useHover.ts","../src/useWindowResize.ts"],"sourcesContent":["import { useState, useCallback } from 'react'\n\nexport type UseHover = (initialValue?: boolean) => {\n hover: boolean\n onMouseEnter: () => void\n onMouseLeave: () => void\n}\n\nconst useHover: UseHover = (initial = false) => {\n const [hover, handleHover] = useState(initial)\n\n const setHover = useCallback(() => handleHover(true), [])\n const unsetHover = useCallback(() => handleHover(false), [])\n\n return {\n hover,\n onMouseEnter: setHover,\n onMouseLeave: unsetHover,\n }\n}\n\nexport default useHover\n","import { useState, useEffect } from 'react'\nimport { throttle } from '@vitus-labs/core'\n\nexport type UseWindowResize = (\n throttleDelay?: number,\n defaultValues?: Partial<{\n width: number\n height: number\n }>\n) => {\n width: number\n height: number\n}\n\nconst useWindowResize: UseWindowResize = (\n throttleDelay = 200,\n { width = 0, height = 0 } = {}\n) => {\n const getSize = () => ({\n width: __CLIENT__ ? window.innerWidth : width,\n height: __CLIENT__ ? window.innerHeight : height,\n })\n\n const [windowSize, setWindowSize] = useState(getSize)\n\n const handleResize = throttle(() => {\n setWindowSize(getSize())\n }, throttleDelay)\n\n useEffect(() => {\n if (__SERVER__) return undefined\n\n window.addEventListener('resize', handleResize, false)\n\n return () => window.removeEventListener('resize', handleResize, false)\n }, []) // Empty array ensures that effect is only run on mount and unmount\n\n return windowSize\n}\n\nexport default useWindowResize\n"],"names":["initial","hover","handleHover","useState","onMouseEnter","useCallback","onMouseLeave","throttleDelay","width","height","getSize","windowSize","setWindowSize","throttle","useEffect"],"mappings":"4VAQ2B,CAACA,GAAU,KACpC,MAAOC,EAAOC,GAAeC,WAASH,GAKtC,MAAO,CACLC,MAAAA,EACAG,aALeC,eAAY,IAAMH,GAAY,IAAO,IAMpDI,aALiBD,eAAY,IAAMH,GAAY,IAAQ,wBCElB,CACvCK,EAAgB,KACdC,MAAAA,EAAQ,EAAGC,OAAAA,EAAS,GAAM,MAE5B,MAAMC,EAAU,MACdF,MAAwCA,EACxCC,OAA0CA,KAGrCE,EAAYC,GAAiBT,WAASO,GAc7C,OAZqBG,YAAS,KAC5BD,EAAcF,OACbH,GAEHO,aAAU,QAMP,IAEIH"}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vitus-labs/hooks",
|
|
3
|
+
"version": "0.24.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "Vit Bokisch <vit@bokisch.cz>",
|
|
6
|
+
"maintainers": [
|
|
7
|
+
"Vit Bokisch <vit@bokisch.cz>"
|
|
8
|
+
],
|
|
9
|
+
"main": "lib/vitus-labs-hooks.js",
|
|
10
|
+
"umd:main": "lib/vitus-labs-hooks.umd.js",
|
|
11
|
+
"module": "lib/vitus-labs-hooks.module.js",
|
|
12
|
+
"typings": "lib/index.d.ts",
|
|
13
|
+
"browser": {
|
|
14
|
+
"./lib/vitus-labs-hooks.js": "./lib/vitus-labs-hooks.js",
|
|
15
|
+
"./lib/vitus-labs-hooks.module.js": "./lib/vitus-labs-hooks.browser.js"
|
|
16
|
+
},
|
|
17
|
+
"unpkg": "lib/vitus-labs-hooks.umd.min.js",
|
|
18
|
+
"jsnext:main": "lib/vitus-labs-hooks.module.js",
|
|
19
|
+
"react-native": "lib/vitus-labs-hooks.native.js",
|
|
20
|
+
"files": [
|
|
21
|
+
"lib/"
|
|
22
|
+
],
|
|
23
|
+
"homepage": "https://github.com/vitus-labs/ui-system/tree/master/packages/hooks",
|
|
24
|
+
"description": "Universal styles",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"prepublish": "yarn build",
|
|
27
|
+
"build": "yarn vl_build",
|
|
28
|
+
"build:watch": "yarn vl_build-watch",
|
|
29
|
+
"lint:css": "stylelint src/*.ts src/*.tsx",
|
|
30
|
+
"lint:ts": "eslint src/*",
|
|
31
|
+
"lint": "yarn lint:css && yarn lint:ts",
|
|
32
|
+
"test": "jest --runInBand",
|
|
33
|
+
"test:coverage": "jest --runInBand --coverage",
|
|
34
|
+
"test:watch": "jest --runInBand --watch",
|
|
35
|
+
"cover": "coveralls < .coverage/lcov.info"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/vitus-labs/ui-system.git"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/vitus-labs/ui-system/issues"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@vitus-labs/core": "^0.13.4",
|
|
49
|
+
"react": ">= 16.8"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@vitus-labs/core": "^0.24.0",
|
|
53
|
+
"@vitus-labs/tools-babel": "^0.26.0",
|
|
54
|
+
"@vitus-labs/tools-rollup": "^0.26.0",
|
|
55
|
+
"@vitus-labs/tools-typescript": "^0.26.0"
|
|
56
|
+
},
|
|
57
|
+
"gitHead": "938a695278cd5a5b51772b3f9794c5a210ef68a5"
|
|
58
|
+
}
|