@sanity/ui 0.37.6-next.18 → 0.37.6-next.19
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/lib/dts/hooks/usePrefersDark.d.ts.map +1 -1
- package/lib/sanity-ui.js +8 -6
- package/lib/sanity-ui.js.map +1 -1
- package/lib/sanity-ui.modern.js +7 -6
- package/lib/sanity-ui.modern.js.map +1 -1
- package/lib/sanity-ui.module.js +8 -6
- package/lib/sanity-ui.module.js.map +1 -1
- package/package.json +4 -4
- package/src/hooks/usePrefersDark.ts +9 -7
package/lib/sanity-ui.modern.js
CHANGED
|
@@ -2764,19 +2764,20 @@ function useMediaIndex() {
|
|
|
2764
2764
|
*/
|
|
2765
2765
|
|
|
2766
2766
|
function usePrefersDark() {
|
|
2767
|
-
const
|
|
2768
|
-
if (typeof window === 'undefined') return
|
|
2769
|
-
return window.matchMedia('(prefers-color-scheme: dark)')
|
|
2770
|
-
});
|
|
2767
|
+
const mq = useMemo(() => {
|
|
2768
|
+
if (typeof window === 'undefined') return undefined;
|
|
2769
|
+
return window.matchMedia('(prefers-color-scheme: dark)');
|
|
2770
|
+
}, []);
|
|
2771
|
+
const [dark, setDark] = useState((mq == null ? void 0 : mq.matches) || false);
|
|
2771
2772
|
useEffect(() => {
|
|
2772
|
-
|
|
2773
|
+
if (!mq) return undefined;
|
|
2773
2774
|
setDark(mq.matches);
|
|
2774
2775
|
|
|
2775
2776
|
const handleChange = () => setDark(mq.matches);
|
|
2776
2777
|
|
|
2777
2778
|
mq.addEventListener('change', handleChange);
|
|
2778
2779
|
return () => mq.removeEventListener('change', handleChange);
|
|
2779
|
-
}, []);
|
|
2780
|
+
}, [mq]);
|
|
2780
2781
|
return dark;
|
|
2781
2782
|
}
|
|
2782
2783
|
|