@lumx/react 4.22.0-next.2 → 4.22.1-alpha.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/index.js +22 -5
- package/index.js.map +1 -1
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -2760,20 +2760,37 @@ const useOverflowTooltipLabel = content => {
|
|
|
2760
2760
|
*/
|
|
2761
2761
|
const isComponentType = type => node => /*#__PURE__*/React__default.isValidElement(node) && node.type === type;
|
|
2762
2762
|
|
|
2763
|
-
/**
|
|
2764
|
-
|
|
2763
|
+
/**
|
|
2764
|
+
* Recursively wrap icons with spaces.
|
|
2765
|
+
*
|
|
2766
|
+
* `isFirst`/`isLast` tell whether the given children are at the very start/end of the whole
|
|
2767
|
+
* children tree, so that an icon on an edge is detected even when nested in a fragment or element.
|
|
2768
|
+
*/
|
|
2769
|
+
function wrap(children, isFirst, isLast) {
|
|
2765
2770
|
if (children === null || children === undefined) return undefined;
|
|
2766
|
-
|
|
2771
|
+
const childArray = Children.toArray(children);
|
|
2772
|
+
return childArray.flatMap((child, index) => {
|
|
2773
|
+
const childIsFirst = isFirst && index === 0;
|
|
2774
|
+
const childIsLast = isLast && index === childArray.length - 1;
|
|
2767
2775
|
if (isComponentType(Icon)(child)) {
|
|
2768
|
-
|
|
2776
|
+
// No space on the edges of the text: the icon is not stuck against anything there.
|
|
2777
|
+
return [...(childIsFirst ? [] : [' ']), child, ...(childIsLast ? [] : [' '])];
|
|
2769
2778
|
}
|
|
2770
2779
|
if (/*#__PURE__*/React__default.isValidElement(child) && child.props && typeof child.props === 'object' && 'children' in child.props) {
|
|
2771
|
-
return /*#__PURE__*/React__default.cloneElement(child, undefined,
|
|
2780
|
+
return /*#__PURE__*/React__default.cloneElement(child, undefined, wrap(child.props.children, childIsFirst, childIsLast));
|
|
2772
2781
|
}
|
|
2773
2782
|
return child;
|
|
2774
2783
|
});
|
|
2775
2784
|
}
|
|
2776
2785
|
|
|
2786
|
+
/**
|
|
2787
|
+
* Force wrap spaces around icons to make sure they are never stuck against text.
|
|
2788
|
+
* Icons at the very start or end of the text are not padded on that side.
|
|
2789
|
+
*/
|
|
2790
|
+
function wrapChildrenIconWithSpaces(children) {
|
|
2791
|
+
return wrap(children, true, true);
|
|
2792
|
+
}
|
|
2793
|
+
|
|
2777
2794
|
/**
|
|
2778
2795
|
* Defines the props of the component.
|
|
2779
2796
|
*/
|