uibee 1.1.5
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/Readme.md +4 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/useDarkMode.d.ts +1 -0
- package/dist/hooks/useDarkMode.js +17 -0
- package/dist/hooks/useVisibility.d.ts +4 -0
- package/dist/hooks/useVisibility.js +23 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/package.json +35 -0
package/Readme.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useDarkMode(): boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
export default function useDarkMode() {
|
|
3
|
+
const [isDark, setIsDark] = useState(false);
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
const darkClassExists = document.documentElement.classList.contains('dark');
|
|
6
|
+
setIsDark(darkClassExists);
|
|
7
|
+
const observer = new MutationObserver(() => {
|
|
8
|
+
setIsDark(document.documentElement.classList.contains('dark'));
|
|
9
|
+
});
|
|
10
|
+
observer.observe(document.documentElement, {
|
|
11
|
+
attributes: true,
|
|
12
|
+
attributeFilter: ['class'],
|
|
13
|
+
});
|
|
14
|
+
return () => observer.disconnect();
|
|
15
|
+
}, []);
|
|
16
|
+
return isDark;
|
|
17
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
export default function useVisibility(onVisible, rootMargin = '200px') {
|
|
3
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
4
|
+
const ref = useRef(null);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
if (typeof window === 'undefined')
|
|
7
|
+
return;
|
|
8
|
+
const isTouchDevice = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
|
|
9
|
+
if (!isTouchDevice)
|
|
10
|
+
return;
|
|
11
|
+
const observer = new IntersectionObserver((entries) => {
|
|
12
|
+
if (entries[0].isIntersecting) {
|
|
13
|
+
setIsVisible(true);
|
|
14
|
+
onVisible();
|
|
15
|
+
observer.disconnect();
|
|
16
|
+
}
|
|
17
|
+
}, { rootMargin });
|
|
18
|
+
if (ref.current)
|
|
19
|
+
observer.observe(ref.current);
|
|
20
|
+
return () => observer.disconnect();
|
|
21
|
+
}, [onVisible, rootMargin]);
|
|
22
|
+
return { ref, isVisible };
|
|
23
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "uibee",
|
|
3
|
+
"version": "1.1.5",
|
|
4
|
+
"description": "Shared components, functions and hooks for reuse across Login projects",
|
|
5
|
+
"homepage": "https://github.com/Login-Linjeforening-for-IT/uibee#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/Login-Linjeforening-for-IT/uibee/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/Login-Linjeforening-for-IT/uibee.git"
|
|
12
|
+
},
|
|
13
|
+
"license": "ISC",
|
|
14
|
+
"author": "",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "dist/index.js",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": "./dist/index.js",
|
|
20
|
+
"./hooks": "./dist/hooks/index.js"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc --declaration"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"react": "^19.1.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/react": "^19.1.13",
|
|
33
|
+
"typescript": "^5.9.2"
|
|
34
|
+
}
|
|
35
|
+
}
|