@uxf/ui 10.0.0-beta.76 → 10.0.0-beta.77
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.
|
@@ -27,9 +27,15 @@ exports._FileInputBase = void 0;
|
|
|
27
27
|
const react_1 = __importStar(require("react"));
|
|
28
28
|
exports._FileInputBase = (0, react_1.forwardRef)((props, ref) => {
|
|
29
29
|
const onChange = async (e) => {
|
|
30
|
+
var _a;
|
|
30
31
|
if (e.target.files) {
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
try {
|
|
33
|
+
const response = await props.onUploadFile(e.target.files[0]);
|
|
34
|
+
await props.onChange(response, e);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
(_a = props.onUploadError) === null || _a === void 0 ? void 0 : _a.call(props, err);
|
|
38
|
+
}
|
|
33
39
|
}
|
|
34
40
|
else {
|
|
35
41
|
props.onChange(null, e);
|
package/file-input/file-input.js
CHANGED
|
@@ -45,27 +45,15 @@ exports.FileInput = (0, react_1.forwardRef)((props, ref) => {
|
|
|
45
45
|
const input = (0, useInputFocus_1.useInputFocus)(innerRef, props.onBlur, props.onFocus);
|
|
46
46
|
const errorId = props.isInvalid && props.id ? `${props.id}--errormessage` : undefined;
|
|
47
47
|
const fileName = props.value ? `${props.value.name}` : props.placeholder || "No file has been selected yet";
|
|
48
|
-
const
|
|
49
|
-
var _a, _b;
|
|
50
|
-
const file = (_a = e === null || e === void 0 ? void 0 : e.target.files) === null || _a === void 0 ? void 0 : _a[0];
|
|
51
|
-
if (!file) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
48
|
+
const onUploadFile = async (file) => {
|
|
54
49
|
setIsUploading(true);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
catch (err) {
|
|
60
|
-
(_b = props.onUploadError) === null || _b === void 0 ? void 0 : _b.call(props, err);
|
|
61
|
-
}
|
|
62
|
-
finally {
|
|
63
|
-
setIsUploading(false);
|
|
64
|
-
}
|
|
50
|
+
const response = await props.onUploadFile(file);
|
|
51
|
+
setIsUploading(false);
|
|
52
|
+
return response;
|
|
65
53
|
};
|
|
66
54
|
return (react_1.default.createElement(form_component_1.FormComponent, { className: (0, cx_1.cx)(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), errorId: errorId, form: props.form, helperText: props.helperText, inputId: id, isRequired: props.isRequired, label: props.label, hiddenLabel: props.hiddenLabel },
|
|
67
55
|
react_1.default.createElement(react_1.default.Fragment, null,
|
|
68
|
-
react_1.default.createElement(_file_input_base_1._FileInputBase, { accept: props.accept, "aria-describedby": errorId, "aria-invalid": props.isInvalid, className: `uxf-file-input__input ${(_a = props.className) !== null && _a !== void 0 ? _a : ""}`, form: props.form, id: id, isDisabled: props.isDisabled || isUploading, isInvalid: props.isInvalid, isReadOnly: props.isReadOnly, isRequired: props.isRequired, name: props.name, onBlur: input.onBlur, onChange: onChange, onFocus: input.onFocus, onUploadError: props.onUploadError, onUploadFile:
|
|
56
|
+
react_1.default.createElement(_file_input_base_1._FileInputBase, { accept: props.accept, "aria-describedby": errorId, "aria-invalid": props.isInvalid, className: `uxf-file-input__input ${(_a = props.className) !== null && _a !== void 0 ? _a : ""}`, form: props.form, id: id, isDisabled: props.isDisabled || isUploading, isInvalid: props.isInvalid, isReadOnly: props.isReadOnly, isRequired: props.isRequired, name: props.name, onBlur: input.onBlur, onChange: props.onChange, onFocus: input.onFocus, onUploadError: props.onUploadError, onUploadFile: onUploadFile, ref: ref, value: props.value }),
|
|
69
57
|
react_1.default.createElement("label", { className: (0, cx_1.cx)("uxf-input", "uxf-file-input__label", input.focused && classes_1.CLASSES.IS_FOCUSED, (props.isDisabled || props.isReadOnly) && classes_1.CLASSES.IS_DISABLED, props.isInvalid && classes_1.CLASSES.IS_INVALID, isUploading && classes_1.CLASSES.IS_LOADING, isUploading && "uxf-file-input__label--has-right-addon", `uxf-input--size-${(_b = props.size) !== null && _b !== void 0 ? _b : "default"}`, `uxf-input--variant-${(_c = props.variant) !== null && _c !== void 0 ? _c : "default"}`), htmlFor: id },
|
|
70
58
|
react_1.default.createElement("div", { className: "uxf-input__left-addon uxf-file-input__label__button" }, !isUploading ? ((_d = props.uploadButtonLabel) !== null && _d !== void 0 ? _d : "Vyberte soubor") : (react_1.default.createElement(loader_1.Loader, { className: "uxf-file-input__label__loader", size: "sm" }))),
|
|
71
59
|
react_1.default.createElement("div", { className: "uxf-file-input__label__wrapper" },
|