@uxf/ui 10.8.0 → 10.8.1
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/_file-input-base/file-input-base.d.ts +1 -1
- package/_file-input-base/file-input-base.js +3 -3
- package/_select-base/_select-base.js +4 -6
- package/avatar-file-input/avatar-file-input.js +8 -1
- package/dropzone/dropzone-input.d.ts +1 -1
- package/dropzone/dropzone-input.js +1 -1
- package/package.json +1 -1
- package/utils/mocks/upload-file.mock.d.ts +1 -1
- package/utils/mocks/upload-file.mock.js +33 -30
|
@@ -8,6 +8,6 @@ export interface FileInputBaseProps extends FormControlProps<FileResponse | null
|
|
|
8
8
|
id?: string;
|
|
9
9
|
maxFileSize?: number;
|
|
10
10
|
onUploadError?: (err: unknown) => void;
|
|
11
|
-
onUploadFile: (file: File) => Promise<FileResponse>;
|
|
11
|
+
onUploadFile: (file: File | undefined) => Promise<FileResponse | null>;
|
|
12
12
|
}
|
|
13
13
|
export declare const _FileInputBase: React.ForwardRefExoticComponent<FileInputBaseProps & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -28,8 +28,8 @@ const react_1 = __importStar(require("react"));
|
|
|
28
28
|
const validator_exceptions_1 = require("../utils/validator/validator-exceptions");
|
|
29
29
|
exports._FileInputBase = (0, react_1.forwardRef)((props, ref) => {
|
|
30
30
|
const onChange = async (e) => {
|
|
31
|
-
var _a;
|
|
32
|
-
if (e.target.files) {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
if ((_a = e.target.files) === null || _a === void 0 ? void 0 : _a.length) {
|
|
33
33
|
try {
|
|
34
34
|
const file = e.target.files[0];
|
|
35
35
|
if (props.maxFileSize && file.size > props.maxFileSize) {
|
|
@@ -39,7 +39,7 @@ exports._FileInputBase = (0, react_1.forwardRef)((props, ref) => {
|
|
|
39
39
|
await props.onChange(response, e);
|
|
40
40
|
}
|
|
41
41
|
catch (err) {
|
|
42
|
-
(
|
|
42
|
+
(_b = props.onUploadError) === null || _b === void 0 ? void 0 : _b.call(props, err);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
@@ -36,10 +36,8 @@ const input_1 = require("@uxf/ui/input");
|
|
|
36
36
|
const label_1 = require("@uxf/ui/label");
|
|
37
37
|
const react_2 = __importStar(require("react"));
|
|
38
38
|
const Option = (props) => {
|
|
39
|
-
var _a, _b, _c, _d;
|
|
40
|
-
const optionKey = (_a = props.keyExtractor) === null || _a === void 0 ? void 0 : _a.call(props, props.option);
|
|
41
39
|
const HUIComponent = props.HUIComponent;
|
|
42
|
-
return (react_2.default.createElement(HUIComponent.Option, { className: (optionState) => (0, cx_1.cx)("uxf-dropdown__item", optionState.active && classes_1.CLASSES.IS_ACTIVE, optionState.disabled && classes_1.CLASSES.IS_DISABLED, optionState.selected && classes_1.CLASSES.IS_SELECTED),
|
|
40
|
+
return (react_2.default.createElement(HUIComponent.Option, { className: (optionState) => (0, cx_1.cx)("uxf-dropdown__item", optionState.active && classes_1.CLASSES.IS_ACTIVE, optionState.disabled && classes_1.CLASSES.IS_DISABLED, optionState.selected && classes_1.CLASSES.IS_SELECTED), value: props.option }, (optionState) => { var _a, _b; return (_b = (_a = props.renderOption) === null || _a === void 0 ? void 0 : _a.call(props, props.option, optionState.selected)) !== null && _b !== void 0 ? _b : props.option.label; }));
|
|
43
41
|
};
|
|
44
42
|
Option.displayName = "UxfUiSelectBaseOption";
|
|
45
43
|
function isHUICombobox(HUIComponent) {
|
|
@@ -68,9 +66,9 @@ const Options = (props) => {
|
|
|
68
66
|
return (react_2.default.createElement(HUIComponent.Options, { className: (0, cx_1.cx)("uxf-dropdown uxf-select-base__options", `uxf-dropdown--size-${(_a = props.size) !== null && _a !== void 0 ? _a : "default"}`, `uxf-dropdown--variant-${(_b = props.variant) !== null && _b !== void 0 ? _b : "default"}`, props.matchWidth
|
|
69
67
|
? "uxf-select-base__options--match-width"
|
|
70
68
|
: "uxf-select-base__options--not-match-width", props.placement === "bottom" && "uxf-dropdown--bottom", props.placement === "top" && "uxf-dropdown--top", props.className), ref: props.forwardRef, static: true, style: props.style }, props.options && props.options.length > 0 ? (props.options.map((option) => {
|
|
71
|
-
var _a;
|
|
72
|
-
const optionKey = (_a = props.keyExtractor) === null || _a === void 0 ? void 0 : _a.call(props, option);
|
|
73
|
-
return (react_2.default.createElement(Option, {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
const optionKey = (_b = (_a = props.keyExtractor) === null || _a === void 0 ? void 0 : _a.call(props, option)) !== null && _b !== void 0 ? _b : option.id;
|
|
71
|
+
return (react_2.default.createElement(Option, { HUIComponent: HUIComponent, key: optionKey, option: option, renderOption: props.renderOption }));
|
|
74
72
|
})) : (react_2.default.createElement("div", { className: "uxf-dropdown__empty-wrapper" }, props.emptyMessage))));
|
|
75
73
|
};
|
|
76
74
|
Options.displayName = "UxfUiSelectBaseOptions";
|
|
@@ -45,7 +45,14 @@ exports.AvatarFileInput = (0, react_1.forwardRef)((props, ref) => {
|
|
|
45
45
|
const stateClassName = (0, cx_1.cx)(((_a = props.isFocused) !== null && _a !== void 0 ? _a : input.focused) && classes_1.CLASSES.IS_FOCUSED, props.isDisabled && classes_1.CLASSES.IS_DISABLED, props.isInvalid && classes_1.CLASSES.IS_INVALID, props.isReadOnly && classes_1.CLASSES.IS_READONLY, props.isRequired && classes_1.CLASSES.IS_REQUIRED);
|
|
46
46
|
const rootClassName = (0, cx_1.cx)(`uxf-avatar-file-input uxf-avatar-file-input--variant-${(_b = props.variant) !== null && _b !== void 0 ? _b : "default"}`, stateClassName, props.className);
|
|
47
47
|
const onSelectFile = () => { var _a; return (_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.click(); };
|
|
48
|
-
const onRemoveFile = () =>
|
|
48
|
+
const onRemoveFile = () => {
|
|
49
|
+
props.onChange(null);
|
|
50
|
+
// this ensures that the file input is cleared on remove, so that the same file can be selected again
|
|
51
|
+
const inputNode = innerRef.current;
|
|
52
|
+
if (inputNode) {
|
|
53
|
+
inputNode.value = "";
|
|
54
|
+
}
|
|
55
|
+
};
|
|
49
56
|
return (react_1.default.createElement(form_component_1.FormComponent, { className: rootClassName, errorId: props.id, helperText: props.helperText, hiddenLabel: props.hiddenLabel, inputId: id, label: props.label },
|
|
50
57
|
react_1.default.createElement("div", { className: "uxf-avatar-file-input__inner-wrapper" },
|
|
51
58
|
react_1.default.createElement("div", { className: (0, cx_1.cx)("uxf-avatar-file-input__input", stateClassName), onClick: onSelectFile },
|
|
@@ -15,6 +15,6 @@ export interface DropzoneInputProps extends FormControlProps<DropzoneFile[] | un
|
|
|
15
15
|
noClick?: boolean;
|
|
16
16
|
noDrag?: boolean;
|
|
17
17
|
onUploadError?: (err: unknown) => void;
|
|
18
|
-
onUploadFile: (file: File, options?: UploadOptions) => Promise<FileResponse>;
|
|
18
|
+
onUploadFile: (file: File | undefined, options?: UploadOptions) => Promise<FileResponse | null>;
|
|
19
19
|
}
|
|
20
20
|
export declare const DropzoneInput: React.ForwardRefExoticComponent<DropzoneInputProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -51,7 +51,7 @@ function progressHandler(progressEvent, file, onValuesChange, values) {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
function fileUploadedHandler(uploadedFile, dropzoneFile, onValuesChange, values) {
|
|
54
|
-
if (values) {
|
|
54
|
+
if (values && uploadedFile) {
|
|
55
55
|
onValuesChange(values.map((f) => f.id === dropzoneFile.id ? { ...uploadedFile, progress: 100, originalFile: f.originalFile } : f));
|
|
56
56
|
}
|
|
57
57
|
}
|
package/package.json
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { FileResponse, UploadOptions } from "@uxf/ui/types";
|
|
2
|
-
export declare function uploadFile(file: File, uploadOptions?: UploadOptions): Promise<FileResponse>;
|
|
2
|
+
export declare function uploadFile(file: File | undefined, uploadOptions?: UploadOptions): Promise<FileResponse | null>;
|
|
@@ -10,37 +10,40 @@ function getRandomUuid() {
|
|
|
10
10
|
.join(""))
|
|
11
11
|
.join("-");
|
|
12
12
|
}
|
|
13
|
-
function uploadFile(file, uploadOptions) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
async function uploadFile(file, uploadOptions) {
|
|
14
|
+
if (file) {
|
|
15
|
+
// axios.put("/api/upload", file, { signal: uploadOptions?.abortController?.signal, onUploadProgress: uploadOptions?.onUploadProgress });
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
const time = file.size / 100;
|
|
18
|
+
const interval = time / 10;
|
|
19
|
+
let loaded = 0;
|
|
20
|
+
const intervalTimer = window.setInterval(() => {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
if ((_a = uploadOptions === null || uploadOptions === void 0 ? void 0 : uploadOptions.abortController) === null || _a === void 0 ? void 0 : _a.signal.aborted) {
|
|
23
|
+
clearInterval(intervalTimer);
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
25
|
+
clearTimeout(timeoutTimer);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
loaded += (file.size / time) * interval;
|
|
29
|
+
(_b = uploadOptions === null || uploadOptions === void 0 ? void 0 : uploadOptions.onUploadProgress) === null || _b === void 0 ? void 0 : _b.call(uploadOptions, {
|
|
30
|
+
lengthComputable: true,
|
|
31
|
+
loaded,
|
|
32
|
+
total: file.size,
|
|
33
|
+
});
|
|
34
|
+
}, interval);
|
|
35
|
+
const timeoutTimer = window.setTimeout(() => {
|
|
22
36
|
clearInterval(intervalTimer);
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
24
37
|
clearTimeout(timeoutTimer);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
clearInterval(intervalTimer);
|
|
36
|
-
clearTimeout(timeoutTimer);
|
|
37
|
-
resolve({
|
|
38
|
-
id: Math.round(Math.random() * 100000000),
|
|
39
|
-
uuid: getRandomUuid(),
|
|
40
|
-
name: file.name,
|
|
41
|
-
extension: file.name.split(".").slice(-1).join(""),
|
|
42
|
-
});
|
|
43
|
-
}, time);
|
|
44
|
-
});
|
|
38
|
+
resolve({
|
|
39
|
+
id: Math.round(Math.random() * 100000000),
|
|
40
|
+
uuid: getRandomUuid(),
|
|
41
|
+
name: file.name,
|
|
42
|
+
extension: file.name.split(".").slice(-1).join(""),
|
|
43
|
+
});
|
|
44
|
+
}, time);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
45
48
|
}
|
|
46
49
|
exports.uploadFile = uploadFile;
|