@instructure/ui-react-utils 10.16.1-snapshot-0 → 10.16.1-snapshot-1
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/CHANGELOG.md +1 -1
- package/es/DeterministicIdContext/DeterministicIdContextProvider.js +6 -4
- package/es/DeterministicIdContext/withDeterministicId.js +6 -4
- package/es/__new-tests__/DeterministicIdContext.test.js +36 -24
- package/es/__new-tests__/callRenderProp.test.js +30 -13
- package/es/__new-tests__/deprecated.test.js +30 -17
- package/es/__new-tests__/experimental.test.js +10 -7
- package/es/__new-tests__/hack.test.js +7 -4
- package/es/__new-tests__/safeCloneElement.test.js +7 -7
- package/es/ensureSingleChild.js +6 -2
- package/es/safeCloneElement.js +3 -3
- package/lib/DeterministicIdContext/DeterministicIdContextProvider.js +5 -5
- package/lib/DeterministicIdContext/withDeterministicId.js +6 -5
- package/lib/__new-tests__/DeterministicIdContext.test.js +36 -25
- package/lib/__new-tests__/callRenderProp.test.js +30 -13
- package/lib/__new-tests__/deprecated.test.js +30 -18
- package/lib/__new-tests__/experimental.test.js +10 -8
- package/lib/__new-tests__/hack.test.js +7 -5
- package/lib/__new-tests__/safeCloneElement.test.js +10 -11
- package/lib/ensureSingleChild.js +7 -5
- package/lib/safeCloneElement.js +3 -4
- package/package.json +7 -7
- package/src/DeterministicIdContext/DeterministicIdContextProvider.tsx +1 -1
- package/src/DeterministicIdContext/withDeterministicId.tsx +2 -2
- package/src/__new-tests__/DeterministicIdContext.test.tsx +3 -3
- package/src/__new-tests__/callRenderProp.test.tsx +3 -3
- package/src/__new-tests__/deprecated.test.tsx +1 -1
- package/src/__new-tests__/experimental.test.tsx +1 -1
- package/src/__new-tests__/hack.test.tsx +1 -1
- package/src/__new-tests__/safeCloneElement.test.tsx +1 -1
- package/src/ensureSingleChild.tsx +1 -1
- package/src/safeCloneElement.ts +5 -4
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/DeterministicIdContext/DeterministicIdContextProvider.d.ts +1 -2
- package/types/DeterministicIdContext/DeterministicIdContextProvider.d.ts.map +1 -1
- package/types/DeterministicIdContext/withDeterministicId.d.ts +2 -2
- package/types/DeterministicIdContext/withDeterministicId.d.ts.map +1 -1
- package/types/ensureSingleChild.d.ts +2 -2
- package/types/ensureSingleChild.d.ts.map +1 -1
- package/types/getElementType.d.ts +1 -1
- package/types/safeCloneElement.d.ts.map +1 -1
package/lib/ensureSingleChild.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.default = void 0;
|
|
8
7
|
exports.ensureSingleChild = ensureSingleChild;
|
|
9
|
-
var _react =
|
|
8
|
+
var _react = require("react");
|
|
10
9
|
var _safeCloneElement = require("./safeCloneElement");
|
|
10
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
11
11
|
/*
|
|
12
12
|
* The MIT License (MIT)
|
|
13
13
|
*
|
|
@@ -45,13 +45,15 @@ var _safeCloneElement = require("./safeCloneElement");
|
|
|
45
45
|
* @param {ReactNode} child
|
|
46
46
|
* @param {Object} props - props for child
|
|
47
47
|
* @returns {ReactElement|null} cloned instance for a single child, or children wrapped in a span
|
|
48
|
-
*/
|
|
49
|
-
function ensureSingleChild(child, props = {}) {
|
|
48
|
+
*/function ensureSingleChild(child, props = {}) {
|
|
50
49
|
const childCount = _react.Children.count(child);
|
|
51
50
|
if (childCount === 0) {
|
|
52
51
|
return null;
|
|
53
52
|
} else if (typeof child === 'string' && child.length > 0 || childCount > 1) {
|
|
54
|
-
return
|
|
53
|
+
return (0, _jsxRuntime.jsx)("span", {
|
|
54
|
+
...props,
|
|
55
|
+
children: child
|
|
56
|
+
});
|
|
55
57
|
} else {
|
|
56
58
|
// TODO: check that we can only end up here if child is ReactElement
|
|
57
59
|
return (0, _safeCloneElement.safeCloneElement)(Array.isArray(child) ? child[0] : child, props);
|
package/lib/safeCloneElement.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.default = void 0;
|
|
8
7
|
exports.safeCloneElement = safeCloneElement;
|
|
9
|
-
var _react =
|
|
8
|
+
var _react = require("react");
|
|
10
9
|
var _console = require("@instructure/console");
|
|
11
10
|
var _createChainedFunction = require("@instructure/ui-utils/lib/createChainedFunction.js");
|
|
12
11
|
/*
|
|
@@ -74,12 +73,12 @@ function safeCloneElement(element, props, ...children) {
|
|
|
74
73
|
}
|
|
75
74
|
});
|
|
76
75
|
if (originalRef == null || cloneRef == null) {
|
|
77
|
-
return /*#__PURE__*/_react.
|
|
76
|
+
return /*#__PURE__*/(0, _react.cloneElement)(element, mergedProps, ...children);
|
|
78
77
|
}
|
|
79
78
|
(0, _console.logWarn)(originalRefIsAFunction, `Cloning an element with a ref that will be overwritten because the ref \
|
|
80
79
|
is not a function. Use a composable callback-style ref instead. \
|
|
81
80
|
Ignoring ref: ${originalRef}`);
|
|
82
|
-
return /*#__PURE__*/_react.
|
|
81
|
+
return /*#__PURE__*/(0, _react.cloneElement)(element, {
|
|
83
82
|
...mergedProps,
|
|
84
83
|
ref(component) {
|
|
85
84
|
if (cloneRefIsFunction) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-react-utils",
|
|
3
|
-
"version": "10.16.1-snapshot-
|
|
3
|
+
"version": "10.16.1-snapshot-1",
|
|
4
4
|
"description": "A React utility library made by Instructure Inc.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@instructure/ui-babel-preset": "10.16.1-snapshot-
|
|
25
|
+
"@instructure/ui-babel-preset": "10.16.1-snapshot-1",
|
|
26
26
|
"@testing-library/jest-dom": "^6.6.3",
|
|
27
27
|
"@testing-library/react": "^16.0.1",
|
|
28
28
|
"vitest": "^2.1.8"
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@babel/runtime": "^7.26.0",
|
|
32
32
|
"@emotion/is-prop-valid": "^1.3.1",
|
|
33
|
-
"@instructure/console": "10.16.1-snapshot-
|
|
34
|
-
"@instructure/shared-types": "10.16.1-snapshot-
|
|
35
|
-
"@instructure/ui-decorator": "10.16.1-snapshot-
|
|
36
|
-
"@instructure/ui-dom-utils": "10.16.1-snapshot-
|
|
37
|
-
"@instructure/ui-utils": "10.16.1-snapshot-
|
|
33
|
+
"@instructure/console": "10.16.1-snapshot-1",
|
|
34
|
+
"@instructure/shared-types": "10.16.1-snapshot-1",
|
|
35
|
+
"@instructure/ui-decorator": "10.16.1-snapshot-1",
|
|
36
|
+
"@instructure/ui-dom-utils": "10.16.1-snapshot-1",
|
|
37
|
+
"@instructure/ui-utils": "10.16.1-snapshot-1",
|
|
38
38
|
"hoist-non-react-statics": "^3.3.2",
|
|
39
39
|
"prop-types": "^15.8.1"
|
|
40
40
|
},
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
import
|
|
24
|
+
import { ComponentClass, forwardRef, useContext } from 'react'
|
|
25
25
|
import type {
|
|
26
26
|
ForwardRefExoticComponent,
|
|
27
27
|
PropsWithoutRef,
|
|
@@ -50,7 +50,7 @@ type WithDeterministicIdProps = {
|
|
|
50
50
|
const withDeterministicId = decorator((ComposedComponent: InstUIComponent) => {
|
|
51
51
|
type Props = PropsWithoutRef<Record<string, unknown>> & RefAttributes<any>
|
|
52
52
|
const WithDeterministicId: ForwardRefExoticComponent<Props> & {
|
|
53
|
-
originalType?:
|
|
53
|
+
originalType?: ComponentClass
|
|
54
54
|
} = forwardRef((props: Props, ref: React.ForwardedRef<any>) => {
|
|
55
55
|
const componentName =
|
|
56
56
|
ComposedComponent.componentId ||
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import
|
|
25
|
+
import { Component } from 'react'
|
|
26
26
|
|
|
27
27
|
import { render, screen } from '@testing-library/react'
|
|
28
28
|
import '@testing-library/jest-dom'
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
import type { WithDeterministicIdProps } from '../DeterministicIdContext'
|
|
35
35
|
|
|
36
36
|
@withDeterministicId()
|
|
37
|
-
class TestComponent extends
|
|
37
|
+
class TestComponent extends Component<
|
|
38
38
|
React.PropsWithChildren<WithDeterministicIdProps>
|
|
39
39
|
> {
|
|
40
40
|
render() {
|
|
@@ -46,7 +46,7 @@ class TestComponent extends React.Component<
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
class WrapperComponent extends
|
|
49
|
+
class WrapperComponent extends Component {
|
|
50
50
|
render() {
|
|
51
51
|
return (
|
|
52
52
|
<div>
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import
|
|
25
|
+
import { Component } from 'react'
|
|
26
26
|
import PropTypes from 'prop-types'
|
|
27
27
|
|
|
28
28
|
import { render } from '@testing-library/react'
|
|
@@ -56,7 +56,7 @@ describe('callRenderProp', () => {
|
|
|
56
56
|
})
|
|
57
57
|
|
|
58
58
|
it('React classes', () => {
|
|
59
|
-
class Foo extends
|
|
59
|
+
class Foo extends Component {
|
|
60
60
|
render() {
|
|
61
61
|
return <div>hello</div>
|
|
62
62
|
}
|
|
@@ -112,7 +112,7 @@ describe('callRenderProp', () => {
|
|
|
112
112
|
|
|
113
113
|
it('should pass props correctly to React classes', () => {
|
|
114
114
|
type FooProps = { shape?: string }
|
|
115
|
-
class Foo extends
|
|
115
|
+
class Foo extends Component<FooProps> {
|
|
116
116
|
static propTypes = {
|
|
117
117
|
shape: PropTypes.oneOf(['circle', 'rectangle'])
|
|
118
118
|
}
|
package/src/safeCloneElement.ts
CHANGED
|
@@ -22,13 +22,14 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import
|
|
25
|
+
import {
|
|
26
26
|
Attributes,
|
|
27
27
|
FunctionComponentElement,
|
|
28
28
|
ComponentElement,
|
|
29
29
|
ReactElement,
|
|
30
30
|
ReactNode,
|
|
31
|
-
DOMElement
|
|
31
|
+
DOMElement,
|
|
32
|
+
cloneElement
|
|
32
33
|
} from 'react'
|
|
33
34
|
|
|
34
35
|
import { logWarn as warn } from '@instructure/console'
|
|
@@ -93,7 +94,7 @@ function safeCloneElement<
|
|
|
93
94
|
})
|
|
94
95
|
|
|
95
96
|
if (originalRef == null || cloneRef == null) {
|
|
96
|
-
return
|
|
97
|
+
return cloneElement<P>(element, mergedProps, ...children) as E
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
warn(
|
|
@@ -103,7 +104,7 @@ is not a function. Use a composable callback-style ref instead. \
|
|
|
103
104
|
Ignoring ref: ${originalRef}`
|
|
104
105
|
)
|
|
105
106
|
|
|
106
|
-
return
|
|
107
|
+
return cloneElement<P>(
|
|
107
108
|
element,
|
|
108
109
|
{
|
|
109
110
|
...mergedProps,
|