@carbon/react 1.12.0-rc.1 → 1.13.0-rc.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/es/components/FluidTextInput/FluidTextInput.js +104 -0
- package/es/components/PaginationNav/PaginationNav.js +1 -1
- package/es/components/Toggletip/index.js +1 -1
- package/es/components/UIShell/SideNav.js +0 -4
- package/es/index.js +1 -0
- package/lib/components/FluidTextInput/FluidTextInput.js +114 -0
- package/lib/components/PaginationNav/PaginationNav.js +1 -1
- package/lib/components/Toggletip/index.js +1 -1
- package/lib/components/UIShell/SideNav.js +0 -4
- package/lib/index.js +2 -0
- package/package.json +8 -8
- package/es/internal/useMatchMedia.js +0 -51
- package/lib/internal/useMatchMedia.js +0 -55
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2022
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { objectWithoutProperties as _objectWithoutProperties, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
|
+
import PropTypes from 'prop-types';
|
|
10
|
+
import React__default from 'react';
|
|
11
|
+
import cx from 'classnames';
|
|
12
|
+
import '../TextInput/index.js';
|
|
13
|
+
import { usePrefix } from '../../internal/usePrefix.js';
|
|
14
|
+
import { FormContext } from '../FluidForm/FormContext.js';
|
|
15
|
+
import TextInput from '../TextInput/TextInput.js';
|
|
16
|
+
|
|
17
|
+
var _excluded = ["className"];
|
|
18
|
+
|
|
19
|
+
function FluidTextInput(_ref) {
|
|
20
|
+
var className = _ref.className,
|
|
21
|
+
other = _objectWithoutProperties(_ref, _excluded);
|
|
22
|
+
|
|
23
|
+
var prefix = usePrefix();
|
|
24
|
+
var classNames = cx("".concat(prefix, "--text-input--fluid"), className);
|
|
25
|
+
return /*#__PURE__*/React__default.createElement(FormContext.Provider, {
|
|
26
|
+
value: {
|
|
27
|
+
isFluid: true
|
|
28
|
+
}
|
|
29
|
+
}, /*#__PURE__*/React__default.createElement(TextInput, _extends({
|
|
30
|
+
className: classNames
|
|
31
|
+
}, other)));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
FluidTextInput.propTypes = {
|
|
35
|
+
/**
|
|
36
|
+
* Specify an optional className to be applied to the outer FluidForm wrapper
|
|
37
|
+
*/
|
|
38
|
+
className: PropTypes.string,
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Optionally provide the default value of the `<input>`
|
|
42
|
+
*/
|
|
43
|
+
defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Specify whether the `<input>` should be disabled
|
|
47
|
+
*/
|
|
48
|
+
disabled: PropTypes.bool,
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Specify a custom `id` for the `<input>`
|
|
52
|
+
*/
|
|
53
|
+
id: PropTypes.string.isRequired,
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Specify whether the control is currently invalid
|
|
57
|
+
*/
|
|
58
|
+
invalid: PropTypes.bool,
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Provide the text that is displayed when the control is in an invalid state
|
|
62
|
+
*/
|
|
63
|
+
invalidText: PropTypes.node,
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Provide the text that will be read by a screen reader when visiting this
|
|
67
|
+
* control
|
|
68
|
+
*/
|
|
69
|
+
labelText: PropTypes.node.isRequired,
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Optionally provide an `onChange` handler that is called whenever `<input>`
|
|
73
|
+
* is updated
|
|
74
|
+
*/
|
|
75
|
+
onChange: PropTypes.func,
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Optionally provide an `onClick` handler that is called whenever the
|
|
79
|
+
* `<input>` is clicked
|
|
80
|
+
*/
|
|
81
|
+
onClick: PropTypes.func,
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Specify the placeholder attribute for the `<input>`
|
|
85
|
+
*/
|
|
86
|
+
placeholder: PropTypes.string,
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Specify the value of the `<input>`
|
|
90
|
+
*/
|
|
91
|
+
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Specify whether the control is currently in warning state
|
|
95
|
+
*/
|
|
96
|
+
warn: PropTypes.bool,
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Provide the text that is displayed when the control is in warning state
|
|
100
|
+
*/
|
|
101
|
+
warnText: PropTypes.node
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export { FluidTextInput as default };
|
|
@@ -130,7 +130,7 @@ Toggletip.propTypes = {
|
|
|
130
130
|
/**
|
|
131
131
|
* Specify how the toggletip should align with the button
|
|
132
132
|
*/
|
|
133
|
-
align: PropTypes.oneOf(['top', 'bottom', 'left', 'right']),
|
|
133
|
+
align: PropTypes.oneOf(['top', 'top-left', 'top-right', 'bottom', 'bottom-left', 'bottom-right', 'left', 'left-bottom', 'left-top', 'right', 'right-bottom', 'right-top']),
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
136
|
* Provide a custom element or component to render the top-level node for the
|
|
@@ -12,7 +12,6 @@ import PropTypes from 'prop-types';
|
|
|
12
12
|
import { AriaLabelPropType } from '../../prop-types/AriaPropTypes.js';
|
|
13
13
|
import { CARBON_SIDENAV_ITEMS } from './_utils.js';
|
|
14
14
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
15
|
-
import { useMatchMedia } from '../../internal/useMatchMedia.js';
|
|
16
15
|
|
|
17
16
|
var _excluded = ["expanded", "defaultExpanded", "isChildOfHeader", "aria-label", "aria-labelledby", "children", "onToggle", "className", "isFixedNav", "isRail", "isPersistent", "addFocusListeners", "addMouseListeners", "onOverlayClick"];
|
|
18
17
|
// import SideNavFooter from './SideNavFooter';
|
|
@@ -120,8 +119,6 @@ var SideNav = /*#__PURE__*/React__default.forwardRef(function SideNav(props, ref
|
|
|
120
119
|
};
|
|
121
120
|
}
|
|
122
121
|
|
|
123
|
-
var isSideNavCollapsed = useMatchMedia("(max-width: 1055px)");
|
|
124
|
-
var ariaHidden = isRail ? false : expanded === false && isSideNavCollapsed;
|
|
125
122
|
return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, isFixedNav ? null :
|
|
126
123
|
/*#__PURE__*/
|
|
127
124
|
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
|
|
@@ -129,7 +126,6 @@ var SideNav = /*#__PURE__*/React__default.forwardRef(function SideNav(props, ref
|
|
|
129
126
|
className: overlayClassName,
|
|
130
127
|
onClick: onOverlayClick
|
|
131
128
|
}), /*#__PURE__*/React__default.createElement("nav", _extends({
|
|
132
|
-
"aria-hidden": ariaHidden,
|
|
133
129
|
ref: ref,
|
|
134
130
|
className: "".concat(prefix, "--side-nav__navigation ").concat(className)
|
|
135
131
|
}, accessibilityLabel, eventHandlers, other), childrenToRender));
|
package/es/index.js
CHANGED
|
@@ -124,6 +124,7 @@ export { default as SideNavIcon } from './components/UIShell/SideNavIcon.js';
|
|
|
124
124
|
export { default as SideNavItem } from './components/UIShell/SideNavItem.js';
|
|
125
125
|
export { default as SideNavLinkText } from './components/UIShell/SideNavLinkText.js';
|
|
126
126
|
export { default as unstable_useContextMenu } from './components/ContextMenu/useContextMenu.js';
|
|
127
|
+
export { default as unstable__FluidTextInput } from './components/FluidTextInput/FluidTextInput.js';
|
|
127
128
|
export { default as unstable_MenuDivider } from './components/Menu/MenuDivider.js';
|
|
128
129
|
export { default as unstable_MenuGroup } from './components/Menu/MenuGroup.js';
|
|
129
130
|
export { default as unstable_MenuItem } from './components/Menu/MenuItem.js';
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2022
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11
|
+
|
|
12
|
+
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
|
|
13
|
+
var PropTypes = require('prop-types');
|
|
14
|
+
var React = require('react');
|
|
15
|
+
var cx = require('classnames');
|
|
16
|
+
require('../TextInput/index.js');
|
|
17
|
+
var usePrefix = require('../../internal/usePrefix.js');
|
|
18
|
+
var FormContext = require('../FluidForm/FormContext.js');
|
|
19
|
+
var TextInput = require('../TextInput/TextInput.js');
|
|
20
|
+
|
|
21
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
22
|
+
|
|
23
|
+
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
24
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
25
|
+
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
|
|
26
|
+
|
|
27
|
+
var _excluded = ["className"];
|
|
28
|
+
|
|
29
|
+
function FluidTextInput(_ref) {
|
|
30
|
+
var className = _ref.className,
|
|
31
|
+
other = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
|
|
32
|
+
|
|
33
|
+
var prefix = usePrefix.usePrefix();
|
|
34
|
+
var classNames = cx__default["default"]("".concat(prefix, "--text-input--fluid"), className);
|
|
35
|
+
return /*#__PURE__*/React__default["default"].createElement(FormContext.FormContext.Provider, {
|
|
36
|
+
value: {
|
|
37
|
+
isFluid: true
|
|
38
|
+
}
|
|
39
|
+
}, /*#__PURE__*/React__default["default"].createElement(TextInput["default"], _rollupPluginBabelHelpers["extends"]({
|
|
40
|
+
className: classNames
|
|
41
|
+
}, other)));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
FluidTextInput.propTypes = {
|
|
45
|
+
/**
|
|
46
|
+
* Specify an optional className to be applied to the outer FluidForm wrapper
|
|
47
|
+
*/
|
|
48
|
+
className: PropTypes__default["default"].string,
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Optionally provide the default value of the `<input>`
|
|
52
|
+
*/
|
|
53
|
+
defaultValue: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].number]),
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Specify whether the `<input>` should be disabled
|
|
57
|
+
*/
|
|
58
|
+
disabled: PropTypes__default["default"].bool,
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Specify a custom `id` for the `<input>`
|
|
62
|
+
*/
|
|
63
|
+
id: PropTypes__default["default"].string.isRequired,
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Specify whether the control is currently invalid
|
|
67
|
+
*/
|
|
68
|
+
invalid: PropTypes__default["default"].bool,
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Provide the text that is displayed when the control is in an invalid state
|
|
72
|
+
*/
|
|
73
|
+
invalidText: PropTypes__default["default"].node,
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Provide the text that will be read by a screen reader when visiting this
|
|
77
|
+
* control
|
|
78
|
+
*/
|
|
79
|
+
labelText: PropTypes__default["default"].node.isRequired,
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Optionally provide an `onChange` handler that is called whenever `<input>`
|
|
83
|
+
* is updated
|
|
84
|
+
*/
|
|
85
|
+
onChange: PropTypes__default["default"].func,
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Optionally provide an `onClick` handler that is called whenever the
|
|
89
|
+
* `<input>` is clicked
|
|
90
|
+
*/
|
|
91
|
+
onClick: PropTypes__default["default"].func,
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Specify the placeholder attribute for the `<input>`
|
|
95
|
+
*/
|
|
96
|
+
placeholder: PropTypes__default["default"].string,
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Specify the value of the `<input>`
|
|
100
|
+
*/
|
|
101
|
+
value: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].number]),
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Specify whether the control is currently in warning state
|
|
105
|
+
*/
|
|
106
|
+
warn: PropTypes__default["default"].bool,
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Provide the text that is displayed when the control is in warning state
|
|
110
|
+
*/
|
|
111
|
+
warnText: PropTypes__default["default"].node
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
exports["default"] = FluidTextInput;
|
|
@@ -140,7 +140,7 @@ Toggletip.propTypes = {
|
|
|
140
140
|
/**
|
|
141
141
|
* Specify how the toggletip should align with the button
|
|
142
142
|
*/
|
|
143
|
-
align: PropTypes__default["default"].oneOf(['top', 'bottom', 'left', 'right']),
|
|
143
|
+
align: PropTypes__default["default"].oneOf(['top', 'top-left', 'top-right', 'bottom', 'bottom-left', 'bottom-right', 'left', 'left-bottom', 'left-top', 'right', 'right-bottom', 'right-top']),
|
|
144
144
|
|
|
145
145
|
/**
|
|
146
146
|
* Provide a custom element or component to render the top-level node for the
|
|
@@ -16,7 +16,6 @@ var PropTypes = require('prop-types');
|
|
|
16
16
|
var AriaPropTypes = require('../../prop-types/AriaPropTypes.js');
|
|
17
17
|
var _utils = require('./_utils.js');
|
|
18
18
|
var usePrefix = require('../../internal/usePrefix.js');
|
|
19
|
-
var useMatchMedia = require('../../internal/useMatchMedia.js');
|
|
20
19
|
|
|
21
20
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
22
21
|
|
|
@@ -130,8 +129,6 @@ var SideNav = /*#__PURE__*/React__default["default"].forwardRef(function SideNav
|
|
|
130
129
|
};
|
|
131
130
|
}
|
|
132
131
|
|
|
133
|
-
var isSideNavCollapsed = useMatchMedia.useMatchMedia("(max-width: 1055px)");
|
|
134
|
-
var ariaHidden = isRail ? false : expanded === false && isSideNavCollapsed;
|
|
135
132
|
return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, isFixedNav ? null :
|
|
136
133
|
/*#__PURE__*/
|
|
137
134
|
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
|
|
@@ -139,7 +136,6 @@ var SideNav = /*#__PURE__*/React__default["default"].forwardRef(function SideNav
|
|
|
139
136
|
className: overlayClassName,
|
|
140
137
|
onClick: onOverlayClick
|
|
141
138
|
}), /*#__PURE__*/React__default["default"].createElement("nav", _rollupPluginBabelHelpers["extends"]({
|
|
142
|
-
"aria-hidden": ariaHidden,
|
|
143
139
|
ref: ref,
|
|
144
140
|
className: "".concat(prefix, "--side-nav__navigation ").concat(className)
|
|
145
141
|
}, accessibilityLabel, eventHandlers, other), childrenToRender));
|
package/lib/index.js
CHANGED
|
@@ -128,6 +128,7 @@ var SideNavIcon = require('./components/UIShell/SideNavIcon.js');
|
|
|
128
128
|
var SideNavItem = require('./components/UIShell/SideNavItem.js');
|
|
129
129
|
var SideNavLinkText = require('./components/UIShell/SideNavLinkText.js');
|
|
130
130
|
var useContextMenu = require('./components/ContextMenu/useContextMenu.js');
|
|
131
|
+
var FluidTextInput = require('./components/FluidTextInput/FluidTextInput.js');
|
|
131
132
|
var MenuDivider = require('./components/Menu/MenuDivider.js');
|
|
132
133
|
var MenuGroup = require('./components/Menu/MenuGroup.js');
|
|
133
134
|
var MenuItem = require('./components/Menu/MenuItem.js');
|
|
@@ -344,6 +345,7 @@ exports.SideNavIcon = SideNavIcon["default"];
|
|
|
344
345
|
exports.SideNavItem = SideNavItem["default"];
|
|
345
346
|
exports.SideNavLinkText = SideNavLinkText["default"];
|
|
346
347
|
exports.unstable_useContextMenu = useContextMenu["default"];
|
|
348
|
+
exports.unstable__FluidTextInput = FluidTextInput["default"];
|
|
347
349
|
exports.unstable_MenuDivider = MenuDivider["default"];
|
|
348
350
|
exports.unstable_MenuGroup = MenuGroup["default"];
|
|
349
351
|
exports.unstable_MenuItem = MenuItem["default"];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carbon/react",
|
|
3
3
|
"description": "React components for the Carbon Design System",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.13.0-rc.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"module": "es/index.js",
|
|
@@ -43,10 +43,10 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@babel/runtime": "^7.18.3",
|
|
46
|
-
"@carbon/feature-flags": "^0.
|
|
47
|
-
"@carbon/icons-react": "^11.
|
|
48
|
-
"@carbon/layout": "^11.
|
|
49
|
-
"@carbon/styles": "^1.
|
|
46
|
+
"@carbon/feature-flags": "^0.9.0-rc.0",
|
|
47
|
+
"@carbon/icons-react": "^11.8.0-rc.0",
|
|
48
|
+
"@carbon/layout": "^11.6.0-rc.0",
|
|
49
|
+
"@carbon/styles": "^1.13.0-rc.0",
|
|
50
50
|
"@carbon/telemetry": "0.1.0",
|
|
51
51
|
"classnames": "2.3.1",
|
|
52
52
|
"copy-to-clipboard": "^3.3.1",
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
"@babel/plugin-transform-react-constant-elements": "^7.17.12",
|
|
73
73
|
"@babel/preset-env": "^7.18.2",
|
|
74
74
|
"@babel/preset-react": "^7.17.12",
|
|
75
|
-
"@carbon/test-utils": "^10.
|
|
76
|
-
"@carbon/themes": "^11.
|
|
75
|
+
"@carbon/test-utils": "^10.26.0-rc.0",
|
|
76
|
+
"@carbon/themes": "^11.9.0-rc.0",
|
|
77
77
|
"@rollup/plugin-babel": "^5.3.0",
|
|
78
78
|
"@rollup/plugin-commonjs": "^21.0.0",
|
|
79
79
|
"@rollup/plugin-node-resolve": "^13.0.0",
|
|
@@ -130,5 +130,5 @@
|
|
|
130
130
|
"**/*.scss",
|
|
131
131
|
"**/*.css"
|
|
132
132
|
],
|
|
133
|
-
"gitHead": "
|
|
133
|
+
"gitHead": "b367a932e322ac783c3d4cf0d5a1f1e2756e8b2e"
|
|
134
134
|
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2016, 2022
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { slicedToArray as _slicedToArray } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
|
-
import { useState, useEffect } from 'react';
|
|
10
|
-
import { canUseDOM } from './environment.js';
|
|
11
|
-
|
|
12
|
-
function useMatchMedia(mediaQueryString) {
|
|
13
|
-
var _useState = useState(function () {
|
|
14
|
-
if (canUseDOM) {
|
|
15
|
-
var mediaQueryList = window.matchMedia(mediaQueryString);
|
|
16
|
-
return mediaQueryList.matches;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return false;
|
|
20
|
-
}),
|
|
21
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
22
|
-
matches = _useState2[0],
|
|
23
|
-
setMatches = _useState2[1];
|
|
24
|
-
|
|
25
|
-
useEffect(function () {
|
|
26
|
-
function listener(event) {
|
|
27
|
-
setMatches(event.matches);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
var mediaQueryList = window.matchMedia(mediaQueryString); // Support fallback to `addListener` for broader browser support
|
|
31
|
-
|
|
32
|
-
if (mediaQueryList.addEventListener) {
|
|
33
|
-
mediaQueryList.addEventListener('change', listener);
|
|
34
|
-
} else {
|
|
35
|
-
mediaQueryList.addListener(listener);
|
|
36
|
-
} // Make sure the media query list is in sync with the matches state
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
setMatches(mediaQueryList.matches);
|
|
40
|
-
return function () {
|
|
41
|
-
if (mediaQueryList.addEventListener) {
|
|
42
|
-
mediaQueryList.removeEventListener('change', listener);
|
|
43
|
-
} else {
|
|
44
|
-
mediaQueryList.removeListener(listener);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
}, [mediaQueryString]);
|
|
48
|
-
return matches;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export { useMatchMedia };
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2016, 2022
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11
|
-
|
|
12
|
-
var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js');
|
|
13
|
-
var React = require('react');
|
|
14
|
-
var environment = require('./environment.js');
|
|
15
|
-
|
|
16
|
-
function useMatchMedia(mediaQueryString) {
|
|
17
|
-
var _useState = React.useState(function () {
|
|
18
|
-
if (environment.canUseDOM) {
|
|
19
|
-
var mediaQueryList = window.matchMedia(mediaQueryString);
|
|
20
|
-
return mediaQueryList.matches;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return false;
|
|
24
|
-
}),
|
|
25
|
-
_useState2 = _rollupPluginBabelHelpers.slicedToArray(_useState, 2),
|
|
26
|
-
matches = _useState2[0],
|
|
27
|
-
setMatches = _useState2[1];
|
|
28
|
-
|
|
29
|
-
React.useEffect(function () {
|
|
30
|
-
function listener(event) {
|
|
31
|
-
setMatches(event.matches);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
var mediaQueryList = window.matchMedia(mediaQueryString); // Support fallback to `addListener` for broader browser support
|
|
35
|
-
|
|
36
|
-
if (mediaQueryList.addEventListener) {
|
|
37
|
-
mediaQueryList.addEventListener('change', listener);
|
|
38
|
-
} else {
|
|
39
|
-
mediaQueryList.addListener(listener);
|
|
40
|
-
} // Make sure the media query list is in sync with the matches state
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
setMatches(mediaQueryList.matches);
|
|
44
|
-
return function () {
|
|
45
|
-
if (mediaQueryList.addEventListener) {
|
|
46
|
-
mediaQueryList.removeEventListener('change', listener);
|
|
47
|
-
} else {
|
|
48
|
-
mediaQueryList.removeListener(listener);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}, [mediaQueryString]);
|
|
52
|
-
return matches;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
exports.useMatchMedia = useMatchMedia;
|