@blocz/react-responsive 3.0.3 → 4.0.0-beta.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/README.md +5 -102
- package/lib/BreakpointsContext.d.ts +9 -9
- package/lib/Only.d.ts +10 -10
- package/lib/css-in-js.d.ts +12 -12
- package/lib/fromBreakpointToMedia.d.ts +2 -2
- package/lib/index.d.ts +6 -7
- package/lib/mediaQueryBuilder.d.ts +2 -2
- package/lib/react-responsive.js +1 -1
- package/lib/react-responsive.js.map +1 -1
- package/lib/react-responsive.modern.js +1 -1
- package/lib/react-responsive.modern.js.map +1 -1
- package/lib/react-responsive.modern.mjs +1 -1
- package/lib/react-responsive.modern.mjs.map +1 -0
- package/lib/react-responsive.umd.js +1 -1
- package/lib/react-responsive.umd.js.map +1 -1
- package/lib/sanitize.d.ts +15 -15
- package/lib/useBreakpoint.d.ts +1 -1
- package/lib/useMediaQuery.d.ts +1 -1
- package/package.json +7 -5
- package/lib/Match.d.ts +0 -17
package/README.md
CHANGED
|
@@ -10,7 +10,6 @@ If you need a responsive layout and adaptive components, `@blocz/react-responsiv
|
|
|
10
10
|
|
|
11
11
|
## Table of contents <!-- omit in toc -->
|
|
12
12
|
|
|
13
|
-
|
|
14
13
|
1. [How to use](#how-to-use)
|
|
15
14
|
1. [`<Only>`](#only)
|
|
16
15
|
1. [Default breakpoints](#default-breakpoints)
|
|
@@ -20,26 +19,22 @@ If you need a responsive layout and adaptive components, `@blocz/react-responsiv
|
|
|
20
19
|
2. [Hooks](#hooks)
|
|
21
20
|
1. [`useBreakpoint()`](#usebreakpoint)
|
|
22
21
|
2. [`useMediaQuery()`](#usemediaquery)
|
|
23
|
-
3. [`<
|
|
24
|
-
1. [`only` and `matchMedia` props](#only-and-matchmedia-props)
|
|
25
|
-
2. [Use a custom component in Match](#use-a-custom-component-in-match)
|
|
26
|
-
4. [`<BreakpointsProvider>`](#breakpointsprovider)
|
|
22
|
+
3. [`<BreakpointsProvider>`](#breakpointsprovider)
|
|
27
23
|
1. [Add more breakpoints](#add-more-breakpoints)
|
|
28
24
|
2. [Change default breakpoints](#change-default-breakpoints)
|
|
29
25
|
3. [Units](#units)
|
|
30
26
|
4. [Direction](#direction)
|
|
31
|
-
|
|
27
|
+
4. [CSS in JS](#css-in-js)
|
|
32
28
|
1. [`toJSON`](#tojson)
|
|
33
29
|
2. [`toCSS`](#tocss)
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
5. [Comparison to other libraries](#comparison-to-other-libraries)
|
|
31
|
+
6. [`matchMedia` polyfill](#matchmedia-polyfill)
|
|
36
32
|
1. [Browser](#browser)
|
|
37
33
|
2. [Node](#node)
|
|
38
|
-
|
|
34
|
+
7. [FAQ](#faq)
|
|
39
35
|
|
|
40
36
|
## How to use
|
|
41
37
|
|
|
42
|
-
|
|
43
38
|
### `<Only>`
|
|
44
39
|
|
|
45
40
|
#### Default breakpoints
|
|
@@ -216,96 +211,6 @@ const App = () => {
|
|
|
216
211
|
};
|
|
217
212
|
```
|
|
218
213
|
|
|
219
|
-
### `<Match>`
|
|
220
|
-
|
|
221
|
-
#### `only` and `matchMedia` props
|
|
222
|
-
|
|
223
|
-
The `Match` will look into every props of its children (and event nested children) to detect `only` and `matchMedia` props. If one of those is found, it will wrap the child in a `Only` component will those props auto-set.
|
|
224
|
-
|
|
225
|
-
```javascript
|
|
226
|
-
import React from "react";
|
|
227
|
-
import { Only, Match } from "@blocz/react-responsive";
|
|
228
|
-
|
|
229
|
-
const App = () => (
|
|
230
|
-
<Match>
|
|
231
|
-
<div only="xs">xs</div>
|
|
232
|
-
<div only="sm">sm</div>
|
|
233
|
-
<div only="md">md</div>
|
|
234
|
-
<div only="sm lg">sm and lg</div>
|
|
235
|
-
<div only="xl">xl</div>
|
|
236
|
-
<div>
|
|
237
|
-
<div>
|
|
238
|
-
<div>
|
|
239
|
-
<div only="smDown">nested smDown</div>
|
|
240
|
-
</div>
|
|
241
|
-
</div>
|
|
242
|
-
</div>
|
|
243
|
-
<div matchMedia="(min-width:768px) and (max-width:992px),(max-width:576px)">
|
|
244
|
-
{"(min-width:768px) and (max-width:992px),(max-width:576px)"}
|
|
245
|
-
</div>
|
|
246
|
-
</Match>
|
|
247
|
-
);
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
#### Use a custom component in Match
|
|
251
|
-
|
|
252
|
-
You can also render the `Match` component as another one:
|
|
253
|
-
|
|
254
|
-
```javascript
|
|
255
|
-
import React from "react";
|
|
256
|
-
import { Only, Match } from "@blocz/react-responsive";
|
|
257
|
-
|
|
258
|
-
const App = () => (
|
|
259
|
-
<Match as="ul">
|
|
260
|
-
<li only="xs">xs</li>
|
|
261
|
-
<li only="sm">sm</li>
|
|
262
|
-
<li only="md">md</li>
|
|
263
|
-
<li only="lg">lg</li>
|
|
264
|
-
<li only="xl">xl</li>
|
|
265
|
-
</Match>
|
|
266
|
-
);
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
If you’re using TypeScript, `Match` will work out of the box for native DOM elements.
|
|
270
|
-
But if you want to use it for custom components, you’ll have to use the type `MatchChildProps`:
|
|
271
|
-
|
|
272
|
-
```tsx
|
|
273
|
-
import * as React from "react";
|
|
274
|
-
import { Match, MatchChildProps } from "@blocz/react-responsive";
|
|
275
|
-
|
|
276
|
-
// MatchChildProps includes the props `only` and `matchMedia`
|
|
277
|
-
interface CustomProps extends MatchChildProps {
|
|
278
|
-
title: string;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const Custom: React.FunctionComponent<CustomProps> = ({ title, children }) => (
|
|
282
|
-
<React.Fragment>
|
|
283
|
-
<h3>{title}</h3>
|
|
284
|
-
<p>{children}</p>
|
|
285
|
-
</React.Fragment>
|
|
286
|
-
);
|
|
287
|
-
|
|
288
|
-
const App = () => (
|
|
289
|
-
<Match>
|
|
290
|
-
<Custom only="xs" title="xs">
|
|
291
|
-
xs
|
|
292
|
-
</Custom>
|
|
293
|
-
<Custom only="sm" title="sm">
|
|
294
|
-
sm
|
|
295
|
-
</Custom>
|
|
296
|
-
<Custom only="md" title="md">
|
|
297
|
-
md
|
|
298
|
-
</Custom>
|
|
299
|
-
<Custom only="lg" title="lg">
|
|
300
|
-
lg
|
|
301
|
-
</Custom>
|
|
302
|
-
<Custom only="xl" title="xl">
|
|
303
|
-
xl
|
|
304
|
-
</Custom>
|
|
305
|
-
</Match>
|
|
306
|
-
);
|
|
307
|
-
```
|
|
308
|
-
|
|
309
214
|
### `<BreakpointsProvider>`
|
|
310
215
|
|
|
311
216
|
`BreakpointsProvider` defines the values of every breakpoints.
|
|
@@ -502,5 +407,3 @@ And if you need an example with `Jest`, `@testing-library/react`, `React` and `@
|
|
|
502
407
|
### FAQ
|
|
503
408
|
|
|
504
409
|
For other questions, please take a look at our [FAQ document](https://github.com/bloczjs/react-responsive/blob/master/FAQ.md).
|
|
505
|
-
|
|
506
|
-
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { ExposedBreakpoints, Breakpoints } from "./sanitize";
|
|
3
|
-
export declare const BreakpointsContext: React.Context<Breakpoints>;
|
|
4
|
-
interface BreakpointsProviderProps {
|
|
5
|
-
breakpoints?: ExposedBreakpoints;
|
|
6
|
-
additionalBreakpoints?: ExposedBreakpoints;
|
|
7
|
-
}
|
|
8
|
-
export declare const BreakpointsProvider: React.FunctionComponent<React.PropsWithChildren<BreakpointsProviderProps>>;
|
|
9
|
-
export {};
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { ExposedBreakpoints, Breakpoints } from "./sanitize";
|
|
3
|
+
export declare const BreakpointsContext: React.Context<Breakpoints>;
|
|
4
|
+
interface BreakpointsProviderProps {
|
|
5
|
+
breakpoints?: ExposedBreakpoints;
|
|
6
|
+
additionalBreakpoints?: ExposedBreakpoints;
|
|
7
|
+
}
|
|
8
|
+
export declare const BreakpointsProvider: React.FunctionComponent<React.PropsWithChildren<BreakpointsProviderProps>>;
|
|
9
|
+
export {};
|
package/lib/Only.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
export
|
|
3
|
-
matchMedia?: string;
|
|
4
|
-
on?: string;
|
|
5
|
-
as?: string | React.ComponentType<OtherProps>;
|
|
6
|
-
};
|
|
7
|
-
export declare function Only<OtherProps = Record<string, never>>({ matchMedia, on, as, children, ...props }: React.PropsWithChildren<OnlyProps<OtherProps>>): React.ReactElement | null;
|
|
8
|
-
export declare namespace Only {
|
|
9
|
-
var displayName: string;
|
|
10
|
-
}
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export type OnlyProps<OtherProps = Record<string, never>> = OtherProps & {
|
|
3
|
+
matchMedia?: string;
|
|
4
|
+
on?: string;
|
|
5
|
+
as?: string | React.ComponentType<OtherProps>;
|
|
6
|
+
};
|
|
7
|
+
export declare function Only<OtherProps = Record<string, never>>({ matchMedia, on, as, children, ...props }: React.PropsWithChildren<OnlyProps<OtherProps>>): React.ReactElement | null;
|
|
8
|
+
export declare namespace Only {
|
|
9
|
+
var displayName: string;
|
|
10
|
+
}
|
package/lib/css-in-js.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { CSSProperties } from "react";
|
|
2
|
-
import { Breakpoints } from "./sanitize";
|
|
3
|
-
|
|
4
|
-
[key: string]: CSSProperties;
|
|
5
|
-
};
|
|
6
|
-
interface Points {
|
|
7
|
-
[breakpoint: string]: CSSinJSProperties;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export declare const toJSON: (breakpoints: Breakpoints) => (points: Points) => CSSinJS;
|
|
11
|
-
export declare const toCSS: (breakpoints: Breakpoints) => (points: Points) => string;
|
|
12
|
-
export {};
|
|
1
|
+
import { CSSProperties } from "react";
|
|
2
|
+
import { Breakpoints } from "./sanitize";
|
|
3
|
+
type CSSinJSProperties = CSSProperties | {
|
|
4
|
+
[key: string]: CSSProperties;
|
|
5
|
+
};
|
|
6
|
+
interface Points {
|
|
7
|
+
[breakpoint: string]: CSSinJSProperties;
|
|
8
|
+
}
|
|
9
|
+
type CSSinJS = Record<string, CSSinJSProperties>;
|
|
10
|
+
export declare const toJSON: (breakpoints: Breakpoints) => (points: Points) => CSSinJS;
|
|
11
|
+
export declare const toCSS: (breakpoints: Breakpoints) => (points: Points) => string;
|
|
12
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Breakpoint } from "./sanitize";
|
|
2
|
-
export declare const fromBreakpointToMedia: (breakpoint: Breakpoint) => string;
|
|
1
|
+
import { Breakpoint } from "./sanitize";
|
|
2
|
+
export declare const fromBreakpointToMedia: (breakpoint: Breakpoint) => string;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
export { BreakpointsProvider, BreakpointsContext } from "./BreakpointsContext";
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export { toJSON, toCSS } from "./css-in-js";
|
|
1
|
+
export { BreakpointsProvider, BreakpointsContext } from "./BreakpointsContext";
|
|
2
|
+
export { Only } from "./Only";
|
|
3
|
+
export { useBreakpoint } from "./useBreakpoint";
|
|
4
|
+
export { useMediaQuery } from "./useMediaQuery";
|
|
5
|
+
export { Units } from "./sanitize";
|
|
6
|
+
export { toJSON, toCSS } from "./css-in-js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Breakpoints } from "./sanitize";
|
|
2
|
-
export declare const mediaQueryBuilder: (breakpoints: Breakpoints) => (on?: string) => string;
|
|
1
|
+
import { Breakpoints } from "./sanitize";
|
|
2
|
+
export declare const mediaQueryBuilder: (breakpoints: Breakpoints) => (on?: string) => string;
|
package/lib/react-responsive.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(e){if(e&&e.__esModule)return e;var
|
|
1
|
+
function e(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,t.get?t:{enumerable:!0,get:function(){return e[r]}})}}),n.default=e,n}var n=/*#__PURE__*/e(require("react"));function r(){return r=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)({}).hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},r.apply(null,arguments)}var t=["em","ex","%","px","cm","mm","in","pt","pc","ch","rem","vh","vw","vmin","vmax"],i=["width","height"],o=function(e){return Object.keys(e).reduce(function(n,r){var o=e[r];if(!Array.isArray(o)||o.length<=1)return n;var a,u,c=o[0],f=o[1],s=o[2],l=o.slice(3);if(l.length>0){var p=new Error('The following fields "'+l+'" have been ignored');console.error(p)}if("number"!=typeof c||"number"!=typeof f)return n;"string"==typeof s?a=s:"object"==typeof s&&(u=s.direction,a=s.unit);var v=Math.min(c,f),d=Math.max(c,f),m=a&&t.includes(a)?a:"px",h=u&&i.includes(u)?u:"width";return n[r]=[v,d,m,h],n[r+"Up"]=[v,Infinity,m,h],n[r+"Down"]=[0,d,m,h],n},{})},a={xs:[0,575,"px"],sm:[576,767,"px"],md:[768,991,"px"],lg:[992,1199,"px"],xl:[1200,Infinity,"px"]},u=n.createContext(o(a)),c=function(e){var t=e.breakpoints,i=e.additionalBreakpoints,c=e.children;return n.createElement(u.Provider,{value:o(r({},void 0===t?a:t,void 0===i?{}:i))},c)};c.displayName="BreakpointsProvider";var f=function(e){var n=[],r=e[0],t=e[1],i=e[2],o=e[3];return 0!==r&&n.push("(min-"+o+":"+r+i+")"),Infinity!==t&&n.push("(max-"+o+":"+t+i+")")," "+n.join(" and ")},s=function(e){var r=n.useMemo(function(){return matchMedia(e)},[e]),t=n.useState(r.matches),i=t[0],o=t[1];return n.useLayoutEffect(function(){o(r.matches);var e=function(e){o(e.matches)};return r.addListener(e),function(){r.removeListener(e)}},[r]),i},l=function(e){var r=n.useContext(u),t=n.useMemo(function(){return function(e){return function(n){if(void 0===n&&(n=""),!n)return"";var r=n.split(" "),t=r.map(function(n){return e[n]}).filter(Boolean).map(function(e){return f(e)}).filter(Boolean).join(",");if(!t){var i=1===r.length;console.error('"'+r.join('", "')+'" '+(i?"is":"are")+"n't "+(i?"a ":"")+"valid breakpoint"+(i?"":"s"))}return t}}(r)},[r]),i=n.useMemo(function(){return t(e)},[t,e]);return s(i||"-")},p=["matchMedia","on","as","children"];function v(e){var r=e.matchMedia,t=e.on,i=e.as,o=e.children,a=function(e,n){if(null==e)return{};var r={};for(var t in e)if({}.hasOwnProperty.call(e,t)){if(n.includes(t))continue;r[t]=e[t]}return r}(e,p),u=l(t),c=s(r||"-");return u||c?n.createElement(i||n.Fragment,i?a:void 0,o):null}v.displayName="Only";var d=function(e){return function(n){var r={};return Object.keys(n).forEach(function(t){var i=e[t];if(!i)throw new Error(t+" is not a valid breakpoint\nValid breakpoints are: "+Object.keys(e));r["@media "+f(i)]=n[t]}),r}},m=function(e){var n="";return Object.entries(e).forEach(function(e){var r=e[0],t=e[1];n+="object"==typeof t?r+" {\n"+m(t)+"}\n":r+": "+t+";\n"}),n};exports.BreakpointsContext=u,exports.BreakpointsProvider=c,exports.Only=v,exports.toCSS=function(e){return function(n){return m(d(e)(n))}},exports.toJSON=d,exports.useBreakpoint=l,exports.useMediaQuery=s;
|
|
2
2
|
//# sourceMappingURL=react-responsive.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-responsive.js","sources":["../src/sanitize.ts","../src/BreakpointsContext.tsx","../src/fromBreakpointToMedia.ts","../src/useMediaQuery.ts","../src/useBreakpoint.ts","../src/mediaQueryBuilder.ts","../src/Only.tsx","../src/Match.tsx","../src/css-in-js.ts"],"sourcesContent":["export type Units =\n | \"em\"\n | \"ex\"\n | \"%\"\n | \"px\"\n | \"cm\"\n | \"mm\"\n | \"in\"\n | \"pt\"\n | \"pc\"\n | \"ch\"\n | \"rem\"\n | \"vh\"\n | \"vw\"\n | \"vmin\"\n | \"vmax\";\n\nconst listOfSupportedUnits: Units[] = [\n \"em\",\n \"ex\",\n \"%\",\n \"px\",\n \"cm\",\n \"mm\",\n \"in\",\n \"pt\",\n \"pc\",\n \"ch\",\n \"rem\",\n \"vh\",\n \"vw\",\n \"vmin\",\n \"vmax\",\n];\n\ntype Directions = \"width\" | \"height\";\n\nconst listOfSupportedDirections: Directions[] = [\"width\", \"height\"];\n\nexport type ExposedBreakpoint =\n | [number, number]\n | [number, number, Units]\n | [number, number, { unit?: Units; direction?: Directions }];\n\nexport interface ExposedBreakpoints {\n [key: string]: ExposedBreakpoint;\n}\n\nexport type Breakpoint = [number, number, Units, Directions];\n\nexport interface Breakpoints {\n [breakpoint: string]: Breakpoint;\n}\n\nexport const sanitize = (inBreakpoints: ExposedBreakpoints): Breakpoints => {\n return Object.keys(inBreakpoints).reduce<Breakpoints>((breakpoints, breakpointName) => {\n const breakpoint = inBreakpoints[breakpointName];\n\n if (!Array.isArray(breakpoint) || breakpoint.length <= 1) {\n return breakpoints;\n }\n\n const [supposedMin, supposedMax, options, ...rest] = breakpoint;\n if (rest.length > 0) {\n const error = new Error(`The following fields \"${rest}\" have been ignored`);\n console.error(error);\n }\n\n if (typeof supposedMin !== \"number\" || typeof supposedMax !== \"number\") {\n return breakpoints;\n }\n\n let supposedUnit: Units | undefined;\n let supposedDirection: Directions | undefined;\n if (typeof options === \"string\") {\n supposedUnit = options;\n } else if (typeof options === \"object\") {\n supposedDirection = options.direction;\n supposedUnit = options.unit;\n }\n\n const min = Math.min(supposedMin, supposedMax);\n const max = Math.max(supposedMin, supposedMax);\n const unit = supposedUnit && listOfSupportedUnits.includes(supposedUnit) ? supposedUnit : \"px\";\n const direction =\n supposedDirection && listOfSupportedDirections.includes(supposedDirection) ? supposedDirection : \"width\";\n\n breakpoints[breakpointName] = [min, max, unit, direction];\n breakpoints[`${breakpointName}Up`] = [min, Infinity, unit, direction];\n breakpoints[`${breakpointName}Down`] = [0, max, unit, direction];\n\n return breakpoints;\n }, {});\n};\n","import * as React from \"react\";\n\nimport { sanitize, ExposedBreakpoints, Breakpoints } from \"./sanitize\";\n\nconst defaultBreakpoints: ExposedBreakpoints = {\n xs: [0, 575, \"px\"], // Extra small devices (portrait phones)\n sm: [576, 767, \"px\"], // Small devices (landscape phones)\n md: [768, 991, \"px\"], // Medium devices (tablets)\n lg: [992, 1199, \"px\"], // Large devices (desktops)\n xl: [1200, Infinity, \"px\"], // Extra large devices (large desktops)\n};\n\nexport const BreakpointsContext = React.createContext<Breakpoints>(sanitize(defaultBreakpoints));\n\ninterface BreakpointsProviderProps {\n breakpoints?: ExposedBreakpoints;\n additionalBreakpoints?: ExposedBreakpoints;\n}\n\nexport const BreakpointsProvider: React.FunctionComponent<React.PropsWithChildren<BreakpointsProviderProps>> = ({\n breakpoints = defaultBreakpoints,\n additionalBreakpoints = {},\n children,\n}) => {\n return (\n <BreakpointsContext.Provider\n value={sanitize({\n ...breakpoints,\n ...additionalBreakpoints,\n })}\n >\n {children}\n </BreakpointsContext.Provider>\n );\n};\n\nBreakpointsProvider.displayName = \"BreakpointsProvider\";\n","import { Breakpoint } from \"./sanitize\";\n\nexport const fromBreakpointToMedia = (breakpoint: Breakpoint): string => {\n const mediaList: string[] = [];\n const [minValue, maxValue, unit, direction] = breakpoint;\n let str;\n\n // Min value\n if (minValue !== 0) {\n str = `${minValue}${unit}`;\n mediaList.push(`(min-${direction}:${str})`);\n }\n\n // Max value\n if (maxValue !== Infinity) {\n str = `${maxValue}${unit}`;\n mediaList.push(`(max-${direction}:${str})`);\n }\n\n return \" \" + mediaList.join(\" and \");\n};\n","import * as React from \"react\";\n\n// const startTransitionFallbackForReact17AndBellow = (cb: () => void) => cb();\n// // @ts-expect-error not supported yet\n// const startTransition = React.startTransition || startTransitionFallbackForReact17AndBellow;\n\nexport const useMediaQuery = (mediaQuery: string): boolean => {\n const mediaQueryList = React.useMemo(() => matchMedia(mediaQuery), [mediaQuery]);\n const [isShown, setIsShown] = React.useState<boolean>(mediaQueryList.matches);\n\n React.useLayoutEffect(() => {\n setIsShown(mediaQueryList.matches);\n const listener = (event: MediaQueryListEvent) => {\n // We use startTransition as those update aren't urgent\n // startTransition(() => {\n setIsShown(event.matches);\n // });\n };\n\n // cannot use addEventListener for IE 11 and safari 13-\n mediaQueryList.addListener(listener);\n return () => {\n mediaQueryList.removeListener(listener);\n };\n }, [mediaQueryList]);\n\n return isShown;\n};\n","import * as React from \"react\";\n\nimport { BreakpointsContext } from \"./BreakpointsContext\";\n\nimport { mediaQueryBuilder } from \"./mediaQueryBuilder\";\n\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport const useBreakpoint = (on?: string): boolean => {\n const breakpoints = React.useContext(BreakpointsContext);\n const toMediaQuery = React.useMemo(() => mediaQueryBuilder(breakpoints), [breakpoints]);\n\n const mediaQuery = React.useMemo(() => toMediaQuery(on), [toMediaQuery, on]);\n\n return useMediaQuery(mediaQuery || \"-\");\n};\n","import { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\nexport const mediaQueryBuilder =\n (breakpoints: Breakpoints) =>\n (on = \"\"): string => {\n if (!on) {\n return \"\";\n }\n const rawBreakpointNames = on.split(\" \");\n const filteredBreakpoints = rawBreakpointNames.map((breakpointName) => breakpoints[breakpointName]).filter(Boolean);\n const mediaQuery = filteredBreakpoints\n .map((breakpoint) => fromBreakpointToMedia(breakpoint))\n .filter(Boolean)\n .join(\",\");\n if (!mediaQuery) {\n const isUniqBreakpoint = rawBreakpointNames.length === 1;\n console.error(\n `\"${rawBreakpointNames.join('\", \"')}\" ${isUniqBreakpoint ? \"is\" : \"are\"}n't ${\n isUniqBreakpoint ? \"a \" : \"\"\n }valid breakpoint${isUniqBreakpoint ? \"\" : \"s\"}`,\n );\n }\n return mediaQuery;\n };\n","import * as React from \"react\";\n\nimport { useBreakpoint } from \"./useBreakpoint\";\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport type OnlyProps<OtherProps = Record<string, never>> = OtherProps & {\n matchMedia?: string;\n on?: string;\n as?: string | React.ComponentType<OtherProps>;\n};\n\nexport function Only<OtherProps = Record<string, never>>({\n matchMedia,\n on,\n as,\n children,\n ...props\n}: React.PropsWithChildren<OnlyProps<OtherProps>>): React.ReactElement | null {\n const matchOn = useBreakpoint(on);\n const matchQuery = useMediaQuery(matchMedia || \"-\");\n const isShown = matchOn || matchQuery;\n\n if (!isShown) {\n return null;\n }\n\n return React.createElement(as || React.Fragment, as ? (props as OtherProps) : undefined, children);\n}\n\nOnly.displayName = \"Only\";\n","import * as React from \"react\";\n\nimport { Only } from \"./Only\";\n\nexport interface MatchChildProps {\n matchMedia?: string;\n only?: string;\n}\n\ndeclare module \"react\" {\n interface HTMLAttributes<T> extends React.AriaAttributes, React.DOMAttributes<T>, MatchChildProps {}\n}\n\ntype Element = React.ReactElement<MatchChildProps & any, string | React.ComponentType<MatchChildProps & any>> | null;\n\nconst parseChildren = (element: Element): Element => {\n if (!element || !element.props) {\n return element;\n }\n\n const _children: Element | Element[] | null = element.props.children;\n if (!_children) {\n return null;\n }\n const children = React.Children.map(_children, parseChildren);\n const { only, matchMedia, ...props } = element.props;\n const clone = React.createElement(element.type, props, children);\n if (!only && !matchMedia) {\n return clone;\n }\n return (\n <Only on={only || \"\"} matchMedia={matchMedia || \"\"}>\n {clone}\n </Only>\n );\n};\n\ninterface MatchProps {\n [key: string]: any;\n children: Element | Element[] | null;\n as?: string;\n}\n\nexport const Match: React.FunctionComponent<MatchProps> = ({ children, as, ...props }) => {\n const computedChildren = React.Children.map(children, parseChildren);\n if (as) {\n return React.createElement(as, props, computedChildren);\n }\n return React.createElement(React.Fragment, null, computedChildren);\n};\n\nMatch.displayName = \"Match\";\n","import { CSSProperties } from \"react\";\nimport { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\ntype CSSinJSProperties =\n | CSSProperties\n | {\n [key: string]: CSSProperties;\n };\n\ninterface Points {\n [breakpoint: string]: CSSinJSProperties;\n}\n\ntype CSSinJS = Record<string, CSSinJSProperties>;\nexport const toJSON =\n (breakpoints: Breakpoints) =>\n (points: Points): CSSinJS => {\n const css: CSSinJS = {};\n Object.keys(points).forEach((point) => {\n const breakpoint = breakpoints[point];\n if (!breakpoint) {\n throw new Error(`${point} is not a valid breakpoint\\nValid breakpoints are: ${Object.keys(breakpoints)}`);\n }\n css[`@media ${fromBreakpointToMedia(breakpoint)}`] = points[point];\n });\n return css;\n };\n\nconst stringify = (object: CSSinJSProperties) => {\n let string = \"\";\n Object.entries(object).forEach(([key, value]) => {\n if (typeof value !== \"object\") {\n string += `${key}: ${value};\\n`;\n return;\n }\n string += `${key} {\\n${stringify(value)}}\\n`;\n });\n return string;\n};\n\nexport const toCSS =\n (breakpoints: Breakpoints) =>\n (points: Points): string =>\n stringify(toJSON(breakpoints)(points));\n"],"names":["listOfSupportedUnits","listOfSupportedDirections","sanitize","inBreakpoints","Object","keys","reduce","breakpoints","breakpointName","Array","isArray","breakpoint","length","supposedUnit","supposedDirection","supposedMax","options","rest","slice","error","Error","console","supposedMin","direction","unit","min","Math","max","includes","Infinity","defaultBreakpoints","xs","sm","md","lg","xl","BreakpointsContext","React","createContext","BreakpointsProvider","_ref","additionalBreakpoints","children","Provider","value","_ref$additionalBreakp","displayName","fromBreakpointToMedia","mediaList","minValue","maxValue","push","str","join","useMediaQuery","mediaQuery","mediaQueryList","useMemo","matchMedia","_React$useState","useState","matches","isShown","setIsShown","useLayoutEffect","listener","event","addListener","removeListener","on","useContext","toMediaQuery","rawBreakpointNames","split","map","filter","Boolean","isUniqBreakpoint","Only","as","props","matchOn","useBreakpoint","matchQuery","createElement","Fragment","undefined","parseChildren","element","_children","Children","only","_objectWithoutPropertiesLoose","_element$props","_excluded","type","clone","_excluded2","computedChildren","Match","toJSON","points","css","forEach","point","stringify","object","string","entries","key"],"mappings":"6pBAiBA,IAA0BA,EAAY,CACpC,KACA,KACA,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,MACA,KAC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AAAA,GACC,IAASC,EAAY,GAQrB,OAPAlG,OAAOC,KAAKgG,GAAQE,QAAQ,SAACC,GAC3B,IAAM7F,EAAaJ,EAAYiG,GAC/B,IAAK7F,EACH,MAAM,IAAAS,MAAaoF,EAA2DpG,sDAAAA,OAAOC,KAAKE,IAE5F+F,YAAcvD,EAAsBpC,IAAiB0F,EAAOG,KAG/DF,IAEYG,EAAG,SAAAA,EAACC,GACjB,IAAIC,EAAS,GAQb,OAPAvG,OAAOwG,QAAQF,GAAQH,QAAQ,SAAA/D,OAAiBqE,EAAArE,EAAA,GAAVI,EAAUJ,EAAA,GAK9CmE,GAJqB,iBAAV/D,EAIEiE,EAAUJ,OAAAA,EAAU7D,GAClC,MAJgBiE,EAAP,KAAejE,EAArB,QAKG+D,2GAIP,SAACpG,GAAD,OACC8F,SAAAA,UACUI,EAACL,EAAO7F,EAAP6F,CAAoBC"}
|
|
1
|
+
{"version":3,"file":"react-responsive.js","sources":["../src/sanitize.ts","../src/BreakpointsContext.tsx","../src/fromBreakpointToMedia.ts","../src/useMediaQuery.ts","../src/useBreakpoint.ts","../src/mediaQueryBuilder.ts","../src/Only.tsx","../src/css-in-js.ts"],"sourcesContent":["export type Units =\n | \"em\"\n | \"ex\"\n | \"%\"\n | \"px\"\n | \"cm\"\n | \"mm\"\n | \"in\"\n | \"pt\"\n | \"pc\"\n | \"ch\"\n | \"rem\"\n | \"vh\"\n | \"vw\"\n | \"vmin\"\n | \"vmax\";\n\nconst listOfSupportedUnits: Units[] = [\n \"em\",\n \"ex\",\n \"%\",\n \"px\",\n \"cm\",\n \"mm\",\n \"in\",\n \"pt\",\n \"pc\",\n \"ch\",\n \"rem\",\n \"vh\",\n \"vw\",\n \"vmin\",\n \"vmax\",\n];\n\ntype Directions = \"width\" | \"height\";\n\nconst listOfSupportedDirections: Directions[] = [\"width\", \"height\"];\n\nexport type ExposedBreakpoint =\n | [number, number]\n | [number, number, Units]\n | [number, number, { unit?: Units; direction?: Directions }];\n\nexport interface ExposedBreakpoints {\n [key: string]: ExposedBreakpoint;\n}\n\nexport type Breakpoint = [number, number, Units, Directions];\n\nexport interface Breakpoints {\n [breakpoint: string]: Breakpoint;\n}\n\nexport const sanitize = (inBreakpoints: ExposedBreakpoints): Breakpoints => {\n return Object.keys(inBreakpoints).reduce<Breakpoints>((breakpoints, breakpointName) => {\n const breakpoint = inBreakpoints[breakpointName];\n\n if (!Array.isArray(breakpoint) || breakpoint.length <= 1) {\n return breakpoints;\n }\n\n const [supposedMin, supposedMax, options, ...rest] = breakpoint;\n if (rest.length > 0) {\n const error = new Error(`The following fields \"${rest}\" have been ignored`);\n console.error(error);\n }\n\n if (typeof supposedMin !== \"number\" || typeof supposedMax !== \"number\") {\n return breakpoints;\n }\n\n let supposedUnit: Units | undefined;\n let supposedDirection: Directions | undefined;\n if (typeof options === \"string\") {\n supposedUnit = options;\n } else if (typeof options === \"object\") {\n supposedDirection = options.direction;\n supposedUnit = options.unit;\n }\n\n const min = Math.min(supposedMin, supposedMax);\n const max = Math.max(supposedMin, supposedMax);\n const unit = supposedUnit && listOfSupportedUnits.includes(supposedUnit) ? supposedUnit : \"px\";\n const direction =\n supposedDirection && listOfSupportedDirections.includes(supposedDirection) ? supposedDirection : \"width\";\n\n breakpoints[breakpointName] = [min, max, unit, direction];\n breakpoints[`${breakpointName}Up`] = [min, Infinity, unit, direction];\n breakpoints[`${breakpointName}Down`] = [0, max, unit, direction];\n\n return breakpoints;\n }, {});\n};\n","import * as React from \"react\";\n\nimport { sanitize, ExposedBreakpoints, Breakpoints } from \"./sanitize\";\n\nconst defaultBreakpoints: ExposedBreakpoints = {\n xs: [0, 575, \"px\"], // Extra small devices (portrait phones)\n sm: [576, 767, \"px\"], // Small devices (landscape phones)\n md: [768, 991, \"px\"], // Medium devices (tablets)\n lg: [992, 1199, \"px\"], // Large devices (desktops)\n xl: [1200, Infinity, \"px\"], // Extra large devices (large desktops)\n};\n\nexport const BreakpointsContext = React.createContext<Breakpoints>(sanitize(defaultBreakpoints));\n\ninterface BreakpointsProviderProps {\n breakpoints?: ExposedBreakpoints;\n additionalBreakpoints?: ExposedBreakpoints;\n}\n\nexport const BreakpointsProvider: React.FunctionComponent<React.PropsWithChildren<BreakpointsProviderProps>> = ({\n breakpoints = defaultBreakpoints,\n additionalBreakpoints = {},\n children,\n}) => {\n return (\n <BreakpointsContext.Provider\n value={sanitize({\n ...breakpoints,\n ...additionalBreakpoints,\n })}\n >\n {children}\n </BreakpointsContext.Provider>\n );\n};\n\nBreakpointsProvider.displayName = \"BreakpointsProvider\";\n","import { Breakpoint } from \"./sanitize\";\n\nexport const fromBreakpointToMedia = (breakpoint: Breakpoint): string => {\n const mediaList: string[] = [];\n const [minValue, maxValue, unit, direction] = breakpoint;\n let str;\n\n // Min value\n if (minValue !== 0) {\n str = `${minValue}${unit}`;\n mediaList.push(`(min-${direction}:${str})`);\n }\n\n // Max value\n if (maxValue !== Infinity) {\n str = `${maxValue}${unit}`;\n mediaList.push(`(max-${direction}:${str})`);\n }\n\n return \" \" + mediaList.join(\" and \");\n};\n","import * as React from \"react\";\n\n// const startTransitionFallbackForReact17AndBellow = (cb: () => void) => cb();\n// // @ts-expect-error not supported yet\n// const startTransition = React.startTransition || startTransitionFallbackForReact17AndBellow;\n\nexport const useMediaQuery = (mediaQuery: string): boolean => {\n const mediaQueryList = React.useMemo(() => matchMedia(mediaQuery), [mediaQuery]);\n const [isShown, setIsShown] = React.useState<boolean>(mediaQueryList.matches);\n\n React.useLayoutEffect(() => {\n setIsShown(mediaQueryList.matches);\n const listener = (event: MediaQueryListEvent) => {\n // We use startTransition as those update aren't urgent\n // startTransition(() => {\n setIsShown(event.matches);\n // });\n };\n\n // cannot use addEventListener for IE 11 and safari 13-\n mediaQueryList.addListener(listener);\n return () => {\n mediaQueryList.removeListener(listener);\n };\n }, [mediaQueryList]);\n\n return isShown;\n};\n","import * as React from \"react\";\n\nimport { BreakpointsContext } from \"./BreakpointsContext\";\n\nimport { mediaQueryBuilder } from \"./mediaQueryBuilder\";\n\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport const useBreakpoint = (on?: string): boolean => {\n const breakpoints = React.useContext(BreakpointsContext);\n const toMediaQuery = React.useMemo(() => mediaQueryBuilder(breakpoints), [breakpoints]);\n\n const mediaQuery = React.useMemo(() => toMediaQuery(on), [toMediaQuery, on]);\n\n return useMediaQuery(mediaQuery || \"-\");\n};\n","import { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\nexport const mediaQueryBuilder =\n (breakpoints: Breakpoints) =>\n (on = \"\"): string => {\n if (!on) {\n return \"\";\n }\n const rawBreakpointNames = on.split(\" \");\n const filteredBreakpoints = rawBreakpointNames.map((breakpointName) => breakpoints[breakpointName]).filter(Boolean);\n const mediaQuery = filteredBreakpoints\n .map((breakpoint) => fromBreakpointToMedia(breakpoint))\n .filter(Boolean)\n .join(\",\");\n if (!mediaQuery) {\n const isUniqBreakpoint = rawBreakpointNames.length === 1;\n console.error(\n `\"${rawBreakpointNames.join('\", \"')}\" ${isUniqBreakpoint ? \"is\" : \"are\"}n't ${\n isUniqBreakpoint ? \"a \" : \"\"\n }valid breakpoint${isUniqBreakpoint ? \"\" : \"s\"}`,\n );\n }\n return mediaQuery;\n };\n","import * as React from \"react\";\n\nimport { useBreakpoint } from \"./useBreakpoint\";\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport type OnlyProps<OtherProps = Record<string, never>> = OtherProps & {\n matchMedia?: string;\n on?: string;\n as?: string | React.ComponentType<OtherProps>;\n};\n\nexport function Only<OtherProps = Record<string, never>>({\n matchMedia,\n on,\n as,\n children,\n ...props\n}: React.PropsWithChildren<OnlyProps<OtherProps>>): React.ReactElement | null {\n const matchOn = useBreakpoint(on);\n const matchQuery = useMediaQuery(matchMedia || \"-\");\n const isShown = matchOn || matchQuery;\n\n if (!isShown) {\n return null;\n }\n\n return React.createElement(\n // @ts-expect-error – this is a complex type\n as || React.Fragment,\n as ? (props as OtherProps) : undefined,\n children,\n );\n}\n\nOnly.displayName = \"Only\";\n","import { CSSProperties } from \"react\";\nimport { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\ntype CSSinJSProperties =\n | CSSProperties\n | {\n [key: string]: CSSProperties;\n };\n\ninterface Points {\n [breakpoint: string]: CSSinJSProperties;\n}\n\ntype CSSinJS = Record<string, CSSinJSProperties>;\nexport const toJSON =\n (breakpoints: Breakpoints) =>\n (points: Points): CSSinJS => {\n const css: CSSinJS = {};\n Object.keys(points).forEach((point) => {\n const breakpoint = breakpoints[point];\n if (!breakpoint) {\n throw new Error(`${point} is not a valid breakpoint\\nValid breakpoints are: ${Object.keys(breakpoints)}`);\n }\n css[`@media ${fromBreakpointToMedia(breakpoint)}`] = points[point];\n });\n return css;\n };\n\nconst stringify = (object: CSSinJSProperties) => {\n let string = \"\";\n Object.entries(object).forEach(([key, value]) => {\n if (typeof value !== \"object\") {\n string += `${key}: ${value};\\n`;\n return;\n }\n string += `${key} {\\n${stringify(value)}}\\n`;\n });\n return string;\n};\n\nexport const toCSS =\n (breakpoints: Breakpoints) =>\n (points: Points): string =>\n stringify(toJSON(breakpoints)(points));\n"],"names":["listOfSupportedUnits","listOfSupportedDirections","sanitize","inBreakpoints","Object","keys","reduce","breakpoints","breakpointName","breakpoint","Array","isArray","length","supposedUnit","supposedDirection","supposedMin","supposedMax","options","rest","slice","error","Error","console","direction","unit","min","Math","max","includes","Infinity","defaultBreakpoints","xs","sm","md","lg","xl","BreakpointsContext","React","createContext","BreakpointsProvider","_ref","_ref$breakpoints","_ref$additionalBreakp","additionalBreakpoints","children","Provider","value","_extends","displayName","fromBreakpointToMedia","mediaList","minValue","maxValue","push","str","join","useMediaQuery","mediaQuery","mediaQueryList","useMemo","matchMedia","_React$useState","useState","matches","isShown","setIsShown","useLayoutEffect","listener","event","addListener","removeListener","useBreakpoint","on","useContext","toMediaQuery","rawBreakpointNames","split","map","filter","Boolean","isUniqBreakpoint","mediaQueryBuilder","Only","as","props","_objectWithoutPropertiesLoose","_excluded","matchOn","matchQuery","createElement","Fragment","undefined","toJSON","points","css","forEach","point","stringify","object","string","entries","key"],"mappings":"6gBAiBA,IAAMA,EAAgC,CACpC,KACA,KACA,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,MACA,KACA,KACA,OACA,QAKIC,EAA0C,CAAC,QAAS,UAiB7CC,EAAW,SAACC,GACvB,OAAOC,OAAOC,KAAKF,GAAeG,OAAoB,SAACC,EAAaC,GAClE,IAAMC,EAAaN,EAAcK,GAEjC,IAAKE,MAAMC,QAAQF,IAAeA,EAAWG,QAAU,EACrD,OAAOL,EAGT,IAUIM,EACAC,EAXGC,EAA8CN,EAAU,GAA3CO,EAAiCP,EAApBQ,GAAAA,EAAoBR,EAAU,GAAlBS,EAAQT,EAAUU,SAC/D,GAAID,EAAKN,OAAS,EAAG,CACnB,IAAMQ,EAAQ,IAAIC,MAA+BH,yBAAAA,EAAyB,uBAC1EI,QAAQF,MAAMA,EAChB,CAEA,GAA2B,iBAAhBL,GAAmD,iBAAhBC,EAC5C,OAAOT,EAKc,iBAAZU,EACTJ,EAAeI,EACa,iBAAZA,IAChBH,EAAoBG,EAAQM,UAC5BV,EAAeI,EAAQO,MAGzB,IAAMC,EAAMC,KAAKD,IAAIV,EAAaC,GAC5BW,EAAMD,KAAKC,IAAIZ,EAAaC,GAC5BQ,EAAOX,GAAgBb,EAAqB4B,SAASf,GAAgBA,EAAe,KACpFU,EACJT,GAAqBb,EAA0B2B,SAASd,GAAqBA,EAAoB,QAMnG,OAJAP,EAAYC,GAAkB,CAACiB,EAAKE,EAAKH,EAAMD,GAC/ChB,EAAeC,EAAc,MAAQ,CAACiB,EAAKI,SAAUL,EAAMD,GAC3DhB,EAAeC,EAAc,QAAU,CAAC,EAAGmB,EAAKH,EAAMD,GAE/ChB,CACT,EAAG,CAAA,EACL,ECzFMuB,EAAyC,CAC7CC,GAAI,CAAC,EAAG,IAAK,MACb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sBxC,IAAiBoF,EAAOG,EAC9D,GACOF,CACT,CAAC,EAEGG,EAAY,SAACC,GACjB,IAAIC,EAAS,GAQb,OAPA/F,OAAOgG,QAAQF,GAAQH,QAAQ,SAAAvD,GAAiB,IAAf6D,EAAG7D,EAAEM,GAAAA,EAAKN,EAAA,GAKzC2D,GAJqB,iBAAVrD,EAIEuD,EAAG,OAAOJ,EAAUnD,GACnC,MAJiBuD,EAAG,KAAKvD,EAAU,KAInC,GACOqD,CACT,0FAGE,SAAC5F,GAAwB,gBACxBsF,GAAc,OACbI,EAAUL,EAAOrF,EAAPqF,CAAoBC,GAAQ,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import*as n from"react";function
|
|
1
|
+
import*as n from"react";function r(){return r=Object.assign?Object.assign.bind():function(n){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var t in e)({}).hasOwnProperty.call(e,t)&&(n[t]=e[t])}return n},r.apply(null,arguments)}var e=["em","ex","%","px","cm","mm","in","pt","pc","ch","rem","vh","vw","vmin","vmax"],t=["width","height"],i=function(n){return Object.keys(n).reduce(function(r,i){var o=n[i];if(!Array.isArray(o)||o.length<=1)return r;var a,u,c=o[0],f=o[1],s=o[2],l=o.slice(3);if(l.length>0){var v=new Error('The following fields "'+l+'" have been ignored');console.error(v)}if("number"!=typeof c||"number"!=typeof f)return r;"string"==typeof s?a=s:"object"==typeof s&&(u=s.direction,a=s.unit);var m=Math.min(c,f),d=Math.max(c,f),p=a&&e.includes(a)?a:"px",h=u&&t.includes(u)?u:"width";return r[i]=[m,d,p,h],r[i+"Up"]=[m,Infinity,p,h],r[i+"Down"]=[0,d,p,h],r},{})},o={xs:[0,575,"px"],sm:[576,767,"px"],md:[768,991,"px"],lg:[992,1199,"px"],xl:[1200,Infinity,"px"]},a=n.createContext(i(o)),u=function(e){var t=e.breakpoints,u=e.additionalBreakpoints,c=e.children;return n.createElement(a.Provider,{value:i(r({},void 0===t?o:t,void 0===u?{}:u))},c)};u.displayName="BreakpointsProvider";var c=function(n){var r=[],e=n[0],t=n[1],i=n[2],o=n[3];return 0!==e&&r.push("(min-"+o+":"+e+i+")"),Infinity!==t&&r.push("(max-"+o+":"+t+i+")")," "+r.join(" and ")},f=function(r){var e=n.useMemo(function(){return matchMedia(r)},[r]),t=n.useState(e.matches),i=t[0],o=t[1];return n.useLayoutEffect(function(){o(e.matches);var n=function(n){o(n.matches)};return e.addListener(n),function(){e.removeListener(n)}},[e]),i},s=function(r){var e=n.useContext(a),t=n.useMemo(function(){return function(n){return function(r){if(void 0===r&&(r=""),!r)return"";var e=r.split(" "),t=e.map(function(r){return n[r]}).filter(Boolean).map(function(n){return c(n)}).filter(Boolean).join(",");if(!t){var i=1===e.length;console.error('"'+e.join('", "')+'" '+(i?"is":"are")+"n't "+(i?"a ":"")+"valid breakpoint"+(i?"":"s"))}return t}}(e)},[e]),i=n.useMemo(function(){return t(r)},[t,r]);return f(i||"-")},l=["matchMedia","on","as","children"];function v(r){var e=r.matchMedia,t=r.on,i=r.as,o=r.children,a=function(n,r){if(null==n)return{};var e={};for(var t in n)if({}.hasOwnProperty.call(n,t)){if(r.includes(t))continue;e[t]=n[t]}return e}(r,l),u=s(t),c=f(e||"-");return u||c?n.createElement(i||n.Fragment,i?a:void 0,o):null}v.displayName="Only";var m=function(n){return function(r){var e={};return Object.keys(r).forEach(function(t){var i=n[t];if(!i)throw new Error(t+" is not a valid breakpoint\nValid breakpoints are: "+Object.keys(n));e["@media "+c(i)]=r[t]}),e}},d=function(n){var r="";return Object.entries(n).forEach(function(n){var e=n[0],t=n[1];r+="object"==typeof t?e+" {\n"+d(t)+"}\n":e+": "+t+";\n"}),r},p=function(n){return function(r){return d(m(n)(r))}};export{a as BreakpointsContext,u as BreakpointsProvider,v as Only,p as toCSS,m as toJSON,s as useBreakpoint,f as useMediaQuery};
|
|
2
2
|
//# sourceMappingURL=react-responsive.modern.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-responsive.modern.js","sources":["../src/sanitize.ts","../src/BreakpointsContext.tsx","../src/fromBreakpointToMedia.ts","../src/useMediaQuery.ts","../src/useBreakpoint.ts","../src/mediaQueryBuilder.ts","../src/Only.tsx","../src/Match.tsx","../src/css-in-js.ts"],"sourcesContent":["export type Units =\n | \"em\"\n | \"ex\"\n | \"%\"\n | \"px\"\n | \"cm\"\n | \"mm\"\n | \"in\"\n | \"pt\"\n | \"pc\"\n | \"ch\"\n | \"rem\"\n | \"vh\"\n | \"vw\"\n | \"vmin\"\n | \"vmax\";\n\nconst listOfSupportedUnits: Units[] = [\n \"em\",\n \"ex\",\n \"%\",\n \"px\",\n \"cm\",\n \"mm\",\n \"in\",\n \"pt\",\n \"pc\",\n \"ch\",\n \"rem\",\n \"vh\",\n \"vw\",\n \"vmin\",\n \"vmax\",\n];\n\ntype Directions = \"width\" | \"height\";\n\nconst listOfSupportedDirections: Directions[] = [\"width\", \"height\"];\n\nexport type ExposedBreakpoint =\n | [number, number]\n | [number, number, Units]\n | [number, number, { unit?: Units; direction?: Directions }];\n\nexport interface ExposedBreakpoints {\n [key: string]: ExposedBreakpoint;\n}\n\nexport type Breakpoint = [number, number, Units, Directions];\n\nexport interface Breakpoints {\n [breakpoint: string]: Breakpoint;\n}\n\nexport const sanitize = (inBreakpoints: ExposedBreakpoints): Breakpoints => {\n return Object.keys(inBreakpoints).reduce<Breakpoints>((breakpoints, breakpointName) => {\n const breakpoint = inBreakpoints[breakpointName];\n\n if (!Array.isArray(breakpoint) || breakpoint.length <= 1) {\n return breakpoints;\n }\n\n const [supposedMin, supposedMax, options, ...rest] = breakpoint;\n if (rest.length > 0) {\n const error = new Error(`The following fields \"${rest}\" have been ignored`);\n console.error(error);\n }\n\n if (typeof supposedMin !== \"number\" || typeof supposedMax !== \"number\") {\n return breakpoints;\n }\n\n let supposedUnit: Units | undefined;\n let supposedDirection: Directions | undefined;\n if (typeof options === \"string\") {\n supposedUnit = options;\n } else if (typeof options === \"object\") {\n supposedDirection = options.direction;\n supposedUnit = options.unit;\n }\n\n const min = Math.min(supposedMin, supposedMax);\n const max = Math.max(supposedMin, supposedMax);\n const unit = supposedUnit && listOfSupportedUnits.includes(supposedUnit) ? supposedUnit : \"px\";\n const direction =\n supposedDirection && listOfSupportedDirections.includes(supposedDirection) ? supposedDirection : \"width\";\n\n breakpoints[breakpointName] = [min, max, unit, direction];\n breakpoints[`${breakpointName}Up`] = [min, Infinity, unit, direction];\n breakpoints[`${breakpointName}Down`] = [0, max, unit, direction];\n\n return breakpoints;\n }, {});\n};\n","import * as React from \"react\";\n\nimport { sanitize, ExposedBreakpoints, Breakpoints } from \"./sanitize\";\n\nconst defaultBreakpoints: ExposedBreakpoints = {\n xs: [0, 575, \"px\"], // Extra small devices (portrait phones)\n sm: [576, 767, \"px\"], // Small devices (landscape phones)\n md: [768, 991, \"px\"], // Medium devices (tablets)\n lg: [992, 1199, \"px\"], // Large devices (desktops)\n xl: [1200, Infinity, \"px\"], // Extra large devices (large desktops)\n};\n\nexport const BreakpointsContext = React.createContext<Breakpoints>(sanitize(defaultBreakpoints));\n\ninterface BreakpointsProviderProps {\n breakpoints?: ExposedBreakpoints;\n additionalBreakpoints?: ExposedBreakpoints;\n}\n\nexport const BreakpointsProvider: React.FunctionComponent<React.PropsWithChildren<BreakpointsProviderProps>> = ({\n breakpoints = defaultBreakpoints,\n additionalBreakpoints = {},\n children,\n}) => {\n return (\n <BreakpointsContext.Provider\n value={sanitize({\n ...breakpoints,\n ...additionalBreakpoints,\n })}\n >\n {children}\n </BreakpointsContext.Provider>\n );\n};\n\nBreakpointsProvider.displayName = \"BreakpointsProvider\";\n","import { Breakpoint } from \"./sanitize\";\n\nexport const fromBreakpointToMedia = (breakpoint: Breakpoint): string => {\n const mediaList: string[] = [];\n const [minValue, maxValue, unit, direction] = breakpoint;\n let str;\n\n // Min value\n if (minValue !== 0) {\n str = `${minValue}${unit}`;\n mediaList.push(`(min-${direction}:${str})`);\n }\n\n // Max value\n if (maxValue !== Infinity) {\n str = `${maxValue}${unit}`;\n mediaList.push(`(max-${direction}:${str})`);\n }\n\n return \" \" + mediaList.join(\" and \");\n};\n","import * as React from \"react\";\n\n// const startTransitionFallbackForReact17AndBellow = (cb: () => void) => cb();\n// // @ts-expect-error not supported yet\n// const startTransition = React.startTransition || startTransitionFallbackForReact17AndBellow;\n\nexport const useMediaQuery = (mediaQuery: string): boolean => {\n const mediaQueryList = React.useMemo(() => matchMedia(mediaQuery), [mediaQuery]);\n const [isShown, setIsShown] = React.useState<boolean>(mediaQueryList.matches);\n\n React.useLayoutEffect(() => {\n setIsShown(mediaQueryList.matches);\n const listener = (event: MediaQueryListEvent) => {\n // We use startTransition as those update aren't urgent\n // startTransition(() => {\n setIsShown(event.matches);\n // });\n };\n\n // cannot use addEventListener for IE 11 and safari 13-\n mediaQueryList.addListener(listener);\n return () => {\n mediaQueryList.removeListener(listener);\n };\n }, [mediaQueryList]);\n\n return isShown;\n};\n","import * as React from \"react\";\n\nimport { BreakpointsContext } from \"./BreakpointsContext\";\n\nimport { mediaQueryBuilder } from \"./mediaQueryBuilder\";\n\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport const useBreakpoint = (on?: string): boolean => {\n const breakpoints = React.useContext(BreakpointsContext);\n const toMediaQuery = React.useMemo(() => mediaQueryBuilder(breakpoints), [breakpoints]);\n\n const mediaQuery = React.useMemo(() => toMediaQuery(on), [toMediaQuery, on]);\n\n return useMediaQuery(mediaQuery || \"-\");\n};\n","import { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\nexport const mediaQueryBuilder =\n (breakpoints: Breakpoints) =>\n (on = \"\"): string => {\n if (!on) {\n return \"\";\n }\n const rawBreakpointNames = on.split(\" \");\n const filteredBreakpoints = rawBreakpointNames.map((breakpointName) => breakpoints[breakpointName]).filter(Boolean);\n const mediaQuery = filteredBreakpoints\n .map((breakpoint) => fromBreakpointToMedia(breakpoint))\n .filter(Boolean)\n .join(\",\");\n if (!mediaQuery) {\n const isUniqBreakpoint = rawBreakpointNames.length === 1;\n console.error(\n `\"${rawBreakpointNames.join('\", \"')}\" ${isUniqBreakpoint ? \"is\" : \"are\"}n't ${\n isUniqBreakpoint ? \"a \" : \"\"\n }valid breakpoint${isUniqBreakpoint ? \"\" : \"s\"}`,\n );\n }\n return mediaQuery;\n };\n","import * as React from \"react\";\n\nimport { useBreakpoint } from \"./useBreakpoint\";\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport type OnlyProps<OtherProps = Record<string, never>> = OtherProps & {\n matchMedia?: string;\n on?: string;\n as?: string | React.ComponentType<OtherProps>;\n};\n\nexport function Only<OtherProps = Record<string, never>>({\n matchMedia,\n on,\n as,\n children,\n ...props\n}: React.PropsWithChildren<OnlyProps<OtherProps>>): React.ReactElement | null {\n const matchOn = useBreakpoint(on);\n const matchQuery = useMediaQuery(matchMedia || \"-\");\n const isShown = matchOn || matchQuery;\n\n if (!isShown) {\n return null;\n }\n\n return React.createElement(as || React.Fragment, as ? (props as OtherProps) : undefined, children);\n}\n\nOnly.displayName = \"Only\";\n","import * as React from \"react\";\n\nimport { Only } from \"./Only\";\n\nexport interface MatchChildProps {\n matchMedia?: string;\n only?: string;\n}\n\ndeclare module \"react\" {\n interface HTMLAttributes<T> extends React.AriaAttributes, React.DOMAttributes<T>, MatchChildProps {}\n}\n\ntype Element = React.ReactElement<MatchChildProps & any, string | React.ComponentType<MatchChildProps & any>> | null;\n\nconst parseChildren = (element: Element): Element => {\n if (!element || !element.props) {\n return element;\n }\n\n const _children: Element | Element[] | null = element.props.children;\n if (!_children) {\n return null;\n }\n const children = React.Children.map(_children, parseChildren);\n const { only, matchMedia, ...props } = element.props;\n const clone = React.createElement(element.type, props, children);\n if (!only && !matchMedia) {\n return clone;\n }\n return (\n <Only on={only || \"\"} matchMedia={matchMedia || \"\"}>\n {clone}\n </Only>\n );\n};\n\ninterface MatchProps {\n [key: string]: any;\n children: Element | Element[] | null;\n as?: string;\n}\n\nexport const Match: React.FunctionComponent<MatchProps> = ({ children, as, ...props }) => {\n const computedChildren = React.Children.map(children, parseChildren);\n if (as) {\n return React.createElement(as, props, computedChildren);\n }\n return React.createElement(React.Fragment, null, computedChildren);\n};\n\nMatch.displayName = \"Match\";\n","import { CSSProperties } from \"react\";\nimport { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\ntype CSSinJSProperties =\n | CSSProperties\n | {\n [key: string]: CSSProperties;\n };\n\ninterface Points {\n [breakpoint: string]: CSSinJSProperties;\n}\n\ntype CSSinJS = Record<string, CSSinJSProperties>;\nexport const toJSON =\n (breakpoints: Breakpoints) =>\n (points: Points): CSSinJS => {\n const css: CSSinJS = {};\n Object.keys(points).forEach((point) => {\n const breakpoint = breakpoints[point];\n if (!breakpoint) {\n throw new Error(`${point} is not a valid breakpoint\\nValid breakpoints are: ${Object.keys(breakpoints)}`);\n }\n css[`@media ${fromBreakpointToMedia(breakpoint)}`] = points[point];\n });\n return css;\n };\n\nconst stringify = (object: CSSinJSProperties) => {\n let string = \"\";\n Object.entries(object).forEach(([key, value]) => {\n if (typeof value !== \"object\") {\n string += `${key}: ${value};\\n`;\n return;\n }\n string += `${key} {\\n${stringify(value)}}\\n`;\n });\n return string;\n};\n\nexport const toCSS =\n (breakpoints: Breakpoints) =>\n (points: Points): string =>\n stringify(toJSON(breakpoints)(points));\n"],"names":["listOfSupportedUnits","listOfSupportedDirections","sanitize","inBreakpoints","Object","keys","reduce","breakpoints","breakpointName","Array","isArray","breakpoint","length","supposedUnit","supposedDirection","supposedMax","options","rest","slice","error","Error","console","supposedMin","direction","unit","min","Math","max","includes","Infinity","defaultBreakpoints","xs","sm","md","lg","xl","BreakpointsContext","React","createContext","BreakpointsProvider","_ref","additionalBreakpoints","children","Provider","value","_ref$additionalBreakp","displayName","fromBreakpointToMedia","mediaList","minValue","maxValue","push","str","join","useMediaQuery","mediaQuery","mediaQueryList","useMemo","matchMedia","_React$useState","useState","matches","isShown","setIsShown","useLayoutEffect","listener","event","addListener","removeListener","on","useContext","toMediaQuery","rawBreakpointNames","split","map","filter","Boolean","isUniqBreakpoint","Only","as","props","matchOn","useBreakpoint","matchQuery","createElement","Fragment","undefined","parseChildren","element","_children","Children","only","_objectWithoutPropertiesLoose","_element$props","_excluded","type","clone","_excluded2","computedChildren","Match","toJSON","points","css","forEach","point","stringify","object","string","entries","key","toCSS"],"mappings":"gYAiBA,IAA0BA,EAAY,CACpC,KACA,KACA,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,MACA,KACA,KACA,OACA,QAK6BC,EAAiB,CAAC,QAAS,UAiB7CC,EAAW,SAACC,GACvB,OAAOC,OAAOC,KAAKF,GAAeG,OAAoB,SAACC,EAAaC,GAClE,MAAmBL,EAAcK,GAEjC,IAAKC,MAAMC,QAAQC,IAAeA,EAAWC,QAAU,EACrD,OAAOL,EAGT,IAUIM,EACAC,IAXiDH,EAAjCI,GAAAA,EAAiCJ,EAArD,GAAiCK,EAAoBL,EAARM,GAAAA,EAAQN,EACrDO,MAAA,GAAA,GAAID,EAAKL,OAAS,EAAG,CACnB,IAAWO,EAAG,IAAIC,+BAA+BH,EAAnC,uBACdI,QAAQF,MAAMA,GAGhB,GAA2B,iBAAhBG,GAAmD,iBAAhBP,EAC5C,OACDR,EAIsB,iBAAZS,EACTH,EAAeG,EACa,qBAC5BF,EAAoBE,EAAQO,UAC5BV,EAAeG,EAAQQ,MAGzB,IAAMC,EAAMC,KAAKD,IAAIH,EAAaP,GACzBY,EAAGD,KAAKC,IAAIL,EAAaP,GAC5BS,EAAOX,GAAgBb,EAAqB4B,SAASf,GAAgBA,EAAe,KAC3EU,EACbT,GAAqBb,EAA0B2B,SAASd,GAAqBA,EAAoB,QAMnG,OAJAP,EAAYC,GAAkB,CAACiB,EAAKE,EAAKH,EAAMD,GAC/ChB,EAAeC,EAAJ,MAA0B,CAACiB,EAAKI,SAAUL,EAAMD,GAC3DhB,EAAeC,EAAJ,QAA4B,CAA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AQ,GAAIjC,WAAYA,GAAc,IAC7CsC,GAJIA,KAe+C,SAA+BxD,GAAA,MAA5BE,EAAAA,SAAUqC,EAAkBvC,EAAlBuC,GAAOC,EAAWY,EAAApD,EAAAyD,GACjEC,EAAG7D,EAAMqD,SAAShB,IAAIhC,EAAU6C,GACtD,OAAIR,EACU1C,EAAC+C,cAAcL,EAAIC,EAAOkB,KAE3Bd,cAAc/C,EAAMgD,SAAU,KAAMa,IAGnDC,EAAMrD,YAAc,QCpCPsD,IAAMA,EACjB,SAAC7F,GAAD,OACC8F,SAAAA,GACC,IAASC,EAAY,GAQrB,OAPAlG,OAAOC,KAAKgG,GAAQE,QAAQ,SAACC,GAC3B,IAAM7F,EAAaJ,EAAYiG,GAC/B,IAAK7F,EACH,MAAM,IAAAS,MAAaoF,EAA2DpG,sDAAAA,OAAOC,KAAKE,IAE5F+F,YAAcvD,EAAsBpC,IAAiB0F,EAAOG,KAG/DF,IAEYG,EAAG,SAAAA,EAACC,GACjB,IAAIC,EAAS,GAQb,OAPAvG,OAAOwG,QAAQF,GAAQH,QAAQ,SAAA/D,OAAiBqE,EAAArE,EAAA,GAAVI,EAAUJ,EAAA,GAK9CmE,GAJqB,iBAAV/D,EAIEiE,EAAUJ,OAAAA,EAAU7D,GAClC,MAJgBiE,EAAP,KAAejE,EAArB,QAKG+D,GAGSG,EAChB,SAACvG,GAAD,OACC8F,SAAAA,UACUI,EAACL,EAAO7F,EAAP6F,CAAoBC"}
|
|
1
|
+
{"version":3,"file":"react-responsive.modern.js","sources":["../src/sanitize.ts","../src/BreakpointsContext.tsx","../src/fromBreakpointToMedia.ts","../src/useMediaQuery.ts","../src/useBreakpoint.ts","../src/mediaQueryBuilder.ts","../src/Only.tsx","../src/css-in-js.ts"],"sourcesContent":["export type Units =\n | \"em\"\n | \"ex\"\n | \"%\"\n | \"px\"\n | \"cm\"\n | \"mm\"\n | \"in\"\n | \"pt\"\n | \"pc\"\n | \"ch\"\n | \"rem\"\n | \"vh\"\n | \"vw\"\n | \"vmin\"\n | \"vmax\";\n\nconst listOfSupportedUnits: Units[] = [\n \"em\",\n \"ex\",\n \"%\",\n \"px\",\n \"cm\",\n \"mm\",\n \"in\",\n \"pt\",\n \"pc\",\n \"ch\",\n \"rem\",\n \"vh\",\n \"vw\",\n \"vmin\",\n \"vmax\",\n];\n\ntype Directions = \"width\" | \"height\";\n\nconst listOfSupportedDirections: Directions[] = [\"width\", \"height\"];\n\nexport type ExposedBreakpoint =\n | [number, number]\n | [number, number, Units]\n | [number, number, { unit?: Units; direction?: Directions }];\n\nexport interface ExposedBreakpoints {\n [key: string]: ExposedBreakpoint;\n}\n\nexport type Breakpoint = [number, number, Units, Directions];\n\nexport interface Breakpoints {\n [breakpoint: string]: Breakpoint;\n}\n\nexport const sanitize = (inBreakpoints: ExposedBreakpoints): Breakpoints => {\n return Object.keys(inBreakpoints).reduce<Breakpoints>((breakpoints, breakpointName) => {\n const breakpoint = inBreakpoints[breakpointName];\n\n if (!Array.isArray(breakpoint) || breakpoint.length <= 1) {\n return breakpoints;\n }\n\n const [supposedMin, supposedMax, options, ...rest] = breakpoint;\n if (rest.length > 0) {\n const error = new Error(`The following fields \"${rest}\" have been ignored`);\n console.error(error);\n }\n\n if (typeof supposedMin !== \"number\" || typeof supposedMax !== \"number\") {\n return breakpoints;\n }\n\n let supposedUnit: Units | undefined;\n let supposedDirection: Directions | undefined;\n if (typeof options === \"string\") {\n supposedUnit = options;\n } else if (typeof options === \"object\") {\n supposedDirection = options.direction;\n supposedUnit = options.unit;\n }\n\n const min = Math.min(supposedMin, supposedMax);\n const max = Math.max(supposedMin, supposedMax);\n const unit = supposedUnit && listOfSupportedUnits.includes(supposedUnit) ? supposedUnit : \"px\";\n const direction =\n supposedDirection && listOfSupportedDirections.includes(supposedDirection) ? supposedDirection : \"width\";\n\n breakpoints[breakpointName] = [min, max, unit, direction];\n breakpoints[`${breakpointName}Up`] = [min, Infinity, unit, direction];\n breakpoints[`${breakpointName}Down`] = [0, max, unit, direction];\n\n return breakpoints;\n }, {});\n};\n","import * as React from \"react\";\n\nimport { sanitize, ExposedBreakpoints, Breakpoints } from \"./sanitize\";\n\nconst defaultBreakpoints: ExposedBreakpoints = {\n xs: [0, 575, \"px\"], // Extra small devices (portrait phones)\n sm: [576, 767, \"px\"], // Small devices (landscape phones)\n md: [768, 991, \"px\"], // Medium devices (tablets)\n lg: [992, 1199, \"px\"], // Large devices (desktops)\n xl: [1200, Infinity, \"px\"], // Extra large devices (large desktops)\n};\n\nexport const BreakpointsContext = React.createContext<Breakpoints>(sanitize(defaultBreakpoints));\n\ninterface BreakpointsProviderProps {\n breakpoints?: ExposedBreakpoints;\n additionalBreakpoints?: ExposedBreakpoints;\n}\n\nexport const BreakpointsProvider: React.FunctionComponent<React.PropsWithChildren<BreakpointsProviderProps>> = ({\n breakpoints = defaultBreakpoints,\n additionalBreakpoints = {},\n children,\n}) => {\n return (\n <BreakpointsContext.Provider\n value={sanitize({\n ...breakpoints,\n ...additionalBreakpoints,\n })}\n >\n {children}\n </BreakpointsContext.Provider>\n );\n};\n\nBreakpointsProvider.displayName = \"BreakpointsProvider\";\n","import { Breakpoint } from \"./sanitize\";\n\nexport const fromBreakpointToMedia = (breakpoint: Breakpoint): string => {\n const mediaList: string[] = [];\n const [minValue, maxValue, unit, direction] = breakpoint;\n let str;\n\n // Min value\n if (minValue !== 0) {\n str = `${minValue}${unit}`;\n mediaList.push(`(min-${direction}:${str})`);\n }\n\n // Max value\n if (maxValue !== Infinity) {\n str = `${maxValue}${unit}`;\n mediaList.push(`(max-${direction}:${str})`);\n }\n\n return \" \" + mediaList.join(\" and \");\n};\n","import * as React from \"react\";\n\n// const startTransitionFallbackForReact17AndBellow = (cb: () => void) => cb();\n// // @ts-expect-error not supported yet\n// const startTransition = React.startTransition || startTransitionFallbackForReact17AndBellow;\n\nexport const useMediaQuery = (mediaQuery: string): boolean => {\n const mediaQueryList = React.useMemo(() => matchMedia(mediaQuery), [mediaQuery]);\n const [isShown, setIsShown] = React.useState<boolean>(mediaQueryList.matches);\n\n React.useLayoutEffect(() => {\n setIsShown(mediaQueryList.matches);\n const listener = (event: MediaQueryListEvent) => {\n // We use startTransition as those update aren't urgent\n // startTransition(() => {\n setIsShown(event.matches);\n // });\n };\n\n // cannot use addEventListener for IE 11 and safari 13-\n mediaQueryList.addListener(listener);\n return () => {\n mediaQueryList.removeListener(listener);\n };\n }, [mediaQueryList]);\n\n return isShown;\n};\n","import * as React from \"react\";\n\nimport { BreakpointsContext } from \"./BreakpointsContext\";\n\nimport { mediaQueryBuilder } from \"./mediaQueryBuilder\";\n\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport const useBreakpoint = (on?: string): boolean => {\n const breakpoints = React.useContext(BreakpointsContext);\n const toMediaQuery = React.useMemo(() => mediaQueryBuilder(breakpoints), [breakpoints]);\n\n const mediaQuery = React.useMemo(() => toMediaQuery(on), [toMediaQuery, on]);\n\n return useMediaQuery(mediaQuery || \"-\");\n};\n","import { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\nexport const mediaQueryBuilder =\n (breakpoints: Breakpoints) =>\n (on = \"\"): string => {\n if (!on) {\n return \"\";\n }\n const rawBreakpointNames = on.split(\" \");\n const filteredBreakpoints = rawBreakpointNames.map((breakpointName) => breakpoints[breakpointName]).filter(Boolean);\n const mediaQuery = filteredBreakpoints\n .map((breakpoint) => fromBreakpointToMedia(breakpoint))\n .filter(Boolean)\n .join(\",\");\n if (!mediaQuery) {\n const isUniqBreakpoint = rawBreakpointNames.length === 1;\n console.error(\n `\"${rawBreakpointNames.join('\", \"')}\" ${isUniqBreakpoint ? \"is\" : \"are\"}n't ${\n isUniqBreakpoint ? \"a \" : \"\"\n }valid breakpoint${isUniqBreakpoint ? \"\" : \"s\"}`,\n );\n }\n return mediaQuery;\n };\n","import * as React from \"react\";\n\nimport { useBreakpoint } from \"./useBreakpoint\";\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport type OnlyProps<OtherProps = Record<string, never>> = OtherProps & {\n matchMedia?: string;\n on?: string;\n as?: string | React.ComponentType<OtherProps>;\n};\n\nexport function Only<OtherProps = Record<string, never>>({\n matchMedia,\n on,\n as,\n children,\n ...props\n}: React.PropsWithChildren<OnlyProps<OtherProps>>): React.ReactElement | null {\n const matchOn = useBreakpoint(on);\n const matchQuery = useMediaQuery(matchMedia || \"-\");\n const isShown = matchOn || matchQuery;\n\n if (!isShown) {\n return null;\n }\n\n return React.createElement(\n // @ts-expect-error – this is a complex type\n as || React.Fragment,\n as ? (props as OtherProps) : undefined,\n children,\n );\n}\n\nOnly.displayName = \"Only\";\n","import { CSSProperties } from \"react\";\nimport { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\ntype CSSinJSProperties =\n | CSSProperties\n | {\n [key: string]: CSSProperties;\n };\n\ninterface Points {\n [breakpoint: string]: CSSinJSProperties;\n}\n\ntype CSSinJS = Record<string, CSSinJSProperties>;\nexport const toJSON =\n (breakpoints: Breakpoints) =>\n (points: Points): CSSinJS => {\n const css: CSSinJS = {};\n Object.keys(points).forEach((point) => {\n const breakpoint = breakpoints[point];\n if (!breakpoint) {\n throw new Error(`${point} is not a valid breakpoint\\nValid breakpoints are: ${Object.keys(breakpoints)}`);\n }\n css[`@media ${fromBreakpointToMedia(breakpoint)}`] = points[point];\n });\n return css;\n };\n\nconst stringify = (object: CSSinJSProperties) => {\n let string = \"\";\n Object.entries(object).forEach(([key, value]) => {\n if (typeof value !== \"object\") {\n string += `${key}: ${value};\\n`;\n return;\n }\n string += `${key} {\\n${stringify(value)}}\\n`;\n });\n return string;\n};\n\nexport const toCSS =\n (breakpoints: Breakpoints) =>\n (points: Points): string =>\n stringify(toJSON(breakpoints)(points));\n"],"names":["listOfSupportedUnits","listOfSupportedDirections","sanitize","inBreakpoints","Object","keys","reduce","breakpoints","breakpointName","breakpoint","Array","isArray","length","supposedUnit","supposedDirection","supposedMin","supposedMax","options","rest","slice","error","Error","console","direction","unit","min","Math","max","includes","Infinity","defaultBreakpoints","xs","sm","md","lg","xl","BreakpointsContext","React","createContext","BreakpointsProvider","_ref","_ref$breakpoints","_ref$additionalBreakp","additionalBreakpoints","children","Provider","value","_extends","displayName","fromBreakpointToMedia","mediaList","minValue","maxValue","push","str","join","useMediaQuery","mediaQuery","mediaQueryList","useMemo","matchMedia","_React$useState","useState","matches","isShown","setIsShown","useLayoutEffect","listener","event","addListener","removeListener","useBreakpoint","on","useContext","toMediaQuery","rawBreakpointNames","split","map","filter","Boolean","isUniqBreakpoint","mediaQueryBuilder","Only","as","props","_objectWithoutPropertiesLoose","_excluded","matchOn","matchQuery","createElement","Fragment","undefined","toJSON","points","css","forEach","point","stringify","object","string","entries","key","toCSS"],"mappings":"gPAiBA,IAAMA,EAAgC,CACpC,KACA,KACA,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,MACA,KACA,KACA,OACA,QAKIC,EAA0C,CAAC,QAAS,UAiB7CC,EAAW,SAACC,GACvB,OAAOC,OAAOC,KAAKF,GAAeG,OAAoB,SAACC,EAAaC,GAClE,IAAMC,EAAaN,EAAcK,GAEjC,IAAKE,MAAMC,QAAQF,IAAeA,EAAWG,QAAU,EACrD,OAAOL,EAGT,IAUIM,EACAC,EAXGC,EAA8CN,EAAU,GAA3CO,EAAiCP,EAApBQ,GAAAA,EAAoBR,EAAU,GAAlBS,EAAQT,EAAUU,SAC/D,GAAID,EAAKN,OAAS,EAAG,CACnB,IAAMQ,EAAQ,IAAIC,MAA+BH,yBAAAA,EAAyB,uBAC1EI,QAAQF,MAAMA,EAChB,CAEA,GAA2B,iBAAhBL,GAAmD,iBAAhBC,EAC5C,OAAOT,EAKc,iBAAZU,EACTJ,EAAeI,EACa,iBAAZA,IAChBH,EAAoBG,EAAQM,UAC5BV,EAAeI,EAAQO,MAGzB,IAAMC,EAAMC,KAAKD,IAAIV,EAAaC,GAC5BW,EAAMD,KAAKC,IAAIZ,EAAaC,GAC5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GAAWC,EAMpBnD,EAAMoD,cAEXN,GAAM9C,EAAMqD,SACZP,EAAMC,OAAuBO,EAC7B/C,GAPO,IASX,CAEAsC,EAAKlC,YAAc,OCnBN,IAAA4C,EACX,SAACrF,GAAwB,gBACxBsF,GACC,IAAMC,EAAe,CAAE,EAQvB,OAPA1F,OAAOC,KAAKwF,GAAQE,QAAQ,SAACC,GAC3B,IAAMvF,EAAaF,EAAYyF,GAC/B,IAAKvF,EACH,MAAU,IAAAY,MAAS2E,wDAA2D5F,OAAOC,KAAKE,IAE5FuF,EAAc7C,UAAAA,EAAsBxC,IAAiBoF,EAAOG,EAC9D,GACOF,CACT,CAAC,EAEGG,EAAY,SAACC,GACjB,IAAIC,EAAS,GAQb,OAPA/F,OAAOgG,QAAQF,GAAQH,QAAQ,SAAAvD,GAAiB,IAAf6D,EAAG7D,EAAEM,GAAAA,EAAKN,EAAA,GAKzC2D,GAJqB,iBAAVrD,EAIEuD,EAAG,OAAOJ,EAAUnD,GACnC,MAJiBuD,EAAG,KAAKvD,EAAU,KAInC,GACOqD,CACT,EAEaG,EACX,SAAC/F,GAAwB,gBACxBsF,GAAc,OACbI,EAAUL,EAAOrF,EAAPqF,CAAoBC,GAAQ,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import*as n from"react";function
|
|
1
|
+
import*as n from"react";function r(){return r=Object.assign?Object.assign.bind():function(n){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var t in e)({}).hasOwnProperty.call(e,t)&&(n[t]=e[t])}return n},r.apply(null,arguments)}var e=["em","ex","%","px","cm","mm","in","pt","pc","ch","rem","vh","vw","vmin","vmax"],t=["width","height"],i=function(n){return Object.keys(n).reduce(function(r,i){var o=n[i];if(!Array.isArray(o)||o.length<=1)return r;var a,u,c=o[0],f=o[1],s=o[2],l=o.slice(3);if(l.length>0){var v=new Error('The following fields "'+l+'" have been ignored');console.error(v)}if("number"!=typeof c||"number"!=typeof f)return r;"string"==typeof s?a=s:"object"==typeof s&&(u=s.direction,a=s.unit);var m=Math.min(c,f),d=Math.max(c,f),p=a&&e.includes(a)?a:"px",h=u&&t.includes(u)?u:"width";return r[i]=[m,d,p,h],r[i+"Up"]=[m,Infinity,p,h],r[i+"Down"]=[0,d,p,h],r},{})},o={xs:[0,575,"px"],sm:[576,767,"px"],md:[768,991,"px"],lg:[992,1199,"px"],xl:[1200,Infinity,"px"]},a=n.createContext(i(o)),u=function(e){var t=e.breakpoints,u=e.additionalBreakpoints,c=e.children;return n.createElement(a.Provider,{value:i(r({},void 0===t?o:t,void 0===u?{}:u))},c)};u.displayName="BreakpointsProvider";var c=function(n){var r=[],e=n[0],t=n[1],i=n[2],o=n[3];return 0!==e&&r.push("(min-"+o+":"+e+i+")"),Infinity!==t&&r.push("(max-"+o+":"+t+i+")")," "+r.join(" and ")},f=function(r){var e=n.useMemo(function(){return matchMedia(r)},[r]),t=n.useState(e.matches),i=t[0],o=t[1];return n.useLayoutEffect(function(){o(e.matches);var n=function(n){o(n.matches)};return e.addListener(n),function(){e.removeListener(n)}},[e]),i},s=function(r){var e=n.useContext(a),t=n.useMemo(function(){return function(n){return function(r){if(void 0===r&&(r=""),!r)return"";var e=r.split(" "),t=e.map(function(r){return n[r]}).filter(Boolean).map(function(n){return c(n)}).filter(Boolean).join(",");if(!t){var i=1===e.length;console.error('"'+e.join('", "')+'" '+(i?"is":"are")+"n't "+(i?"a ":"")+"valid breakpoint"+(i?"":"s"))}return t}}(e)},[e]),i=n.useMemo(function(){return t(r)},[t,r]);return f(i||"-")},l=["matchMedia","on","as","children"];function v(r){var e=r.matchMedia,t=r.on,i=r.as,o=r.children,a=function(n,r){if(null==n)return{};var e={};for(var t in n)if({}.hasOwnProperty.call(n,t)){if(r.includes(t))continue;e[t]=n[t]}return e}(r,l),u=s(t),c=f(e||"-");return u||c?n.createElement(i||n.Fragment,i?a:void 0,o):null}v.displayName="Only";var m=function(n){return function(r){var e={};return Object.keys(r).forEach(function(t){var i=n[t];if(!i)throw new Error(t+" is not a valid breakpoint\nValid breakpoints are: "+Object.keys(n));e["@media "+c(i)]=r[t]}),e}},d=function(n){var r="";return Object.entries(n).forEach(function(n){var e=n[0],t=n[1];r+="object"==typeof t?e+" {\n"+d(t)+"}\n":e+": "+t+";\n"}),r},p=function(n){return function(r){return d(m(n)(r))}};export{a as BreakpointsContext,u as BreakpointsProvider,v as Only,p as toCSS,m as toJSON,s as useBreakpoint,f as useMediaQuery};
|
|
2
2
|
//# sourceMappingURL=react-responsive.modern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-responsive.modern.mjs","sources":["../src/sanitize.ts","../src/BreakpointsContext.tsx","../src/fromBreakpointToMedia.ts","../src/useMediaQuery.ts","../src/useBreakpoint.ts","../src/mediaQueryBuilder.ts","../src/Only.tsx","../src/css-in-js.ts"],"sourcesContent":["export type Units =\n | \"em\"\n | \"ex\"\n | \"%\"\n | \"px\"\n | \"cm\"\n | \"mm\"\n | \"in\"\n | \"pt\"\n | \"pc\"\n | \"ch\"\n | \"rem\"\n | \"vh\"\n | \"vw\"\n | \"vmin\"\n | \"vmax\";\n\nconst listOfSupportedUnits: Units[] = [\n \"em\",\n \"ex\",\n \"%\",\n \"px\",\n \"cm\",\n \"mm\",\n \"in\",\n \"pt\",\n \"pc\",\n \"ch\",\n \"rem\",\n \"vh\",\n \"vw\",\n \"vmin\",\n \"vmax\",\n];\n\ntype Directions = \"width\" | \"height\";\n\nconst listOfSupportedDirections: Directions[] = [\"width\", \"height\"];\n\nexport type ExposedBreakpoint =\n | [number, number]\n | [number, number, Units]\n | [number, number, { unit?: Units; direction?: Directions }];\n\nexport interface ExposedBreakpoints {\n [key: string]: ExposedBreakpoint;\n}\n\nexport type Breakpoint = [number, number, Units, Directions];\n\nexport interface Breakpoints {\n [breakpoint: string]: Breakpoint;\n}\n\nexport const sanitize = (inBreakpoints: ExposedBreakpoints): Breakpoints => {\n return Object.keys(inBreakpoints).reduce<Breakpoints>((breakpoints, breakpointName) => {\n const breakpoint = inBreakpoints[breakpointName];\n\n if (!Array.isArray(breakpoint) || breakpoint.length <= 1) {\n return breakpoints;\n }\n\n const [supposedMin, supposedMax, options, ...rest] = breakpoint;\n if (rest.length > 0) {\n const error = new Error(`The following fields \"${rest}\" have been ignored`);\n console.error(error);\n }\n\n if (typeof supposedMin !== \"number\" || typeof supposedMax !== \"number\") {\n return breakpoints;\n }\n\n let supposedUnit: Units | undefined;\n let supposedDirection: Directions | undefined;\n if (typeof options === \"string\") {\n supposedUnit = options;\n } else if (typeof options === \"object\") {\n supposedDirection = options.direction;\n supposedUnit = options.unit;\n }\n\n const min = Math.min(supposedMin, supposedMax);\n const max = Math.max(supposedMin, supposedMax);\n const unit = supposedUnit && listOfSupportedUnits.includes(supposedUnit) ? supposedUnit : \"px\";\n const direction =\n supposedDirection && listOfSupportedDirections.includes(supposedDirection) ? supposedDirection : \"width\";\n\n breakpoints[breakpointName] = [min, max, unit, direction];\n breakpoints[`${breakpointName}Up`] = [min, Infinity, unit, direction];\n breakpoints[`${breakpointName}Down`] = [0, max, unit, direction];\n\n return breakpoints;\n }, {});\n};\n","import * as React from \"react\";\n\nimport { sanitize, ExposedBreakpoints, Breakpoints } from \"./sanitize\";\n\nconst defaultBreakpoints: ExposedBreakpoints = {\n xs: [0, 575, \"px\"], // Extra small devices (portrait phones)\n sm: [576, 767, \"px\"], // Small devices (landscape phones)\n md: [768, 991, \"px\"], // Medium devices (tablets)\n lg: [992, 1199, \"px\"], // Large devices (desktops)\n xl: [1200, Infinity, \"px\"], // Extra large devices (large desktops)\n};\n\nexport const BreakpointsContext = React.createContext<Breakpoints>(sanitize(defaultBreakpoints));\n\ninterface BreakpointsProviderProps {\n breakpoints?: ExposedBreakpoints;\n additionalBreakpoints?: ExposedBreakpoints;\n}\n\nexport const BreakpointsProvider: React.FunctionComponent<React.PropsWithChildren<BreakpointsProviderProps>> = ({\n breakpoints = defaultBreakpoints,\n additionalBreakpoints = {},\n children,\n}) => {\n return (\n <BreakpointsContext.Provider\n value={sanitize({\n ...breakpoints,\n ...additionalBreakpoints,\n })}\n >\n {children}\n </BreakpointsContext.Provider>\n );\n};\n\nBreakpointsProvider.displayName = \"BreakpointsProvider\";\n","import { Breakpoint } from \"./sanitize\";\n\nexport const fromBreakpointToMedia = (breakpoint: Breakpoint): string => {\n const mediaList: string[] = [];\n const [minValue, maxValue, unit, direction] = breakpoint;\n let str;\n\n // Min value\n if (minValue !== 0) {\n str = `${minValue}${unit}`;\n mediaList.push(`(min-${direction}:${str})`);\n }\n\n // Max value\n if (maxValue !== Infinity) {\n str = `${maxValue}${unit}`;\n mediaList.push(`(max-${direction}:${str})`);\n }\n\n return \" \" + mediaList.join(\" and \");\n};\n","import * as React from \"react\";\n\n// const startTransitionFallbackForReact17AndBellow = (cb: () => void) => cb();\n// // @ts-expect-error not supported yet\n// const startTransition = React.startTransition || startTransitionFallbackForReact17AndBellow;\n\nexport const useMediaQuery = (mediaQuery: string): boolean => {\n const mediaQueryList = React.useMemo(() => matchMedia(mediaQuery), [mediaQuery]);\n const [isShown, setIsShown] = React.useState<boolean>(mediaQueryList.matches);\n\n React.useLayoutEffect(() => {\n setIsShown(mediaQueryList.matches);\n const listener = (event: MediaQueryListEvent) => {\n // We use startTransition as those update aren't urgent\n // startTransition(() => {\n setIsShown(event.matches);\n // });\n };\n\n // cannot use addEventListener for IE 11 and safari 13-\n mediaQueryList.addListener(listener);\n return () => {\n mediaQueryList.removeListener(listener);\n };\n }, [mediaQueryList]);\n\n return isShown;\n};\n","import * as React from \"react\";\n\nimport { BreakpointsContext } from \"./BreakpointsContext\";\n\nimport { mediaQueryBuilder } from \"./mediaQueryBuilder\";\n\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport const useBreakpoint = (on?: string): boolean => {\n const breakpoints = React.useContext(BreakpointsContext);\n const toMediaQuery = React.useMemo(() => mediaQueryBuilder(breakpoints), [breakpoints]);\n\n const mediaQuery = React.useMemo(() => toMediaQuery(on), [toMediaQuery, on]);\n\n return useMediaQuery(mediaQuery || \"-\");\n};\n","import { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\nexport const mediaQueryBuilder =\n (breakpoints: Breakpoints) =>\n (on = \"\"): string => {\n if (!on) {\n return \"\";\n }\n const rawBreakpointNames = on.split(\" \");\n const filteredBreakpoints = rawBreakpointNames.map((breakpointName) => breakpoints[breakpointName]).filter(Boolean);\n const mediaQuery = filteredBreakpoints\n .map((breakpoint) => fromBreakpointToMedia(breakpoint))\n .filter(Boolean)\n .join(\",\");\n if (!mediaQuery) {\n const isUniqBreakpoint = rawBreakpointNames.length === 1;\n console.error(\n `\"${rawBreakpointNames.join('\", \"')}\" ${isUniqBreakpoint ? \"is\" : \"are\"}n't ${\n isUniqBreakpoint ? \"a \" : \"\"\n }valid breakpoint${isUniqBreakpoint ? \"\" : \"s\"}`,\n );\n }\n return mediaQuery;\n };\n","import * as React from \"react\";\n\nimport { useBreakpoint } from \"./useBreakpoint\";\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport type OnlyProps<OtherProps = Record<string, never>> = OtherProps & {\n matchMedia?: string;\n on?: string;\n as?: string | React.ComponentType<OtherProps>;\n};\n\nexport function Only<OtherProps = Record<string, never>>({\n matchMedia,\n on,\n as,\n children,\n ...props\n}: React.PropsWithChildren<OnlyProps<OtherProps>>): React.ReactElement | null {\n const matchOn = useBreakpoint(on);\n const matchQuery = useMediaQuery(matchMedia || \"-\");\n const isShown = matchOn || matchQuery;\n\n if (!isShown) {\n return null;\n }\n\n return React.createElement(\n // @ts-expect-error – this is a complex type\n as || React.Fragment,\n as ? (props as OtherProps) : undefined,\n children,\n );\n}\n\nOnly.displayName = \"Only\";\n","import { CSSProperties } from \"react\";\nimport { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\ntype CSSinJSProperties =\n | CSSProperties\n | {\n [key: string]: CSSProperties;\n };\n\ninterface Points {\n [breakpoint: string]: CSSinJSProperties;\n}\n\ntype CSSinJS = Record<string, CSSinJSProperties>;\nexport const toJSON =\n (breakpoints: Breakpoints) =>\n (points: Points): CSSinJS => {\n const css: CSSinJS = {};\n Object.keys(points).forEach((point) => {\n const breakpoint = breakpoints[point];\n if (!breakpoint) {\n throw new Error(`${point} is not a valid breakpoint\\nValid breakpoints are: ${Object.keys(breakpoints)}`);\n }\n css[`@media ${fromBreakpointToMedia(breakpoint)}`] = points[point];\n });\n return css;\n };\n\nconst stringify = (object: CSSinJSProperties) => {\n let string = \"\";\n Object.entries(object).forEach(([key, value]) => {\n if (typeof value !== \"object\") {\n string += `${key}: ${value};\\n`;\n return;\n }\n string += `${key} {\\n${stringify(value)}}\\n`;\n });\n return string;\n};\n\nexport const toCSS =\n (breakpoints: Breakpoints) =>\n (points: Points): string =>\n stringify(toJSON(breakpoints)(points));\n"],"names":["listOfSupportedUnits","listOfSupportedDirections","sanitize","inBreakpoints","Object","keys","reduce","breakpoints","breakpointName","breakpoint","Array","isArray","length","supposedMin","supposedMax","options","rest","error","Error","console","supposedUnit","supposedDirection","direction","unit","min","Math","max","includes","Infinity","defaultBreakpoints","xs","sm","md","lg","xl","BreakpointsContext","React","createContext","BreakpointsProvider","additionalBreakpoints","children","Provider","value","_extends","displayName","fromBreakpointToMedia","mediaList","minValue","maxValue","str","push","join","useMediaQuery","mediaQuery","mediaQueryList","useMemo","matchMedia","isShown","setIsShown","useState","matches","useLayoutEffect","listener","event","addListener","removeListener","useBreakpoint","on","useContext","toMediaQuery","rawBreakpointNames","split","map","filter","Boolean","isUniqBreakpoint","mediaQueryBuilder","Only","_ref","as","props","_objectWithoutPropertiesLoose","_excluded","matchOn","matchQuery","createElement","Fragment","undefined","toJSON","points","css","forEach","point","stringify","object","string","entries","key","toCSS"],"mappings":"gPAiBA,MAAMA,EAAgC,CACpC,KACA,KACA,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,MACA,KACA,KACA,OACA,QAKIC,EAA0C,CAAC,Q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,EAAcC,GAAc,IAAG,wCEHxB,SAAAwB,EAAIC,GAAqC,IAAAtB,WACvDA,EAAUW,GACVA,EAAEY,GACFA,EAAEvC,SACFA,GAE+CsC,EAD5CE,yIAAKC,CAAAH,EAAAI,GAER,MAAMC,EAAUjB,EAAcC,GACxBiB,EAAahC,EAAcI,GAAc,KAG/C,OAFgB2B,GAAWC,EAMpBhD,EAAMiD,cAEXN,GAAM3C,EAAMkD,SACZP,EAAMC,OAAuBO,EAC7B/C,GAPO,IASX,CAEAqC,EAAKjC,YAAc,OCnBN,MAAA4C,EACVjF,GACAkF,IACC,MAAMC,EAAe,GAQrB,OAPAtF,OAAOC,KAAKoF,GAAQE,QAASC,IAC3B,MAAMnF,EAAaF,EAAYqF,GAC/B,IAAKnF,EACH,MAAM,IAAIS,MAAM,GAAG0E,uDAA2DxF,OAAOC,KAAKE,MAE5FmF,EAAI,UAAU7C,EAAsBpC,MAAiBgF,EAAOG,EAAK,GAE5DF,GAGLG,EAAaC,IACjB,IAAIC,EAAS,GAQb,OAPA3F,OAAO4F,QAAQF,GAAQH,QAAQ,EAAEM,EAAKvD,MAKpCqD,GAJqB,iBAAVrD,EAID,GAAGuD,QAAUJ,EAAUnD,QAHrB,GAAGuD,MAAQvD,SAKlBqD,GAGIG,EACV3F,GACAkF,GACCI,EAAUL,EAAOjF,EAAPiF,CAAoBC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e||self)["@blocz/react-responsive"]={},e.React)}(this,function(e,n){function r(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,t.get?t:{enumerable:!0,get:function(){return e[r]}})}}),n.default=e,n}var t=/*#__PURE__*/r(n);function i(){return i=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e||self)["@blocz/react-responsive"]={},e.React)}(this,function(e,n){function r(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,t.get?t:{enumerable:!0,get:function(){return e[r]}})}}),n.default=e,n}var t=/*#__PURE__*/r(n);function i(){return i=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)({}).hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},i.apply(null,arguments)}var o=["em","ex","%","px","cm","mm","in","pt","pc","ch","rem","vh","vw","vmin","vmax"],a=["width","height"],u=function(e){return Object.keys(e).reduce(function(n,r){var t=e[r];if(!Array.isArray(t)||t.length<=1)return n;var i,u,c=t[0],f=t[1],s=t[2],l=t.slice(3);if(l.length>0){var d=new Error('The following fields "'+l+'" have been ignored');console.error(d)}if("number"!=typeof c||"number"!=typeof f)return n;"string"==typeof s?i=s:"object"==typeof s&&(u=s.direction,i=s.unit);var p=Math.min(c,f),v=Math.max(c,f),m=i&&o.includes(i)?i:"px",h=u&&a.includes(u)?u:"width";return n[r]=[p,v,m,h],n[r+"Up"]=[p,Infinity,m,h],n[r+"Down"]=[0,v,m,h],n},{})},c={xs:[0,575,"px"],sm:[576,767,"px"],md:[768,991,"px"],lg:[992,1199,"px"],xl:[1200,Infinity,"px"]},f=t.createContext(u(c)),s=function(e){var n=e.breakpoints,r=e.additionalBreakpoints,o=e.children;return t.createElement(f.Provider,{value:u(i({},void 0===n?c:n,void 0===r?{}:r))},o)};s.displayName="BreakpointsProvider";var l=function(e){var n=[],r=e[0],t=e[1],i=e[2],o=e[3];return 0!==r&&n.push("(min-"+o+":"+r+i+")"),Infinity!==t&&n.push("(max-"+o+":"+t+i+")")," "+n.join(" and ")},d=function(e){var n=t.useMemo(function(){return matchMedia(e)},[e]),r=t.useState(n.matches),i=r[0],o=r[1];return t.useLayoutEffect(function(){o(n.matches);var e=function(e){o(e.matches)};return n.addListener(e),function(){n.removeListener(e)}},[n]),i},p=function(e){var n=t.useContext(f),r=t.useMemo(function(){return function(e){return function(n){if(void 0===n&&(n=""),!n)return"";var r=n.split(" "),t=r.map(function(n){return e[n]}).filter(Boolean).map(function(e){return l(e)}).filter(Boolean).join(",");if(!t){var i=1===r.length;console.error('"'+r.join('", "')+'" '+(i?"is":"are")+"n't "+(i?"a ":"")+"valid breakpoint"+(i?"":"s"))}return t}}(n)},[n]),i=t.useMemo(function(){return r(e)},[r,e]);return d(i||"-")},v=["matchMedia","on","as","children"];function m(e){var n=e.matchMedia,r=e.on,i=e.as,o=e.children,a=function(e,n){if(null==e)return{};var r={};for(var t in e)if({}.hasOwnProperty.call(e,t)){if(n.includes(t))continue;r[t]=e[t]}return r}(e,v),u=p(r),c=d(n||"-");return u||c?t.createElement(i||t.Fragment,i?a:void 0,o):null}m.displayName="Only";var h=function(e){return function(n){var r={};return Object.keys(n).forEach(function(t){var i=e[t];if(!i)throw new Error(t+" is not a valid breakpoint\nValid breakpoints are: "+Object.keys(e));r["@media "+l(i)]=n[t]}),r}},y=function(e){var n="";return Object.entries(e).forEach(function(e){var r=e[0],t=e[1];n+="object"==typeof t?r+" {\n"+y(t)+"}\n":r+": "+t+";\n"}),n};e.BreakpointsContext=f,e.BreakpointsProvider=s,e.Only=m,e.toCSS=function(e){return function(n){return y(h(e)(n))}},e.toJSON=h,e.useBreakpoint=p,e.useMediaQuery=d});
|
|
2
2
|
//# sourceMappingURL=react-responsive.umd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-responsive.umd.js","sources":["../src/sanitize.ts","../src/BreakpointsContext.tsx","../src/fromBreakpointToMedia.ts","../src/useMediaQuery.ts","../src/useBreakpoint.ts","../src/mediaQueryBuilder.ts","../src/Only.tsx","../src/Match.tsx","../src/css-in-js.ts"],"sourcesContent":["export type Units =\n | \"em\"\n | \"ex\"\n | \"%\"\n | \"px\"\n | \"cm\"\n | \"mm\"\n | \"in\"\n | \"pt\"\n | \"pc\"\n | \"ch\"\n | \"rem\"\n | \"vh\"\n | \"vw\"\n | \"vmin\"\n | \"vmax\";\n\nconst listOfSupportedUnits: Units[] = [\n \"em\",\n \"ex\",\n \"%\",\n \"px\",\n \"cm\",\n \"mm\",\n \"in\",\n \"pt\",\n \"pc\",\n \"ch\",\n \"rem\",\n \"vh\",\n \"vw\",\n \"vmin\",\n \"vmax\",\n];\n\ntype Directions = \"width\" | \"height\";\n\nconst listOfSupportedDirections: Directions[] = [\"width\", \"height\"];\n\nexport type ExposedBreakpoint =\n | [number, number]\n | [number, number, Units]\n | [number, number, { unit?: Units; direction?: Directions }];\n\nexport interface ExposedBreakpoints {\n [key: string]: ExposedBreakpoint;\n}\n\nexport type Breakpoint = [number, number, Units, Directions];\n\nexport interface Breakpoints {\n [breakpoint: string]: Breakpoint;\n}\n\nexport const sanitize = (inBreakpoints: ExposedBreakpoints): Breakpoints => {\n return Object.keys(inBreakpoints).reduce<Breakpoints>((breakpoints, breakpointName) => {\n const breakpoint = inBreakpoints[breakpointName];\n\n if (!Array.isArray(breakpoint) || breakpoint.length <= 1) {\n return breakpoints;\n }\n\n const [supposedMin, supposedMax, options, ...rest] = breakpoint;\n if (rest.length > 0) {\n const error = new Error(`The following fields \"${rest}\" have been ignored`);\n console.error(error);\n }\n\n if (typeof supposedMin !== \"number\" || typeof supposedMax !== \"number\") {\n return breakpoints;\n }\n\n let supposedUnit: Units | undefined;\n let supposedDirection: Directions | undefined;\n if (typeof options === \"string\") {\n supposedUnit = options;\n } else if (typeof options === \"object\") {\n supposedDirection = options.direction;\n supposedUnit = options.unit;\n }\n\n const min = Math.min(supposedMin, supposedMax);\n const max = Math.max(supposedMin, supposedMax);\n const unit = supposedUnit && listOfSupportedUnits.includes(supposedUnit) ? supposedUnit : \"px\";\n const direction =\n supposedDirection && listOfSupportedDirections.includes(supposedDirection) ? supposedDirection : \"width\";\n\n breakpoints[breakpointName] = [min, max, unit, direction];\n breakpoints[`${breakpointName}Up`] = [min, Infinity, unit, direction];\n breakpoints[`${breakpointName}Down`] = [0, max, unit, direction];\n\n return breakpoints;\n }, {});\n};\n","import * as React from \"react\";\n\nimport { sanitize, ExposedBreakpoints, Breakpoints } from \"./sanitize\";\n\nconst defaultBreakpoints: ExposedBreakpoints = {\n xs: [0, 575, \"px\"], // Extra small devices (portrait phones)\n sm: [576, 767, \"px\"], // Small devices (landscape phones)\n md: [768, 991, \"px\"], // Medium devices (tablets)\n lg: [992, 1199, \"px\"], // Large devices (desktops)\n xl: [1200, Infinity, \"px\"], // Extra large devices (large desktops)\n};\n\nexport const BreakpointsContext = React.createContext<Breakpoints>(sanitize(defaultBreakpoints));\n\ninterface BreakpointsProviderProps {\n breakpoints?: ExposedBreakpoints;\n additionalBreakpoints?: ExposedBreakpoints;\n}\n\nexport const BreakpointsProvider: React.FunctionComponent<React.PropsWithChildren<BreakpointsProviderProps>> = ({\n breakpoints = defaultBreakpoints,\n additionalBreakpoints = {},\n children,\n}) => {\n return (\n <BreakpointsContext.Provider\n value={sanitize({\n ...breakpoints,\n ...additionalBreakpoints,\n })}\n >\n {children}\n </BreakpointsContext.Provider>\n );\n};\n\nBreakpointsProvider.displayName = \"BreakpointsProvider\";\n","import { Breakpoint } from \"./sanitize\";\n\nexport const fromBreakpointToMedia = (breakpoint: Breakpoint): string => {\n const mediaList: string[] = [];\n const [minValue, maxValue, unit, direction] = breakpoint;\n let str;\n\n // Min value\n if (minValue !== 0) {\n str = `${minValue}${unit}`;\n mediaList.push(`(min-${direction}:${str})`);\n }\n\n // Max value\n if (maxValue !== Infinity) {\n str = `${maxValue}${unit}`;\n mediaList.push(`(max-${direction}:${str})`);\n }\n\n return \" \" + mediaList.join(\" and \");\n};\n","import * as React from \"react\";\n\n// const startTransitionFallbackForReact17AndBellow = (cb: () => void) => cb();\n// // @ts-expect-error not supported yet\n// const startTransition = React.startTransition || startTransitionFallbackForReact17AndBellow;\n\nexport const useMediaQuery = (mediaQuery: string): boolean => {\n const mediaQueryList = React.useMemo(() => matchMedia(mediaQuery), [mediaQuery]);\n const [isShown, setIsShown] = React.useState<boolean>(mediaQueryList.matches);\n\n React.useLayoutEffect(() => {\n setIsShown(mediaQueryList.matches);\n const listener = (event: MediaQueryListEvent) => {\n // We use startTransition as those update aren't urgent\n // startTransition(() => {\n setIsShown(event.matches);\n // });\n };\n\n // cannot use addEventListener for IE 11 and safari 13-\n mediaQueryList.addListener(listener);\n return () => {\n mediaQueryList.removeListener(listener);\n };\n }, [mediaQueryList]);\n\n return isShown;\n};\n","import * as React from \"react\";\n\nimport { BreakpointsContext } from \"./BreakpointsContext\";\n\nimport { mediaQueryBuilder } from \"./mediaQueryBuilder\";\n\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport const useBreakpoint = (on?: string): boolean => {\n const breakpoints = React.useContext(BreakpointsContext);\n const toMediaQuery = React.useMemo(() => mediaQueryBuilder(breakpoints), [breakpoints]);\n\n const mediaQuery = React.useMemo(() => toMediaQuery(on), [toMediaQuery, on]);\n\n return useMediaQuery(mediaQuery || \"-\");\n};\n","import { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\nexport const mediaQueryBuilder =\n (breakpoints: Breakpoints) =>\n (on = \"\"): string => {\n if (!on) {\n return \"\";\n }\n const rawBreakpointNames = on.split(\" \");\n const filteredBreakpoints = rawBreakpointNames.map((breakpointName) => breakpoints[breakpointName]).filter(Boolean);\n const mediaQuery = filteredBreakpoints\n .map((breakpoint) => fromBreakpointToMedia(breakpoint))\n .filter(Boolean)\n .join(\",\");\n if (!mediaQuery) {\n const isUniqBreakpoint = rawBreakpointNames.length === 1;\n console.error(\n `\"${rawBreakpointNames.join('\", \"')}\" ${isUniqBreakpoint ? \"is\" : \"are\"}n't ${\n isUniqBreakpoint ? \"a \" : \"\"\n }valid breakpoint${isUniqBreakpoint ? \"\" : \"s\"}`,\n );\n }\n return mediaQuery;\n };\n","import * as React from \"react\";\n\nimport { useBreakpoint } from \"./useBreakpoint\";\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport type OnlyProps<OtherProps = Record<string, never>> = OtherProps & {\n matchMedia?: string;\n on?: string;\n as?: string | React.ComponentType<OtherProps>;\n};\n\nexport function Only<OtherProps = Record<string, never>>({\n matchMedia,\n on,\n as,\n children,\n ...props\n}: React.PropsWithChildren<OnlyProps<OtherProps>>): React.ReactElement | null {\n const matchOn = useBreakpoint(on);\n const matchQuery = useMediaQuery(matchMedia || \"-\");\n const isShown = matchOn || matchQuery;\n\n if (!isShown) {\n return null;\n }\n\n return React.createElement(as || React.Fragment, as ? (props as OtherProps) : undefined, children);\n}\n\nOnly.displayName = \"Only\";\n","import * as React from \"react\";\n\nimport { Only } from \"./Only\";\n\nexport interface MatchChildProps {\n matchMedia?: string;\n only?: string;\n}\n\ndeclare module \"react\" {\n interface HTMLAttributes<T> extends React.AriaAttributes, React.DOMAttributes<T>, MatchChildProps {}\n}\n\ntype Element = React.ReactElement<MatchChildProps & any, string | React.ComponentType<MatchChildProps & any>> | null;\n\nconst parseChildren = (element: Element): Element => {\n if (!element || !element.props) {\n return element;\n }\n\n const _children: Element | Element[] | null = element.props.children;\n if (!_children) {\n return null;\n }\n const children = React.Children.map(_children, parseChildren);\n const { only, matchMedia, ...props } = element.props;\n const clone = React.createElement(element.type, props, children);\n if (!only && !matchMedia) {\n return clone;\n }\n return (\n <Only on={only || \"\"} matchMedia={matchMedia || \"\"}>\n {clone}\n </Only>\n );\n};\n\ninterface MatchProps {\n [key: string]: any;\n children: Element | Element[] | null;\n as?: string;\n}\n\nexport const Match: React.FunctionComponent<MatchProps> = ({ children, as, ...props }) => {\n const computedChildren = React.Children.map(children, parseChildren);\n if (as) {\n return React.createElement(as, props, computedChildren);\n }\n return React.createElement(React.Fragment, null, computedChildren);\n};\n\nMatch.displayName = \"Match\";\n","import { CSSProperties } from \"react\";\nimport { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\ntype CSSinJSProperties =\n | CSSProperties\n | {\n [key: string]: CSSProperties;\n };\n\ninterface Points {\n [breakpoint: string]: CSSinJSProperties;\n}\n\ntype CSSinJS = Record<string, CSSinJSProperties>;\nexport const toJSON =\n (breakpoints: Breakpoints) =>\n (points: Points): CSSinJS => {\n const css: CSSinJS = {};\n Object.keys(points).forEach((point) => {\n const breakpoint = breakpoints[point];\n if (!breakpoint) {\n throw new Error(`${point} is not a valid breakpoint\\nValid breakpoints are: ${Object.keys(breakpoints)}`);\n }\n css[`@media ${fromBreakpointToMedia(breakpoint)}`] = points[point];\n });\n return css;\n };\n\nconst stringify = (object: CSSinJSProperties) => {\n let string = \"\";\n Object.entries(object).forEach(([key, value]) => {\n if (typeof value !== \"object\") {\n string += `${key}: ${value};\\n`;\n return;\n }\n string += `${key} {\\n${stringify(value)}}\\n`;\n });\n return string;\n};\n\nexport const toCSS =\n (breakpoints: Breakpoints) =>\n (points: Points): string =>\n stringify(toJSON(breakpoints)(points));\n"],"names":["listOfSupportedUnits","listOfSupportedDirections","sanitize","inBreakpoints","Object","keys","reduce","breakpoints","breakpointName","Array","isArray","breakpoint","length","supposedUnit","supposedDirection","supposedMax","options","rest","slice","error","Error","console","supposedMin","direction","unit","min","Math","max","includes","Infinity","defaultBreakpoints","xs","sm","md","lg","xl","BreakpointsContext","React","createContext","BreakpointsProvider","_ref","additionalBreakpoints","children","Provider","value","_ref$additionalBreakp","displayName","fromBreakpointToMedia","mediaList","minValue","maxValue","push","str","join","useMediaQuery","mediaQuery","mediaQueryList","useMemo","matchMedia","_React$useState","useState","matches","isShown","setIsShown","useLayoutEffect","listener","event","addListener","removeListener","on","useContext","toMediaQuery","rawBreakpointNames","split","map","filter","Boolean","isUniqBreakpoint","Only","as","props","matchOn","useBreakpoint","matchQuery","createElement","Fragment","undefined","parseChildren","element","_children","Children","only","_objectWithoutPropertiesLoose","_element$props","_excluded","type","clone","_excluded2","computedChildren","Match","toJSON","points","css","forEach","point","stringify","object","string","entries","key"],"mappings":"q6BAiBA,IAA0BA,EAAY,CACpC,KACA,KACA,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,MACA,KACA,KACA,OACA,QAK6BC,EAAiB,CAAC,QAAS,UAiB7CC,EAAW,SAACC,GACvB,OAAOC,OAAOC,KAAKF,GAAeG,OAAoB,SAACC,EAAaC,GAClE,MAAmBL,EAAcK,GAEjC,IAAKC,MAAMC,QAAQC,IAAeA,EAAWC,QAAU,EACrD,OAAOL,EAGT,IAUIM,EACAC,IAXiDH,EAAjCI,GAAAA,EAAiCJ,EAArD,GAAiCK,EAAoBL,EAARM,GAAAA,EAAQN,EACrDO,MAAA,GAAA,GAAID,EAAKL,OAAS,EAAG,CACnB,IAAWO,EAAG,IAAIC,+BAA+BH,EAAnC,uBACdI,QAAQF,MAAMA,GAGhB,GAA2B,iBAAhBG,GAAmD,iBAAhBP,EAC5C,OACDR,EAIsB,iBAAZS,EACTH,EAAeG,EACa,qBAC5BF,EAAoBE,EAAQO,UAC5BV,EAAeG,EAAQQ,MAGzB,IAAMC,EAAMC,KAAKD,IAAIH,EAAaP,GACzBY,EAAGD,KAAKC,IAAIL,EAAaP,GAC5BS,EAAOX,GAAgBb,EAAqB4B,SAASf,GAAgBA,EAAe,KAC3EU,EACbT,GAAqBb,EAA0B2B,SAASd,GAAqBA,EAAoB,QAMnG,OAJAP,EAAYC,GAAkB,CAACiB,EAAKE,EAAKH,EAAMD,GAC/ChB,EAAeC,EAAJ,MAA0B,CAACiB,EAAKI,SAAUL,EAAMD,GAC3DhB,EAAeC,EAAJ,QAA4B,CAAC,EAAGmB,EAAKH,EAAMD,GAGvDhB,GAAE,KCxFCuB,EAAyC,CAC7CC,GAAI,CAAC,EAAG,IAAK,MACbC,GAAI,CAAC,IAAK,IAAK,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WY,EAAApD,EAAAyD,GACjEC,EAAG7D,EAAMqD,SAAShB,IAAIhC,EAAU6C,GACtD,OAAIR,EACU1C,EAAC+C,cAAcL,EAAIC,EAAOkB,KAE3Bd,cAAc/C,EAAMgD,SAAU,KAAMa,IAGnDC,EAAMrD,YAAc,QCpCPsD,IAAMA,EACjB,SAAC7F,GAAD,OACC8F,SAAAA,GACC,IAASC,EAAY,GAQrB,OAPAlG,OAAOC,KAAKgG,GAAQE,QAAQ,SAACC,GAC3B,IAAM7F,EAAaJ,EAAYiG,GAC/B,IAAK7F,EACH,MAAM,IAAAS,MAAaoF,EAA2DpG,sDAAAA,OAAOC,KAAKE,IAE5F+F,YAAcvD,EAAsBpC,IAAiB0F,EAAOG,KAG/DF,IAEYG,EAAG,SAAAA,EAACC,GACjB,IAAIC,EAAS,GAQb,OAPAvG,OAAOwG,QAAQF,GAAQH,QAAQ,SAAA/D,OAAiBqE,EAAArE,EAAA,GAAVI,EAAUJ,EAAA,GAK9CmE,GAJqB,iBAAV/D,EAIEiE,EAAUJ,OAAAA,EAAU7D,GAClC,MAJgBiE,EAAP,KAAejE,EAArB,QAKG+D,6EAIP,SAACpG,GAAD,OACC8F,SAAAA,UACUI,EAACL,EAAO7F,EAAP6F,CAAoBC"}
|
|
1
|
+
{"version":3,"file":"react-responsive.umd.js","sources":["../src/sanitize.ts","../src/BreakpointsContext.tsx","../src/fromBreakpointToMedia.ts","../src/useMediaQuery.ts","../src/useBreakpoint.ts","../src/mediaQueryBuilder.ts","../src/Only.tsx","../src/css-in-js.ts"],"sourcesContent":["export type Units =\n | \"em\"\n | \"ex\"\n | \"%\"\n | \"px\"\n | \"cm\"\n | \"mm\"\n | \"in\"\n | \"pt\"\n | \"pc\"\n | \"ch\"\n | \"rem\"\n | \"vh\"\n | \"vw\"\n | \"vmin\"\n | \"vmax\";\n\nconst listOfSupportedUnits: Units[] = [\n \"em\",\n \"ex\",\n \"%\",\n \"px\",\n \"cm\",\n \"mm\",\n \"in\",\n \"pt\",\n \"pc\",\n \"ch\",\n \"rem\",\n \"vh\",\n \"vw\",\n \"vmin\",\n \"vmax\",\n];\n\ntype Directions = \"width\" | \"height\";\n\nconst listOfSupportedDirections: Directions[] = [\"width\", \"height\"];\n\nexport type ExposedBreakpoint =\n | [number, number]\n | [number, number, Units]\n | [number, number, { unit?: Units; direction?: Directions }];\n\nexport interface ExposedBreakpoints {\n [key: string]: ExposedBreakpoint;\n}\n\nexport type Breakpoint = [number, number, Units, Directions];\n\nexport interface Breakpoints {\n [breakpoint: string]: Breakpoint;\n}\n\nexport const sanitize = (inBreakpoints: ExposedBreakpoints): Breakpoints => {\n return Object.keys(inBreakpoints).reduce<Breakpoints>((breakpoints, breakpointName) => {\n const breakpoint = inBreakpoints[breakpointName];\n\n if (!Array.isArray(breakpoint) || breakpoint.length <= 1) {\n return breakpoints;\n }\n\n const [supposedMin, supposedMax, options, ...rest] = breakpoint;\n if (rest.length > 0) {\n const error = new Error(`The following fields \"${rest}\" have been ignored`);\n console.error(error);\n }\n\n if (typeof supposedMin !== \"number\" || typeof supposedMax !== \"number\") {\n return breakpoints;\n }\n\n let supposedUnit: Units | undefined;\n let supposedDirection: Directions | undefined;\n if (typeof options === \"string\") {\n supposedUnit = options;\n } else if (typeof options === \"object\") {\n supposedDirection = options.direction;\n supposedUnit = options.unit;\n }\n\n const min = Math.min(supposedMin, supposedMax);\n const max = Math.max(supposedMin, supposedMax);\n const unit = supposedUnit && listOfSupportedUnits.includes(supposedUnit) ? supposedUnit : \"px\";\n const direction =\n supposedDirection && listOfSupportedDirections.includes(supposedDirection) ? supposedDirection : \"width\";\n\n breakpoints[breakpointName] = [min, max, unit, direction];\n breakpoints[`${breakpointName}Up`] = [min, Infinity, unit, direction];\n breakpoints[`${breakpointName}Down`] = [0, max, unit, direction];\n\n return breakpoints;\n }, {});\n};\n","import * as React from \"react\";\n\nimport { sanitize, ExposedBreakpoints, Breakpoints } from \"./sanitize\";\n\nconst defaultBreakpoints: ExposedBreakpoints = {\n xs: [0, 575, \"px\"], // Extra small devices (portrait phones)\n sm: [576, 767, \"px\"], // Small devices (landscape phones)\n md: [768, 991, \"px\"], // Medium devices (tablets)\n lg: [992, 1199, \"px\"], // Large devices (desktops)\n xl: [1200, Infinity, \"px\"], // Extra large devices (large desktops)\n};\n\nexport const BreakpointsContext = React.createContext<Breakpoints>(sanitize(defaultBreakpoints));\n\ninterface BreakpointsProviderProps {\n breakpoints?: ExposedBreakpoints;\n additionalBreakpoints?: ExposedBreakpoints;\n}\n\nexport const BreakpointsProvider: React.FunctionComponent<React.PropsWithChildren<BreakpointsProviderProps>> = ({\n breakpoints = defaultBreakpoints,\n additionalBreakpoints = {},\n children,\n}) => {\n return (\n <BreakpointsContext.Provider\n value={sanitize({\n ...breakpoints,\n ...additionalBreakpoints,\n })}\n >\n {children}\n </BreakpointsContext.Provider>\n );\n};\n\nBreakpointsProvider.displayName = \"BreakpointsProvider\";\n","import { Breakpoint } from \"./sanitize\";\n\nexport const fromBreakpointToMedia = (breakpoint: Breakpoint): string => {\n const mediaList: string[] = [];\n const [minValue, maxValue, unit, direction] = breakpoint;\n let str;\n\n // Min value\n if (minValue !== 0) {\n str = `${minValue}${unit}`;\n mediaList.push(`(min-${direction}:${str})`);\n }\n\n // Max value\n if (maxValue !== Infinity) {\n str = `${maxValue}${unit}`;\n mediaList.push(`(max-${direction}:${str})`);\n }\n\n return \" \" + mediaList.join(\" and \");\n};\n","import * as React from \"react\";\n\n// const startTransitionFallbackForReact17AndBellow = (cb: () => void) => cb();\n// // @ts-expect-error not supported yet\n// const startTransition = React.startTransition || startTransitionFallbackForReact17AndBellow;\n\nexport const useMediaQuery = (mediaQuery: string): boolean => {\n const mediaQueryList = React.useMemo(() => matchMedia(mediaQuery), [mediaQuery]);\n const [isShown, setIsShown] = React.useState<boolean>(mediaQueryList.matches);\n\n React.useLayoutEffect(() => {\n setIsShown(mediaQueryList.matches);\n const listener = (event: MediaQueryListEvent) => {\n // We use startTransition as those update aren't urgent\n // startTransition(() => {\n setIsShown(event.matches);\n // });\n };\n\n // cannot use addEventListener for IE 11 and safari 13-\n mediaQueryList.addListener(listener);\n return () => {\n mediaQueryList.removeListener(listener);\n };\n }, [mediaQueryList]);\n\n return isShown;\n};\n","import * as React from \"react\";\n\nimport { BreakpointsContext } from \"./BreakpointsContext\";\n\nimport { mediaQueryBuilder } from \"./mediaQueryBuilder\";\n\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport const useBreakpoint = (on?: string): boolean => {\n const breakpoints = React.useContext(BreakpointsContext);\n const toMediaQuery = React.useMemo(() => mediaQueryBuilder(breakpoints), [breakpoints]);\n\n const mediaQuery = React.useMemo(() => toMediaQuery(on), [toMediaQuery, on]);\n\n return useMediaQuery(mediaQuery || \"-\");\n};\n","import { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\nexport const mediaQueryBuilder =\n (breakpoints: Breakpoints) =>\n (on = \"\"): string => {\n if (!on) {\n return \"\";\n }\n const rawBreakpointNames = on.split(\" \");\n const filteredBreakpoints = rawBreakpointNames.map((breakpointName) => breakpoints[breakpointName]).filter(Boolean);\n const mediaQuery = filteredBreakpoints\n .map((breakpoint) => fromBreakpointToMedia(breakpoint))\n .filter(Boolean)\n .join(\",\");\n if (!mediaQuery) {\n const isUniqBreakpoint = rawBreakpointNames.length === 1;\n console.error(\n `\"${rawBreakpointNames.join('\", \"')}\" ${isUniqBreakpoint ? \"is\" : \"are\"}n't ${\n isUniqBreakpoint ? \"a \" : \"\"\n }valid breakpoint${isUniqBreakpoint ? \"\" : \"s\"}`,\n );\n }\n return mediaQuery;\n };\n","import * as React from \"react\";\n\nimport { useBreakpoint } from \"./useBreakpoint\";\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport type OnlyProps<OtherProps = Record<string, never>> = OtherProps & {\n matchMedia?: string;\n on?: string;\n as?: string | React.ComponentType<OtherProps>;\n};\n\nexport function Only<OtherProps = Record<string, never>>({\n matchMedia,\n on,\n as,\n children,\n ...props\n}: React.PropsWithChildren<OnlyProps<OtherProps>>): React.ReactElement | null {\n const matchOn = useBreakpoint(on);\n const matchQuery = useMediaQuery(matchMedia || \"-\");\n const isShown = matchOn || matchQuery;\n\n if (!isShown) {\n return null;\n }\n\n return React.createElement(\n // @ts-expect-error – this is a complex type\n as || React.Fragment,\n as ? (props as OtherProps) : undefined,\n children,\n );\n}\n\nOnly.displayName = \"Only\";\n","import { CSSProperties } from \"react\";\nimport { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\ntype CSSinJSProperties =\n | CSSProperties\n | {\n [key: string]: CSSProperties;\n };\n\ninterface Points {\n [breakpoint: string]: CSSinJSProperties;\n}\n\ntype CSSinJS = Record<string, CSSinJSProperties>;\nexport const toJSON =\n (breakpoints: Breakpoints) =>\n (points: Points): CSSinJS => {\n const css: CSSinJS = {};\n Object.keys(points).forEach((point) => {\n const breakpoint = breakpoints[point];\n if (!breakpoint) {\n throw new Error(`${point} is not a valid breakpoint\\nValid breakpoints are: ${Object.keys(breakpoints)}`);\n }\n css[`@media ${fromBreakpointToMedia(breakpoint)}`] = points[point];\n });\n return css;\n };\n\nconst stringify = (object: CSSinJSProperties) => {\n let string = \"\";\n Object.entries(object).forEach(([key, value]) => {\n if (typeof value !== \"object\") {\n string += `${key}: ${value};\\n`;\n return;\n }\n string += `${key} {\\n${stringify(value)}}\\n`;\n });\n return string;\n};\n\nexport const toCSS =\n (breakpoints: Breakpoints) =>\n (points: Points): string =>\n stringify(toJSON(breakpoints)(points));\n"],"names":["listOfSupportedUnits","listOfSupportedDirections","sanitize","inBreakpoints","Object","keys","reduce","breakpoints","breakpointName","breakpoint","Array","isArray","length","supposedUnit","supposedDirection","supposedMin","supposedMax","options","rest","slice","error","Error","console","direction","unit","min","Math","max","includes","Infinity","defaultBreakpoints","xs","sm","md","lg","xl","BreakpointsContext","React","createContext","BreakpointsProvider","_ref","_ref$breakpoints","_ref$additionalBreakp","additionalBreakpoints","children","Provider","value","_extends","displayName","fromBreakpointToMedia","mediaList","minValue","maxValue","push","str","join","useMediaQuery","mediaQuery","mediaQueryList","useMemo","matchMedia","_React$useState","useState","matches","isShown","setIsShown","useLayoutEffect","listener","event","addListener","removeListener","useBreakpoint","on","useContext","toMediaQuery","rawBreakpointNames","split","map","filter","Boolean","isUniqBreakpoint","mediaQueryBuilder","Only","as","props","_objectWithoutPropertiesLoose","_excluded","matchOn","matchQuery","createElement","Fragment","undefined","toJSON","points","css","forEach","point","stringify","object","string","entries","key"],"mappings":"qxBAiBA,IAAMA,EAAgC,CACpC,KACA,KACA,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,MACA,KACA,KACA,OACA,QAKIC,EAA0C,CAAC,QAAS,UAiB7CC,EAAW,SAACC,GACvB,OAAOC,OAAOC,KAAKF,GAAeG,OAAoB,SAACC,EAAaC,GAClE,IAAMC,EAAaN,EAAcK,GAEjC,IAAKE,MAAMC,QAAQF,IAAeA,EAAWG,QAAU,EACrD,OAAOL,EAGT,IAUIM,EACAC,EAXGC,EAA8CN,EAAU,GAA3CO,EAAiCP,EAApBQ,GAAAA,EAAoBR,EAAU,GAAlBS,EAAQT,EAAUU,SAC/D,GAAID,EAAKN,OAAS,EAAG,CACnB,IAAMQ,EAAQ,IAAIC,MAA+BH,yBAAAA,EAAyB,uBAC1EI,QAAQF,MAAMA,EAChB,CAEA,GAA2B,iBAAhBL,GAAmD,iBAAhBC,EAC5C,OAAOT,EAKc,iBAAZU,EACTJ,EAAeI,EACa,iBAAZA,IAChBH,EAAoBG,EAAQM,UAC5BV,EAAeI,EAAQO,MAGzB,IAAMC,EAAMC,KAAKD,IAAIV,EAAaC,GAC5BW,EAAMD,KAAKC,IAAIZ,EAAaC,GAC5BQ,EAAOX,GAAgBb,EAAqB4B,SAASf,GAAgBA,EAAe,KACpFU,EACJT,GAAqBb,EAA0B2B,SAASd,GAAqBA,EAAoB,QAMnG,OAJAP,EAAYC,GAAkB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ACX,SAACrF,GAAwB,gBACxBsF,GACC,IAAMC,EAAe,CAAE,EAQvB,OAPA1F,OAAOC,KAAKwF,GAAQE,QAAQ,SAACC,GAC3B,IAAMvF,EAAaF,EAAYyF,GAC/B,IAAKvF,EACH,MAAU,IAAAY,MAAS2E,wDAA2D5F,OAAOC,KAAKE,IAE5FuF,EAAc7C,UAAAA,EAAsBxC,IAAiBoF,EAAOG,EAC9D,GACOF,CACT,CAAC,EAEGG,EAAY,SAACC,GACjB,IAAIC,EAAS,GAQb,OAPA/F,OAAOgG,QAAQF,GAAQH,QAAQ,SAAAvD,GAAiB,IAAf6D,EAAG7D,EAAEM,GAAAA,EAAKN,EAAA,GAKzC2D,GAJqB,iBAAVrD,EAIEuD,EAAG,OAAOJ,EAAUnD,GACnC,MAJiBuD,EAAG,KAAKvD,EAAU,KAInC,GACOqD,CACT,kEAGE,SAAC5F,GAAwB,gBACxBsF,GAAc,OACbI,EAAUL,EAAOrF,EAAPqF,CAAoBC,GAAQ,CAAA"}
|
package/lib/sanitize.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
unit?: Units;
|
|
5
|
-
direction?: Directions;
|
|
6
|
-
}];
|
|
7
|
-
export interface ExposedBreakpoints {
|
|
8
|
-
[key: string]: ExposedBreakpoint;
|
|
9
|
-
}
|
|
10
|
-
export
|
|
11
|
-
export interface Breakpoints {
|
|
12
|
-
[breakpoint: string]: Breakpoint;
|
|
13
|
-
}
|
|
14
|
-
export declare const sanitize: (inBreakpoints: ExposedBreakpoints) => Breakpoints;
|
|
15
|
-
export {};
|
|
1
|
+
export type Units = "em" | "ex" | "%" | "px" | "cm" | "mm" | "in" | "pt" | "pc" | "ch" | "rem" | "vh" | "vw" | "vmin" | "vmax";
|
|
2
|
+
type Directions = "width" | "height";
|
|
3
|
+
export type ExposedBreakpoint = [number, number] | [number, number, Units] | [number, number, {
|
|
4
|
+
unit?: Units;
|
|
5
|
+
direction?: Directions;
|
|
6
|
+
}];
|
|
7
|
+
export interface ExposedBreakpoints {
|
|
8
|
+
[key: string]: ExposedBreakpoint;
|
|
9
|
+
}
|
|
10
|
+
export type Breakpoint = [number, number, Units, Directions];
|
|
11
|
+
export interface Breakpoints {
|
|
12
|
+
[breakpoint: string]: Breakpoint;
|
|
13
|
+
}
|
|
14
|
+
export declare const sanitize: (inBreakpoints: ExposedBreakpoints) => Breakpoints;
|
|
15
|
+
export {};
|
package/lib/useBreakpoint.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useBreakpoint: (on?: string) => boolean;
|
|
1
|
+
export declare const useBreakpoint: (on?: string) => boolean;
|
package/lib/useMediaQuery.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useMediaQuery: (mediaQuery: string) => boolean;
|
|
1
|
+
export declare const useMediaQuery: (mediaQuery: string) => boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocz/react-responsive",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-beta.0",
|
|
4
4
|
"description": "🔍 <Only /> displays some contents for a specific screen size",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
},
|
|
19
19
|
"./package.json": "./package.json"
|
|
20
20
|
},
|
|
21
|
-
"repository":
|
|
21
|
+
"repository": {
|
|
22
|
+
"url": "git+ssh://git@github.com/bloczjs/react-responsive.git"
|
|
23
|
+
},
|
|
22
24
|
"keywords": [
|
|
23
25
|
"adaptive",
|
|
24
26
|
"breakpoint",
|
|
@@ -40,10 +42,10 @@
|
|
|
40
42
|
},
|
|
41
43
|
"homepage": "https://github.com/bloczjs/react-responsive#readme",
|
|
42
44
|
"devDependencies": {
|
|
43
|
-
"@types/react": "^
|
|
44
|
-
"microbundle": "^0.15.
|
|
45
|
+
"@types/react": "^19.0.1",
|
|
46
|
+
"microbundle": "^0.15.1"
|
|
45
47
|
},
|
|
46
48
|
"peerDependencies": {
|
|
47
|
-
"react": "16.8.0 -
|
|
49
|
+
"react": "16.8.0 - 19.x.x"
|
|
48
50
|
}
|
|
49
51
|
}
|
package/lib/Match.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
export interface MatchChildProps {
|
|
3
|
-
matchMedia?: string;
|
|
4
|
-
only?: string;
|
|
5
|
-
}
|
|
6
|
-
declare module "react" {
|
|
7
|
-
interface HTMLAttributes<T> extends React.AriaAttributes, React.DOMAttributes<T>, MatchChildProps {
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
declare type Element = React.ReactElement<MatchChildProps & any, string | React.ComponentType<MatchChildProps & any>> | null;
|
|
11
|
-
interface MatchProps {
|
|
12
|
-
[key: string]: any;
|
|
13
|
-
children: Element | Element[] | null;
|
|
14
|
-
as?: string;
|
|
15
|
-
}
|
|
16
|
-
export declare const Match: React.FunctionComponent<MatchProps>;
|
|
17
|
-
export {};
|