@zohodesk/utils 1.3.14 → 1.3.15
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 +7 -1
- package/es/index.js +2 -1
- package/es/renderNode.js +28 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# DOT - Util Collections
|
|
2
2
|
|
|
3
3
|
In this package, We provide lots of util fuctions for web devlopment
|
|
4
4
|
|
|
5
|
+
# 1.3.15
|
|
6
|
+
|
|
7
|
+
- **renderNodeUtils**
|
|
8
|
+
- `renderNode` function added to render content that can be either a function or a React element.
|
|
9
|
+
- `isRenderable` function added to check if the content is renderable (either a function or a valid React element).
|
|
10
|
+
|
|
5
11
|
# 1.3.14
|
|
6
12
|
|
|
7
13
|
- **StringUtils**
|
package/es/index.js
CHANGED
|
@@ -7,4 +7,5 @@ export { default as combineCustomStyle } from "./combineCustomStyle";
|
|
|
7
7
|
export { default as compileClassNames } from "./compileClassNames";
|
|
8
8
|
export { default as ErrorBoundary } from "./ErrorBoundary";
|
|
9
9
|
export { default as loadResource } from "./loadResource";
|
|
10
|
-
export { default as accessKeyCodes, accessKeyNames } from "./accessKeyCodes";
|
|
10
|
+
export { default as accessKeyCodes, accessKeyNames } from "./accessKeyCodes";
|
|
11
|
+
export { default as renderNode, isRenderable } from "./renderNode";
|
package/es/renderNode.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React, { isValidElement } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Utility function to render content that can be either a function or a React element
|
|
4
|
+
* @param {Function|React.ReactElement|null|undefined} content - The content to render
|
|
5
|
+
* @param {Object} props - Optional props to pass to the function if content is a function
|
|
6
|
+
* @returns {React.ReactElement|null} - The rendered content or null
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export default function renderNode(content, props) {
|
|
10
|
+
let result = content;
|
|
11
|
+
|
|
12
|
+
if (typeof content === 'function') {
|
|
13
|
+
result = content(props);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return /*#__PURE__*/isValidElement(result) ? result : null;
|
|
17
|
+
}
|
|
18
|
+
;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if the content is renderable (function or valid React element)
|
|
21
|
+
* @param {any} content - The content to check
|
|
22
|
+
* @returns {boolean} - True if content is renderable
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export function isRenderable(content) {
|
|
26
|
+
return typeof content === 'function' || /*#__PURE__*/isValidElement(content);
|
|
27
|
+
}
|
|
28
|
+
;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zohodesk/utils",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.3.15",
|
|
4
|
+
"description": "DOT Utils Collection",
|
|
5
5
|
"main": "es/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
7
7
|
"private": false,
|
|
@@ -32,4 +32,4 @@
|
|
|
32
32
|
"es",
|
|
33
33
|
"!**/__tests__"
|
|
34
34
|
]
|
|
35
|
-
}
|
|
35
|
+
}
|