@ctlyst.id/internal-ui 5.4.9 → 5.4.10
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/dist/index.d.mts +21 -3
- package/dist/index.d.ts +21 -3
- package/dist/index.js +30 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
@@ -803,7 +803,7 @@ type UploaderProps = FlexProps & {
|
|
803
803
|
/**
|
804
804
|
* callback when validation is not valid
|
805
805
|
*/
|
806
|
-
onHandleRejections?: (file: File, image: HTMLImageElement | null) => void;
|
806
|
+
onHandleRejections?: (file: File, image: HTMLImageElement | null, type?: string | keyof typeof ErrorCode) => void;
|
807
807
|
/**
|
808
808
|
* Text for drag active
|
809
809
|
* - if `dragActiveText` is undefined. Text will take from default constant.
|
@@ -894,6 +894,23 @@ type UploaderProps = FlexProps & {
|
|
894
894
|
isShowReupload?: boolean;
|
895
895
|
size?: 'sm' | 'lg';
|
896
896
|
buttonChangeText?: string;
|
897
|
+
/**
|
898
|
+
* Custom error messages for different error types
|
899
|
+
* Each error type can have a custom message and display type
|
900
|
+
* - message: The error message to display
|
901
|
+
* - type: How to display the error ('toast' for popup notification, 'inline' for inline text)
|
902
|
+
* Example:
|
903
|
+
* {
|
904
|
+
* 'file-invalid-type': { message: 'Invalid file type', type: 'inline' },
|
905
|
+
* 'file-too-large': { message: 'File too large', type: 'toast' }
|
906
|
+
* }
|
907
|
+
*/
|
908
|
+
customErrorRejection?: {
|
909
|
+
[key in ErrorCode]?: {
|
910
|
+
message: string;
|
911
|
+
type: 'inline' | 'toast';
|
912
|
+
};
|
913
|
+
};
|
897
914
|
};
|
898
915
|
|
899
916
|
declare const Uploader: React__default.FC<UploaderProps>;
|
@@ -933,10 +950,11 @@ declare enum ErrorCode {
|
|
933
950
|
FileTooLarge = "file-too-large",
|
934
951
|
FileTooSmall = "file-too-small",
|
935
952
|
TooManyFiles = "too-many-files",
|
936
|
-
FileInvalidDimension = "file-invalid-dimension"
|
953
|
+
FileInvalidDimension = "file-invalid-dimension",
|
954
|
+
FileInvalid = "file-invalid"
|
937
955
|
}
|
938
956
|
|
939
|
-
declare const defaultOnHandleRejections: (fileRejection: FileRejection[], config: Pick<UploaderProps, 'acceptFormat' | 'maxFileSize'>, handleRejection: (message: string, file: File, image: HTMLImageElement | null) => void) => void;
|
957
|
+
declare const defaultOnHandleRejections: (fileRejection: FileRejection[], config: Pick<UploaderProps, 'acceptFormat' | 'maxFileSize'>, handleRejection: (message: string, file: File, image: HTMLImageElement | null, type?: string) => void) => void;
|
940
958
|
|
941
959
|
interface ImageRes {
|
942
960
|
width: number;
|
package/dist/index.d.ts
CHANGED
@@ -803,7 +803,7 @@ type UploaderProps = FlexProps & {
|
|
803
803
|
/**
|
804
804
|
* callback when validation is not valid
|
805
805
|
*/
|
806
|
-
onHandleRejections?: (file: File, image: HTMLImageElement | null) => void;
|
806
|
+
onHandleRejections?: (file: File, image: HTMLImageElement | null, type?: string | keyof typeof ErrorCode) => void;
|
807
807
|
/**
|
808
808
|
* Text for drag active
|
809
809
|
* - if `dragActiveText` is undefined. Text will take from default constant.
|
@@ -894,6 +894,23 @@ type UploaderProps = FlexProps & {
|
|
894
894
|
isShowReupload?: boolean;
|
895
895
|
size?: 'sm' | 'lg';
|
896
896
|
buttonChangeText?: string;
|
897
|
+
/**
|
898
|
+
* Custom error messages for different error types
|
899
|
+
* Each error type can have a custom message and display type
|
900
|
+
* - message: The error message to display
|
901
|
+
* - type: How to display the error ('toast' for popup notification, 'inline' for inline text)
|
902
|
+
* Example:
|
903
|
+
* {
|
904
|
+
* 'file-invalid-type': { message: 'Invalid file type', type: 'inline' },
|
905
|
+
* 'file-too-large': { message: 'File too large', type: 'toast' }
|
906
|
+
* }
|
907
|
+
*/
|
908
|
+
customErrorRejection?: {
|
909
|
+
[key in ErrorCode]?: {
|
910
|
+
message: string;
|
911
|
+
type: 'inline' | 'toast';
|
912
|
+
};
|
913
|
+
};
|
897
914
|
};
|
898
915
|
|
899
916
|
declare const Uploader: React__default.FC<UploaderProps>;
|
@@ -933,10 +950,11 @@ declare enum ErrorCode {
|
|
933
950
|
FileTooLarge = "file-too-large",
|
934
951
|
FileTooSmall = "file-too-small",
|
935
952
|
TooManyFiles = "too-many-files",
|
936
|
-
FileInvalidDimension = "file-invalid-dimension"
|
953
|
+
FileInvalidDimension = "file-invalid-dimension",
|
954
|
+
FileInvalid = "file-invalid"
|
937
955
|
}
|
938
956
|
|
939
|
-
declare const defaultOnHandleRejections: (fileRejection: FileRejection[], config: Pick<UploaderProps, 'acceptFormat' | 'maxFileSize'>, handleRejection: (message: string, file: File, image: HTMLImageElement | null) => void) => void;
|
957
|
+
declare const defaultOnHandleRejections: (fileRejection: FileRejection[], config: Pick<UploaderProps, 'acceptFormat' | 'maxFileSize'>, handleRejection: (message: string, file: File, image: HTMLImageElement | null, type?: string) => void) => void;
|
940
958
|
|
941
959
|
interface ImageRes {
|
942
960
|
width: number;
|
package/dist/index.js
CHANGED
@@ -6082,6 +6082,7 @@ var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
|
|
6082
6082
|
ErrorCode2["FileTooSmall"] = "file-too-small";
|
6083
6083
|
ErrorCode2["TooManyFiles"] = "too-many-files";
|
6084
6084
|
ErrorCode2["FileInvalidDimension"] = "file-invalid-dimension";
|
6085
|
+
ErrorCode2["FileInvalid"] = "file-invalid";
|
6085
6086
|
return ErrorCode2;
|
6086
6087
|
})(ErrorCode || {});
|
6087
6088
|
var error_code_default = ErrorCode;
|
@@ -6098,19 +6099,24 @@ var defaultOnHandleRejections = (fileRejection, config2, handleRejection) => {
|
|
6098
6099
|
handleRejection(
|
6099
6100
|
(_d = (_b = config2.acceptFormat) == null ? void 0 : _b.message) != null ? _d : formatValidationMessage((_c = config2.acceptFormat) == null ? void 0 : _c.validate),
|
6100
6101
|
file,
|
6101
|
-
null
|
6102
|
+
null,
|
6103
|
+
error_code_default.FileInvalidType
|
6102
6104
|
);
|
6103
6105
|
}
|
6104
6106
|
break;
|
6105
6107
|
}
|
6106
6108
|
case error_code_default.FileTooLarge: {
|
6107
6109
|
if (config2.maxFileSize) {
|
6108
|
-
handleRejection(config2.maxFileSize.message, file, null);
|
6110
|
+
handleRejection(config2.maxFileSize.message, file, null, error_code_default.FileTooLarge);
|
6109
6111
|
}
|
6110
6112
|
break;
|
6111
6113
|
}
|
6114
|
+
case error_code_default.TooManyFiles: {
|
6115
|
+
handleRejection(errors3[0].message, file, null, error_code_default.TooManyFiles);
|
6116
|
+
break;
|
6117
|
+
}
|
6112
6118
|
default:
|
6113
|
-
handleRejection(errors3[0].message, file, null);
|
6119
|
+
handleRejection(errors3[0].message, file, null, error_code_default.FileInvalid);
|
6114
6120
|
break;
|
6115
6121
|
}
|
6116
6122
|
};
|
@@ -6139,25 +6145,41 @@ var Uploader = ({
|
|
6139
6145
|
value,
|
6140
6146
|
isShowCloseButton = true,
|
6141
6147
|
testId,
|
6142
|
-
isError,
|
6143
|
-
errorText,
|
6148
|
+
isError: propIsError,
|
6149
|
+
errorText: propErrorText,
|
6144
6150
|
isShowReupload = true,
|
6145
6151
|
size: size2 = "lg",
|
6146
6152
|
validatorExt,
|
6147
6153
|
buttonChangeText = "Ubah Foto",
|
6154
|
+
customErrorRejection,
|
6148
6155
|
...props
|
6149
6156
|
}) => {
|
6150
6157
|
const [filePreview, setFilePreview] = (0, import_react94.useState)();
|
6158
|
+
const [isError, setIsError] = (0, import_react94.useState)(propIsError);
|
6159
|
+
const [errorText, setErrorText] = (0, import_react94.useState)(propErrorText);
|
6151
6160
|
const toast2 = useToast();
|
6152
6161
|
const handleRejection = (0, import_react94.useCallback)(
|
6153
|
-
(message, file, image) => {
|
6162
|
+
(message, file, image, errorCode) => {
|
6154
6163
|
if (onHandleRejections) {
|
6155
|
-
onHandleRejections(file, image);
|
6164
|
+
onHandleRejections(file, image, errorCode);
|
6165
|
+
}
|
6166
|
+
if (customErrorRejection == null ? void 0 : customErrorRejection[errorCode]) {
|
6167
|
+
const error = customErrorRejection[errorCode];
|
6168
|
+
if ((error == null ? void 0 : error.type) === "toast") {
|
6169
|
+
return toast2.error(error.message);
|
6170
|
+
}
|
6171
|
+
if ((error == null ? void 0 : error.type) === "inline") {
|
6172
|
+
setIsError(true);
|
6173
|
+
setErrorText(error.message);
|
6174
|
+
return error.message;
|
6175
|
+
}
|
6156
6176
|
}
|
6177
|
+
setIsError(true);
|
6178
|
+
setErrorText(message);
|
6157
6179
|
return toast2.error(message);
|
6158
6180
|
},
|
6159
6181
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
6160
|
-
[onHandleRejections]
|
6182
|
+
[onHandleRejections, customErrorRejection]
|
6161
6183
|
);
|
6162
6184
|
const onDropAccepted = (0, import_react94.useCallback)(
|
6163
6185
|
(files) => {
|