@ctlyst.id/internal-ui 5.4.8 → 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 +22 -3
- package/dist/index.d.ts +22 -3
- package/dist/index.js +37 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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.
|
@@ -893,6 +893,24 @@ type UploaderProps = FlexProps & {
|
|
893
893
|
testId?: string;
|
894
894
|
isShowReupload?: boolean;
|
895
895
|
size?: 'sm' | 'lg';
|
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
|
+
};
|
896
914
|
};
|
897
915
|
|
898
916
|
declare const Uploader: React__default.FC<UploaderProps>;
|
@@ -932,10 +950,11 @@ declare enum ErrorCode {
|
|
932
950
|
FileTooLarge = "file-too-large",
|
933
951
|
FileTooSmall = "file-too-small",
|
934
952
|
TooManyFiles = "too-many-files",
|
935
|
-
FileInvalidDimension = "file-invalid-dimension"
|
953
|
+
FileInvalidDimension = "file-invalid-dimension",
|
954
|
+
FileInvalid = "file-invalid"
|
936
955
|
}
|
937
956
|
|
938
|
-
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;
|
939
958
|
|
940
959
|
interface ImageRes {
|
941
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.
|
@@ -893,6 +893,24 @@ type UploaderProps = FlexProps & {
|
|
893
893
|
testId?: string;
|
894
894
|
isShowReupload?: boolean;
|
895
895
|
size?: 'sm' | 'lg';
|
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
|
+
};
|
896
914
|
};
|
897
915
|
|
898
916
|
declare const Uploader: React__default.FC<UploaderProps>;
|
@@ -932,10 +950,11 @@ declare enum ErrorCode {
|
|
932
950
|
FileTooLarge = "file-too-large",
|
933
951
|
FileTooSmall = "file-too-small",
|
934
952
|
TooManyFiles = "too-many-files",
|
935
|
-
FileInvalidDimension = "file-invalid-dimension"
|
953
|
+
FileInvalidDimension = "file-invalid-dimension",
|
954
|
+
FileInvalid = "file-invalid"
|
936
955
|
}
|
937
956
|
|
938
|
-
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;
|
939
958
|
|
940
959
|
interface ImageRes {
|
941
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,24 +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,
|
6153
|
+
buttonChangeText = "Ubah Foto",
|
6154
|
+
customErrorRejection,
|
6147
6155
|
...props
|
6148
6156
|
}) => {
|
6149
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);
|
6150
6160
|
const toast2 = useToast();
|
6151
6161
|
const handleRejection = (0, import_react94.useCallback)(
|
6152
|
-
(message, file, image) => {
|
6162
|
+
(message, file, image, errorCode) => {
|
6153
6163
|
if (onHandleRejections) {
|
6154
|
-
onHandleRejections(file, image);
|
6164
|
+
onHandleRejections(file, image, errorCode);
|
6155
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
|
+
}
|
6176
|
+
}
|
6177
|
+
setIsError(true);
|
6178
|
+
setErrorText(message);
|
6156
6179
|
return toast2.error(message);
|
6157
6180
|
},
|
6158
6181
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
6159
|
-
[onHandleRejections]
|
6182
|
+
[onHandleRejections, customErrorRejection]
|
6160
6183
|
);
|
6161
6184
|
const onDropAccepted = (0, import_react94.useCallback)(
|
6162
6185
|
(files) => {
|
@@ -6255,6 +6278,10 @@ var Uploader = ({
|
|
6255
6278
|
setFilePreview(value.name);
|
6256
6279
|
return;
|
6257
6280
|
}
|
6281
|
+
if (acceptFileType == null ? void 0 : acceptFileType.some((type) => type === value.type)) {
|
6282
|
+
setFilePreview(value.name);
|
6283
|
+
return;
|
6284
|
+
}
|
6258
6285
|
setFilePreview(URL.createObjectURL(value));
|
6259
6286
|
}
|
6260
6287
|
} else {
|
@@ -6317,7 +6344,7 @@ var Uploader = ({
|
|
6317
6344
|
"data-test-id": `CT_component_base-image-uploader_image-preview${testId ? `_${testId}` : ""}`,
|
6318
6345
|
justify: "center",
|
6319
6346
|
align: "center",
|
6320
|
-
children: filePreview.includes("blob") ? /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(
|
6347
|
+
children: filePreview.includes("blob") && !acceptFile.some(([type]) => typeof type === "string" && type.includes("image/")) ? /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(
|
6321
6348
|
import_react93.Image,
|
6322
6349
|
{
|
6323
6350
|
h: size2 === "lg" ? "120" : "100",
|
@@ -6362,7 +6389,7 @@ var Uploader = ({
|
|
6362
6389
|
size: "sm",
|
6363
6390
|
variant: "outline",
|
6364
6391
|
onClick: open,
|
6365
|
-
children:
|
6392
|
+
children: buttonChangeText
|
6366
6393
|
}
|
6367
6394
|
) }),
|
6368
6395
|
renderErrorText(errorText),
|