@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.
@@ -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
- (_a = props.onUploadError) === null || _a === void 0 ? void 0 : _a.call(props, err);
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), key: optionKey !== null && optionKey !== void 0 ? optionKey : props.option.id, value: props.option }, (_d = (_c = (_b = props.renderOption) === null || _b === void 0 ? void 0 : _b.call(props, props.option)) !== null && _c !== void 0 ? _c : optionKey) !== null && _d !== void 0 ? _d : props.option.label));
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, { key: optionKey, keyExtractor: props.keyExtractor, option: option, HUIComponent: HUIComponent }));
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 = () => props.onChange(null);
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/ui",
3
- "version": "10.8.0",
3
+ "version": "10.8.1",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -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
- // axios.put("/api/upload", file, { signal: uploadOptions?.abortController?.signal, onUploadProgress: uploadOptions?.onUploadProgress });
15
- return new Promise((resolve) => {
16
- const time = file.size / 100;
17
- const interval = time / 10;
18
- let loaded = 0;
19
- const intervalTimer = window.setInterval(() => {
20
- var _a, _b;
21
- if ((_a = uploadOptions === null || uploadOptions === void 0 ? void 0 : uploadOptions.abortController) === null || _a === void 0 ? void 0 : _a.signal.aborted) {
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
- return;
26
- }
27
- loaded += (file.size / time) * interval;
28
- (_b = uploadOptions === null || uploadOptions === void 0 ? void 0 : uploadOptions.onUploadProgress) === null || _b === void 0 ? void 0 : _b.call(uploadOptions, {
29
- lengthComputable: true,
30
- loaded,
31
- total: file.size,
32
- });
33
- }, interval);
34
- const timeoutTimer = window.setTimeout(() => {
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;