@instructure/ui-responsive 11.7.8 → 11.7.9-pr-snapshot-1792147648392

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.
@@ -1,108 +1,32 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
1
  import { matchMedia as defaultMatchMedia } from '@instructure/ui-dom-utils';
25
2
  import { jsonToMediaQuery } from './jsonToMediaQuery.js';
26
-
27
- /**
28
- * ---
29
- * category: utilities/layout
30
- * ---
31
- * Given an object of named queries, listens for changes in the
32
- * window size and notifies which queries match via a function
33
- * callback. The callback method is only called when the query
34
- * matches change, not on all window resizes.
35
- *
36
- * This function shares an interface with
37
- * [addElementQueryMatchListener](addElementQueryMatchListener)
38
- * so that they can be used interchangeably.
39
- *
40
- * The [Responsive](Responsive) component with the `match` prop
41
- * set to `media` utilizes this function. This is a low level utility
42
- * method and, in most cases, [Responsive](Responsive) should be
43
- * used instead.
44
- *
45
- * ```js-code
46
- * class MyComponent extends Component {
47
- * state = {
48
- * matches: []
49
- * }
50
- *
51
- * _listener = null
52
- *
53
- * componentDidMount () {
54
- * const query = {myFirstQuery: { minWidth: 100 }, mySecondQuery: { maxHeight: '30rem'}}
55
- * const el = findDOMNode(this)
56
- *
57
- * this._listener = addMediaQueryMatchListener(query, el, this.updateMatches)
58
- * }
59
- *
60
- * componentWillUnmount () {
61
- * if (this._listener) {
62
- * this._listener.remove()
63
- * }
64
- * }
65
- *
66
- * updateMatches = (matches) => {
67
- * this.setState({ matches })
68
- * }
69
- * ...
70
- * }
71
- * ```
72
- * @module addMediaQueryMatchListener
73
- * @param {Object} query - object consisting of names and query objects
74
- * @param {Node|Window|React.ReactElement|React.Component|function} el - a DOM node or a function returning a DOM node
75
- * @param {function} cb - called with an array of the names of the currently matching queries whenever a matching query changes
76
- * @param {object} matchMedia - called with an array of the names of the currently matching queries whenever a matching query changes
77
- * @returns {function} remove() function to call to remove the listener
78
- */
79
- const addMediaQueryMatchListener = (query, el, cb, matchMedia = defaultMatchMedia) => {
80
- const node = typeof el === 'function' ? el() : el;
81
- const updateMediaMatches = mediaQueryLists => {
82
- const matches = Object.keys(mediaQueryLists).filter(key => mediaQueryLists[key].matches).map(key => key);
83
- cb(matches);
84
- };
85
- const mediaQueryLists = {};
86
- const listenerCallback = () => {
3
+ const addMediaQueryMatchListener = (query, el, cb, matchMedia = defaultMatchMedia)=>{
4
+ const node = typeof el === 'function' ? el() : el;
5
+ const updateMediaMatches = (mediaQueryLists)=>{
6
+ const matches = Object.keys(mediaQueryLists).filter((key)=>mediaQueryLists[key].matches).map((key)=>key);
7
+ cb(matches);
8
+ };
9
+ const mediaQueryLists = {};
10
+ const listenerCallback = ()=>{
11
+ updateMediaMatches(mediaQueryLists);
12
+ };
13
+ Object.keys(query).forEach((key)=>{
14
+ const mediaQueryList = matchMedia(jsonToMediaQuery(query[key], node), node);
15
+ if (mediaQueryList) {
16
+ mediaQueryList.addListener(listenerCallback);
17
+ mediaQueryLists[key] = mediaQueryList;
18
+ }
19
+ });
87
20
  updateMediaMatches(mediaQueryLists);
88
- };
89
- Object.keys(query).forEach(key => {
90
- const mediaQueryList = matchMedia(jsonToMediaQuery(query[key], node), node);
91
- if (mediaQueryList) {
92
- mediaQueryList.addListener(listenerCallback);
93
- mediaQueryLists[key] = mediaQueryList;
94
- }
95
- });
96
- updateMediaMatches(mediaQueryLists);
97
- return {
98
- remove() {
99
- if (mediaQueryLists) {
100
- Object.keys(mediaQueryLists).forEach(key => {
101
- mediaQueryLists[key].removeListener(listenerCallback);
102
- });
103
- }
104
- }
105
- };
21
+ return {
22
+ remove () {
23
+ if (mediaQueryLists) {
24
+ Object.keys(mediaQueryLists).forEach((key)=>{
25
+ mediaQueryLists[key].removeListener(listenerCallback);
26
+ });
27
+ }
28
+ }
29
+ };
106
30
  };
107
31
  export default addMediaQueryMatchListener;
108
- export { addMediaQueryMatchListener };
32
+ export { addMediaQueryMatchListener };
@@ -1,79 +1,35 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
1
  import { px } from '@instructure/ui-utils';
25
- /**
26
- * ---
27
- * category: utilities/layout
28
- * ---
29
- *
30
- * Given a valid json query object, converts it to a standard media query
31
- * string. Valid queries should be an object consisting of condition:breakpoint
32
- * pairs with the following condition types `minWidth`, `maxWidth`, `minHeight`,
33
- * or `maxHeight` where breakpoint value is either a string or a number.
34
- *
35
- * Example input
36
- * ```js-code
37
- * { minWidth: 350, maxWidth: 600 }
38
- * ```
39
- * Example output
40
- * ```js-code
41
- * '(min-width: 350px) and (max-Width: 600px)'
42
- * ```
43
- * @module jsonToMediaQuery
44
- * @param {Object} query - an object consisting of the query type and value
45
- * @param {Document | Window | Node | React.ReactElement | React.Component} el - component or DOM node which will be passed to the pixel conversion if the unit type is `em`
46
- * @returns {string} media query string
47
- */
48
2
  function jsonToMediaQuery(query, el) {
49
- // Ensure the query is of the correct form
50
- const keys = Object.keys(query);
51
- if (keys.length > 4) {
52
- throw new Error('Expected maximum 4 keys in query object.');
53
- }
54
- let mediaQuery = '';
55
- const QUERY_SEPARATOR = 'and';
56
- for (const key of keys) {
57
- const validKeys = ['minHeight', 'maxHeight', 'minWidth', 'maxWidth'];
58
- if (validKeys.indexOf(key) === -1) {
59
- throw new Error(`Invalid key \`${key}\` in query object. Valid keys should consist of one of the following: ` + `${validKeys.join(', ')} (case sensitive)`);
3
+ const keys = Object.keys(query);
4
+ if (keys.length > 4) {
5
+ throw new Error('Expected maximum 4 keys in query object.');
60
6
  }
61
- const value = query[key];
62
-
63
- // TS catches this, but we want to throw error in runtime too
64
- if (typeof value !== 'string' && typeof value !== 'number') {
65
- throw new Error('The value of the query object must be a string or number.');
7
+ let mediaQuery = '';
8
+ const QUERY_SEPARATOR = 'and';
9
+ for (const key of keys){
10
+ const validKeys = [
11
+ 'minHeight',
12
+ 'maxHeight',
13
+ 'minWidth',
14
+ 'maxWidth'
15
+ ];
16
+ if (validKeys.indexOf(key) === -1) {
17
+ throw new Error(`Invalid key \`${key}\` in query object. Valid keys should consist of one of the following: ` + `${validKeys.join(', ')} (case sensitive)`);
18
+ }
19
+ const value = query[key];
20
+ if (typeof value !== 'string' && typeof value !== 'number') {
21
+ throw new Error('The value of the query object must be a string or number.');
22
+ }
23
+ if (!value) {
24
+ throw new Error('No value supplied for query object');
25
+ }
26
+ mediaQuery += `(${hyphenateQueryKey(key)}: ${px(value, el)}px) ${QUERY_SEPARATOR} `;
66
27
  }
67
- if (!value) {
68
- throw new Error('No value supplied for query object');
69
- }
70
- mediaQuery += `(${hyphenateQueryKey(key)}: ${px(value, el)}px) ${QUERY_SEPARATOR} `;
71
- }
72
- return mediaQuery.slice(0, -QUERY_SEPARATOR.length - 2);
28
+ return mediaQuery.slice(0, -QUERY_SEPARATOR.length - 2);
73
29
  }
74
30
  function hyphenateQueryKey(key) {
75
- const lowerCaseKey = key.toLowerCase();
76
- return lowerCaseKey.slice(0, 3) + '-' + lowerCaseKey.slice(3);
31
+ const lowerCaseKey = key.toLowerCase();
32
+ return lowerCaseKey.slice(0, 3) + '-' + lowerCaseKey.slice(3);
77
33
  }
78
34
  export default jsonToMediaQuery;
79
- export { jsonToMediaQuery };
35
+ export { jsonToMediaQuery };
@@ -1,82 +1,23 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
1
  import { px } from '@instructure/ui-utils';
25
-
26
- /**
27
- * An object consisting of query names and boolean true false if it matches
28
- */
29
-
30
- /**
31
- * ---
32
- * category: utilities/layout
33
- * ---
34
- *
35
- * Given a query and an element, return a function that takes
36
- * size as an argument and returns an object consisting of
37
- * query names and a boolean true false if it matches.
38
- * @module parseQuery
39
- * @param {Object} query - an object consisting of query names
40
- * mapped to individual queries
41
- * @param {Document | Window | Node | null} el - component or DOM node
42
- * @returns {function} takes size {width, height} as an argument
43
- * and returns an object consisting of query names and boolean
44
- * true false if it matches
45
- */
46
2
  function parseQuery(query, el) {
47
- const rules = {};
48
-
49
- // converting values to numerical values and adding initial values to all query keys
50
- Object.keys(query).forEach(selectorName => {
51
- const {
52
- minWidth,
53
- maxWidth,
54
- minHeight,
55
- maxHeight
56
- } = query[selectorName];
57
- rules[selectorName] = {
58
- minWidth: minWidth && px(minWidth, el) || 0,
59
- maxWidth: maxWidth && px(maxWidth, el) || Infinity,
60
- minHeight: minHeight && px(minHeight, el) || 0,
61
- maxHeight: maxHeight && px(maxHeight, el) || Infinity
62
- };
63
- });
64
- return function ({
65
- width,
66
- height
67
- }) {
68
- const selectorMap = {};
69
- Object.entries(rules).forEach(([selectorName, query]) => {
70
- const {
71
- minWidth,
72
- maxWidth,
73
- minHeight,
74
- maxHeight
75
- } = query;
76
- selectorMap[selectorName] = minWidth <= width && width <= maxWidth && minHeight <= height && height <= maxHeight;
3
+ const rules = {};
4
+ Object.keys(query).forEach((selectorName)=>{
5
+ const { minWidth, maxWidth, minHeight, maxHeight } = query[selectorName];
6
+ rules[selectorName] = {
7
+ minWidth: minWidth && px(minWidth, el) || 0,
8
+ maxWidth: maxWidth && px(maxWidth, el) || Infinity,
9
+ minHeight: minHeight && px(minHeight, el) || 0,
10
+ maxHeight: maxHeight && px(maxHeight, el) || Infinity
11
+ };
77
12
  });
78
- return selectorMap;
79
- };
13
+ return function({ width, height }) {
14
+ const selectorMap = {};
15
+ Object.entries(rules).forEach(([selectorName, query])=>{
16
+ const { minWidth, maxWidth, minHeight, maxHeight } = query;
17
+ selectorMap[selectorName] = minWidth <= width && width <= maxWidth && minHeight <= height && height <= maxHeight;
18
+ });
19
+ return selectorMap;
20
+ };
80
21
  }
81
22
  export default parseQuery;
82
- export { parseQuery };
23
+ export { parseQuery };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@instructure/ui-responsive",
3
- "version": "11.7.8",
3
+ "version": "11.7.9-pr-snapshot-1792147648392",
4
+ "type": "module",
4
5
  "description": "A component that allows for rendering a component differently based on either the element or the viewport size",
5
6
  "author": "Instructure, Inc. Engineering and Product Design",
6
7
  "module": "./es/index.js",
7
- "main": "./lib/index.js",
8
8
  "types": "./types/index.d.ts",
9
9
  "repository": {
10
10
  "type": "git",
@@ -14,18 +14,17 @@
14
14
  "bugs": "https://github.com/instructure/instructure-ui/issues",
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
- "@babel/runtime": "^7.29.7",
18
- "@instructure/console": "11.7.8",
19
- "@instructure/ui-dom-utils": "11.7.8",
20
- "@instructure/debounce": "11.7.8",
21
- "@instructure/shared-types": "11.7.8",
22
- "@instructure/ui-react-utils": "11.7.8",
23
- "@instructure/ui-utils": "11.7.8"
17
+ "@swc/helpers": "^0.5.23",
18
+ "@instructure/console": "11.7.9-pr-snapshot-1792147648392",
19
+ "@instructure/shared-types": "11.7.9-pr-snapshot-1792147648392",
20
+ "@instructure/ui-dom-utils": "11.7.9-pr-snapshot-1792147648392",
21
+ "@instructure/debounce": "11.7.9-pr-snapshot-1792147648392",
22
+ "@instructure/ui-react-utils": "11.7.9-pr-snapshot-1792147648392",
23
+ "@instructure/ui-utils": "11.7.9-pr-snapshot-1792147648392"
24
24
  },
25
25
  "devDependencies": {
26
26
  "vitest": "^5.0.0",
27
- "@instructure/ui-babel-preset": "11.7.8",
28
- "@instructure/ui-color-utils": "11.7.8"
27
+ "@instructure/ui-color-utils": "11.7.9-pr-snapshot-1792147648392"
29
28
  },
30
29
  "peerDependencies": {
31
30
  "react": ">=18 <=19"
@@ -35,7 +34,6 @@
35
34
  },
36
35
  "sideEffects": false,
37
36
  "exports": {
38
- "./lib/*": "./lib/*",
39
37
  "./es/*": "./es/*",
40
38
  "./types/*": "./types/*",
41
39
  "./package.json": "./package.json",
@@ -44,28 +42,24 @@
44
42
  "src": "./src/exports/a.ts",
45
43
  "types": "./types/exports/a.d.ts",
46
44
  "import": "./es/exports/a.js",
47
- "require": "./lib/exports/a.js",
48
45
  "default": "./es/exports/a.js"
49
46
  },
50
47
  "./v11_6": {
51
48
  "src": "./src/exports/a.ts",
52
49
  "types": "./types/exports/a.d.ts",
53
50
  "import": "./es/exports/a.js",
54
- "require": "./lib/exports/a.js",
55
51
  "default": "./es/exports/a.js"
56
52
  },
57
53
  "./v11_7": {
58
54
  "src": "./src/exports/a.ts",
59
55
  "types": "./types/exports/a.d.ts",
60
56
  "import": "./es/exports/a.js",
61
- "require": "./lib/exports/a.js",
62
57
  "default": "./es/exports/a.js"
63
58
  },
64
59
  "./latest": {
65
60
  "src": "./src/exports/a.ts",
66
61
  "types": "./types/exports/a.d.ts",
67
62
  "import": "./es/exports/a.js",
68
- "require": "./lib/exports/a.js",
69
63
  "default": "./es/exports/a.js"
70
64
  }
71
65
  },
@@ -73,7 +67,7 @@
73
67
  "lint": "ui-scripts lint",
74
68
  "lint:fix": "ui-scripts lint --fix",
75
69
  "clean": "ui-scripts clean",
76
- "build": "ui-scripts build --modules es,cjs",
70
+ "build": "ui-scripts build",
77
71
  "build:watch": "pnpm run ts:check -- --watch & ui-scripts build --watch",
78
72
  "build:types": "tsc -p tsconfig.build.json",
79
73
  "ts:check": "tsc -p tsconfig.build.json --noEmit --emitDeclarationOnly false"
@@ -13,7 +13,6 @@
13
13
  { "path": "../ui-dom-utils/tsconfig.build.json" },
14
14
  { "path": "../ui-react-utils/tsconfig.build.json" },
15
15
  { "path": "../ui-utils/tsconfig.build.json" },
16
- { "path": "../ui-babel-preset/tsconfig.build.json" },
17
16
  { "path": "../ui-color-utils/tsconfig.build.json" }
18
17
  ]
19
18
  }
@@ -1,167 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.Responsive = void 0;
7
- var _react = require("react");
8
- var _deepEqual = require("@instructure/ui-utils/lib/deepEqual.js");
9
- var _console = require("@instructure/console");
10
- var _addElementQueryMatchListener = require("../../utils/v1/addElementQueryMatchListener.js");
11
- var _addMediaQueryMatchListener = require("../../utils/v1/addMediaQueryMatchListener.js");
12
- var _findDOMNode = require("@instructure/ui-dom-utils/lib/findDOMNode.js");
13
- var _props = require("./props.js");
14
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
15
- /*
16
- * The MIT License (MIT)
17
- *
18
- * Copyright (c) 2015 - present Instructure, Inc.
19
- *
20
- * Permission is hereby granted, free of charge, to any person obtaining a copy
21
- * of this software and associated documentation files (the "Software"), to deal
22
- * in the Software without restriction, including without limitation the rights
23
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
24
- * copies of the Software, and to permit persons to whom the Software is
25
- * furnished to do so, subject to the following conditions:
26
- *
27
- * The above copyright notice and this permission notice shall be included in all
28
- * copies or substantial portions of the Software.
29
- *
30
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36
- * SOFTWARE.
37
- */
38
-
39
- /**
40
- ---
41
- category: components
42
- ---
43
-
44
- **/class Responsive extends _react.Component {
45
- static displayName = 'Responsive';
46
- static allowedProps = _props.allowedProps;
47
- static defaultProps = {
48
- children: null,
49
- match: 'element',
50
- props: null
51
- };
52
- ref = null;
53
- _matchListener = null;
54
- state = {
55
- matches: [],
56
- hasRendered: false
57
- };
58
- handleRef = el => {
59
- const {
60
- elementRef
61
- } = this.props;
62
- this.ref = el;
63
- if (typeof elementRef === 'function') {
64
- elementRef(el);
65
- }
66
- };
67
- componentDidMount() {
68
- (0, _console.logError)(!!(this.props.render || this.props.children), `[Responsive] must have either a \`render\` prop or \`children\` prop.`);
69
- if (this.props.match === 'element') {
70
- // Because Responsive renders an empty div initially, it always needs to
71
- // re-render with the children provided. If there are no matches the match
72
- // listener won't trigger an update, so we handle this update explicitly.
73
- const initialMatches = (0, _addElementQueryMatchListener.updateElementMatches)(this.props.query, this) || [];
74
- this.setState({
75
- matches: initialMatches,
76
- hasRendered: true
77
- });
78
- } else {
79
- this.setState({
80
- hasRendered: true
81
- });
82
- }
83
- this._matchListener = this.addMatchListener(this.props.query, this.updateMatches);
84
- }
85
- componentWillUnmount() {
86
- this.removeMatchListener();
87
- }
88
- componentDidUpdate(prevProps) {
89
- const {
90
- match,
91
- query
92
- } = this.props;
93
- if (match !== prevProps.match || !(0, _deepEqual.deepEqual)(query, prevProps.query)) {
94
- this.removeMatchListener();
95
- this._matchListener = this.addMatchListener(query, this.updateMatches, match);
96
- }
97
- }
98
- addMatchListener(query, updateMatches, match = this.props.match) {
99
- const matchListener = match === 'element' ? _addElementQueryMatchListener.addElementQueryMatchListener : _addMediaQueryMatchListener.addMediaQueryMatchListener;
100
- return matchListener(query, () => (0, _findDOMNode.findDOMNode)(this), updateMatches);
101
- }
102
- removeMatchListener() {
103
- if (this._matchListener) {
104
- this._matchListener.remove();
105
- }
106
- }
107
- updateMatches = (matches, cb) => {
108
- this.setState({
109
- matches
110
- }, () => {
111
- if (typeof cb === 'function') {
112
- cb();
113
- }
114
- });
115
- };
116
- mergeProps(matches, props) {
117
- if (!props) {
118
- return null;
119
- }
120
- const mergedProps = {};
121
- matches.forEach(match => {
122
- const matchProps = props[match];
123
-
124
- // Iterate over the props for the current match. If that the prop is
125
- // already in `mergedProps` that means that the prop was defined for
126
- // multiple breakpoints, and more than one of those breakpoints is being
127
- // currently applied so we log a warning.
128
- Object.keys(matchProps).forEach(prop => {
129
- const currentValue = mergedProps[prop];
130
- (0, _console.warn)(!(prop in mergedProps), [`[Responsive] The prop \`${prop}\` is defined at 2 or more breakpoints`, `which are currently applied at the same time. Its current value, \`${currentValue}\`,`, `will be overwritten as \`${matchProps[prop]}\`.`].join(' '));
131
- mergedProps[prop] = matchProps[prop];
132
- });
133
- });
134
- return mergedProps;
135
- }
136
- render() {
137
- const {
138
- matches,
139
- hasRendered
140
- } = this.state;
141
- const {
142
- props,
143
- render,
144
- children,
145
- display
146
- } = this.props;
147
- let renderFunc;
148
- // Responsive needs to render once to measure the dom and obtain matches.
149
- // Calling the render prop on this initial render can cause visual side
150
- // effects and is slower than rendering an empty div.
151
- if (hasRendered) {
152
- // Render via the children or render method, whichever is supplied. If
153
- // both are supplied, give preference to children.
154
- renderFunc = children || render;
155
- }
156
- return (0, _jsxRuntime.jsx)("div", {
157
- ref: this.handleRef,
158
- style: {
159
- display
160
- },
161
- "data-cid": this.props['data-cid'],
162
- children: renderFunc && renderFunc(this.mergeProps(matches, props), matches)
163
- });
164
- }
165
- }
166
- exports.Responsive = Responsive;
167
- var _default = exports.default = Responsive;
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.allowedProps = void 0;
7
- /*
8
- * The MIT License (MIT)
9
- *
10
- * Copyright (c) 2015 - present Instructure, Inc.
11
- *
12
- * Permission is hereby granted, free of charge, to any person obtaining a copy
13
- * of this software and associated documentation files (the "Software"), to deal
14
- * in the Software without restriction, including without limitation the rights
15
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
- * copies of the Software, and to permit persons to whom the Software is
17
- * furnished to do so, subject to the following conditions:
18
- *
19
- * The above copyright notice and this permission notice shall be included in all
20
- * copies or substantial portions of the Software.
21
- *
22
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
- * SOFTWARE.
29
- */
30
-
31
- /**
32
- * Consists of an object where the keys match the breakpoint names used in the query. The values are objects with keys representing prop names and values representing prop values Ex. `{small: { myProp: 'fillscreen' }, large: { myProp: 'fillcontainer' }}`
33
- */
34
-
35
- const allowedProps = exports.allowedProps = ['match', 'query', 'props', 'render', 'children', 'display', 'elementRef'];