@lumx/react 3.18.2-alpha.3 → 3.19.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 +3 -1
- package/index.js +45 -27
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/navigation/NavigationItem.tsx +1 -1
- package/src/components/text/Text.stories.tsx +23 -1
- package/src/components/text/Text.tsx +1 -1
- package/src/components/uploader/Uploader.stories.tsx +12 -3
- package/src/components/uploader/Uploader.test.tsx +31 -10
- package/src/components/uploader/Uploader.tsx +29 -7
- package/src/hooks/useOverflowTooltipLabel.tsx +21 -18
- package/src/utils/disabled/DisabledStateProvider.stories.tsx +2 -0
package/index.d.ts
CHANGED
|
@@ -3328,11 +3328,13 @@ interface FileInputProps extends Omit<React.ComponentProps<'input'>, 'onChange'>
|
|
|
3328
3328
|
/**
|
|
3329
3329
|
* Defines the props of the component.
|
|
3330
3330
|
*/
|
|
3331
|
-
interface UploaderProps extends GenericProps, HasTheme {
|
|
3331
|
+
interface UploaderProps extends GenericProps, HasTheme, HasAriaDisabled {
|
|
3332
3332
|
/** Image aspect ratio. */
|
|
3333
3333
|
aspectRatio?: AspectRatio;
|
|
3334
3334
|
/** Icon (SVG path). */
|
|
3335
3335
|
icon?: string;
|
|
3336
|
+
/** Disabled state */
|
|
3337
|
+
isDisabled?: boolean;
|
|
3336
3338
|
/** Label text. */
|
|
3337
3339
|
label?: string;
|
|
3338
3340
|
/** Size variant. */
|
package/index.js
CHANGED
|
@@ -7229,26 +7229,28 @@ const useTooltipContext = () => React__default.useContext(TooltipContext);
|
|
|
7229
7229
|
|
|
7230
7230
|
/**
|
|
7231
7231
|
* Compute a tooltip label based on a label element `innerText` if the text overflows.
|
|
7232
|
-
*
|
|
7233
|
-
* Warning: only works on first render, does not update on label element resize.
|
|
7232
|
+
* Updates dynamically on content changes (but not on resize!)
|
|
7234
7233
|
*/
|
|
7235
|
-
const useOverflowTooltipLabel =
|
|
7234
|
+
const useOverflowTooltipLabel = content => {
|
|
7236
7235
|
const parentTooltip = useTooltipContext();
|
|
7237
7236
|
const [tooltipLabel, setTooltipLabel] = React__default.useState(undefined);
|
|
7238
|
-
const
|
|
7239
|
-
|
|
7240
|
-
|
|
7241
|
-
|
|
7242
|
-
|
|
7243
|
-
|
|
7244
|
-
|
|
7245
|
-
//
|
|
7246
|
-
|
|
7237
|
+
const [labelElement, setLabelElement] = React__default.useState(null);
|
|
7238
|
+
React__default.useLayoutEffect(() => {
|
|
7239
|
+
if (
|
|
7240
|
+
// Not inside a tooltip
|
|
7241
|
+
!parentTooltip && labelElement &&
|
|
7242
|
+
// Not inside a visually hidden
|
|
7243
|
+
!(labelElement !== null && labelElement !== void 0 && labelElement.closest(`.${VISUALLY_HIDDEN}`)) &&
|
|
7244
|
+
// Text overflows
|
|
7245
|
+
labelElement.offsetWidth < labelElement.scrollWidth) {
|
|
7246
|
+
// Set tooltip label
|
|
7247
7247
|
setTooltipLabel(labelElement.innerText);
|
|
7248
|
+
} else {
|
|
7249
|
+
setTooltipLabel(undefined);
|
|
7248
7250
|
}
|
|
7249
|
-
}, [parentTooltip]);
|
|
7251
|
+
}, [labelElement, parentTooltip, content]);
|
|
7250
7252
|
return {
|
|
7251
|
-
labelRef,
|
|
7253
|
+
labelRef: setLabelElement,
|
|
7252
7254
|
tooltipLabel
|
|
7253
7255
|
};
|
|
7254
7256
|
};
|
|
@@ -7329,7 +7331,7 @@ const Text = forwardRef((props, ref) => {
|
|
|
7329
7331
|
const {
|
|
7330
7332
|
tooltipLabel,
|
|
7331
7333
|
labelRef
|
|
7332
|
-
} = useOverflowTooltipLabel();
|
|
7334
|
+
} = useOverflowTooltipLabel(children);
|
|
7333
7335
|
return /*#__PURE__*/React__default.createElement(Component, _extends({
|
|
7334
7336
|
ref: useMergeRefs(ref, labelRef),
|
|
7335
7337
|
className: classNames(className, handleBasicClasses({
|
|
@@ -9371,7 +9373,7 @@ const NavigationItem = Object.assign(forwardRefPolymorphic((props, ref) => {
|
|
|
9371
9373
|
const {
|
|
9372
9374
|
tooltipLabel,
|
|
9373
9375
|
labelRef
|
|
9374
|
-
} = useOverflowTooltipLabel();
|
|
9376
|
+
} = useOverflowTooltipLabel(label);
|
|
9375
9377
|
const buttonProps = Element === 'button' ? {
|
|
9376
9378
|
type: 'button'
|
|
9377
9379
|
} : {};
|
|
@@ -14177,7 +14179,7 @@ Tooltip.displayName = COMPONENT_NAME$2;
|
|
|
14177
14179
|
Tooltip.className = CLASSNAME$2;
|
|
14178
14180
|
Tooltip.defaultProps = DEFAULT_PROPS$2;
|
|
14179
14181
|
|
|
14180
|
-
const _excluded$1 = ["aspectRatio", "className", "label", "icon", "size", "theme", "variant", "fileInputProps"];
|
|
14182
|
+
const _excluded$1 = ["aspectRatio", "className", "label", "icon", "size", "theme", "variant", "fileInputProps", "onClick"];
|
|
14181
14183
|
|
|
14182
14184
|
/**
|
|
14183
14185
|
* Uploader variants.
|
|
@@ -14227,6 +14229,11 @@ const DEFAULT_PROPS$1 = {
|
|
|
14227
14229
|
* @return React element.
|
|
14228
14230
|
*/
|
|
14229
14231
|
const Uploader = forwardRef((props, ref) => {
|
|
14232
|
+
const {
|
|
14233
|
+
disabledStateProps,
|
|
14234
|
+
otherProps,
|
|
14235
|
+
isAnyDisabled
|
|
14236
|
+
} = useDisableStateProps(props);
|
|
14230
14237
|
const defaultTheme = useTheme() || Theme.light;
|
|
14231
14238
|
const {
|
|
14232
14239
|
aspectRatio = DEFAULT_PROPS$1.aspectRatio,
|
|
@@ -14236,11 +14243,19 @@ const Uploader = forwardRef((props, ref) => {
|
|
|
14236
14243
|
size = DEFAULT_PROPS$1.size,
|
|
14237
14244
|
theme = defaultTheme,
|
|
14238
14245
|
variant = DEFAULT_PROPS$1.variant,
|
|
14239
|
-
fileInputProps
|
|
14240
|
-
|
|
14241
|
-
|
|
14246
|
+
fileInputProps,
|
|
14247
|
+
onClick
|
|
14248
|
+
} = otherProps,
|
|
14249
|
+
forwardedProps = _objectWithoutProperties(otherProps, _excluded$1);
|
|
14242
14250
|
// Adjust to square aspect ratio when using circle variants.
|
|
14243
14251
|
const adjustedAspectRatio = variant === UploaderVariant.circle ? AspectRatio.square : aspectRatio;
|
|
14252
|
+
const handleClick = React__default.useCallback(evt => {
|
|
14253
|
+
if (isAnyDisabled) {
|
|
14254
|
+
evt.preventDefault();
|
|
14255
|
+
} else {
|
|
14256
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(evt);
|
|
14257
|
+
}
|
|
14258
|
+
}, [isAnyDisabled, onClick]);
|
|
14244
14259
|
const generatedInputId = useId();
|
|
14245
14260
|
const inputId = (fileInputProps === null || fileInputProps === void 0 ? void 0 : fileInputProps.id) || generatedInputId;
|
|
14246
14261
|
const [isDragHovering, unsetDragHovering, setDragHovering] = useBooleanState(false);
|
|
@@ -14251,28 +14266,30 @@ const Uploader = forwardRef((props, ref) => {
|
|
|
14251
14266
|
}
|
|
14252
14267
|
} : {
|
|
14253
14268
|
Component: 'button',
|
|
14254
|
-
props: {
|
|
14269
|
+
props: _objectSpread2({
|
|
14255
14270
|
type: 'button'
|
|
14256
|
-
}
|
|
14271
|
+
}, disabledStateProps)
|
|
14257
14272
|
};
|
|
14258
14273
|
const onChange = React__default.useMemo(() => {
|
|
14259
|
-
if (!(fileInputProps !== null && fileInputProps !== void 0 && fileInputProps.onChange)) return undefined;
|
|
14274
|
+
if (isAnyDisabled || !(fileInputProps !== null && fileInputProps !== void 0 && fileInputProps.onChange)) return undefined;
|
|
14260
14275
|
return evt => {
|
|
14261
14276
|
const fileList = evt.target.files;
|
|
14262
14277
|
const files = fileList ? Array.from(fileList) : [];
|
|
14263
14278
|
fileInputProps.onChange(files, evt);
|
|
14264
14279
|
};
|
|
14265
|
-
}, [fileInputProps]);
|
|
14280
|
+
}, [isAnyDisabled, fileInputProps]);
|
|
14266
14281
|
return /*#__PURE__*/React__default.createElement(wrapper.Component, _extends({
|
|
14267
14282
|
ref: ref
|
|
14268
14283
|
}, wrapper.props, forwardedProps, {
|
|
14284
|
+
onClick: handleClick,
|
|
14269
14285
|
className: classNames(className, handleBasicClasses({
|
|
14270
14286
|
aspectRatio: adjustedAspectRatio,
|
|
14271
14287
|
prefix: CLASSNAME$1,
|
|
14272
14288
|
size,
|
|
14273
14289
|
theme,
|
|
14274
14290
|
variant,
|
|
14275
|
-
isDragHovering
|
|
14291
|
+
isDragHovering,
|
|
14292
|
+
isDisabled: isAnyDisabled
|
|
14276
14293
|
}))
|
|
14277
14294
|
}), /*#__PURE__*/React__default.createElement("span", {
|
|
14278
14295
|
className: `${CLASSNAME$1}__background`
|
|
@@ -14287,8 +14304,9 @@ const Uploader = forwardRef((props, ref) => {
|
|
|
14287
14304
|
}, label)), fileInputProps && /*#__PURE__*/React__default.createElement("input", _extends({
|
|
14288
14305
|
type: "file",
|
|
14289
14306
|
id: inputId,
|
|
14290
|
-
className: `${CLASSNAME$1}__input`
|
|
14291
|
-
}, fileInputProps, {
|
|
14307
|
+
className: `${CLASSNAME$1}__input ${VISUALLY_HIDDEN}`
|
|
14308
|
+
}, disabledStateProps, fileInputProps, {
|
|
14309
|
+
readOnly: isAnyDisabled,
|
|
14292
14310
|
onChange: onChange,
|
|
14293
14311
|
onDragEnter: setDragHovering,
|
|
14294
14312
|
onDragLeave: unsetDragHovering,
|