@lumx/react 3.12.1-alpha.5 → 3.12.1-alpha.7
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 +2 -8
- package/index.js +74 -40
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/link/Link.stories.tsx +23 -86
- package/src/components/link/Link.test.tsx +13 -25
- package/src/components/link/Link.tsx +88 -41
- package/src/components/text/Text.test.tsx +29 -9
- package/src/components/text/Text.tsx +11 -5
- package/src/stories/controls/icons.ts +0 -1
- package/src/stories/generated/Link/Demos.stories.tsx +8 -0
- package/src/utils/react/wrapChildrenIconWithSpaces.test.tsx +0 -37
- package/src/utils/react/wrapChildrenIconWithSpaces.tsx +0 -22
package/index.d.ts
CHANGED
|
@@ -1926,17 +1926,11 @@ interface LinkProps extends GenericProps {
|
|
|
1926
1926
|
href?: HTMLAnchorProps['href'];
|
|
1927
1927
|
/** Whether the component is disabled or not. */
|
|
1928
1928
|
isDisabled?: boolean;
|
|
1929
|
-
/**
|
|
1930
|
-
* Left icon (SVG path).
|
|
1931
|
-
* @deprecated Instead, simply nest `<Icon />` in the children
|
|
1932
|
-
*/
|
|
1929
|
+
/** Left icon (SVG path). */
|
|
1933
1930
|
leftIcon?: string;
|
|
1934
1931
|
/** Custom react component for the link (can be used to inject react router Link). */
|
|
1935
1932
|
linkAs?: 'a' | any;
|
|
1936
|
-
/**
|
|
1937
|
-
* Right icon (SVG path).
|
|
1938
|
-
* @deprecated Instead, simply nest `<Icon />` in the children
|
|
1939
|
-
*/
|
|
1933
|
+
/** Right icon (SVG path). */
|
|
1940
1934
|
rightIcon?: string;
|
|
1941
1935
|
/** Link target. */
|
|
1942
1936
|
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, createContext, useContext, useReducer } from 'react';
|
|
2
|
+
import React__default, { useState, useEffect, useMemo, useRef, Children, isValidElement, cloneElement, useLayoutEffect, useCallback, Fragment, 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,20 +7457,6 @@ 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
|
-
|
|
7474
7460
|
const _excluded$_ = ["as", "children", "className", "color", "colorVariant", "noWrap", "typography", "truncate", "whiteSpace", "style"];
|
|
7475
7461
|
|
|
7476
7462
|
/**
|
|
@@ -7544,7 +7530,15 @@ const Text = forwardRef((props, ref) => {
|
|
|
7544
7530
|
}), typographyClass, colorClass, noWrap && `${CLASSNAME$V}--no-wrap`),
|
|
7545
7531
|
title: tooltipLabel,
|
|
7546
7532
|
style: _objectSpread2(_objectSpread2(_objectSpread2({}, truncateLinesStyle), whiteSpaceStyle), style)
|
|
7547
|
-
}, forwardedProps),
|
|
7533
|
+
}, forwardedProps), children && Children.toArray(children).map((child, index) => {
|
|
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
|
+
}));
|
|
7548
7542
|
});
|
|
7549
7543
|
Text.displayName = COMPONENT_NAME$V;
|
|
7550
7544
|
Text.className = CLASSNAME$V;
|
|
@@ -9089,6 +9083,31 @@ const COMPONENT_NAME$K = 'Link';
|
|
|
9089
9083
|
* Component default class name and class prefix.
|
|
9090
9084
|
*/
|
|
9091
9085
|
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
|
+
};
|
|
9092
9111
|
|
|
9093
9112
|
/**
|
|
9094
9113
|
* Link component.
|
|
@@ -9113,34 +9132,49 @@ const Link = forwardRef((props, ref) => {
|
|
|
9113
9132
|
typography
|
|
9114
9133
|
} = props,
|
|
9115
9134
|
forwardedProps = _objectWithoutProperties(props, _excluded$O);
|
|
9116
|
-
const
|
|
9117
|
-
|
|
9118
|
-
|
|
9119
|
-
|
|
9120
|
-
|
|
9121
|
-
|
|
9122
|
-
|
|
9123
|
-
|
|
9124
|
-
|
|
9135
|
+
const renderedChildren = useMemo(() => /*#__PURE__*/React__default.createElement(React__default.Fragment, null, leftIcon && !isEmpty(leftIcon) && /*#__PURE__*/React__default.createElement(Icon, {
|
|
9136
|
+
icon: leftIcon,
|
|
9137
|
+
className: `${CLASSNAME$K}__left-icon`,
|
|
9138
|
+
size: getIconSize(typography)
|
|
9139
|
+
}), children && /*#__PURE__*/React__default.createElement("span", {
|
|
9140
|
+
className: classNames(`${CLASSNAME$K}__content`, {
|
|
9141
|
+
[`lumx-typography-${typography}`]: typography
|
|
9142
|
+
})
|
|
9143
|
+
}, children), rightIcon && !isEmpty(rightIcon) && /*#__PURE__*/React__default.createElement(Icon, {
|
|
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);
|
|
9125
9165
|
}
|
|
9126
|
-
return
|
|
9127
|
-
|
|
9128
|
-
}, forwardedProps,
|
|
9166
|
+
return renderLink(_objectSpread2(_objectSpread2({
|
|
9167
|
+
linkAs
|
|
9168
|
+
}, forwardedProps), {}, {
|
|
9169
|
+
href,
|
|
9170
|
+
target,
|
|
9129
9171
|
className: classNames(className, handleBasicClasses({
|
|
9130
9172
|
prefix: CLASSNAME$K,
|
|
9131
9173
|
color,
|
|
9132
|
-
colorVariant
|
|
9133
|
-
|
|
9134
|
-
|
|
9135
|
-
}),
|
|
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
|
-
}))));
|
|
9174
|
+
colorVariant
|
|
9175
|
+
})),
|
|
9176
|
+
ref: ref
|
|
9177
|
+
}), renderedChildren);
|
|
9144
9178
|
});
|
|
9145
9179
|
Link.displayName = COMPONENT_NAME$K;
|
|
9146
9180
|
Link.className = CLASSNAME$K;
|