@lumx/react 3.12.1-alpha.7 → 3.13.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.d.ts +8 -2
- package/index.js +48 -75
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/link/Link.stories.tsx +88 -23
- package/src/components/link/Link.test.tsx +25 -13
- package/src/components/link/Link.tsx +41 -88
- package/src/components/tabs/TabProvider.tsx +9 -1
- package/src/components/text/Text.test.tsx +9 -29
- package/src/components/text/Text.tsx +5 -11
- package/src/stories/controls/icons.ts +1 -0
- package/src/utils/react/wrapChildrenIconWithSpaces.test.tsx +37 -0
- package/src/utils/react/wrapChildrenIconWithSpaces.tsx +22 -0
- package/src/stories/generated/Link/Demos.stories.tsx +0 -8
package/index.d.ts
CHANGED
|
@@ -1926,11 +1926,17 @@ interface LinkProps extends GenericProps {
|
|
|
1926
1926
|
href?: HTMLAnchorProps['href'];
|
|
1927
1927
|
/** Whether the component is disabled or not. */
|
|
1928
1928
|
isDisabled?: boolean;
|
|
1929
|
-
/**
|
|
1929
|
+
/**
|
|
1930
|
+
* Left icon (SVG path).
|
|
1931
|
+
* @deprecated Instead, simply nest `<Icon />` in the children
|
|
1932
|
+
*/
|
|
1930
1933
|
leftIcon?: string;
|
|
1931
1934
|
/** Custom react component for the link (can be used to inject react router Link). */
|
|
1932
1935
|
linkAs?: 'a' | any;
|
|
1933
|
-
/**
|
|
1936
|
+
/**
|
|
1937
|
+
* Right icon (SVG path).
|
|
1938
|
+
* @deprecated Instead, simply nest `<Icon />` in the children
|
|
1939
|
+
*/
|
|
1934
1940
|
rightIcon?: string;
|
|
1935
1941
|
/** Link target. */
|
|
1936
1942
|
target?: HTMLAnchorProps['target'];
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import React__default, { useState, useEffect, useMemo, useRef, Children, isValidElement, cloneElement, useLayoutEffect, useCallback,
|
|
2
|
+
import React__default, { useState, useEffect, useMemo, useRef, Children, isValidElement, cloneElement, useLayoutEffect, useCallback, createContext, useContext, useReducer } from 'react';
|
|
3
3
|
import isBoolean from 'lodash/isBoolean';
|
|
4
4
|
import isEmpty from 'lodash/isEmpty';
|
|
5
5
|
import kebabCase from 'lodash/kebabCase';
|
|
@@ -7457,6 +7457,20 @@ const useOverflowTooltipLabel = () => {
|
|
|
7457
7457
|
};
|
|
7458
7458
|
};
|
|
7459
7459
|
|
|
7460
|
+
/** Force wrap spaces around icons to make sure they are never stuck against text. */
|
|
7461
|
+
function wrapChildrenIconWithSpaces(children) {
|
|
7462
|
+
if (children === null || children === undefined) return undefined;
|
|
7463
|
+
return Children.toArray(children).flatMap(child => {
|
|
7464
|
+
if (isComponentType(Icon)(child)) {
|
|
7465
|
+
return [' ', child, ' '];
|
|
7466
|
+
}
|
|
7467
|
+
if (/*#__PURE__*/React__default.isValidElement(child) && child.props && typeof child.props === 'object' && 'children' in child.props) {
|
|
7468
|
+
return /*#__PURE__*/React__default.cloneElement(child, undefined, wrapChildrenIconWithSpaces(child.props.children));
|
|
7469
|
+
}
|
|
7470
|
+
return child;
|
|
7471
|
+
});
|
|
7472
|
+
}
|
|
7473
|
+
|
|
7460
7474
|
const _excluded$_ = ["as", "children", "className", "color", "colorVariant", "noWrap", "typography", "truncate", "whiteSpace", "style"];
|
|
7461
7475
|
|
|
7462
7476
|
/**
|
|
@@ -7530,15 +7544,7 @@ const Text = forwardRef((props, ref) => {
|
|
|
7530
7544
|
}), typographyClass, colorClass, noWrap && `${CLASSNAME$V}--no-wrap`),
|
|
7531
7545
|
title: tooltipLabel,
|
|
7532
7546
|
style: _objectSpread2(_objectSpread2(_objectSpread2({}, truncateLinesStyle), whiteSpaceStyle), style)
|
|
7533
|
-
}, forwardedProps),
|
|
7534
|
-
// Force wrap spaces around icons to make sure they are never stuck against text.
|
|
7535
|
-
if (isComponent(Icon)(child)) {
|
|
7536
|
-
return /*#__PURE__*/React__default.createElement(Fragment, {
|
|
7537
|
-
key: child.key || index
|
|
7538
|
-
}, " ", child, " ");
|
|
7539
|
-
}
|
|
7540
|
-
return child;
|
|
7541
|
-
}));
|
|
7547
|
+
}, forwardedProps), wrapChildrenIconWithSpaces(children));
|
|
7542
7548
|
});
|
|
7543
7549
|
Text.displayName = COMPONENT_NAME$V;
|
|
7544
7550
|
Text.className = CLASSNAME$V;
|
|
@@ -9083,31 +9089,6 @@ const COMPONENT_NAME$K = 'Link';
|
|
|
9083
9089
|
* Component default class name and class prefix.
|
|
9084
9090
|
*/
|
|
9085
9091
|
const CLASSNAME$K = getRootClassName(COMPONENT_NAME$K);
|
|
9086
|
-
const getIconSize = typography => {
|
|
9087
|
-
switch (typography) {
|
|
9088
|
-
case Typography.display1:
|
|
9089
|
-
return Size.m;
|
|
9090
|
-
case Typography.headline:
|
|
9091
|
-
case Typography.title:
|
|
9092
|
-
case Typography.custom.title1:
|
|
9093
|
-
case Typography.custom.title2:
|
|
9094
|
-
case Typography.custom.title3:
|
|
9095
|
-
case Typography.custom.title4:
|
|
9096
|
-
case Typography.custom.title5:
|
|
9097
|
-
case Typography.custom.title6:
|
|
9098
|
-
case Typography.body2:
|
|
9099
|
-
case Typography.subtitle2:
|
|
9100
|
-
return Size.s;
|
|
9101
|
-
case Typography.body1:
|
|
9102
|
-
case Typography.subtitle1:
|
|
9103
|
-
return Size.xs;
|
|
9104
|
-
case Typography.caption:
|
|
9105
|
-
case Typography.overline:
|
|
9106
|
-
return Size.xxs;
|
|
9107
|
-
default:
|
|
9108
|
-
return Size.s;
|
|
9109
|
-
}
|
|
9110
|
-
};
|
|
9111
9092
|
|
|
9112
9093
|
/**
|
|
9113
9094
|
* Link component.
|
|
@@ -9132,49 +9113,34 @@ const Link = forwardRef((props, ref) => {
|
|
|
9132
9113
|
typography
|
|
9133
9114
|
} = props,
|
|
9134
9115
|
forwardedProps = _objectWithoutProperties(props, _excluded$O);
|
|
9135
|
-
const
|
|
9136
|
-
|
|
9137
|
-
|
|
9138
|
-
|
|
9139
|
-
|
|
9140
|
-
|
|
9141
|
-
|
|
9142
|
-
|
|
9143
|
-
|
|
9144
|
-
icon: rightIcon,
|
|
9145
|
-
className: `${CLASSNAME$K}__right-icon`,
|
|
9146
|
-
size: getIconSize(typography)
|
|
9147
|
-
})), [leftIcon, typography, children, rightIcon]);
|
|
9148
|
-
|
|
9149
|
-
/**
|
|
9150
|
-
* If there is no linkAs prop and no href, we returned a <button> instead of a <a>.
|
|
9151
|
-
* If the component is disabled, we also returned a <button> since disabled is not compatible with <a>.
|
|
9152
|
-
*/
|
|
9153
|
-
if (!linkAs && isEmpty(href) || isDisabled) {
|
|
9154
|
-
return /*#__PURE__*/React__default.createElement("button", _extends({
|
|
9155
|
-
type: "button"
|
|
9156
|
-
}, forwardedProps, {
|
|
9157
|
-
ref: ref,
|
|
9158
|
-
disabled: isDisabled,
|
|
9159
|
-
className: classNames(className, handleBasicClasses({
|
|
9160
|
-
prefix: CLASSNAME$K,
|
|
9161
|
-
color,
|
|
9162
|
-
colorVariant
|
|
9163
|
-
}))
|
|
9164
|
-
}), renderedChildren);
|
|
9116
|
+
const isLink = linkAs || href;
|
|
9117
|
+
const Component = isLink && !isDisabled ? linkAs || 'a' : 'button';
|
|
9118
|
+
const baseProps = {};
|
|
9119
|
+
if (Component === 'button') {
|
|
9120
|
+
baseProps.type = 'button';
|
|
9121
|
+
baseProps.disabled = isDisabled;
|
|
9122
|
+
} else if (isLink) {
|
|
9123
|
+
baseProps.href = href;
|
|
9124
|
+
baseProps.target = target;
|
|
9165
9125
|
}
|
|
9166
|
-
return
|
|
9167
|
-
|
|
9168
|
-
}, forwardedProps
|
|
9169
|
-
href,
|
|
9170
|
-
target,
|
|
9126
|
+
return /*#__PURE__*/React__default.createElement(Component, _extends({
|
|
9127
|
+
ref: ref
|
|
9128
|
+
}, forwardedProps, baseProps, {
|
|
9171
9129
|
className: classNames(className, handleBasicClasses({
|
|
9172
9130
|
prefix: CLASSNAME$K,
|
|
9173
9131
|
color,
|
|
9174
|
-
colorVariant
|
|
9175
|
-
|
|
9176
|
-
|
|
9177
|
-
}),
|
|
9132
|
+
colorVariant,
|
|
9133
|
+
hasTypography: !!typography
|
|
9134
|
+
}), typography && getTypographyClassName(typography))
|
|
9135
|
+
}), wrapChildrenIconWithSpaces(/*#__PURE__*/React__default.createElement(React__default.Fragment, null, leftIcon && /*#__PURE__*/React__default.createElement(Icon, {
|
|
9136
|
+
icon: leftIcon,
|
|
9137
|
+
className: `${CLASSNAME$K}__left-icon`
|
|
9138
|
+
}), children && /*#__PURE__*/React__default.createElement("span", {
|
|
9139
|
+
className: `${CLASSNAME$K}__content`
|
|
9140
|
+
}, children), rightIcon && /*#__PURE__*/React__default.createElement(Icon, {
|
|
9141
|
+
icon: rightIcon,
|
|
9142
|
+
className: `${CLASSNAME$K}__right-icon`
|
|
9143
|
+
}))));
|
|
9178
9144
|
});
|
|
9179
9145
|
Link.displayName = COMPONENT_NAME$K;
|
|
9180
9146
|
Link.className = CLASSNAME$K;
|
|
@@ -12954,7 +12920,14 @@ const TabProvider = props => {
|
|
|
12954
12920
|
if (state === INIT_STATE || !onChange || propState.activeTabIndex === state.activeTabIndex) {
|
|
12955
12921
|
return;
|
|
12956
12922
|
}
|
|
12957
|
-
|
|
12923
|
+
|
|
12924
|
+
// Escape rendering/useEffect context
|
|
12925
|
+
queueMicrotask(() => {
|
|
12926
|
+
// Wait for React to commit last state changes (avoid looping state update)
|
|
12927
|
+
ReactDOM.flushSync(() => {
|
|
12928
|
+
onChange(state.activeTabIndex);
|
|
12929
|
+
});
|
|
12930
|
+
});
|
|
12958
12931
|
},
|
|
12959
12932
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
12960
12933
|
[onChange, state.activeTabIndex]);
|