@deepnoid/ui 0.1.164 → 0.1.166
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/.turbo/turbo-build.log +169 -169
- package/dist/{chunk-OOX5X2MN.mjs → chunk-W7MZB2KA.mjs} +39 -17
- package/dist/{chunk-INRA6IED.mjs → chunk-XTS6WKFD.mjs} +32 -5
- package/dist/components/fileUpload/fileUpload.d.mts +8 -2
- package/dist/components/fileUpload/fileUpload.d.ts +8 -2
- package/dist/components/fileUpload/fileUpload.js +39 -17
- package/dist/components/fileUpload/fileUpload.mjs +1 -1
- package/dist/components/fileUpload/index.d.mts +1 -1
- package/dist/components/fileUpload/index.d.ts +1 -1
- package/dist/components/fileUpload/index.js +39 -17
- package/dist/components/fileUpload/index.mjs +1 -1
- package/dist/components/picker/datePicker.mjs +2 -2
- package/dist/components/picker/index.mjs +6 -6
- package/dist/components/starRating/index.js +32 -5
- package/dist/components/starRating/index.mjs +1 -1
- package/dist/components/starRating/starRating.js +32 -5
- package/dist/components/starRating/starRating.mjs +1 -1
- package/dist/components/table/index.mjs +3 -3
- package/dist/components/table/table-body.mjs +3 -3
- package/dist/components/table/table-head.mjs +3 -3
- package/dist/components/table/table.mjs +3 -3
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +71 -22
- package/dist/index.mjs +28 -28
- package/package.json +1 -1
- package/dist/{chunk-PX4RCHOE.mjs → chunk-DWW4ZESK.mjs} +3 -3
- package/dist/{chunk-NJFJJIWK.mjs → chunk-W66K4FK5.mjs} +3 -3
|
@@ -29,29 +29,32 @@ function FileUpload({
|
|
|
29
29
|
helperMessage,
|
|
30
30
|
showProgress,
|
|
31
31
|
name,
|
|
32
|
-
classNames
|
|
32
|
+
classNames,
|
|
33
|
+
defaultFile
|
|
33
34
|
}) {
|
|
34
35
|
const fileInputRef = useRef(null);
|
|
35
36
|
const uploadIntervalRef = useRef(null);
|
|
36
|
-
const [
|
|
37
|
+
const [currentFile, setCurrentFile] = useState(null);
|
|
37
38
|
const [uploadProgress, setUploadProgress] = useState(0);
|
|
38
39
|
const [message, setMessage] = useState(errorMessage);
|
|
40
|
+
const [displayFileName, setDisplayFileName] = useState(() => (defaultFile == null ? void 0 : defaultFile.name) || "");
|
|
41
|
+
const [hasUploadedFile, setHasUploadedFile] = useState(false);
|
|
39
42
|
const slots = fileUploadStyle();
|
|
40
43
|
const handleButtonClick = () => {
|
|
41
44
|
var _a;
|
|
42
45
|
(_a = fileInputRef.current) == null ? void 0 : _a.click();
|
|
43
46
|
};
|
|
44
|
-
const validateFile = (
|
|
45
|
-
if (accept.length && !accept.includes(
|
|
47
|
+
const validateFile = (file) => {
|
|
48
|
+
if (accept.length && !accept.includes(file.type)) {
|
|
46
49
|
return acceptErrorMessage;
|
|
47
50
|
}
|
|
48
|
-
const sizeMB =
|
|
51
|
+
const sizeMB = file.size / 1024 / 1024;
|
|
49
52
|
if (sizeMB > maxSizeMB) {
|
|
50
53
|
return `${sizeErrorMessage} (${maxSizeMB}MB)`;
|
|
51
54
|
}
|
|
52
55
|
return null;
|
|
53
56
|
};
|
|
54
|
-
const startUploadSimulation = (
|
|
57
|
+
const startUploadSimulation = (file) => {
|
|
55
58
|
let progress = 0;
|
|
56
59
|
setUploadProgress(0);
|
|
57
60
|
uploadIntervalRef.current = window.setInterval(() => {
|
|
@@ -59,7 +62,7 @@ function FileUpload({
|
|
|
59
62
|
setUploadProgress(progress);
|
|
60
63
|
if (progress >= 100) {
|
|
61
64
|
clearInterval(uploadIntervalRef.current);
|
|
62
|
-
onFileUpload == null ? void 0 : onFileUpload(
|
|
65
|
+
onFileUpload == null ? void 0 : onFileUpload(file);
|
|
63
66
|
}
|
|
64
67
|
}, 100);
|
|
65
68
|
};
|
|
@@ -70,20 +73,26 @@ function FileUpload({
|
|
|
70
73
|
const error = validateFile(selectedFile);
|
|
71
74
|
if (error) {
|
|
72
75
|
setMessage(error);
|
|
73
|
-
|
|
76
|
+
setCurrentFile(null);
|
|
77
|
+
setDisplayFileName((defaultFile == null ? void 0 : defaultFile.name) || "");
|
|
78
|
+
setHasUploadedFile(false);
|
|
74
79
|
return;
|
|
75
80
|
}
|
|
76
|
-
|
|
81
|
+
setCurrentFile(selectedFile);
|
|
82
|
+
setDisplayFileName(selectedFile.name);
|
|
77
83
|
setMessage("");
|
|
84
|
+
setHasUploadedFile(true);
|
|
78
85
|
startUploadSimulation(selectedFile);
|
|
79
86
|
};
|
|
80
87
|
const handleCancelUpload = () => {
|
|
81
88
|
if (uploadIntervalRef.current) {
|
|
82
89
|
clearInterval(uploadIntervalRef.current);
|
|
83
90
|
}
|
|
84
|
-
|
|
91
|
+
setCurrentFile(null);
|
|
85
92
|
setUploadProgress(0);
|
|
86
93
|
setMessage("");
|
|
94
|
+
setDisplayFileName((defaultFile == null ? void 0 : defaultFile.name) || "");
|
|
95
|
+
setHasUploadedFile(false);
|
|
87
96
|
if (onCancelUpload) onCancelUpload();
|
|
88
97
|
};
|
|
89
98
|
useEffect(() => {
|
|
@@ -94,8 +103,11 @@ function FileUpload({
|
|
|
94
103
|
};
|
|
95
104
|
}, []);
|
|
96
105
|
useEffect(() => {
|
|
97
|
-
|
|
98
|
-
|
|
106
|
+
if (errorMessage !== void 0) {
|
|
107
|
+
setMessage(errorMessage);
|
|
108
|
+
}
|
|
109
|
+
}, [errorMessage]);
|
|
110
|
+
const shouldShowCloseButton = hasUploadedFile;
|
|
99
111
|
return /* @__PURE__ */ jsxs("div", { className: slots.base({ class: classNames == null ? void 0 : classNames.base }), children: [
|
|
100
112
|
/* @__PURE__ */ jsxs("div", { className: slots.container({ class: classNames == null ? void 0 : classNames.container }), children: [
|
|
101
113
|
/* @__PURE__ */ jsxs("div", { className: slots.inputWrapper(), children: [
|
|
@@ -107,14 +119,15 @@ function FileUpload({
|
|
|
107
119
|
variant: "outline",
|
|
108
120
|
full: true,
|
|
109
121
|
placeholder,
|
|
110
|
-
|
|
122
|
+
value: displayFileName,
|
|
111
123
|
errorMessage: message
|
|
112
124
|
}
|
|
113
125
|
),
|
|
114
|
-
|
|
126
|
+
shouldShowCloseButton && /* @__PURE__ */ jsx(
|
|
115
127
|
icon_button_default,
|
|
116
128
|
{
|
|
117
129
|
name: "close",
|
|
130
|
+
size: "sm",
|
|
118
131
|
variant: "ghost",
|
|
119
132
|
color: "neutral",
|
|
120
133
|
onClick: handleCancelUpload,
|
|
@@ -123,10 +136,19 @@ function FileUpload({
|
|
|
123
136
|
}
|
|
124
137
|
)
|
|
125
138
|
] }),
|
|
126
|
-
/* @__PURE__ */ jsx(
|
|
139
|
+
/* @__PURE__ */ jsx(
|
|
140
|
+
button_default,
|
|
141
|
+
{
|
|
142
|
+
type: "button",
|
|
143
|
+
variant: "outline",
|
|
144
|
+
onClick: handleButtonClick,
|
|
145
|
+
disabled: !!(currentFile && hasUploadedFile),
|
|
146
|
+
children: buttonText
|
|
147
|
+
}
|
|
148
|
+
),
|
|
127
149
|
/* @__PURE__ */ jsx("input", { ref: fileInputRef, type: "file", hidden: true, accept: accept.join(","), onChange: handleFileChange })
|
|
128
150
|
] }),
|
|
129
|
-
showProgress &&
|
|
151
|
+
showProgress && currentFile && hasUploadedFile && uploadProgress < 100 && /* @__PURE__ */ jsx(progress_default, { value: uploadProgress }),
|
|
130
152
|
!message && helperMessage && /* @__PURE__ */ jsx("p", { className: slots.helperMessage(), children: helperMessage })
|
|
131
153
|
] });
|
|
132
154
|
}
|
|
@@ -137,7 +159,7 @@ var fileUploadStyle = tv({
|
|
|
137
159
|
base: ["flex", "flex-col", "gap-[5px]"],
|
|
138
160
|
container: ["flex", "gap-[10px]"],
|
|
139
161
|
inputWrapper: ["relative", "flex-1"],
|
|
140
|
-
cancelButton: ["absolute", "top-1/2", "right-0", "-translate-y-1/2"],
|
|
162
|
+
cancelButton: ["absolute", "top-1/2", "right-0", "-translate-y-1/2", "mr-[4px]"],
|
|
141
163
|
errorMessage: ["text-danger-main", "text-sm"],
|
|
142
164
|
helperMessage: ["text-neutral-main", "text-sm"]
|
|
143
165
|
}
|
|
@@ -23,18 +23,28 @@ var StarRating = forwardRef((originalProps, ref) => {
|
|
|
23
23
|
allowHalf = false,
|
|
24
24
|
classNames,
|
|
25
25
|
filledColor = "text-primary-main",
|
|
26
|
-
emptyColor = "text-neutral-
|
|
26
|
+
emptyColor = "text-neutral-soft"
|
|
27
27
|
} = { ...props, ...variantProps };
|
|
28
28
|
const slots = useMemo(() => starRatingStyle({ ...variantProps }), [variantProps]);
|
|
29
29
|
const [hoverRating, setHoverRating] = useState(0);
|
|
30
30
|
const handleStarClick = (starIndex, isHalf = false) => {
|
|
31
31
|
if (readOnly || !onChange) return;
|
|
32
|
-
|
|
32
|
+
let newRating;
|
|
33
|
+
if (allowHalf && isHalf) {
|
|
34
|
+
newRating = starIndex - 0.5;
|
|
35
|
+
} else {
|
|
36
|
+
newRating = starIndex;
|
|
37
|
+
}
|
|
33
38
|
onChange(newRating);
|
|
34
39
|
};
|
|
35
40
|
const handleStarHover = (starIndex, isHalf = false) => {
|
|
36
41
|
if (readOnly) return;
|
|
37
|
-
|
|
42
|
+
let newHoverRating;
|
|
43
|
+
if (allowHalf && isHalf) {
|
|
44
|
+
newHoverRating = starIndex - 0.5;
|
|
45
|
+
} else {
|
|
46
|
+
newHoverRating = starIndex;
|
|
47
|
+
}
|
|
38
48
|
setHoverRating(newHoverRating);
|
|
39
49
|
};
|
|
40
50
|
const handleMouseLeave = () => {
|
|
@@ -47,7 +57,9 @@ var StarRating = forwardRef((originalProps, ref) => {
|
|
|
47
57
|
const renderStar = (starIndex) => {
|
|
48
58
|
const currentRating = readOnly ? value : hoverRating || value;
|
|
49
59
|
const isFull = currentRating >= starIndex;
|
|
50
|
-
const
|
|
60
|
+
const isEmpty = currentRating < starIndex - 1;
|
|
61
|
+
const isPartial = !isFull && !isEmpty;
|
|
62
|
+
const fillPercentage = isPartial ? (currentRating - (starIndex - 1)) * 100 : 0;
|
|
51
63
|
return /* @__PURE__ */ jsxs("div", { className: slots.starWrapper({ class: classNames == null ? void 0 : classNames.starWrapper }), children: [
|
|
52
64
|
!readOnly && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
53
65
|
/* @__PURE__ */ jsx(
|
|
@@ -67,7 +79,22 @@ var StarRating = forwardRef((originalProps, ref) => {
|
|
|
67
79
|
}
|
|
68
80
|
)
|
|
69
81
|
] }),
|
|
70
|
-
/* @__PURE__ */
|
|
82
|
+
/* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
83
|
+
(isFull || isPartial) && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
84
|
+
/* @__PURE__ */ jsx(Icon_default, { name: "star", fill: true, className: emptyColor, size }),
|
|
85
|
+
/* @__PURE__ */ jsx(
|
|
86
|
+
"div",
|
|
87
|
+
{
|
|
88
|
+
className: "absolute left-0 top-0 overflow-hidden",
|
|
89
|
+
style: {
|
|
90
|
+
width: isFull ? "100%" : `${fillPercentage}%`
|
|
91
|
+
},
|
|
92
|
+
children: /* @__PURE__ */ jsx(Icon_default, { name: "star", fill: true, className: filledColor, size })
|
|
93
|
+
}
|
|
94
|
+
)
|
|
95
|
+
] }),
|
|
96
|
+
isEmpty && /* @__PURE__ */ jsx(Icon_default, { name: "star", fill: true, className: emptyColor, size })
|
|
97
|
+
] })
|
|
71
98
|
] }, starIndex);
|
|
72
99
|
};
|
|
73
100
|
return /* @__PURE__ */ jsx("div", { ref, className: slots.base({ class: classNames == null ? void 0 : classNames.base }), onMouseLeave: handleMouseLeave, children: createRange(stars).map(renderStar) });
|
|
@@ -3,6 +3,11 @@ import * as tailwind_merge from 'tailwind-merge';
|
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
import { SlotsToClasses } from '../../utils/types.mjs';
|
|
5
5
|
|
|
6
|
+
type DefaultFile = {
|
|
7
|
+
name: string;
|
|
8
|
+
size?: number;
|
|
9
|
+
type?: string;
|
|
10
|
+
};
|
|
6
11
|
type FileUploadProps = {
|
|
7
12
|
buttonText: string;
|
|
8
13
|
maxSizeMB?: number;
|
|
@@ -17,8 +22,9 @@ type FileUploadProps = {
|
|
|
17
22
|
showProgress?: boolean;
|
|
18
23
|
name?: string;
|
|
19
24
|
classNames?: SlotsToClasses<FileUploadSlots>;
|
|
25
|
+
defaultFile?: DefaultFile;
|
|
20
26
|
};
|
|
21
|
-
declare function FileUpload({ buttonText, maxSizeMB, placeholder, errorMessage, accept, acceptErrorMessage, sizeErrorMessage, onFileUpload, onCancelUpload, helperMessage, showProgress, name, classNames, }: FileUploadProps): react_jsx_runtime.JSX.Element;
|
|
27
|
+
declare function FileUpload({ buttonText, maxSizeMB, placeholder, errorMessage, accept, acceptErrorMessage, sizeErrorMessage, onFileUpload, onCancelUpload, helperMessage, showProgress, name, classNames, defaultFile, }: FileUploadProps): react_jsx_runtime.JSX.Element;
|
|
22
28
|
declare namespace FileUpload {
|
|
23
29
|
var displayName: string;
|
|
24
30
|
}
|
|
@@ -80,4 +86,4 @@ declare const fileUploadStyle: tailwind_variants.TVReturnType<{
|
|
|
80
86
|
}, undefined, unknown, unknown, undefined>>;
|
|
81
87
|
type FileUploadSlots = keyof ReturnType<typeof fileUploadStyle>;
|
|
82
88
|
|
|
83
|
-
export { FileUpload, FileUpload as default, fileUploadStyle };
|
|
89
|
+
export { type DefaultFile, FileUpload, type FileUploadProps, FileUpload as default, fileUploadStyle };
|
|
@@ -3,6 +3,11 @@ import * as tailwind_merge from 'tailwind-merge';
|
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
import { SlotsToClasses } from '../../utils/types.js';
|
|
5
5
|
|
|
6
|
+
type DefaultFile = {
|
|
7
|
+
name: string;
|
|
8
|
+
size?: number;
|
|
9
|
+
type?: string;
|
|
10
|
+
};
|
|
6
11
|
type FileUploadProps = {
|
|
7
12
|
buttonText: string;
|
|
8
13
|
maxSizeMB?: number;
|
|
@@ -17,8 +22,9 @@ type FileUploadProps = {
|
|
|
17
22
|
showProgress?: boolean;
|
|
18
23
|
name?: string;
|
|
19
24
|
classNames?: SlotsToClasses<FileUploadSlots>;
|
|
25
|
+
defaultFile?: DefaultFile;
|
|
20
26
|
};
|
|
21
|
-
declare function FileUpload({ buttonText, maxSizeMB, placeholder, errorMessage, accept, acceptErrorMessage, sizeErrorMessage, onFileUpload, onCancelUpload, helperMessage, showProgress, name, classNames, }: FileUploadProps): react_jsx_runtime.JSX.Element;
|
|
27
|
+
declare function FileUpload({ buttonText, maxSizeMB, placeholder, errorMessage, accept, acceptErrorMessage, sizeErrorMessage, onFileUpload, onCancelUpload, helperMessage, showProgress, name, classNames, defaultFile, }: FileUploadProps): react_jsx_runtime.JSX.Element;
|
|
22
28
|
declare namespace FileUpload {
|
|
23
29
|
var displayName: string;
|
|
24
30
|
}
|
|
@@ -80,4 +86,4 @@ declare const fileUploadStyle: tailwind_variants.TVReturnType<{
|
|
|
80
86
|
}, undefined, unknown, unknown, undefined>>;
|
|
81
87
|
type FileUploadSlots = keyof ReturnType<typeof fileUploadStyle>;
|
|
82
88
|
|
|
83
|
-
export { FileUpload, FileUpload as default, fileUploadStyle };
|
|
89
|
+
export { type DefaultFile, FileUpload, type FileUploadProps, FileUpload as default, fileUploadStyle };
|
|
@@ -6639,29 +6639,32 @@ function FileUpload({
|
|
|
6639
6639
|
helperMessage,
|
|
6640
6640
|
showProgress,
|
|
6641
6641
|
name,
|
|
6642
|
-
classNames
|
|
6642
|
+
classNames,
|
|
6643
|
+
defaultFile
|
|
6643
6644
|
}) {
|
|
6644
6645
|
const fileInputRef = (0, import_react7.useRef)(null);
|
|
6645
6646
|
const uploadIntervalRef = (0, import_react7.useRef)(null);
|
|
6646
|
-
const [
|
|
6647
|
+
const [currentFile, setCurrentFile] = (0, import_react7.useState)(null);
|
|
6647
6648
|
const [uploadProgress, setUploadProgress] = (0, import_react7.useState)(0);
|
|
6648
6649
|
const [message, setMessage] = (0, import_react7.useState)(errorMessage);
|
|
6650
|
+
const [displayFileName, setDisplayFileName] = (0, import_react7.useState)(() => (defaultFile == null ? void 0 : defaultFile.name) || "");
|
|
6651
|
+
const [hasUploadedFile, setHasUploadedFile] = (0, import_react7.useState)(false);
|
|
6649
6652
|
const slots = fileUploadStyle();
|
|
6650
6653
|
const handleButtonClick = () => {
|
|
6651
6654
|
var _a;
|
|
6652
6655
|
(_a = fileInputRef.current) == null ? void 0 : _a.click();
|
|
6653
6656
|
};
|
|
6654
|
-
const validateFile = (
|
|
6655
|
-
if (accept.length && !accept.includes(
|
|
6657
|
+
const validateFile = (file) => {
|
|
6658
|
+
if (accept.length && !accept.includes(file.type)) {
|
|
6656
6659
|
return acceptErrorMessage;
|
|
6657
6660
|
}
|
|
6658
|
-
const sizeMB =
|
|
6661
|
+
const sizeMB = file.size / 1024 / 1024;
|
|
6659
6662
|
if (sizeMB > maxSizeMB) {
|
|
6660
6663
|
return `${sizeErrorMessage} (${maxSizeMB}MB)`;
|
|
6661
6664
|
}
|
|
6662
6665
|
return null;
|
|
6663
6666
|
};
|
|
6664
|
-
const startUploadSimulation = (
|
|
6667
|
+
const startUploadSimulation = (file) => {
|
|
6665
6668
|
let progress = 0;
|
|
6666
6669
|
setUploadProgress(0);
|
|
6667
6670
|
uploadIntervalRef.current = window.setInterval(() => {
|
|
@@ -6669,7 +6672,7 @@ function FileUpload({
|
|
|
6669
6672
|
setUploadProgress(progress);
|
|
6670
6673
|
if (progress >= 100) {
|
|
6671
6674
|
clearInterval(uploadIntervalRef.current);
|
|
6672
|
-
onFileUpload == null ? void 0 : onFileUpload(
|
|
6675
|
+
onFileUpload == null ? void 0 : onFileUpload(file);
|
|
6673
6676
|
}
|
|
6674
6677
|
}, 100);
|
|
6675
6678
|
};
|
|
@@ -6680,20 +6683,26 @@ function FileUpload({
|
|
|
6680
6683
|
const error = validateFile(selectedFile);
|
|
6681
6684
|
if (error) {
|
|
6682
6685
|
setMessage(error);
|
|
6683
|
-
|
|
6686
|
+
setCurrentFile(null);
|
|
6687
|
+
setDisplayFileName((defaultFile == null ? void 0 : defaultFile.name) || "");
|
|
6688
|
+
setHasUploadedFile(false);
|
|
6684
6689
|
return;
|
|
6685
6690
|
}
|
|
6686
|
-
|
|
6691
|
+
setCurrentFile(selectedFile);
|
|
6692
|
+
setDisplayFileName(selectedFile.name);
|
|
6687
6693
|
setMessage("");
|
|
6694
|
+
setHasUploadedFile(true);
|
|
6688
6695
|
startUploadSimulation(selectedFile);
|
|
6689
6696
|
};
|
|
6690
6697
|
const handleCancelUpload = () => {
|
|
6691
6698
|
if (uploadIntervalRef.current) {
|
|
6692
6699
|
clearInterval(uploadIntervalRef.current);
|
|
6693
6700
|
}
|
|
6694
|
-
|
|
6701
|
+
setCurrentFile(null);
|
|
6695
6702
|
setUploadProgress(0);
|
|
6696
6703
|
setMessage("");
|
|
6704
|
+
setDisplayFileName((defaultFile == null ? void 0 : defaultFile.name) || "");
|
|
6705
|
+
setHasUploadedFile(false);
|
|
6697
6706
|
if (onCancelUpload) onCancelUpload();
|
|
6698
6707
|
};
|
|
6699
6708
|
(0, import_react7.useEffect)(() => {
|
|
@@ -6704,8 +6713,11 @@ function FileUpload({
|
|
|
6704
6713
|
};
|
|
6705
6714
|
}, []);
|
|
6706
6715
|
(0, import_react7.useEffect)(() => {
|
|
6707
|
-
|
|
6708
|
-
|
|
6716
|
+
if (errorMessage !== void 0) {
|
|
6717
|
+
setMessage(errorMessage);
|
|
6718
|
+
}
|
|
6719
|
+
}, [errorMessage]);
|
|
6720
|
+
const shouldShowCloseButton = hasUploadedFile;
|
|
6709
6721
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: slots.base({ class: classNames == null ? void 0 : classNames.base }), children: [
|
|
6710
6722
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: slots.container({ class: classNames == null ? void 0 : classNames.container }), children: [
|
|
6711
6723
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: slots.inputWrapper(), children: [
|
|
@@ -6717,14 +6729,15 @@ function FileUpload({
|
|
|
6717
6729
|
variant: "outline",
|
|
6718
6730
|
full: true,
|
|
6719
6731
|
placeholder,
|
|
6720
|
-
|
|
6732
|
+
value: displayFileName,
|
|
6721
6733
|
errorMessage: message
|
|
6722
6734
|
}
|
|
6723
6735
|
),
|
|
6724
|
-
|
|
6736
|
+
shouldShowCloseButton && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
6725
6737
|
icon_button_default,
|
|
6726
6738
|
{
|
|
6727
6739
|
name: "close",
|
|
6740
|
+
size: "sm",
|
|
6728
6741
|
variant: "ghost",
|
|
6729
6742
|
color: "neutral",
|
|
6730
6743
|
onClick: handleCancelUpload,
|
|
@@ -6733,10 +6746,19 @@ function FileUpload({
|
|
|
6733
6746
|
}
|
|
6734
6747
|
)
|
|
6735
6748
|
] }),
|
|
6736
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
6749
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
6750
|
+
button_default,
|
|
6751
|
+
{
|
|
6752
|
+
type: "button",
|
|
6753
|
+
variant: "outline",
|
|
6754
|
+
onClick: handleButtonClick,
|
|
6755
|
+
disabled: !!(currentFile && hasUploadedFile),
|
|
6756
|
+
children: buttonText
|
|
6757
|
+
}
|
|
6758
|
+
),
|
|
6737
6759
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("input", { ref: fileInputRef, type: "file", hidden: true, accept: accept.join(","), onChange: handleFileChange })
|
|
6738
6760
|
] }),
|
|
6739
|
-
showProgress &&
|
|
6761
|
+
showProgress && currentFile && hasUploadedFile && uploadProgress < 100 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(progress_default, { value: uploadProgress }),
|
|
6740
6762
|
!message && helperMessage && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: slots.helperMessage(), children: helperMessage })
|
|
6741
6763
|
] });
|
|
6742
6764
|
}
|
|
@@ -6747,7 +6769,7 @@ var fileUploadStyle = (0, import_tailwind_variants6.tv)({
|
|
|
6747
6769
|
base: ["flex", "flex-col", "gap-[5px]"],
|
|
6748
6770
|
container: ["flex", "gap-[10px]"],
|
|
6749
6771
|
inputWrapper: ["relative", "flex-1"],
|
|
6750
|
-
cancelButton: ["absolute", "top-1/2", "right-0", "-translate-y-1/2"],
|
|
6772
|
+
cancelButton: ["absolute", "top-1/2", "right-0", "-translate-y-1/2", "mr-[4px]"],
|
|
6751
6773
|
errorMessage: ["text-danger-main", "text-sm"],
|
|
6752
6774
|
helperMessage: ["text-neutral-main", "text-sm"]
|
|
6753
6775
|
}
|
|
@@ -6639,29 +6639,32 @@ function FileUpload({
|
|
|
6639
6639
|
helperMessage,
|
|
6640
6640
|
showProgress,
|
|
6641
6641
|
name,
|
|
6642
|
-
classNames
|
|
6642
|
+
classNames,
|
|
6643
|
+
defaultFile
|
|
6643
6644
|
}) {
|
|
6644
6645
|
const fileInputRef = (0, import_react7.useRef)(null);
|
|
6645
6646
|
const uploadIntervalRef = (0, import_react7.useRef)(null);
|
|
6646
|
-
const [
|
|
6647
|
+
const [currentFile, setCurrentFile] = (0, import_react7.useState)(null);
|
|
6647
6648
|
const [uploadProgress, setUploadProgress] = (0, import_react7.useState)(0);
|
|
6648
6649
|
const [message, setMessage] = (0, import_react7.useState)(errorMessage);
|
|
6650
|
+
const [displayFileName, setDisplayFileName] = (0, import_react7.useState)(() => (defaultFile == null ? void 0 : defaultFile.name) || "");
|
|
6651
|
+
const [hasUploadedFile, setHasUploadedFile] = (0, import_react7.useState)(false);
|
|
6649
6652
|
const slots = fileUploadStyle();
|
|
6650
6653
|
const handleButtonClick = () => {
|
|
6651
6654
|
var _a;
|
|
6652
6655
|
(_a = fileInputRef.current) == null ? void 0 : _a.click();
|
|
6653
6656
|
};
|
|
6654
|
-
const validateFile = (
|
|
6655
|
-
if (accept.length && !accept.includes(
|
|
6657
|
+
const validateFile = (file) => {
|
|
6658
|
+
if (accept.length && !accept.includes(file.type)) {
|
|
6656
6659
|
return acceptErrorMessage;
|
|
6657
6660
|
}
|
|
6658
|
-
const sizeMB =
|
|
6661
|
+
const sizeMB = file.size / 1024 / 1024;
|
|
6659
6662
|
if (sizeMB > maxSizeMB) {
|
|
6660
6663
|
return `${sizeErrorMessage} (${maxSizeMB}MB)`;
|
|
6661
6664
|
}
|
|
6662
6665
|
return null;
|
|
6663
6666
|
};
|
|
6664
|
-
const startUploadSimulation = (
|
|
6667
|
+
const startUploadSimulation = (file) => {
|
|
6665
6668
|
let progress = 0;
|
|
6666
6669
|
setUploadProgress(0);
|
|
6667
6670
|
uploadIntervalRef.current = window.setInterval(() => {
|
|
@@ -6669,7 +6672,7 @@ function FileUpload({
|
|
|
6669
6672
|
setUploadProgress(progress);
|
|
6670
6673
|
if (progress >= 100) {
|
|
6671
6674
|
clearInterval(uploadIntervalRef.current);
|
|
6672
|
-
onFileUpload == null ? void 0 : onFileUpload(
|
|
6675
|
+
onFileUpload == null ? void 0 : onFileUpload(file);
|
|
6673
6676
|
}
|
|
6674
6677
|
}, 100);
|
|
6675
6678
|
};
|
|
@@ -6680,20 +6683,26 @@ function FileUpload({
|
|
|
6680
6683
|
const error = validateFile(selectedFile);
|
|
6681
6684
|
if (error) {
|
|
6682
6685
|
setMessage(error);
|
|
6683
|
-
|
|
6686
|
+
setCurrentFile(null);
|
|
6687
|
+
setDisplayFileName((defaultFile == null ? void 0 : defaultFile.name) || "");
|
|
6688
|
+
setHasUploadedFile(false);
|
|
6684
6689
|
return;
|
|
6685
6690
|
}
|
|
6686
|
-
|
|
6691
|
+
setCurrentFile(selectedFile);
|
|
6692
|
+
setDisplayFileName(selectedFile.name);
|
|
6687
6693
|
setMessage("");
|
|
6694
|
+
setHasUploadedFile(true);
|
|
6688
6695
|
startUploadSimulation(selectedFile);
|
|
6689
6696
|
};
|
|
6690
6697
|
const handleCancelUpload = () => {
|
|
6691
6698
|
if (uploadIntervalRef.current) {
|
|
6692
6699
|
clearInterval(uploadIntervalRef.current);
|
|
6693
6700
|
}
|
|
6694
|
-
|
|
6701
|
+
setCurrentFile(null);
|
|
6695
6702
|
setUploadProgress(0);
|
|
6696
6703
|
setMessage("");
|
|
6704
|
+
setDisplayFileName((defaultFile == null ? void 0 : defaultFile.name) || "");
|
|
6705
|
+
setHasUploadedFile(false);
|
|
6697
6706
|
if (onCancelUpload) onCancelUpload();
|
|
6698
6707
|
};
|
|
6699
6708
|
(0, import_react7.useEffect)(() => {
|
|
@@ -6704,8 +6713,11 @@ function FileUpload({
|
|
|
6704
6713
|
};
|
|
6705
6714
|
}, []);
|
|
6706
6715
|
(0, import_react7.useEffect)(() => {
|
|
6707
|
-
|
|
6708
|
-
|
|
6716
|
+
if (errorMessage !== void 0) {
|
|
6717
|
+
setMessage(errorMessage);
|
|
6718
|
+
}
|
|
6719
|
+
}, [errorMessage]);
|
|
6720
|
+
const shouldShowCloseButton = hasUploadedFile;
|
|
6709
6721
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: slots.base({ class: classNames == null ? void 0 : classNames.base }), children: [
|
|
6710
6722
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: slots.container({ class: classNames == null ? void 0 : classNames.container }), children: [
|
|
6711
6723
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: slots.inputWrapper(), children: [
|
|
@@ -6717,14 +6729,15 @@ function FileUpload({
|
|
|
6717
6729
|
variant: "outline",
|
|
6718
6730
|
full: true,
|
|
6719
6731
|
placeholder,
|
|
6720
|
-
|
|
6732
|
+
value: displayFileName,
|
|
6721
6733
|
errorMessage: message
|
|
6722
6734
|
}
|
|
6723
6735
|
),
|
|
6724
|
-
|
|
6736
|
+
shouldShowCloseButton && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
6725
6737
|
icon_button_default,
|
|
6726
6738
|
{
|
|
6727
6739
|
name: "close",
|
|
6740
|
+
size: "sm",
|
|
6728
6741
|
variant: "ghost",
|
|
6729
6742
|
color: "neutral",
|
|
6730
6743
|
onClick: handleCancelUpload,
|
|
@@ -6733,10 +6746,19 @@ function FileUpload({
|
|
|
6733
6746
|
}
|
|
6734
6747
|
)
|
|
6735
6748
|
] }),
|
|
6736
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
6749
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
6750
|
+
button_default,
|
|
6751
|
+
{
|
|
6752
|
+
type: "button",
|
|
6753
|
+
variant: "outline",
|
|
6754
|
+
onClick: handleButtonClick,
|
|
6755
|
+
disabled: !!(currentFile && hasUploadedFile),
|
|
6756
|
+
children: buttonText
|
|
6757
|
+
}
|
|
6758
|
+
),
|
|
6737
6759
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("input", { ref: fileInputRef, type: "file", hidden: true, accept: accept.join(","), onChange: handleFileChange })
|
|
6738
6760
|
] }),
|
|
6739
|
-
showProgress &&
|
|
6761
|
+
showProgress && currentFile && hasUploadedFile && uploadProgress < 100 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(progress_default, { value: uploadProgress }),
|
|
6740
6762
|
!message && helperMessage && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: slots.helperMessage(), children: helperMessage })
|
|
6741
6763
|
] });
|
|
6742
6764
|
}
|
|
@@ -6747,7 +6769,7 @@ var fileUploadStyle = (0, import_tailwind_variants6.tv)({
|
|
|
6747
6769
|
base: ["flex", "flex-col", "gap-[5px]"],
|
|
6748
6770
|
container: ["flex", "gap-[10px]"],
|
|
6749
6771
|
inputWrapper: ["relative", "flex-1"],
|
|
6750
|
-
cancelButton: ["absolute", "top-1/2", "right-0", "-translate-y-1/2"],
|
|
6772
|
+
cancelButton: ["absolute", "top-1/2", "right-0", "-translate-y-1/2", "mr-[4px]"],
|
|
6751
6773
|
errorMessage: ["text-danger-main", "text-sm"],
|
|
6752
6774
|
helperMessage: ["text-neutral-main", "text-sm"]
|
|
6753
6775
|
}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import {
|
|
3
3
|
datePickerStyle,
|
|
4
4
|
datePicker_default
|
|
5
|
-
} from "../../chunk-
|
|
6
|
-
import "../../chunk-XZYQFBCT.mjs";
|
|
5
|
+
} from "../../chunk-W66K4FK5.mjs";
|
|
7
6
|
import "../../chunk-FWFEKWWD.mjs";
|
|
7
|
+
import "../../chunk-XZYQFBCT.mjs";
|
|
8
8
|
import "../../chunk-2GCSFWHD.mjs";
|
|
9
9
|
import "../../chunk-VNRGOOSY.mjs";
|
|
10
10
|
import "../../chunk-MY5U63QO.mjs";
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import "../../chunk-4VWG4726.mjs";
|
|
3
|
-
import {
|
|
4
|
-
datePicker_default
|
|
5
|
-
} from "../../chunk-NJFJJIWK.mjs";
|
|
6
|
-
import {
|
|
7
|
-
day_default
|
|
8
|
-
} from "../../chunk-XZYQFBCT.mjs";
|
|
9
3
|
import {
|
|
10
4
|
timePicker_default
|
|
11
5
|
} from "../../chunk-BM3MR3JR.mjs";
|
|
12
6
|
import "../../chunk-QCEKPS7U.mjs";
|
|
13
7
|
import "../../chunk-5G6CCE55.mjs";
|
|
8
|
+
import {
|
|
9
|
+
datePicker_default
|
|
10
|
+
} from "../../chunk-W66K4FK5.mjs";
|
|
14
11
|
import "../../chunk-FWFEKWWD.mjs";
|
|
12
|
+
import {
|
|
13
|
+
day_default
|
|
14
|
+
} from "../../chunk-XZYQFBCT.mjs";
|
|
15
15
|
import "../../chunk-2GCSFWHD.mjs";
|
|
16
16
|
import "../../chunk-VNRGOOSY.mjs";
|
|
17
17
|
import "../../chunk-MY5U63QO.mjs";
|