@lumx/react 3.12.0 → 3.12.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 CHANGED
@@ -1865,6 +1865,8 @@ declare const InputHelper: Comp<InputHelperProps, HTMLParagraphElement>;
1865
1865
  * Defines the props of the component.
1866
1866
  */
1867
1867
  interface InputLabelProps extends GenericProps, HasTheme {
1868
+ /** Typography variant. */
1869
+ typography?: Typography;
1868
1870
  /** Label content. */
1869
1871
  children: string | ReactNode;
1870
1872
  /** Native htmlFor property. */
@@ -1924,11 +1926,17 @@ interface LinkProps extends GenericProps {
1924
1926
  href?: HTMLAnchorProps['href'];
1925
1927
  /** Whether the component is disabled or not. */
1926
1928
  isDisabled?: boolean;
1927
- /** Left icon (SVG path). */
1929
+ /**
1930
+ * Left icon (SVG path).
1931
+ * @deprecated Just nest `<Icon />` in the children
1932
+ */
1928
1933
  leftIcon?: string;
1929
1934
  /** Custom react component for the link (can be used to inject react router Link). */
1930
1935
  linkAs?: 'a' | any;
1931
- /** Right icon (SVG path). */
1936
+ /**
1937
+ * Right icon (SVG path).
1938
+ * @deprecated Just nest `<Icon />` in the children
1939
+ */
1932
1940
  rightIcon?: string;
1933
1941
  /** Link target. */
1934
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, Fragment, createContext, useContext, useReducer } from 'react';
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';
@@ -25,6 +25,23 @@ import take from 'lodash/take';
25
25
  import isObject from 'lodash/isObject';
26
26
  import set from 'lodash/set';
27
27
 
28
+ function _defineProperty(e, r, t) {
29
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
30
+ value: t,
31
+ enumerable: !0,
32
+ configurable: !0,
33
+ writable: !0
34
+ }) : e[r] = t, e;
35
+ }
36
+ function _extends() {
37
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
38
+ for (var e = 1; e < arguments.length; e++) {
39
+ var t = arguments[e];
40
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
41
+ }
42
+ return n;
43
+ }, _extends.apply(null, arguments);
44
+ }
28
45
  function ownKeys(e, r) {
29
46
  var t = Object.keys(e);
30
47
  if (Object.getOwnPropertySymbols) {
@@ -46,6 +63,26 @@ function _objectSpread2(e) {
46
63
  }
47
64
  return e;
48
65
  }
66
+ function _objectWithoutProperties(e, t) {
67
+ if (null == e) return {};
68
+ var o,
69
+ r,
70
+ i = _objectWithoutPropertiesLoose(e, t);
71
+ if (Object.getOwnPropertySymbols) {
72
+ var n = Object.getOwnPropertySymbols(e);
73
+ for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
74
+ }
75
+ return i;
76
+ }
77
+ function _objectWithoutPropertiesLoose(r, e) {
78
+ if (null == r) return {};
79
+ var t = {};
80
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
81
+ if (-1 !== e.indexOf(n)) continue;
82
+ t[n] = r[n];
83
+ }
84
+ return t;
85
+ }
49
86
  function _toPrimitive(t, r) {
50
87
  if ("object" != typeof t || !t) return t;
51
88
  var e = t[Symbol.toPrimitive];
@@ -58,62 +95,7 @@ function _toPrimitive(t, r) {
58
95
  }
59
96
  function _toPropertyKey(t) {
60
97
  var i = _toPrimitive(t, "string");
61
- return "symbol" == typeof i ? i : String(i);
62
- }
63
- function _defineProperty(obj, key, value) {
64
- key = _toPropertyKey(key);
65
- if (key in obj) {
66
- Object.defineProperty(obj, key, {
67
- value: value,
68
- enumerable: true,
69
- configurable: true,
70
- writable: true
71
- });
72
- } else {
73
- obj[key] = value;
74
- }
75
- return obj;
76
- }
77
- function _extends() {
78
- _extends = Object.assign ? Object.assign.bind() : function (target) {
79
- for (var i = 1; i < arguments.length; i++) {
80
- var source = arguments[i];
81
- for (var key in source) {
82
- if (Object.prototype.hasOwnProperty.call(source, key)) {
83
- target[key] = source[key];
84
- }
85
- }
86
- }
87
- return target;
88
- };
89
- return _extends.apply(this, arguments);
90
- }
91
- function _objectWithoutPropertiesLoose(source, excluded) {
92
- if (source == null) return {};
93
- var target = {};
94
- var sourceKeys = Object.keys(source);
95
- var key, i;
96
- for (i = 0; i < sourceKeys.length; i++) {
97
- key = sourceKeys[i];
98
- if (excluded.indexOf(key) >= 0) continue;
99
- target[key] = source[key];
100
- }
101
- return target;
102
- }
103
- function _objectWithoutProperties(source, excluded) {
104
- if (source == null) return {};
105
- var target = _objectWithoutPropertiesLoose(source, excluded);
106
- var key, i;
107
- if (Object.getOwnPropertySymbols) {
108
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
109
- for (i = 0; i < sourceSymbolKeys.length; i++) {
110
- key = sourceSymbolKeys[i];
111
- if (excluded.indexOf(key) >= 0) continue;
112
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
113
- target[key] = source[key];
114
- }
115
- }
116
- return target;
98
+ return "symbol" == typeof i ? i : i + "";
117
99
  }
118
100
 
119
101
  /**
@@ -1465,7 +1447,7 @@ const ListItem = forwardRef((props, ref) => {
1465
1447
  }), isClickable({
1466
1448
  linkProps,
1467
1449
  onItemSelected
1468
- }) ? ( /* Clickable list item */
1450
+ }) ? (/* Clickable list item */
1469
1451
  renderLink(_objectSpread2(_objectSpread2({
1470
1452
  linkAs,
1471
1453
  tabIndex: !isDisabled && role === 'button' ? 0 : undefined,
@@ -1780,8 +1762,8 @@ function flattenChildren(children) {
1780
1762
  const nodeKeys = keys.concat((_get = get(node, 'key')) !== null && _get !== void 0 ? _get : index);
1781
1763
  if (reactIs.exports.isFragment(node)) {
1782
1764
  acc.push(...recur(node.props.children, nodeKeys));
1783
- } else if ( /*#__PURE__*/isValidElement(node)) {
1784
- acc.push( /*#__PURE__*/cloneElement(node, {
1765
+ } else if (/*#__PURE__*/isValidElement(node)) {
1766
+ acc.push(/*#__PURE__*/cloneElement(node, {
1785
1767
  key: nodeKeys.join('.')
1786
1768
  }));
1787
1769
  } else if (typeof node === 'string' || typeof node === 'number') {
@@ -4725,7 +4707,7 @@ const _InnerPopover = forwardRef((props, ref) => {
4725
4707
  useFocusTrap(withFocusTrap && isOpen && focusZoneElement, focusElement === null || focusElement === void 0 ? void 0 : focusElement.current);
4726
4708
  const clickAwayRefs = useRef([popoverRef, anchorRef]);
4727
4709
  const mergedRefs = useMergeRefs(setPopperElement, ref, popoverRef);
4728
- return isOpen ? renderPopover( /*#__PURE__*/React__default.createElement(Component, _extends({}, forwardedProps, {
4710
+ return isOpen ? renderPopover(/*#__PURE__*/React__default.createElement(Component, _extends({}, forwardedProps, {
4729
4711
  ref: mergedRefs,
4730
4712
  className: classNames(className, handleBasicClasses({
4731
4713
  prefix: CLASSNAME$1d,
@@ -5348,11 +5330,21 @@ const Button = forwardRef((props, ref) => {
5348
5330
  }, forwardedProps), {
5349
5331
  className: buttonClassName,
5350
5332
  variant: "button"
5351
- }), leftIcon && !isEmpty(leftIcon) && /*#__PURE__*/React__default.createElement(Icon, {
5333
+ }), leftIcon && !isEmpty(leftIcon) &&
5334
+ /*#__PURE__*/
5335
+ // Theme is handled in the button scss
5336
+ React__default.createElement(ThemeProvider, {
5337
+ value: undefined
5338
+ }, /*#__PURE__*/React__default.createElement(Icon, {
5352
5339
  icon: leftIcon
5353
- }), children && (isComponent(Text)(children) ? children : /*#__PURE__*/React__default.createElement("span", null, children)), rightIcon && !isEmpty(rightIcon) && /*#__PURE__*/React__default.createElement(Icon, {
5340
+ })), children && (isComponent(Text)(children) ? children : /*#__PURE__*/React__default.createElement("span", null, children)), rightIcon && !isEmpty(rightIcon) &&
5341
+ /*#__PURE__*/
5342
+ // Theme is handled in the button scss
5343
+ React__default.createElement(ThemeProvider, {
5344
+ value: undefined
5345
+ }, /*#__PURE__*/React__default.createElement(Icon, {
5354
5346
  icon: rightIcon
5355
- }));
5347
+ })));
5356
5348
  });
5357
5349
  Button.displayName = COMPONENT_NAME$1a;
5358
5350
  Button.className = CLASSNAME$18;
@@ -6943,7 +6935,7 @@ const Dialog = forwardRef((props, ref) => {
6943
6935
  // eslint-disable-next-line react-hooks/rules-of-hooks
6944
6936
  const isVisible = useTransitionVisibility(rootRef, Boolean(isOpen), DIALOG_TRANSITION_DURATION, onVisibilityChange);
6945
6937
  const shouldPreventCloseOnClickAway = preventAutoClose || preventCloseOnClick;
6946
- return isOpen || isVisible ? /*#__PURE__*/createPortal( /*#__PURE__*/React__default.createElement("div", _extends({
6938
+ return isOpen || isVisible ? /*#__PURE__*/createPortal(/*#__PURE__*/React__default.createElement("div", _extends({
6947
6939
  ref: mergeRefs(rootRef, ref)
6948
6940
  }, forwardedProps, {
6949
6941
  className: classNames(className, handleBasicClasses({
@@ -7465,6 +7457,23 @@ const useOverflowTooltipLabel = () => {
7465
7457
  };
7466
7458
  };
7467
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 (! /*#__PURE__*/React__default.isValidElement(child)) {
7465
+ return child;
7466
+ }
7467
+ if (child.type === React__default.Fragment) {
7468
+ return wrapChildrenIconWithSpaces(child.props.children);
7469
+ }
7470
+ if (isComponentType(Icon)(child)) {
7471
+ return [' ', child, ' '];
7472
+ }
7473
+ return child;
7474
+ });
7475
+ }
7476
+
7468
7477
  const _excluded$_ = ["as", "children", "className", "color", "colorVariant", "noWrap", "typography", "truncate", "whiteSpace", "style"];
7469
7478
 
7470
7479
  /**
@@ -7538,15 +7547,7 @@ const Text = forwardRef((props, ref) => {
7538
7547
  }), typographyClass, colorClass, noWrap && `${CLASSNAME$V}--no-wrap`),
7539
7548
  title: tooltipLabel,
7540
7549
  style: _objectSpread2(_objectSpread2(_objectSpread2({}, truncateLinesStyle), whiteSpaceStyle), style)
7541
- }, forwardedProps), children && Children.toArray(children).map((child, index) => {
7542
- // Force wrap spaces around icons to make sure they are never stuck against text.
7543
- if (isComponent(Icon)(child)) {
7544
- return /*#__PURE__*/React__default.createElement(Fragment, {
7545
- key: child.key || index
7546
- }, " ", child, " ");
7547
- }
7548
- return child;
7549
- }));
7550
+ }, forwardedProps), wrapChildrenIconWithSpaces(children));
7550
7551
  });
7551
7552
  Text.displayName = COMPONENT_NAME$V;
7552
7553
  Text.className = CLASSNAME$V;
@@ -8885,7 +8886,7 @@ InlineList.displayName = COMPONENT_NAME$N;
8885
8886
  InlineList.className = CLASSNAME$N;
8886
8887
  InlineList.defaultProps = DEFAULT_PROPS$D;
8887
8888
 
8888
- const _excluded$Q = ["children", "className", "htmlFor", "isRequired", "theme"];
8889
+ const _excluded$Q = ["children", "className", "htmlFor", "isRequired", "theme", "typography"];
8889
8890
 
8890
8891
  /**
8891
8892
  * Defines the props of the component.
@@ -8920,9 +8921,11 @@ const InputLabel = forwardRef((props, ref) => {
8920
8921
  className,
8921
8922
  htmlFor,
8922
8923
  isRequired,
8923
- theme = defaultTheme
8924
+ theme = defaultTheme,
8925
+ typography
8924
8926
  } = props,
8925
8927
  forwardedProps = _objectWithoutProperties(props, _excluded$Q);
8928
+ const typographyClass = typography && getTypographyClassName(typography);
8926
8929
  return /*#__PURE__*/React__default.createElement("label", _extends({
8927
8930
  ref: ref
8928
8931
  }, forwardedProps, {
@@ -8930,8 +8933,9 @@ const InputLabel = forwardRef((props, ref) => {
8930
8933
  className: classNames(className, handleBasicClasses({
8931
8934
  prefix: CLASSNAME$M,
8932
8935
  isRequired,
8933
- theme
8934
- }))
8936
+ theme,
8937
+ hasCustomTypography: Boolean(typography)
8938
+ }), typographyClass)
8935
8939
  }), children);
8936
8940
  });
8937
8941
  InputLabel.displayName = COMPONENT_NAME$M;
@@ -9088,31 +9092,6 @@ const COMPONENT_NAME$K = 'Link';
9088
9092
  * Component default class name and class prefix.
9089
9093
  */
9090
9094
  const CLASSNAME$K = getRootClassName(COMPONENT_NAME$K);
9091
- const getIconSize = typography => {
9092
- switch (typography) {
9093
- case Typography.display1:
9094
- return Size.m;
9095
- case Typography.headline:
9096
- case Typography.title:
9097
- case Typography.custom.title1:
9098
- case Typography.custom.title2:
9099
- case Typography.custom.title3:
9100
- case Typography.custom.title4:
9101
- case Typography.custom.title5:
9102
- case Typography.custom.title6:
9103
- case Typography.body2:
9104
- case Typography.subtitle2:
9105
- return Size.s;
9106
- case Typography.body1:
9107
- case Typography.subtitle1:
9108
- return Size.xs;
9109
- case Typography.caption:
9110
- case Typography.overline:
9111
- return Size.xxs;
9112
- default:
9113
- return Size.s;
9114
- }
9115
- };
9116
9095
 
9117
9096
  /**
9118
9097
  * Link component.
@@ -9137,49 +9116,31 @@ const Link = forwardRef((props, ref) => {
9137
9116
  typography
9138
9117
  } = props,
9139
9118
  forwardedProps = _objectWithoutProperties(props, _excluded$O);
9140
- const renderedChildren = useMemo(() => /*#__PURE__*/React__default.createElement(React__default.Fragment, null, leftIcon && !isEmpty(leftIcon) && /*#__PURE__*/React__default.createElement(Icon, {
9141
- icon: leftIcon,
9142
- className: `${CLASSNAME$K}__left-icon`,
9143
- size: getIconSize(typography)
9144
- }), children && /*#__PURE__*/React__default.createElement("span", {
9145
- className: classNames(`${CLASSNAME$K}__content`, {
9146
- [`lumx-typography-${typography}`]: typography
9147
- })
9148
- }, children), rightIcon && !isEmpty(rightIcon) && /*#__PURE__*/React__default.createElement(Icon, {
9149
- icon: rightIcon,
9150
- className: `${CLASSNAME$K}__right-icon`,
9151
- size: getIconSize(typography)
9152
- })), [leftIcon, typography, children, rightIcon]);
9153
-
9154
- /**
9155
- * If there is no linkAs prop and no href, we returned a <button> instead of a <a>.
9156
- * If the component is disabled, we also returned a <button> since disabled is not compatible with <a>.
9157
- */
9158
- if (!linkAs && isEmpty(href) || isDisabled) {
9159
- return /*#__PURE__*/React__default.createElement("button", _extends({
9160
- type: "button"
9161
- }, forwardedProps, {
9162
- ref: ref,
9163
- disabled: isDisabled,
9164
- className: classNames(className, handleBasicClasses({
9165
- prefix: CLASSNAME$K,
9166
- color,
9167
- colorVariant
9168
- }))
9169
- }), renderedChildren);
9119
+ const isLink = linkAs || href;
9120
+ const Component = isLink && !isDisabled ? linkAs || 'a' : 'button';
9121
+ const baseProps = {};
9122
+ if (Component === 'button') {
9123
+ baseProps.type = 'button';
9124
+ baseProps.disabled = isDisabled;
9125
+ } else if (isLink) {
9126
+ baseProps.href = href;
9127
+ baseProps.target = target;
9170
9128
  }
9171
- return renderLink(_objectSpread2(_objectSpread2({
9172
- linkAs
9173
- }, forwardedProps), {}, {
9174
- href,
9175
- target,
9129
+ return /*#__PURE__*/React__default.createElement(Component, _extends({
9130
+ ref: ref
9131
+ }, forwardedProps, baseProps, {
9176
9132
  className: classNames(className, handleBasicClasses({
9177
9133
  prefix: CLASSNAME$K,
9178
9134
  color,
9179
9135
  colorVariant
9180
- })),
9181
- ref: ref
9182
- }), renderedChildren);
9136
+ }), typography && getTypographyClassName(typography))
9137
+ }), wrapChildrenIconWithSpaces(/*#__PURE__*/React__default.createElement(React__default.Fragment, null, leftIcon && /*#__PURE__*/React__default.createElement(Icon, {
9138
+ icon: leftIcon,
9139
+ className: `${CLASSNAME$K}__left-icon`
9140
+ }), children, rightIcon && /*#__PURE__*/React__default.createElement(Icon, {
9141
+ icon: rightIcon,
9142
+ className: `${CLASSNAME$K}__right-icon`
9143
+ }))));
9183
9144
  });
9184
9145
  Link.displayName = COMPONENT_NAME$K;
9185
9146
  Link.className = CLASSNAME$K;
@@ -13937,7 +13898,7 @@ const useInjectTooltipRef = options => {
13937
13898
  if (!label) return children;
13938
13899
 
13939
13900
  // Non-disabled element
13940
- if ( /*#__PURE__*/React__default.isValidElement(children) && children.props.disabled !== true && children.props.isDisabled !== true) {
13901
+ if (/*#__PURE__*/React__default.isValidElement(children) && children.props.disabled !== true && children.props.isDisabled !== true) {
13941
13902
  const ref = mergeRefs(children.ref, setAnchorElement);
13942
13903
  const props = _objectSpread2(_objectSpread2({}, children.props), {}, {
13943
13904
  ref
@@ -14009,7 +13970,7 @@ function useTooltipOpen(delay, anchorElement) {
14009
13970
  if (!IS_BROWSER) update();else timer = setTimeout(update, duration);
14010
13971
  };
14011
13972
  const hoverNotSupported = isHoverNotSupported();
14012
- const hasTouch = ('ontouchstart' in window);
13973
+ const hasTouch = 'ontouchstart' in window;
14013
13974
 
14014
13975
  // Adapt open/close delay
14015
13976
  const openDelay = delay || (hoverNotSupported ? TOOLTIP_LONG_PRESS_DELAY.open : TOOLTIP_HOVER_DELAY.open);
@@ -14197,7 +14158,7 @@ const Tooltip = forwardRef((props, ref) => {
14197
14158
  }, [isOpen, update, popperElement]);
14198
14159
  const labelLines = label ? label.split('\n') : [];
14199
14160
  const tooltipRef = useMergeRefs(ref, setPopperElement, onPopperMount);
14200
- return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(TooltipContextProvider, null, wrappedChildren), isMounted && /*#__PURE__*/createPortal( /*#__PURE__*/React__default.createElement("div", _extends({
14161
+ return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(TooltipContextProvider, null, wrappedChildren), isMounted && /*#__PURE__*/createPortal(/*#__PURE__*/React__default.createElement("div", _extends({
14201
14162
  ref: tooltipRef
14202
14163
  }, forwardedProps, {
14203
14164
  id: id,