@purr-core/hooks.media-query 0.0.8 → 0.0.9
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/index.cjs +1 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +1 -0
- package/package.json +2 -2
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var react=require('react'),c=require('@purr-core/hooks.isomorphic-layout-effect');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var c__default=/*#__PURE__*/_interopDefault(c);var f=typeof window>"u",u=(n,{defaultValue:o=false,initializeWithValue:a=true}={})=>{let r=e=>f?o:window.matchMedia(e).matches,[i,s]=react.useState(()=>a?r(n):o),t=()=>{s(r(n));};return c__default.default(()=>{let 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]),i},m=u;module.exports=m;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The options for the useMediaQuery hook.
|
|
3
|
+
*
|
|
4
|
+
* @interface IMediaQueryOptionProps
|
|
5
|
+
* @property {boolean} [defaultValue=false] - The default value of the media query.
|
|
6
|
+
* @property {boolean} [initializeWithValue=true] - Whether to initialize the value with the default value.
|
|
7
|
+
*/
|
|
8
|
+
interface IMediaQueryOptionProps {
|
|
9
|
+
defaultValue?: boolean;
|
|
10
|
+
initializeWithValue?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A hook that returns the matches state of a media query.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} query - The query for the media query.
|
|
16
|
+
* @param {IMediaQueryOptionProps} options - The options for the hook.
|
|
17
|
+
* @returns {boolean} The matches state of the media query.
|
|
18
|
+
*/
|
|
19
|
+
declare const useMediaQuery: (query: string, { defaultValue, initializeWithValue, }?: IMediaQueryOptionProps) => boolean;
|
|
20
|
+
|
|
21
|
+
export { useMediaQuery as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The options for the useMediaQuery hook.
|
|
3
|
+
*
|
|
4
|
+
* @interface IMediaQueryOptionProps
|
|
5
|
+
* @property {boolean} [defaultValue=false] - The default value of the media query.
|
|
6
|
+
* @property {boolean} [initializeWithValue=true] - Whether to initialize the value with the default value.
|
|
7
|
+
*/
|
|
8
|
+
interface IMediaQueryOptionProps {
|
|
9
|
+
defaultValue?: boolean;
|
|
10
|
+
initializeWithValue?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A hook that returns the matches state of a media query.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} query - The query for the media query.
|
|
16
|
+
* @param {IMediaQueryOptionProps} options - The options for the hook.
|
|
17
|
+
* @returns {boolean} The matches state of the media query.
|
|
18
|
+
*/
|
|
19
|
+
declare const useMediaQuery: (query: string, { defaultValue, initializeWithValue, }?: IMediaQueryOptionProps) => boolean;
|
|
20
|
+
|
|
21
|
+
export { useMediaQuery as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {useState}from'react';import c from'@purr-core/hooks.isomorphic-layout-effect';var f=typeof window>"u",u=(n,{defaultValue:o=false,initializeWithValue:a=true}={})=>{let r=e=>f?o:window.matchMedia(e).matches,[i,s]=useState(()=>a?r(n):o),t=()=>{s(r(n));};return c(()=>{let 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]),i},m=u;export{m as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purr-core/hooks.media-query",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"typescript": "*",
|
|
25
25
|
"react": "*",
|
|
26
|
-
"@purr-core/hooks.isomorphic-layout-effect": "0.0.
|
|
26
|
+
"@purr-core/hooks.isomorphic-layout-effect": "0.0.9"
|
|
27
27
|
},
|
|
28
28
|
"author": "@DinhThienPhuc",
|
|
29
29
|
"license": "ISC",
|