@lumx/react 3.18.2-alpha.3 → 3.18.2-alpha.4
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 +27 -11
- package/index.js.map +1 -1
- package/package.json +3 -3
- 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/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
|
@@ -14177,7 +14177,7 @@ Tooltip.displayName = COMPONENT_NAME$2;
|
|
|
14177
14177
|
Tooltip.className = CLASSNAME$2;
|
|
14178
14178
|
Tooltip.defaultProps = DEFAULT_PROPS$2;
|
|
14179
14179
|
|
|
14180
|
-
const _excluded$1 = ["aspectRatio", "className", "label", "icon", "size", "theme", "variant", "fileInputProps"];
|
|
14180
|
+
const _excluded$1 = ["aspectRatio", "className", "label", "icon", "size", "theme", "variant", "fileInputProps", "onClick"];
|
|
14181
14181
|
|
|
14182
14182
|
/**
|
|
14183
14183
|
* Uploader variants.
|
|
@@ -14227,6 +14227,11 @@ const DEFAULT_PROPS$1 = {
|
|
|
14227
14227
|
* @return React element.
|
|
14228
14228
|
*/
|
|
14229
14229
|
const Uploader = forwardRef((props, ref) => {
|
|
14230
|
+
const {
|
|
14231
|
+
disabledStateProps,
|
|
14232
|
+
otherProps,
|
|
14233
|
+
isAnyDisabled
|
|
14234
|
+
} = useDisableStateProps(props);
|
|
14230
14235
|
const defaultTheme = useTheme() || Theme.light;
|
|
14231
14236
|
const {
|
|
14232
14237
|
aspectRatio = DEFAULT_PROPS$1.aspectRatio,
|
|
@@ -14236,11 +14241,19 @@ const Uploader = forwardRef((props, ref) => {
|
|
|
14236
14241
|
size = DEFAULT_PROPS$1.size,
|
|
14237
14242
|
theme = defaultTheme,
|
|
14238
14243
|
variant = DEFAULT_PROPS$1.variant,
|
|
14239
|
-
fileInputProps
|
|
14240
|
-
|
|
14241
|
-
|
|
14244
|
+
fileInputProps,
|
|
14245
|
+
onClick
|
|
14246
|
+
} = otherProps,
|
|
14247
|
+
forwardedProps = _objectWithoutProperties(otherProps, _excluded$1);
|
|
14242
14248
|
// Adjust to square aspect ratio when using circle variants.
|
|
14243
14249
|
const adjustedAspectRatio = variant === UploaderVariant.circle ? AspectRatio.square : aspectRatio;
|
|
14250
|
+
const handleClick = React__default.useCallback(evt => {
|
|
14251
|
+
if (isAnyDisabled) {
|
|
14252
|
+
evt.preventDefault();
|
|
14253
|
+
} else {
|
|
14254
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(evt);
|
|
14255
|
+
}
|
|
14256
|
+
}, [isAnyDisabled, onClick]);
|
|
14244
14257
|
const generatedInputId = useId();
|
|
14245
14258
|
const inputId = (fileInputProps === null || fileInputProps === void 0 ? void 0 : fileInputProps.id) || generatedInputId;
|
|
14246
14259
|
const [isDragHovering, unsetDragHovering, setDragHovering] = useBooleanState(false);
|
|
@@ -14251,28 +14264,30 @@ const Uploader = forwardRef((props, ref) => {
|
|
|
14251
14264
|
}
|
|
14252
14265
|
} : {
|
|
14253
14266
|
Component: 'button',
|
|
14254
|
-
props: {
|
|
14267
|
+
props: _objectSpread2({
|
|
14255
14268
|
type: 'button'
|
|
14256
|
-
}
|
|
14269
|
+
}, disabledStateProps)
|
|
14257
14270
|
};
|
|
14258
14271
|
const onChange = React__default.useMemo(() => {
|
|
14259
|
-
if (!(fileInputProps !== null && fileInputProps !== void 0 && fileInputProps.onChange)) return undefined;
|
|
14272
|
+
if (isAnyDisabled || !(fileInputProps !== null && fileInputProps !== void 0 && fileInputProps.onChange)) return undefined;
|
|
14260
14273
|
return evt => {
|
|
14261
14274
|
const fileList = evt.target.files;
|
|
14262
14275
|
const files = fileList ? Array.from(fileList) : [];
|
|
14263
14276
|
fileInputProps.onChange(files, evt);
|
|
14264
14277
|
};
|
|
14265
|
-
}, [fileInputProps]);
|
|
14278
|
+
}, [isAnyDisabled, fileInputProps]);
|
|
14266
14279
|
return /*#__PURE__*/React__default.createElement(wrapper.Component, _extends({
|
|
14267
14280
|
ref: ref
|
|
14268
14281
|
}, wrapper.props, forwardedProps, {
|
|
14282
|
+
onClick: handleClick,
|
|
14269
14283
|
className: classNames(className, handleBasicClasses({
|
|
14270
14284
|
aspectRatio: adjustedAspectRatio,
|
|
14271
14285
|
prefix: CLASSNAME$1,
|
|
14272
14286
|
size,
|
|
14273
14287
|
theme,
|
|
14274
14288
|
variant,
|
|
14275
|
-
isDragHovering
|
|
14289
|
+
isDragHovering,
|
|
14290
|
+
isDisabled: isAnyDisabled
|
|
14276
14291
|
}))
|
|
14277
14292
|
}), /*#__PURE__*/React__default.createElement("span", {
|
|
14278
14293
|
className: `${CLASSNAME$1}__background`
|
|
@@ -14287,8 +14302,9 @@ const Uploader = forwardRef((props, ref) => {
|
|
|
14287
14302
|
}, label)), fileInputProps && /*#__PURE__*/React__default.createElement("input", _extends({
|
|
14288
14303
|
type: "file",
|
|
14289
14304
|
id: inputId,
|
|
14290
|
-
className: `${CLASSNAME$1}__input`
|
|
14291
|
-
}, fileInputProps, {
|
|
14305
|
+
className: `${CLASSNAME$1}__input ${VISUALLY_HIDDEN}`
|
|
14306
|
+
}, disabledStateProps, fileInputProps, {
|
|
14307
|
+
readOnly: isAnyDisabled,
|
|
14292
14308
|
onChange: onChange,
|
|
14293
14309
|
onDragEnter: setDragHovering,
|
|
14294
14310
|
onDragLeave: unsetDragHovering,
|