@carbon/react 1.8.0 → 1.10.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.
Files changed (34) hide show
  1. package/es/components/ComposedModal/ComposedModal.js +172 -577
  2. package/es/components/ComposedModal/{next/ModalFooter.js → ModalFooter.js} +4 -4
  3. package/es/components/ComposedModal/{next/ModalHeader.js → ModalHeader.js} +2 -2
  4. package/es/components/DataTable/tools/sorting.js +8 -0
  5. package/es/components/Icon/Icon.Skeleton.js +4 -12
  6. package/es/components/InlineCheckbox/InlineCheckbox.js +0 -1
  7. package/es/components/Menu/Menu.js +1 -1
  8. package/es/components/NumberInput/NumberInput.Skeleton.js +3 -4
  9. package/es/components/NumberInput/NumberInput.js +311 -362
  10. package/es/components/TileGroup/TileGroup.js +1 -1
  11. package/es/index.js +5 -4
  12. package/es/internal/useControllableState.js +1 -1
  13. package/lib/components/ComposedModal/ComposedModal.js +174 -581
  14. package/lib/components/ComposedModal/{next/ModalFooter.js → ModalFooter.js} +4 -4
  15. package/lib/components/ComposedModal/{next/ModalHeader.js → ModalHeader.js} +2 -2
  16. package/lib/components/DataTable/tools/sorting.js +8 -0
  17. package/lib/components/Icon/Icon.Skeleton.js +4 -12
  18. package/lib/components/InlineCheckbox/InlineCheckbox.js +0 -1
  19. package/lib/components/Menu/Menu.js +1 -1
  20. package/lib/components/NumberInput/NumberInput.Skeleton.js +3 -4
  21. package/lib/components/NumberInput/NumberInput.js +308 -379
  22. package/lib/components/TileGroup/TileGroup.js +1 -1
  23. package/lib/index.js +57 -56
  24. package/lib/internal/useControllableState.js +1 -1
  25. package/package.json +6 -6
  26. package/scss/utilities/_hide-at-breakpoint.scss +9 -0
  27. package/es/components/ComposedModal/index.js +0 -19
  28. package/es/components/ComposedModal/next/ComposedModal.js +0 -225
  29. package/es/internal/FeatureFlags.js +0 -52
  30. package/es/prop-types/requiredIfValueExists.js +0 -32
  31. package/lib/components/ComposedModal/index.js +0 -45
  32. package/lib/components/ComposedModal/next/ComposedModal.js +0 -236
  33. package/lib/internal/FeatureFlags.js +0 -56
  34. package/lib/prop-types/requiredIfValueExists.js +0 -36
@@ -1,32 +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
- /**
9
- * @param {Function} propType The original prop type checker.
10
- * @returns {Function} The new prop type checker for `onChange` that makes it required if `value` exists and `readOnly` does not exist.
11
- */
12
- function requiredIfValueExists(propType) {
13
- return function check(props, propName, componentName) {
14
- var onChange = props[propName],
15
- value = props.value,
16
- readOnly = props.readOnly;
17
- var exists = onChange !== undefined;
18
- var valueExists = value !== undefined;
19
-
20
- if (process.env.NODE_ENV !== "production" && !exists && valueExists && !readOnly) {
21
- return new Error("You provided a value prop to `".concat(componentName, "` without an `onChange` handler. ") + 'This will render a read-only field. ' + 'If the field should be mutable use `defaultValue`. Otherwise, set either `onChange` or `readOnly`.');
22
- }
23
-
24
- for (var _len = arguments.length, rest = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
25
- rest[_key - 3] = arguments[_key];
26
- }
27
-
28
- return propType.apply(void 0, [props, propName, componentName].concat(rest));
29
- };
30
- }
31
-
32
- export { requiredIfValueExists as default };
@@ -1,45 +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 FeatureFlags = require('@carbon/feature-flags');
13
- var ModalHeader$1 = require('./next/ModalHeader.js');
14
- var ModalFooter$1 = require('./next/ModalFooter.js');
15
- var ComposedModal$2 = require('./next/ComposedModal.js');
16
- var ComposedModal$1 = require('./ComposedModal.js');
17
-
18
- function _interopNamespace(e) {
19
- if (e && e.__esModule) return e;
20
- var n = Object.create(null);
21
- if (e) {
22
- Object.keys(e).forEach(function (k) {
23
- if (k !== 'default') {
24
- var d = Object.getOwnPropertyDescriptor(e, k);
25
- Object.defineProperty(n, k, d.get ? d : {
26
- enumerable: true,
27
- get: function () { return e[k]; }
28
- });
29
- }
30
- });
31
- }
32
- n["default"] = e;
33
- return Object.freeze(n);
34
- }
35
-
36
- var FeatureFlags__namespace = /*#__PURE__*/_interopNamespace(FeatureFlags);
37
-
38
- var ModalHeader = FeatureFlags__namespace.enabled('enable-v11-release') ? ModalHeader$1.ModalHeader : ComposedModal$1.ModalHeader;
39
- var ModalFooter = FeatureFlags__namespace.enabled('enable-v11-release') ? ModalFooter$1.ModalFooter : ComposedModal$1.ModalFooter;
40
- var ComposedModal = FeatureFlags__namespace.enabled('enable-v11-release') ? ComposedModal$2["default"] : ComposedModal$1["default"];
41
-
42
- exports.ModalBody = ComposedModal$1.ModalBody;
43
- exports.ComposedModal = ComposedModal;
44
- exports.ModalFooter = ModalFooter;
45
- exports.ModalHeader = ModalHeader;
@@ -1,236 +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 PropTypes = require('prop-types');
15
- var ModalHeader = require('./ModalHeader.js');
16
- var ComposedModal$1 = require('../ComposedModal.js');
17
- var cx = require('classnames');
18
- var toggleClass = require('../../../tools/toggleClass.js');
19
- var requiredIfGivenPropIsTruthy = require('../../../prop-types/requiredIfGivenPropIsTruthy.js');
20
- var wrapFocus = require('../../../internal/wrapFocus.js');
21
- var usePrefix = require('../../../internal/usePrefix.js');
22
-
23
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
24
-
25
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
26
- var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
27
- var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
28
-
29
- var _ModalBody$propTypes, _ComposedModal$propTy;
30
-
31
- var _excluded = ["className", "children", "hasForm", "hasScrollingContent"],
32
- _excluded2 = ["aria-labelledby", "aria-label", "children", "className", "containerClassName", "danger", "onClose", "onKeyDown", "open", "preventCloseOnClickOutside", "selectorPrimaryFocus", "selectorsFloatingMenus", "size"];
33
- var ModalBody = /*#__PURE__*/React__default["default"].forwardRef(function ModalBody(_ref, ref) {
34
- var _cx;
35
-
36
- var customClassName = _ref.className,
37
- children = _ref.children,
38
- hasForm = _ref.hasForm,
39
- hasScrollingContent = _ref.hasScrollingContent,
40
- rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
41
-
42
- var prefix = usePrefix.usePrefix();
43
- var contentClass = cx__default["default"]((_cx = {}, _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--modal-content"), true), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--modal-content--with-form"), hasForm), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--modal-scroll-content"), hasScrollingContent), _rollupPluginBabelHelpers.defineProperty(_cx, customClassName, customClassName), _cx));
44
- var hasScrollingContentProps = hasScrollingContent ? {
45
- tabIndex: 0,
46
- role: 'region'
47
- } : {};
48
- return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({
49
- className: contentClass
50
- }, hasScrollingContentProps, rest, {
51
- ref: ref
52
- }), children), hasScrollingContent && /*#__PURE__*/React__default["default"].createElement("div", {
53
- className: "".concat(prefix, "--modal-content--overflow-indicator")
54
- }));
55
- });
56
- ModalBody.propTypes = (_ModalBody$propTypes = {}, _rollupPluginBabelHelpers.defineProperty(_ModalBody$propTypes, 'aria-label', requiredIfGivenPropIsTruthy["default"]('hasScrollingContent', PropTypes__default["default"].string)), _rollupPluginBabelHelpers.defineProperty(_ModalBody$propTypes, "children", PropTypes__default["default"].node), _rollupPluginBabelHelpers.defineProperty(_ModalBody$propTypes, "className", PropTypes__default["default"].string), _rollupPluginBabelHelpers.defineProperty(_ModalBody$propTypes, "hasForm", PropTypes__default["default"].bool), _rollupPluginBabelHelpers.defineProperty(_ModalBody$propTypes, "hasScrollingContent", PropTypes__default["default"].bool), _ModalBody$propTypes);
57
- var ComposedModal = /*#__PURE__*/React__default["default"].forwardRef(function ComposedModal(_ref2, ref) {
58
- var _cx2, _cx3;
59
-
60
- var ariaLabelledBy = _ref2['aria-labelledby'],
61
- ariaLabel = _ref2['aria-label'],
62
- children = _ref2.children,
63
- customClassName = _ref2.className,
64
- containerClassName = _ref2.containerClassName,
65
- danger = _ref2.danger,
66
- onClose = _ref2.onClose,
67
- onKeyDown = _ref2.onKeyDown,
68
- open = _ref2.open,
69
- preventCloseOnClickOutside = _ref2.preventCloseOnClickOutside,
70
- selectorPrimaryFocus = _ref2.selectorPrimaryFocus,
71
- selectorsFloatingMenus = _ref2.selectorsFloatingMenus,
72
- size = _ref2.size,
73
- rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref2, _excluded2);
74
-
75
- var prefix = usePrefix.usePrefix();
76
-
77
- var _useState = React.useState(open),
78
- _useState2 = _rollupPluginBabelHelpers.slicedToArray(_useState, 2),
79
- isOpen = _useState2[0],
80
- setisOpen = _useState2[1];
81
-
82
- var _useState3 = React.useState(open),
83
- _useState4 = _rollupPluginBabelHelpers.slicedToArray(_useState3, 2),
84
- prevOpen = _useState4[0],
85
- setPrevOpen = _useState4[1];
86
-
87
- var innerModal = React.useRef();
88
- var button = React.useRef();
89
- var startSentinel = React.useRef();
90
- var endSentinel = React.useRef();
91
-
92
- if (open !== prevOpen) {
93
- setisOpen(open);
94
- setPrevOpen(open);
95
- }
96
-
97
- function handleKeyDown(evt) {
98
- // Esc key
99
- if (evt.which === 27) {
100
- closeModal(evt);
101
- }
102
-
103
- onKeyDown(evt);
104
- }
105
-
106
- function handleClick(evt) {
107
- if (!innerModal.current.contains(evt.target) && preventCloseOnClickOutside) {
108
- return;
109
- }
110
-
111
- if (innerModal.current && !innerModal.current.contains(evt.target)) {
112
- closeModal(evt);
113
- }
114
- }
115
-
116
- function handleBlur(_ref3) {
117
- var oldActiveNode = _ref3.target,
118
- currentActiveNode = _ref3.relatedTarget;
119
-
120
- if (open && currentActiveNode && oldActiveNode) {
121
- var bodyNode = innerModal.current;
122
- var startSentinelNode = startSentinel.current;
123
- var endSentinelNode = endSentinel.current;
124
- wrapFocus["default"]({
125
- bodyNode: bodyNode,
126
- startSentinelNode: startSentinelNode,
127
- endSentinelNode: endSentinelNode,
128
- currentActiveNode: currentActiveNode,
129
- oldActiveNode: oldActiveNode,
130
- selectorsFloatingMenus: selectorsFloatingMenus
131
- });
132
- }
133
- }
134
-
135
- function closeModal(evt) {
136
- if (!onClose || onClose(evt) !== false) {
137
- setisOpen(false);
138
- }
139
- }
140
-
141
- var modalClass = cx__default["default"]((_cx2 = {}, _rollupPluginBabelHelpers.defineProperty(_cx2, "".concat(prefix, "--modal"), true), _rollupPluginBabelHelpers.defineProperty(_cx2, 'is-visible', isOpen), _rollupPluginBabelHelpers.defineProperty(_cx2, customClassName, customClassName), _rollupPluginBabelHelpers.defineProperty(_cx2, "".concat(prefix, "--modal--danger"), danger), _cx2));
142
- var containerClass = cx__default["default"]((_cx3 = {}, _rollupPluginBabelHelpers.defineProperty(_cx3, "".concat(prefix, "--modal-container"), true), _rollupPluginBabelHelpers.defineProperty(_cx3, "".concat(prefix, "--modal-container--").concat(size), size), _rollupPluginBabelHelpers.defineProperty(_cx3, containerClassName, containerClassName), _cx3)); // Generate aria-label based on Modal Header label if one is not provided (L253)
143
-
144
- var generatedAriaLabel;
145
- var childrenWithProps = React__default["default"].Children.toArray(children).map(function (child) {
146
- switch (child.type) {
147
- case React__default["default"].createElement(ModalHeader.ModalHeader).type:
148
- generatedAriaLabel = child.props.label;
149
- return /*#__PURE__*/React__default["default"].cloneElement(child, {
150
- closeModal: closeModal
151
- });
152
-
153
- case React__default["default"].createElement(ComposedModal$1.ModalFooter).type:
154
- return /*#__PURE__*/React__default["default"].cloneElement(child, {
155
- closeModal: closeModal,
156
- inputref: button
157
- });
158
-
159
- default:
160
- return child;
161
- }
162
- });
163
- React.useEffect(function () {
164
- if (prevOpen !== isOpen) {
165
- toggleClass["default"](document.body, "".concat(prefix, "--body--with-modal-open"), isOpen);
166
- }
167
- });
168
- React.useEffect(function () {
169
- return function () {
170
- return toggleClass["default"](document.body, "".concat(prefix, "--body--with-modal-open"), false);
171
- };
172
- });
173
- React.useEffect(function () {
174
- toggleClass["default"](document.body, "".concat(prefix, "--body--with-modal-open"), open);
175
- }, [open, prefix]);
176
- React.useEffect(function () {
177
- var focusButton = function focusButton(focusContainerElement) {
178
- if (focusContainerElement) {
179
- var primaryFocusElement = focusContainerElement.querySelector(selectorPrimaryFocus);
180
-
181
- if (primaryFocusElement) {
182
- primaryFocusElement.focus();
183
- return;
184
- }
185
-
186
- if (button.current) {
187
- button.current.focus();
188
- }
189
- }
190
- };
191
-
192
- if (!open) {
193
- return;
194
- }
195
-
196
- if (innerModal.current) {
197
- focusButton(innerModal.current);
198
- }
199
- }, [open, selectorPrimaryFocus]);
200
- return /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({}, rest, {
201
- role: "presentation",
202
- ref: ref,
203
- "aria-hidden": !open,
204
- onBlur: handleBlur,
205
- onClick: handleClick,
206
- onKeyDown: handleKeyDown,
207
- className: modalClass,
208
- tabIndex: "-1"
209
- }), /*#__PURE__*/React__default["default"].createElement("div", {
210
- className: containerClass,
211
- role: "dialog",
212
- "aria-modal": "true",
213
- "aria-label": ariaLabel ? ariaLabel : generatedAriaLabel,
214
- "aria-labelledby": ariaLabelledBy
215
- }, /*#__PURE__*/React__default["default"].createElement("button", {
216
- type: "button",
217
- ref: startSentinel,
218
- className: "".concat(prefix, "--visually-hidden")
219
- }, "Focus sentinel"), /*#__PURE__*/React__default["default"].createElement("div", {
220
- ref: innerModal,
221
- className: "".concat(prefix, "--modal-container-body")
222
- }, childrenWithProps), /*#__PURE__*/React__default["default"].createElement("button", {
223
- type: "button",
224
- ref: endSentinel,
225
- className: "".concat(prefix, "--visually-hidden")
226
- }, "Focus sentinel")));
227
- });
228
- ComposedModal.propTypes = (_ComposedModal$propTy = {}, _rollupPluginBabelHelpers.defineProperty(_ComposedModal$propTy, 'aria-label', PropTypes__default["default"].string), _rollupPluginBabelHelpers.defineProperty(_ComposedModal$propTy, 'aria-labelledby', PropTypes__default["default"].string), _rollupPluginBabelHelpers.defineProperty(_ComposedModal$propTy, "children", PropTypes__default["default"].node), _rollupPluginBabelHelpers.defineProperty(_ComposedModal$propTy, "className", PropTypes__default["default"].string), _rollupPluginBabelHelpers.defineProperty(_ComposedModal$propTy, "containerClassName", PropTypes__default["default"].string), _rollupPluginBabelHelpers.defineProperty(_ComposedModal$propTy, "danger", PropTypes__default["default"].bool), _rollupPluginBabelHelpers.defineProperty(_ComposedModal$propTy, "onClose", PropTypes__default["default"].func), _rollupPluginBabelHelpers.defineProperty(_ComposedModal$propTy, "onKeyDown", PropTypes__default["default"].func), _rollupPluginBabelHelpers.defineProperty(_ComposedModal$propTy, "open", PropTypes__default["default"].bool), _rollupPluginBabelHelpers.defineProperty(_ComposedModal$propTy, "preventCloseOnClickOutside", PropTypes__default["default"].bool), _rollupPluginBabelHelpers.defineProperty(_ComposedModal$propTy, "selectorPrimaryFocus", PropTypes__default["default"].string), _rollupPluginBabelHelpers.defineProperty(_ComposedModal$propTy, "selectorsFloatingMenus", PropTypes__default["default"].string), _rollupPluginBabelHelpers.defineProperty(_ComposedModal$propTy, "size", PropTypes__default["default"].oneOf(['xs', 'sm', 'md', 'lg'])), _ComposedModal$propTy);
229
- ComposedModal.defaultProps = {
230
- onKeyDown: function onKeyDown() {},
231
- selectorPrimaryFocus: '[data-modal-primary-focus]'
232
- };
233
- var ComposedModalNext = ComposedModal;
234
-
235
- exports.ModalBody = ModalBody;
236
- exports["default"] = ComposedModalNext;
@@ -1,56 +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 FeatureFlags = require('@carbon/feature-flags');
13
-
14
- /**
15
- * This file contains the list of the default values of compile-time feature flags.
16
- *
17
- * Build toolchain can replace variable here and/or the references
18
- * in order to apply non-default values to those feature flags.
19
- *
20
- * @example Render `foo` if `aFeatureFlag` is `true`, render `bar` otherwise.
21
- * import { aFeatureFlag } from '/path/to/FeatureFlags';
22
- * ...
23
- * const MyComponent = props => (<div {...props}>{aFeatureFlag ? 'foo' : 'bar'}</div>);
24
- */
25
-
26
- /**
27
- * With this flag, certain components will be created in either a controlled or controlled
28
- * mode based on the existence of a value prop.
29
- *
30
- * The following components will have the significance of their props slightly altered as outlined below.
31
- *
32
- * Components: `<NumberInput>`
33
- *
34
- * * `value` → when provided, enables controlled mode.
35
- * For the rest of the component's lifecycle, it will be controlled by this prop as it's single source of truth.
36
- * * `defaultValue` → Optional starting value, used for for uncontrolled mode only (no value prop).
37
- * The value prop takes precedence over defaultValue.
38
- * * `onChange` → Optional event handler.
39
- * However, if value is provided and a handler is not, we'll throw a warning indicating the component is now read-only
40
- * * `readOnly` → silences the above warning, acknowledging the read-only state of the component
41
- *
42
- * This flag also disables prop -> state sync in several components, notably `<NumberInput>`.
43
- *
44
- * This flag also updates event handlers to pass an up-to-date value in the second parameter,
45
- * so applications can use it in both controlled and uncontrolled components.
46
- *
47
- * * _With_ this feature flag, the signature of the event handler will be altered to provide additional context in the second parameter: `onChange(event, { value, ...rest })` where:
48
- * * `event` is the (React) raw event
49
- * * `value` is the new value
50
- * * `rest` tells you additional information based on the source component
51
- * * _Without_ this feature flag the event handler has component-specific signature, e.g. `onChange(event, direction)`.
52
- */
53
-
54
- var useControlledStateWithValue = FeatureFlags.enabled('enable-use-controlled-state-with-value');
55
-
56
- exports.useControlledStateWithValue = useControlledStateWithValue;
@@ -1,36 +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
- /**
13
- * @param {Function} propType The original prop type checker.
14
- * @returns {Function} The new prop type checker for `onChange` that makes it required if `value` exists and `readOnly` does not exist.
15
- */
16
- function requiredIfValueExists(propType) {
17
- return function check(props, propName, componentName) {
18
- var onChange = props[propName],
19
- value = props.value,
20
- readOnly = props.readOnly;
21
- var exists = onChange !== undefined;
22
- var valueExists = value !== undefined;
23
-
24
- if (process.env.NODE_ENV !== "production" && !exists && valueExists && !readOnly) {
25
- return new Error("You provided a value prop to `".concat(componentName, "` without an `onChange` handler. ") + 'This will render a read-only field. ' + 'If the field should be mutable use `defaultValue`. Otherwise, set either `onChange` or `readOnly`.');
26
- }
27
-
28
- for (var _len = arguments.length, rest = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
29
- rest[_key - 3] = arguments[_key];
30
- }
31
-
32
- return propType.apply(void 0, [props, propName, componentName].concat(rest));
33
- };
34
- }
35
-
36
- exports["default"] = requiredIfValueExists;