@blocz/react-responsive 3.0.2 → 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 CHANGED
@@ -1,16 +1,4 @@
1
- # @blocz/react-responsive
2
-
3
- <center>
4
-
5
- [![npm version][2]][3]
6
- [![downloads][4]][5]
7
- [![js-standard-style][6]][7]
8
-
9
- [![gzipped size][10]][11]
10
- [![stability][0]][1]
11
- [![speed][8]][9]
12
-
13
- </center>
1
+ # @blocz/react-responsive <!-- omit in toc -->
14
2
 
15
3
  `@blocz/react-responsive` is inspired by the `.visible` classes from [bootstrap 4](https://getbootstrap.com/docs/4.0/migration/#responsive-utilities) (or `.hidden` classes from [bootstrap 3](https://getbootstrap.com/docs/3.3/css/#responsive-utilities-classes)): only display a certain content for a precise screen size.
16
4
 
@@ -20,34 +8,32 @@ If you need a responsive layout and adaptive components, `@blocz/react-responsiv
20
8
 
21
9
  [See changelog](https://github.com/bloczjs/react-responsive/blob/master/CHANGELOG.md)
22
10
 
23
- ## How to use
11
+ ## Table of contents <!-- omit in toc -->
12
+
13
+ 1. [How to use](#how-to-use)
14
+ 1. [`<Only>`](#only)
15
+ 1. [Default breakpoints](#default-breakpoints)
16
+ 2. [Additional `Up` and `Down`](#additional-up-and-down)
17
+ 3. [Match Media Queries](#match-media-queries)
18
+ 4. [Render as component](#render-as-component)
19
+ 2. [Hooks](#hooks)
20
+ 1. [`useBreakpoint()`](#usebreakpoint)
21
+ 2. [`useMediaQuery()`](#usemediaquery)
22
+ 3. [`<BreakpointsProvider>`](#breakpointsprovider)
23
+ 1. [Add more breakpoints](#add-more-breakpoints)
24
+ 2. [Change default breakpoints](#change-default-breakpoints)
25
+ 3. [Units](#units)
26
+ 4. [Direction](#direction)
27
+ 4. [CSS in JS](#css-in-js)
28
+ 1. [`toJSON`](#tojson)
29
+ 2. [`toCSS`](#tocss)
30
+ 5. [Comparison to other libraries](#comparison-to-other-libraries)
31
+ 6. [`matchMedia` polyfill](#matchmedia-polyfill)
32
+ 1. [Browser](#browser)
33
+ 2. [Node](#node)
34
+ 7. [FAQ](#faq)
24
35
 
25
- 1. [@blocz/react-responsive](#bloczreact-responsive)
26
- 1. [How to use](#how-to-use)
27
- 1. [`<Only>`](#only)
28
- 1. [Default breakpoints](#default-breakpoints)
29
- 2. [Additional `Up` and `Down`](#additional-up-and-down)
30
- 3. [Match Media Queries](#match-media-queries)
31
- 4. [Render as component](#render-as-component)
32
- 2. [Hooks](#hooks)
33
- 1. [`useBreakpoint()`](#usebreakpoint)
34
- 2. [`useMediaQuery()`](#usemediaquery)
35
- 3. [`<Match>`](#match)
36
- 1. [`only` and `matchMedia` props](#only-and-matchmedia-props)
37
- 2. [Use a custom component in Match](#use-a-custom-component-in-match)
38
- 4. [`<BreakpointsProvider>`](#breakpointsprovider)
39
- 1. [Add more breakpoints](#add-more-breakpoints)
40
- 2. [Change default breakpoints](#change-default-breakpoints)
41
- 3. [Units](#units)
42
- 4. [Direction](#direction)
43
- 5. [CSS in JS](#css-in-js)
44
- 1. [`toJSON`](#tojson)
45
- 2. [`toCSS`](#tocss)
46
- 6. [Comparison to other libraries](#comparison-to-other-libraries)
47
- 7. [`matchMedia` polyfill](#matchmedia-polyfill)
48
- 1. [Browser](#browser)
49
- 2. [Node](#node)
50
- 8. [FAQ](#faq)
36
+ ## How to use
51
37
 
52
38
  ### `<Only>`
53
39
 
@@ -225,96 +211,6 @@ const App = () => {
225
211
  };
226
212
  ```
227
213
 
228
- ### `<Match>`
229
-
230
- #### `only` and `matchMedia` props
231
-
232
- 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.
233
-
234
- ```javascript
235
- import React from "react";
236
- import { Only, Match } from "@blocz/react-responsive";
237
-
238
- const App = () => (
239
- <Match>
240
- <div only="xs">xs</div>
241
- <div only="sm">sm</div>
242
- <div only="md">md</div>
243
- <div only="sm lg">sm and lg</div>
244
- <div only="xl">xl</div>
245
- <div>
246
- <div>
247
- <div>
248
- <div only="smDown">nested smDown</div>
249
- </div>
250
- </div>
251
- </div>
252
- <div matchMedia="(min-width:768px) and (max-width:992px),(max-width:576px)">
253
- {"(min-width:768px) and (max-width:992px),(max-width:576px)"}
254
- </div>
255
- </Match>
256
- );
257
- ```
258
-
259
- #### Use a custom component in Match
260
-
261
- You can also render the `Match` component as another one:
262
-
263
- ```javascript
264
- import React from "react";
265
- import { Only, Match } from "@blocz/react-responsive";
266
-
267
- const App = () => (
268
- <Match as="ul">
269
- <li only="xs">xs</li>
270
- <li only="sm">sm</li>
271
- <li only="md">md</li>
272
- <li only="lg">lg</li>
273
- <li only="xl">xl</li>
274
- </Match>
275
- );
276
- ```
277
-
278
- If you’re using TypeScript, `Match` will work out of the box for native DOM elements.
279
- But if you want to use it for custom components, you’ll have to use the type `MatchChildProps`:
280
-
281
- ```tsx
282
- import * as React from "react";
283
- import { Match, MatchChildProps } from "@blocz/react-responsive";
284
-
285
- // MatchChildProps includes the props `only` and `matchMedia`
286
- interface CustomProps extends MatchChildProps {
287
- title: string;
288
- }
289
-
290
- const Custom: React.FunctionComponent<CustomProps> = ({ title, children }) => (
291
- <React.Fragment>
292
- <h3>{title}</h3>
293
- <p>{children}</p>
294
- </React.Fragment>
295
- );
296
-
297
- const App = () => (
298
- <Match>
299
- <Custom only="xs" title="xs">
300
- xs
301
- </Custom>
302
- <Custom only="sm" title="sm">
303
- sm
304
- </Custom>
305
- <Custom only="md" title="md">
306
- md
307
- </Custom>
308
- <Custom only="lg" title="lg">
309
- lg
310
- </Custom>
311
- <Custom only="xl" title="xl">
312
- xl
313
- </Custom>
314
- </Match>
315
- );
316
- ```
317
-
318
214
  ### `<BreakpointsProvider>`
319
215
 
320
216
  `BreakpointsProvider` defines the values of every breakpoints.
@@ -456,7 +352,7 @@ Example with [`emotion`](https://emotion.sh):
456
352
  ```jsx
457
353
  import React from "react";
458
354
  import { toCSS as createToCSS, BreakpointsContext } from "@blocz/react-responsive";
459
- import { css } from "emotion";
355
+ import { css } from "@emotion/css";
460
356
 
461
357
  const styles = {
462
358
  mdDown: {
@@ -511,16 +407,3 @@ And if you need an example with `Jest`, `@testing-library/react`, `React` and `@
511
407
  ### FAQ
512
408
 
513
409
  For other questions, please take a look at our [FAQ document](https://github.com/bloczjs/react-responsive/blob/master/FAQ.md).
514
-
515
- [0]: https://img.shields.io/badge/stability-stable-brightgreen.svg?style=flat-square
516
- [1]: https://nodejs.org/api/documentation.html#documentation_stability_index
517
- [2]: https://img.shields.io/npm/v/@blocz/react-responsive.svg?style=flat-square
518
- [3]: https://npmjs.org/package/@blocz/react-responsive
519
- [4]: http://img.shields.io/npm/dm/@blocz/react-responsive.svg?style=flat-square
520
- [5]: https://npmjs.org/package/@blocz/react-responsive
521
- [6]: https://img.shields.io/badge/code%20style-prettier-brightgreen.svg?style=flat-square
522
- [7]: https://prettier.io/
523
- [8]: https://img.shields.io/badge/speed-blazingly%20fast-orange.svg?style=flat-square
524
- [9]: https://twitter.com/acdlite/status/974390255393505280
525
- [10]: http://img.badgesize.io/https://unpkg.com/@blocz/react-responsive/lib/@blocz/react-responsive.js?compression=gzip&style=flat-square
526
- [11]: https://unpkg.com/@blocz/react-responsive/lib/
@@ -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<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 declare 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
- }
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
+ }
@@ -1,12 +1,12 @@
1
- import { CSSProperties } from "react";
2
- import { Breakpoints } from "./sanitize";
3
- declare type CSSinJSProperties = CSSProperties | {
4
- [key: string]: CSSProperties;
5
- };
6
- interface Points {
7
- [breakpoint: string]: CSSinJSProperties;
8
- }
9
- declare 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
+ 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 { Match, MatchChildProps } from "./Match";
3
- export { Only } from "./Only";
4
- export { useBreakpoint } from "./useBreakpoint";
5
- export { useMediaQuery } from "./useMediaQuery";
6
- export { Units } from "./sanitize";
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;
@@ -1,2 +1,2 @@
1
- var e=require("react");function n(){return(n=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e}).apply(this,arguments)}function r(e,n){if(null==e)return{};var r,t,i={},a=Object.keys(e);for(t=0;t<a.length;t++)n.indexOf(r=a[t])>=0||(i[r]=e[r]);return i}var t=["em","ex","%","px","cm","mm","in","pt","pc","ch","rem","vh","vw","vmin","vmax"],i=["width","height"],a=function(e){return Object.keys(e).reduce(function(n,r){var a=e[r];if(!Array.isArray(a)||a.length<=1)return n;var o,u,c=a[0],s=a[1],f=a[2],l=a.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 s)return n;"string"==typeof f?o=f:"object"==typeof f&&(u=f.direction,o=f.unit);var d=Math.min(c,s),m=Math.max(c,s),v=o&&t.includes(o)?o:"px",h=u&&i.includes(u)?u:"width";return n[r]=[d,m,v,h],n[r+"Up"]=[d,Infinity,v,h],n[r+"Down"]=[0,m,v,h],n},{})},o={xs:[0,575,"px"],sm:[576,767,"px"],md:[768,991,"px"],lg:[992,1199,"px"],xl:[1200,Infinity,"px"]},u=e.createContext(a(o)),c=function(r){var t=r.breakpoints,i=r.additionalBreakpoints,c=r.children;return e.createElement(u.Provider,{value:a(n({},void 0===t?o:t,void 0===i?{}:i))},c)};c.displayName="BreakpointsProvider";var s=function(e){var n=[],r=e[0],t=e[1],i=e[2],a=e[3];return 0!==r&&n.push("(min-"+a+":"+r+i+")"),Infinity!==t&&n.push("(max-"+a+":"+t+i+")")," "+n.join(" and ")},f=function(n){var r=e.useMemo(function(){return matchMedia(n)},[n]),t=e.useState(r.matches),i=t[0],a=t[1];return e.useLayoutEffect(function(){a(r.matches);var e=function(e){return a(e.matches)};return r.addListener(e),function(){r.removeListener(e)}},[r]),i},l=function(n){var r=e.useContext(u),t=e.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 s(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=e.useMemo(function(){return t(n)},[t,n]);return f(i||"-")};function p(n){var t=n.matchMedia,i=n.on,a=n.as,o=n.children,u=r(n,["matchMedia","on","as","children"]),c=l(i),s=f(t||"-");return c||s?e.createElement(a||e.Fragment,a?u:void 0,o):null}p.displayName="Only";var d=function n(t){if(!t||!t.props)return t;var i=t.props.children;if(!i)return null;var a=e.Children.map(i,n),o=t.props,u=o.only,c=o.matchMedia,s=r(o,["only","matchMedia"]),f=e.createElement(t.type,s,a);return u||c?e.createElement(p,{on:u||"",matchMedia:c||""},f):f},m=function(n){var t=n.children,i=n.as,a=r(n,["children","as"]),o=e.Children.map(t,d);return i?e.createElement(i,a,o):e.createElement(e.Fragment,null,o)};m.displayName="Match";var v=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 "+s(i)]=n[t]}),r}},h=function e(n){var r="";return Object.entries(n).forEach(function(n){var t=n[0],i=n[1];r+="object"==typeof i?t+" {\n"+e(i)+"}\n":t+": "+i+";\n"}),r};exports.BreakpointsContext=u,exports.BreakpointsProvider=c,exports.Match=m,exports.Only=p,exports.toCSS=function(e){return function(n){return h(v(e)(n))}},exports.toJSON=v,exports.useBreakpoint=l,exports.useMediaQuery=f;
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<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\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) => setIsShown(event.matches);\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 = (breakpoints: Breakpoints) => (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 = (breakpoints: Breakpoints) => (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 = (breakpoints: Breakpoints) => (points: Points): string => 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","error","Error","console","direction","unit","min","Math","max","includes","Infinity","defaultBreakpoints","xs","sm","md","lg","xl","BreakpointsContext","React","BreakpointsProvider","additionalBreakpoints","children","Provider","value","displayName","fromBreakpointToMedia","mediaList","minValue","maxValue","push","join","useMediaQuery","mediaQuery","mediaQueryList","matchMedia","matches","isShown","setIsShown","listener","event","addListener","removeListener","useBreakpoint","on","toMediaQuery","rawBreakpointNames","split","map","filter","Boolean","isUniqBreakpoint","mediaQueryBuilder","Only","as","props","matchOn","matchQuery","undefined","parseChildren","element","_children","only","clone","type","Match","computedChildren","toJSON","points","css","forEach","point","stringify","object","string","entries","key"],"mappings":"0WAiBA,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,MAaLM,EACAC,EAXGC,EAA8CN,KAAjCO,EAAiCP,KAApBQ,EAAoBR,KAARS,EAAQT,WACrD,GAAIS,EAAKN,OAAS,EAAG,CACnB,IAAMO,EAAQ,IAAIC,+BAA+BF,yBACjDG,QAAQF,MAAMA,GAGhB,GAA2B,iBAAhBJ,GAAmD,iBAAhBC,EAC5C,OAAOT,EAKc,iBAAZU,EACTJ,EAAeI,EACa,iBAAZA,IAChBH,EAAoBG,EAAQK,UAC5BT,EAAeI,EAAQM,MAGzB,IAAMC,EAAMC,KAAKD,IAAIT,EAAaC,GAC5BU,EAAMD,KAAKC,IAAIX,EAAaC,GAC5BO,EAAOV,GAAgBb,EAAqB2B,SAASd,GAAgBA,EAAe,KACpFS,EACJR,GAAqBb,EAA0B0B,SAASb,GAAqBA,EAAoB,QAMnG,OAJAP,EAAYC,GAAkB,CAACgB,EAAKE,EAAKH,EAAMD,GAC/Cf,EAAeC,QAAsB,CAACgB,EAAKI,SAAUL,EAAMD,GAC3Df,EAAeC,UAAwB,CAAC,EAAGkB,EAAKH,EAAMD,GAE/Cf,GACN,KCxFCsB,EAAyC,CAC7CC,GAAI,CAAC,EAAG,IAAK,MACbC,GAAI,CAAC,IAAK,IA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sBlC,IAAiB4E,EAAOG,KAEvDF,IAGHG,EAAY,SAAZA,EAAaC,GACjB,IAAIC,EAAS,GAQb,OAPAvF,OAAOwF,QAAQF,GAAQH,QAAQ,gBAAEM,OAAKpD,OAKpCkD,GAJqB,iBAAVlD,EAIEoD,SAAUJ,EAAUhD,SAHlBoD,OAAQpD,UAKlBkD,2GAGY,SAACpF,mBAA8B8E,UAA2BI,EAAUL,EAAO7E,EAAP6E,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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vD,EAAU,KAInC,GACOqD,CACT,0FAGE,SAAC5F,GAAwB,gBACxBsF,GAAc,OACbI,EAAUL,EAAOrF,EAAPqF,CAAoBC,GAAQ,CAAA"}
@@ -1,2 +1,2 @@
1
- import{createContext as n,createElement as r,useMemo as e,useState as t,useLayoutEffect as i,useContext as a,Fragment as o,Children as u}from"react";function c(){return(c=Object.assign||function(n){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(n[t]=e[t])}return n}).apply(this,arguments)}function f(n,r){if(null==n)return{};var e,t,i={},a=Object.keys(n);for(t=0;t<a.length;t++)r.indexOf(e=a[t])>=0||(i[e]=n[e]);return i}var l=["em","ex","%","px","cm","mm","in","pt","pc","ch","rem","vh","vw","vmin","vmax"],p=["width","height"],s=function(n){return Object.keys(n).reduce(function(r,e){var t=n[e];if(!Array.isArray(t)||t.length<=1)return r;var i,a,o=t[0],u=t[1],c=t[2],f=t.slice(3);if(f.length>0){var s=new Error('The following fields "'+f+'" have been ignored');console.error(s)}if("number"!=typeof o||"number"!=typeof u)return r;"string"==typeof c?i=c:"object"==typeof c&&(a=c.direction,i=c.unit);var v=Math.min(o,u),d=Math.max(o,u),h=i&&l.includes(i)?i:"px",m=a&&p.includes(a)?a:"width";return r[e]=[v,d,h,m],r[e+"Up"]=[v,Infinity,h,m],r[e+"Down"]=[0,d,h,m],r},{})},v={xs:[0,575,"px"],sm:[576,767,"px"],md:[768,991,"px"],lg:[992,1199,"px"],xl:[1200,Infinity,"px"]},d=n(s(v)),h=function(n){var e=n.breakpoints,t=n.additionalBreakpoints,i=n.children;return r(d.Provider,{value:s(c({},void 0===e?v:e,void 0===t?{}:t))},i)};h.displayName="BreakpointsProvider";var m=function(n){var r=[],e=n[0],t=n[1],i=n[2],a=n[3];return 0!==e&&r.push("(min-"+a+":"+e+i+")"),Infinity!==t&&r.push("(max-"+a+":"+t+i+")")," "+r.join(" and ")},y=function(n){var r=e(function(){return matchMedia(n)},[n]),a=t(r.matches),o=a[0],u=a[1];return i(function(){u(r.matches);var n=function(n){return u(n.matches)};return r.addListener(n),function(){r.removeListener(n)}},[r]),o},b=function(n){var r=a(d),t=e(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 m(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}}(r)},[r]),i=e(function(){return t(n)},[t,n]);return y(i||"-")};function x(n){var e=n.matchMedia,t=n.on,i=n.as,a=n.children,u=f(n,["matchMedia","on","as","children"]),c=b(t),l=y(e||"-");return c||l?r(i||o,i?u:void 0,a):null}x.displayName="Only";var j=function n(e){if(!e||!e.props)return e;var t=e.props.children;if(!t)return null;var i=u.map(t,n),a=e.props,o=a.only,c=a.matchMedia,l=f(a,["only","matchMedia"]),p=r(e.type,l,i);return o||c?r(x,{on:o||"",matchMedia:c||""},p):p},g=function(n){var e=n.children,t=n.as,i=f(n,["children","as"]),a=u.map(e,j);return t?r(t,i,a):r(o,null,a)};g.displayName="Match";var k=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 "+m(i)]=r[t]}),e}},O=function n(r){var e="";return Object.entries(r).forEach(function(r){var t=r[0],i=r[1];e+="object"==typeof i?t+" {\n"+n(i)+"}\n":t+": "+i+";\n"}),e},w=function(n){return function(r){return O(k(n)(r))}};export{d as BreakpointsContext,h as BreakpointsProvider,g as Match,x as Only,w as toCSS,k as toJSON,b as useBreakpoint,y as useMediaQuery};
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<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\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) => setIsShown(event.matches);\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 = (breakpoints: Breakpoints) => (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 = (breakpoints: Breakpoints) => (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 = (breakpoints: Breakpoints) => (points: Points): string => 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","error","Error","console","direction","unit","min","Math","max","includes","Infinity","defaultBreakpoints","xs","sm","md","lg","xl","BreakpointsContext","React","BreakpointsProvider","additionalBreakpoints","children","Provider","value","displayName","fromBreakpointToMedia","mediaList","minValue","maxValue","push","join","useMediaQuery","mediaQuery","mediaQueryList","matchMedia","matches","isShown","setIsShown","listener","event","addListener","removeListener","useBreakpoint","on","toMediaQuery","rawBreakpointNames","split","map","filter","Boolean","isUniqBreakpoint","mediaQueryBuilder","Only","as","props","matchOn","matchQuery","undefined","parseChildren","element","_children","only","clone","type","Match","computedChildren","toJSON","points","css","forEach","point","stringify","object","string","entries","key","toCSS"],"mappings":"weAiBA,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,MAaLM,EACAC,EAXGC,EAA8CN,KAAjCO,EAAiCP,KAApBQ,EAAoBR,KAARS,EAAQT,WACrD,GAAIS,EAAKN,OAAS,EAAG,CACnB,IAAMO,EAAQ,IAAIC,+BAA+BF,yBACjDG,QAAQF,MAAMA,GAGhB,GAA2B,iBAAhBJ,GAAmD,iBAAhBC,EAC5C,OAAOT,EAKc,iBAAZU,EACTJ,EAAeI,EACa,iBAAZA,IAChBH,EAAoBG,EAAQK,UAC5BT,EAAeI,EAAQM,MAGzB,IAAMC,EAAMC,KAAKD,IAAIT,EAAaC,GAC5BU,E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GAAOC,yBACtEW,EAAmB/C,EAAe6B,IAAI1B,EAAUqC,GACtD,OAAIL,EACKnC,EAAoBmC,EAAIC,EAAOW,GAEjC/C,EAAoBA,EAAgB,KAAM+C,IAGnDD,EAAMxC,YAAc,QCpCP0C,IAAAA,EAAS,SAAC7E,mBAA8B8E,GACnD,IAAMC,EAAe,GAQrB,OAPAlF,OAAOC,KAAKgF,GAAQE,QAAQ,SAACC,GAC3B,IAAM/E,EAAaF,EAAYiF,GAC/B,IAAK/E,EACH,UAAUW,MAASoE,wDAA2DpF,OAAOC,KAAKE,IAE5F+E,YAAc3C,EAAsBlC,IAAiB4E,EAAOG,KAEvDF,IAGHG,EAAY,SAAZA,EAAaC,GACjB,IAAIC,EAAS,GAQb,OAPAvF,OAAOwF,QAAQF,GAAQH,QAAQ,gBAAEM,OAAKpD,OAKpCkD,GAJqB,iBAAVlD,EAIEoD,SAAUJ,EAAUhD,SAHlBoD,OAAQpD,UAKlBkD,GAGIG,EAAQ,SAACvF,mBAA8B8E,UAA2BI,EAAUL,EAAO7E,EAAP6E,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,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,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AAMvF,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{createContext as n,createElement as r,useMemo as e,useState as t,useLayoutEffect as i,useContext as a,Fragment as o,Children as u}from"react";function c(){return(c=Object.assign||function(n){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(n[t]=e[t])}return n}).apply(this,arguments)}function f(n,r){if(null==n)return{};var e,t,i={},a=Object.keys(n);for(t=0;t<a.length;t++)r.indexOf(e=a[t])>=0||(i[e]=n[e]);return i}var l=["em","ex","%","px","cm","mm","in","pt","pc","ch","rem","vh","vw","vmin","vmax"],p=["width","height"],s=function(n){return Object.keys(n).reduce(function(r,e){var t=n[e];if(!Array.isArray(t)||t.length<=1)return r;var i,a,o=t[0],u=t[1],c=t[2],f=t.slice(3);if(f.length>0){var s=new Error('The following fields "'+f+'" have been ignored');console.error(s)}if("number"!=typeof o||"number"!=typeof u)return r;"string"==typeof c?i=c:"object"==typeof c&&(a=c.direction,i=c.unit);var v=Math.min(o,u),d=Math.max(o,u),h=i&&l.includes(i)?i:"px",m=a&&p.includes(a)?a:"width";return r[e]=[v,d,h,m],r[e+"Up"]=[v,Infinity,h,m],r[e+"Down"]=[0,d,h,m],r},{})},v={xs:[0,575,"px"],sm:[576,767,"px"],md:[768,991,"px"],lg:[992,1199,"px"],xl:[1200,Infinity,"px"]},d=n(s(v)),h=function(n){var e=n.breakpoints,t=n.additionalBreakpoints,i=n.children;return r(d.Provider,{value:s(c({},void 0===e?v:e,void 0===t?{}:t))},i)};h.displayName="BreakpointsProvider";var m=function(n){var r=[],e=n[0],t=n[1],i=n[2],a=n[3];return 0!==e&&r.push("(min-"+a+":"+e+i+")"),Infinity!==t&&r.push("(max-"+a+":"+t+i+")")," "+r.join(" and ")},y=function(n){var r=e(function(){return matchMedia(n)},[n]),a=t(r.matches),o=a[0],u=a[1];return i(function(){u(r.matches);var n=function(n){return u(n.matches)};return r.addListener(n),function(){r.removeListener(n)}},[r]),o},b=function(n){var r=a(d),t=e(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 m(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}}(r)},[r]),i=e(function(){return t(n)},[t,n]);return y(i||"-")};function x(n){var e=n.matchMedia,t=n.on,i=n.as,a=n.children,u=f(n,["matchMedia","on","as","children"]),c=b(t),l=y(e||"-");return c||l?r(i||o,i?u:void 0,a):null}x.displayName="Only";var j=function n(e){if(!e||!e.props)return e;var t=e.props.children;if(!t)return null;var i=u.map(t,n),a=e.props,o=a.only,c=a.matchMedia,l=f(a,["only","matchMedia"]),p=r(e.type,l,i);return o||c?r(x,{on:o||"",matchMedia:c||""},p):p},g=function(n){var e=n.children,t=n.as,i=f(n,["children","as"]),a=u.map(e,j);return t?r(t,i,a):r(o,null,a)};g.displayName="Match";var k=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 "+m(i)]=r[t]}),e}},O=function n(r){var e="";return Object.entries(r).forEach(function(r){var t=r[0],i=r[1];e+="object"==typeof i?t+" {\n"+n(i)+"}\n":t+": "+i+";\n"}),e},w=function(n){return function(r){return O(k(n)(r))}};export{d as BreakpointsContext,h as BreakpointsProvider,g as Match,x as Only,w as toCSS,k as toJSON,b as useBreakpoint,y as useMediaQuery};
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,QAAS,UAiB7CC,EAAYC,GAChBC,OAAOC,KAAKF,GAAeG,OAAoB,CAACC,EAAaC,KAClE,MAAMC,EAAaN,EAAcK,GAEjC,IAAKE,MAAMC,QAAQF,IAAeA,EAAWG,QAAU,EACrD,OAAOL,EAGT,MAAOM,EAAaC,EAAaC,KAAYC,GAAQP,EACrD,GAAIO,EAAKJ,OAAS,EAAG,CACnB,MAAMK,EAAQ,IAAIC,MAAM,yBAAyBF,wBACjDG,QAAQF,MAAMA,EAChB,CAEA,GAA2B,iBAAhBJ,GAAmD,iBAAhBC,EAC5C,OAAOP,EAGT,IAAIa,EACAC,EACmB,iBAAZN,EACTK,EAAeL,EACa,iBAAZA,IAChBM,EAAoBN,EAAQO,UAC5BF,EAAeL,EAAQQ,MAGzB,MAAMC,EAAMC,KAAKD,IAAIX,EAAaC,GAC5BY,EAAMD,KAAKC,IAAIb,EAAaC,GAC5BS,EAAOH,GAAgBpB,EAAqB2B,SAASP,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E5DF,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(){return(r=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e}).apply(this,arguments)}function t(e,n){if(null==e)return{};var r,t,i={},o=Object.keys(e);for(t=0;t<o.length;t++)n.indexOf(r=o[t])>=0||(i[r]=e[r]);return i}var i=["em","ex","%","px","cm","mm","in","pt","pc","ch","rem","vh","vw","vmin","vmax"],o=["width","height"],a=function(e){return Object.keys(e).reduce(function(n,r){var t=e[r];if(!Array.isArray(t)||t.length<=1)return n;var a,u,c=t[0],f=t[1],l=t[2],s=t.slice(3);if(s.length>0){var p=new Error('The following fields "'+s+'" have been ignored');console.error(p)}if("number"!=typeof c||"number"!=typeof f)return n;"string"==typeof l?a=l:"object"==typeof l&&(u=l.direction,a=l.unit);var d=Math.min(c,f),m=Math.max(c,f),h=a&&i.includes(a)?a:"px",v=u&&o.includes(u)?u:"width";return n[r]=[d,m,h,v],n[r+"Up"]=[d,Infinity,h,v],n[r+"Down"]=[0,m,h,v],n},{})},u={xs:[0,575,"px"],sm:[576,767,"px"],md:[768,991,"px"],lg:[992,1199,"px"],xl:[1200,Infinity,"px"]},c=n.createContext(a(u)),f=function(e){var t=e.breakpoints,i=e.additionalBreakpoints,o=e.children;return n.createElement(c.Provider,{value:a(r({},void 0===t?u:t,void 0===i?{}:i))},o)};f.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 ")},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){return o(e.matches)};return r.addListener(e),function(){r.removeListener(e)}},[r]),i},p=function(e){var r=n.useContext(c),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 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}}(r)},[r]),i=n.useMemo(function(){return t(e)},[t,e]);return s(i||"-")};function d(e){var r=e.matchMedia,i=e.on,o=e.as,a=e.children,u=t(e,["matchMedia","on","as","children"]),c=p(i),f=s(r||"-");return c||f?n.createElement(o||n.Fragment,o?u:void 0,a):null}d.displayName="Only";var m=function e(r){if(!r||!r.props)return r;var i=r.props.children;if(!i)return null;var o=n.Children.map(i,e),a=r.props,u=a.only,c=a.matchMedia,f=t(a,["only","matchMedia"]),l=n.createElement(r.type,f,o);return u||c?n.createElement(d,{on:u||"",matchMedia:c||""},l):l},h=function(e){var r=e.children,i=e.as,o=t(e,["children","as"]),a=n.Children.map(r,m);return i?n.createElement(i,o,a):n.createElement(n.Fragment,null,a)};h.displayName="Match";var v=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(n){var r="";return Object.entries(n).forEach(function(n){var t=n[0],i=n[1];r+="object"==typeof i?t+" {\n"+e(i)+"}\n":t+": "+i+";\n"}),r};e.BreakpointsContext=c,e.BreakpointsProvider=f,e.Match=h,e.Only=d,e.toCSS=function(e){return function(n){return y(v(e)(n))}},e.toJSON=v,e.useBreakpoint=p,e.useMediaQuery=s});
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<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\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) => setIsShown(event.matches);\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 = (breakpoints: Breakpoints) => (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 = (breakpoints: Breakpoints) => (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 = (breakpoints: Breakpoints) => (points: Points): string => 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","error","Error","console","direction","unit","min","Math","max","includes","Infinity","defaultBreakpoints","xs","sm","md","lg","xl","BreakpointsContext","React","BreakpointsProvider","additionalBreakpoints","children","Provider","value","displayName","fromBreakpointToMedia","mediaList","minValue","maxValue","push","join","useMediaQuery","mediaQuery","mediaQueryList","matchMedia","matches","isShown","setIsShown","listener","event","addListener","removeListener","useBreakpoint","on","toMediaQuery","rawBreakpointNames","split","map","filter","Boolean","isUniqBreakpoint","mediaQueryBuilder","Only","as","props","matchOn","matchQuery","undefined","parseChildren","element","_children","only","clone","type","Match","computedChildren","toJSON","points","css","forEach","point","stringify","object","string","entries","key"],"mappings":"0mBAiBA,IAAMA,EAAgC,CACpC,KACA,KACA,IACA,KACA,KACA,KACA,KACA,KACA,KACA,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EAAP6E,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,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
- declare type Directions = "width" | "height";
3
- export declare 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 declare 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 {};
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 {};
@@ -1 +1 @@
1
- export declare const useBreakpoint: (on?: string | undefined) => boolean;
1
+ export declare const useBreakpoint: (on?: string) => boolean;
@@ -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.0.2",
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,
@@ -10,6 +10,7 @@
10
10
  "types": "lib/index.d.ts",
11
11
  "exports": {
12
12
  ".": {
13
+ "types": "./lib/index.d.ts",
13
14
  "require": "./lib/react-responsive.js",
14
15
  "import": "./lib/react-responsive.modern.mjs",
15
16
  "browser": "./lib/react-responsive.modern.js",
@@ -17,7 +18,9 @@
17
18
  },
18
19
  "./package.json": "./package.json"
19
20
  },
20
- "repository": "git@github.com:bloczjs/react-responsive.git",
21
+ "repository": {
22
+ "url": "git+ssh://git@github.com/bloczjs/react-responsive.git"
23
+ },
21
24
  "keywords": [
22
25
  "adaptive",
23
26
  "breakpoint",
@@ -31,18 +34,18 @@
31
34
  "license": "MIT",
32
35
  "bugs": "https://github.com/bloczjs/react-responsive/issues",
33
36
  "scripts": {
34
- "build": "yarn -s build:microbundle && cp lib/react-responsive.modern.js lib/react-responsive.modern.mjs",
35
- "build:dev": "yarn -s build:microbundle --compress false",
37
+ "build": "yarn build:microbundle && cp lib/react-responsive.modern.js lib/react-responsive.modern.mjs",
38
+ "build:dev": "yarn build:microbundle --compress false",
36
39
  "build:microbundle": "microbundle --name $npm_package_name --globals react=React",
37
40
  "link:readme": "rm ../../README.md && ln -s packages/react-responsive/README.md ../..",
38
- "prepublishOnly": "rm -rf lib && yarn -s build"
41
+ "prepublishOnly": "rm -rf lib && yarn build"
39
42
  },
40
43
  "homepage": "https://github.com/bloczjs/react-responsive#readme",
41
44
  "devDependencies": {
42
- "@types/react": "^17.0.0",
43
- "microbundle": "0.13.0"
45
+ "@types/react": "^19.0.1",
46
+ "microbundle": "^0.15.1"
44
47
  },
45
48
  "peerDependencies": {
46
- "react": "16.8.0 - 17.x.x"
49
+ "react": "16.8.0 - 19.x.x"
47
50
  }
48
- }
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 {};