@purr-core/hooks.media-query 0.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.
- package/dist/_hook.d.ts +6 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +19 -0
- package/package.json +37 -0
package/dist/_hook.d.ts
ADDED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const o=require("react"),d=require("@purr-core/hooks.isomorphic-layout-effect"),h=typeof window>"u",u=(n,{defaultValue:s=!1,initializeWithValue:i=!0}={})=>{const r=e=>h?s:window.matchMedia(e).matches,[c,a]=o.useState(()=>i?r(n):s),t=()=>{a(r(n))};return d(()=>{const e=window.matchMedia(n);return t(),e.addListener?e.addListener(t):e.addEventListener("change",t),()=>{e.removeListener?e.removeListener(t):e.removeEventListener("change",t)}},[n]),c};module.exports=u;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './_hook';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useState as c } from "react";
|
|
2
|
+
import d from "@purr-core/hooks.isomorphic-layout-effect";
|
|
3
|
+
const m = typeof window > "u", u = (n, {
|
|
4
|
+
defaultValue: r = !1,
|
|
5
|
+
initializeWithValue: a = !0
|
|
6
|
+
} = {}) => {
|
|
7
|
+
const s = (e) => m ? r : window.matchMedia(e).matches, [i, o] = c(() => a ? s(n) : r), t = () => {
|
|
8
|
+
o(s(n));
|
|
9
|
+
};
|
|
10
|
+
return d(() => {
|
|
11
|
+
const e = window.matchMedia(n);
|
|
12
|
+
return t(), e.addListener ? e.addListener(t) : e.addEventListener("change", t), () => {
|
|
13
|
+
e.removeListener ? e.removeListener(t) : e.removeEventListener("change", t);
|
|
14
|
+
};
|
|
15
|
+
}, [n]), i;
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
u as default
|
|
19
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@purr-core/hooks.media-query",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"typescript": "*",
|
|
25
|
+
"react": "*",
|
|
26
|
+
"@purr-core/hooks.isomorphic-layout-effect": "0.0.0"
|
|
27
|
+
},
|
|
28
|
+
"author": "@DinhThienPhuc",
|
|
29
|
+
"license": "ISC",
|
|
30
|
+
"description": "",
|
|
31
|
+
"sideEffects": false,
|
|
32
|
+
"scripts": {
|
|
33
|
+
"dev": "vite build --watch",
|
|
34
|
+
"build": "tsc && vite build",
|
|
35
|
+
"lint": "eslint . --ext ts,tsx --max-warnings 0"
|
|
36
|
+
}
|
|
37
|
+
}
|