@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.module.js
CHANGED
|
@@ -2861,15 +2861,17 @@ function useMediaIndex() {
|
|
|
2861
2861
|
*/
|
|
2862
2862
|
|
|
2863
2863
|
function usePrefersDark() {
|
|
2864
|
-
var
|
|
2865
|
-
if (typeof window === 'undefined') return
|
|
2866
|
-
return window.matchMedia('(prefers-color-scheme: dark)')
|
|
2867
|
-
})
|
|
2864
|
+
var mq = useMemo(function () {
|
|
2865
|
+
if (typeof window === 'undefined') return undefined;
|
|
2866
|
+
return window.matchMedia('(prefers-color-scheme: dark)');
|
|
2867
|
+
}, []);
|
|
2868
|
+
|
|
2869
|
+
var _useState = useState((mq == null ? void 0 : mq.matches) || false),
|
|
2868
2870
|
dark = _useState[0],
|
|
2869
2871
|
setDark = _useState[1];
|
|
2870
2872
|
|
|
2871
2873
|
useEffect(function () {
|
|
2872
|
-
|
|
2874
|
+
if (!mq) return undefined;
|
|
2873
2875
|
setDark(mq.matches);
|
|
2874
2876
|
|
|
2875
2877
|
var handleChange = function handleChange() {
|
|
@@ -2880,7 +2882,7 @@ function usePrefersDark() {
|
|
|
2880
2882
|
return function () {
|
|
2881
2883
|
return mq.removeEventListener('change', handleChange);
|
|
2882
2884
|
};
|
|
2883
|
-
}, []);
|
|
2885
|
+
}, [mq]);
|
|
2884
2886
|
return dark;
|
|
2885
2887
|
}
|
|
2886
2888
|
|