@crestbase/web-shared-ui 1.0.1 → 1.0.3
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/README.md +117 -4
- package/dist/components/button/CircleBtn.d.ts +9 -0
- package/dist/components/button/CircleBtn.js +5 -0
- package/dist/components/button/ShadowButton.d.ts +8 -0
- package/dist/components/button/ShadowButton.js +5 -0
- package/dist/components/button/index.d.ts +12 -3
- package/dist/components/button/index.js +17 -3
- package/dist/components/core/Accordion.d.ts +11 -0
- package/dist/components/core/Accordion.js +7 -0
- package/dist/components/core/AddressInput.d.ts +34 -0
- package/dist/components/core/AddressInput.js +88 -0
- package/dist/components/core/BottomSheet.d.ts +10 -0
- package/dist/components/core/BottomSheet.js +15 -0
- package/dist/components/core/Calendar.d.ts +17 -0
- package/dist/components/core/Calendar.js +440 -0
- package/dist/components/core/CalendarExtended.d.ts +36 -0
- package/dist/components/core/CalendarExtended.js +154 -0
- package/dist/components/core/Checkbox.d.ts +13 -0
- package/dist/components/core/Checkbox.js +10 -0
- package/dist/components/core/CustomDropdown.d.ts +19 -0
- package/dist/components/core/CustomDropdown.js +41 -0
- package/dist/components/core/Modal.d.ts +12 -0
- package/dist/components/core/Modal.js +12 -0
- package/dist/components/core/NumberInput.d.ts +12 -0
- package/dist/components/core/NumberInput.js +34 -0
- package/dist/components/core/NumberInputWithCommas.d.ts +10 -0
- package/dist/components/core/NumberInputWithCommas.js +19 -0
- package/dist/components/core/OptionsDropdown.d.ts +35 -0
- package/dist/components/core/OptionsDropdown.js +50 -0
- package/dist/components/core/OtpInput.d.ts +9 -0
- package/dist/components/core/OtpInput.js +54 -0
- package/dist/components/core/PreviewArea.d.ts +18 -0
- package/dist/components/core/PreviewArea.js +31 -0
- package/dist/components/core/SelectionList.d.ts +16 -0
- package/dist/components/core/SelectionList.js +9 -0
- package/dist/components/core/SquareCheckbox.d.ts +10 -0
- package/dist/components/core/SquareCheckbox.js +5 -0
- package/dist/components/core/TabNavigation.d.ts +19 -0
- package/dist/components/core/TabNavigation.js +11 -0
- package/dist/components/core/Textarea.d.ts +10 -0
- package/dist/components/core/Textarea.js +8 -0
- package/dist/components/core/Toggle.d.ts +10 -0
- package/dist/components/core/Toggle.js +11 -0
- package/dist/components/core/Upload.d.ts +28 -0
- package/dist/components/core/Upload.js +76 -0
- package/dist/components/core/UploadArea.d.ts +14 -0
- package/dist/components/core/UploadArea.js +13 -0
- package/dist/components/core/input.d.ts +11 -0
- package/dist/components/core/input.js +24 -0
- package/dist/components/index.d.ts +41 -1
- package/dist/components/index.js +25 -1
- package/dist/components/navigation/Logo.d.ts +7 -0
- package/dist/components/navigation/Logo.js +7 -0
- package/dist/components/notification/GlobalNotificationProvider.d.ts +4 -0
- package/dist/components/notification/GlobalNotificationProvider.js +6 -0
- package/dist/components/notification/NotificationPopup.d.ts +1 -0
- package/dist/components/notification/NotificationPopup.js +73 -0
- package/dist/components/notification/notificationStore.d.ts +15 -0
- package/dist/components/notification/notificationStore.js +12 -0
- package/dist/components/svg/Crestbase.d.ts +6 -0
- package/dist/components/svg/Crestbase.js +5 -0
- package/dist/components/svg/CrestbaseColored.d.ts +6 -0
- package/dist/components/svg/CrestbaseColored.js +5 -0
- package/dist/components/svg/UploadIcon.d.ts +5 -0
- package/dist/components/svg/UploadIcon.js +4 -0
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/index.js +4 -0
- package/dist/hooks/useFileUpload.d.ts +35 -0
- package/dist/hooks/useFileUpload.js +219 -0
- package/dist/hooks/useFileUploadWithNotifications.d.ts +36 -0
- package/dist/hooks/useFileUploadWithNotifications.js +39 -0
- package/dist/hooks/useResponsive.d.ts +38 -0
- package/dist/hooks/useResponsive.js +97 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/styles.css +2 -0
- package/dist/types/property.d.ts +17 -0
- package/dist/types/property.js +2 -0
- package/dist/utils/fileValidation.d.ts +21 -0
- package/dist/utils/fileValidation.js +82 -0
- package/dist/utils/googleMapsLoader.d.ts +40 -0
- package/dist/utils/googleMapsLoader.js +108 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +13 -0
- package/package.json +22 -12
- package/dist/components/button/index.d.ts.map +0 -1
- package/dist/components/button/index.js.map +0 -1
- package/dist/components/index.d.ts.map +0 -1
- package/dist/components/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useState } from "react";
|
|
3
|
+
import { isVideoFileGeneric, isImageFile, isVideoFile } from "../utils";
|
|
4
|
+
export const useFileUpload = ({ existingFiles, uploadedFiles: initialUploadedFiles, onFileSelect, onUploadStatusChange, onError, }) => {
|
|
5
|
+
const [selectedFiles, setSelectedFiles] = useState({});
|
|
6
|
+
const [filePreviewUrls, setFilePreviewUrls] = useState({});
|
|
7
|
+
const [existingFilesByTab, setExistingFilesByTab] = useState({});
|
|
8
|
+
const [removedExistingFiles, setRemovedExistingFiles] = useState({});
|
|
9
|
+
const [uploadedFiles, setUploadedFiles] = useState(initialUploadedFiles || {});
|
|
10
|
+
const [validationError, setValidationError] = useState(undefined);
|
|
11
|
+
const defaultTabs = [
|
|
12
|
+
{ id: "photo1", label: "Photo 1" },
|
|
13
|
+
{ id: "video", label: "Video" },
|
|
14
|
+
{ id: "photo2", label: "Photo 2" },
|
|
15
|
+
{ id: "photo3", label: "Photo 3" },
|
|
16
|
+
{ id: "photo4", label: "Photo 4" },
|
|
17
|
+
{ id: "photo5", label: "Photo 5" },
|
|
18
|
+
{ id: "photo6", label: "Photo 6" },
|
|
19
|
+
{ id: "photo7", label: "Photo 7" },
|
|
20
|
+
{ id: "photo8", label: "Photo 8" },
|
|
21
|
+
{ id: "photo9", label: "Photo 9" },
|
|
22
|
+
{ id: "photo10", label: "Photo 10" },
|
|
23
|
+
{ id: "photo11", label: "Photo 11" },
|
|
24
|
+
{ id: "photo12", label: "Photo 12" },
|
|
25
|
+
{ id: "photo13", label: "Photo 13" },
|
|
26
|
+
{ id: "photo14", label: "Photo 14" },
|
|
27
|
+
];
|
|
28
|
+
const isVideoFileLocal = useCallback((file) => {
|
|
29
|
+
return isVideoFileGeneric(file);
|
|
30
|
+
}, []);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (existingFiles && existingFiles.length > 0) {
|
|
33
|
+
const filesByTab = {};
|
|
34
|
+
const videos = existingFiles.filter(isVideoFileLocal);
|
|
35
|
+
const images = existingFiles.filter((file) => !isVideoFileLocal(file));
|
|
36
|
+
if (videos.length > 0) {
|
|
37
|
+
filesByTab["video"] = videos;
|
|
38
|
+
}
|
|
39
|
+
const photoTabs = defaultTabs.filter((tab) => tab.id.startsWith("photo"));
|
|
40
|
+
images.forEach((image, index) => {
|
|
41
|
+
const tabIndex = index % photoTabs.length;
|
|
42
|
+
const tabId = photoTabs[tabIndex].id;
|
|
43
|
+
if (!filesByTab[tabId]) {
|
|
44
|
+
filesByTab[tabId] = [];
|
|
45
|
+
}
|
|
46
|
+
filesByTab[tabId].push(image);
|
|
47
|
+
});
|
|
48
|
+
setExistingFilesByTab(filesByTab);
|
|
49
|
+
}
|
|
50
|
+
}, [existingFiles, isVideoFileLocal]);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
const newPreviewUrls = {};
|
|
53
|
+
Object.keys(selectedFiles).forEach((tabId) => {
|
|
54
|
+
const files = selectedFiles[tabId];
|
|
55
|
+
if (files && files.length > 0) {
|
|
56
|
+
newPreviewUrls[tabId] = files.map((file) => URL.createObjectURL(file));
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
newPreviewUrls[tabId] = [];
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
setFilePreviewUrls(newPreviewUrls);
|
|
63
|
+
// Cleanup object URLs to avoid memory leaks
|
|
64
|
+
return () => {
|
|
65
|
+
Object.values(filePreviewUrls)
|
|
66
|
+
.flat()
|
|
67
|
+
.forEach((url) => {
|
|
68
|
+
try {
|
|
69
|
+
URL.revokeObjectURL(url);
|
|
70
|
+
}
|
|
71
|
+
catch (_) {
|
|
72
|
+
// ignore
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
}, [selectedFiles]);
|
|
77
|
+
// Notify parent when files change (all tabs combined)
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
const allFiles = [];
|
|
80
|
+
Object.values(selectedFiles).forEach((files) => {
|
|
81
|
+
allFiles.push(...files);
|
|
82
|
+
});
|
|
83
|
+
if (allFiles.length > 0) {
|
|
84
|
+
const dt = new DataTransfer();
|
|
85
|
+
allFiles.forEach((file) => dt.items.add(file));
|
|
86
|
+
onFileSelect?.(dt.files);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
onFileSelect?.(null);
|
|
90
|
+
}
|
|
91
|
+
}, [selectedFiles, onFileSelect]);
|
|
92
|
+
const addFiles = (tabId, files) => {
|
|
93
|
+
if (!files || files.length === 0)
|
|
94
|
+
return;
|
|
95
|
+
let validFiles = files;
|
|
96
|
+
if (tabId === "video") {
|
|
97
|
+
// Only allow videos in the video tab
|
|
98
|
+
validFiles = files.filter(isVideoFile);
|
|
99
|
+
const invalid = files.filter((f) => !isVideoFile(f));
|
|
100
|
+
if (invalid.length > 0) {
|
|
101
|
+
const msg = "Only video files are allowed in the video tab";
|
|
102
|
+
setValidationError(msg);
|
|
103
|
+
onError?.(msg);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
setValidationError(undefined);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
// Photo tabs only allow images
|
|
111
|
+
validFiles = files.filter(isImageFile);
|
|
112
|
+
const invalid = files.filter((f) => !isImageFile(f));
|
|
113
|
+
if (invalid.length > 0) {
|
|
114
|
+
const msg = "Only image files are allowed in photo tabs";
|
|
115
|
+
setValidationError(msg);
|
|
116
|
+
onError?.(msg);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
setValidationError(undefined);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Replace files in the tab (original behavior), not append
|
|
123
|
+
setSelectedFiles((prev) => ({
|
|
124
|
+
...prev,
|
|
125
|
+
[tabId]: validFiles,
|
|
126
|
+
}));
|
|
127
|
+
};
|
|
128
|
+
const removeFile = (tabId, index) => {
|
|
129
|
+
const currentFiles = selectedFiles[tabId] || [];
|
|
130
|
+
const currentExisting = existingFilesByTab[tabId] || [];
|
|
131
|
+
if (index < currentFiles.length) {
|
|
132
|
+
// Removing a newly selected file
|
|
133
|
+
setSelectedFiles((prev) => {
|
|
134
|
+
const updated = { ...prev };
|
|
135
|
+
updated[tabId] = (updated[tabId] || []).filter((_, i) => i !== index);
|
|
136
|
+
if (updated[tabId]?.length === 0)
|
|
137
|
+
delete updated[tabId];
|
|
138
|
+
return updated;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
// Removing an existing file
|
|
143
|
+
const existingIndex = index - currentFiles.length;
|
|
144
|
+
const fileToRemove = currentExisting[existingIndex];
|
|
145
|
+
if (!fileToRemove)
|
|
146
|
+
return;
|
|
147
|
+
setExistingFilesByTab((prev) => {
|
|
148
|
+
const updated = { ...prev };
|
|
149
|
+
const list = [...(updated[tabId] || [])];
|
|
150
|
+
list.splice(existingIndex, 1);
|
|
151
|
+
updated[tabId] = list;
|
|
152
|
+
if (updated[tabId]?.length === 0)
|
|
153
|
+
delete updated[tabId];
|
|
154
|
+
return updated;
|
|
155
|
+
});
|
|
156
|
+
setRemovedExistingFiles((prev) => {
|
|
157
|
+
const updated = { ...prev };
|
|
158
|
+
updated[tabId] = [...(updated[tabId] || []), fileToRemove];
|
|
159
|
+
return updated;
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
const markFilesAsUploaded = (tabId, fileNames) => {
|
|
164
|
+
setUploadedFiles((prev) => ({ ...prev, [tabId]: fileNames }));
|
|
165
|
+
onUploadStatusChange?.(tabId, fileNames);
|
|
166
|
+
};
|
|
167
|
+
const getUnuploadedFiles = (tabId) => {
|
|
168
|
+
const files = selectedFiles[tabId] || [];
|
|
169
|
+
const uploadedNames = new Set(uploadedFiles[tabId] || []);
|
|
170
|
+
return files.filter((f) => !uploadedNames.has(f.name));
|
|
171
|
+
};
|
|
172
|
+
const getFileChanges = () => {
|
|
173
|
+
return {
|
|
174
|
+
newFiles: selectedFiles,
|
|
175
|
+
existingFiles: existingFilesByTab,
|
|
176
|
+
removedFiles: removedExistingFiles,
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
const clearAllFiles = () => {
|
|
180
|
+
setSelectedFiles({});
|
|
181
|
+
setFilePreviewUrls({});
|
|
182
|
+
setRemovedExistingFiles({});
|
|
183
|
+
setUploadedFiles({});
|
|
184
|
+
setValidationError(undefined);
|
|
185
|
+
};
|
|
186
|
+
const updateExistingFiles = (files) => {
|
|
187
|
+
const filesByTab = {};
|
|
188
|
+
const videos = files.filter(isVideoFileLocal);
|
|
189
|
+
const images = files.filter((file) => !isVideoFileLocal(file));
|
|
190
|
+
if (videos.length > 0) {
|
|
191
|
+
filesByTab["video"] = videos;
|
|
192
|
+
}
|
|
193
|
+
const photoTabs = defaultTabs.filter((tab) => tab.id.startsWith("photo"));
|
|
194
|
+
images.forEach((image, index) => {
|
|
195
|
+
const tabIndex = index % photoTabs.length;
|
|
196
|
+
const tabId = photoTabs[tabIndex].id;
|
|
197
|
+
if (!filesByTab[tabId]) {
|
|
198
|
+
filesByTab[tabId] = [];
|
|
199
|
+
}
|
|
200
|
+
filesByTab[tabId].push(image);
|
|
201
|
+
});
|
|
202
|
+
setExistingFilesByTab(filesByTab);
|
|
203
|
+
};
|
|
204
|
+
return {
|
|
205
|
+
selectedFiles,
|
|
206
|
+
filePreviewUrls,
|
|
207
|
+
existingFilesByTab,
|
|
208
|
+
uploadedFiles,
|
|
209
|
+
defaultTabs,
|
|
210
|
+
validationError,
|
|
211
|
+
addFiles,
|
|
212
|
+
removeFile,
|
|
213
|
+
markFilesAsUploaded,
|
|
214
|
+
getUnuploadedFiles,
|
|
215
|
+
getFileChanges,
|
|
216
|
+
clearAllFiles,
|
|
217
|
+
updateExistingFiles,
|
|
218
|
+
};
|
|
219
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { UseFileUploadProps } from "./useFileUpload";
|
|
2
|
+
export interface UseFileUploadWithNotificationsProps extends UseFileUploadProps {
|
|
3
|
+
enableNotifications?: boolean;
|
|
4
|
+
successMessage?: string;
|
|
5
|
+
/** Optional prefix for validation or generic error messages */
|
|
6
|
+
errorMessagePrefix?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A thin wrapper around `useFileUpload` that triggers shared notifications
|
|
10
|
+
* for validation errors and successful uploads, while preserving the original API.
|
|
11
|
+
*
|
|
12
|
+
* This keeps the core upload hook UI-agnostic and optionalizes notifications.
|
|
13
|
+
*/
|
|
14
|
+
export declare const useFileUploadWithNotifications: (props: UseFileUploadWithNotificationsProps) => {
|
|
15
|
+
selectedFiles: Record<string, File[]>;
|
|
16
|
+
filePreviewUrls: Record<string, string[]>;
|
|
17
|
+
existingFilesByTab: Record<string, import("./useFileUpload").ExistingFile[]>;
|
|
18
|
+
uploadedFiles: Record<string, string[]>;
|
|
19
|
+
defaultTabs: {
|
|
20
|
+
id: string;
|
|
21
|
+
label: string;
|
|
22
|
+
}[];
|
|
23
|
+
validationError: string | undefined;
|
|
24
|
+
addFiles: (tabId: string, files: File[]) => void;
|
|
25
|
+
removeFile: (tabId: string, index: number) => void;
|
|
26
|
+
markFilesAsUploaded: (tabId: string, fileNames: string[]) => void;
|
|
27
|
+
getUnuploadedFiles: (tabId: string) => File[];
|
|
28
|
+
getFileChanges: () => {
|
|
29
|
+
newFiles: Record<string, File[]>;
|
|
30
|
+
existingFiles: Record<string, import("./useFileUpload").ExistingFile[]>;
|
|
31
|
+
removedFiles: Record<string, import("./useFileUpload").ExistingFile[]>;
|
|
32
|
+
};
|
|
33
|
+
clearAllFiles: () => void;
|
|
34
|
+
updateExistingFiles: (files: import("./useFileUpload").ExistingFile[]) => void;
|
|
35
|
+
};
|
|
36
|
+
export default useFileUploadWithNotifications;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useFileUpload } from "./useFileUpload";
|
|
3
|
+
import { useNotificationStore } from "../components/notification/notificationStore";
|
|
4
|
+
/**
|
|
5
|
+
* A thin wrapper around `useFileUpload` that triggers shared notifications
|
|
6
|
+
* for validation errors and successful uploads, while preserving the original API.
|
|
7
|
+
*
|
|
8
|
+
* This keeps the core upload hook UI-agnostic and optionalizes notifications.
|
|
9
|
+
*/
|
|
10
|
+
export const useFileUploadWithNotifications = (props) => {
|
|
11
|
+
const { addNotification } = useNotificationStore();
|
|
12
|
+
const enable = props?.enableNotifications ?? true;
|
|
13
|
+
const onError = (message) => {
|
|
14
|
+
// Pass through to consumer first
|
|
15
|
+
props?.onError?.(message);
|
|
16
|
+
// Then show a shared error notification if enabled
|
|
17
|
+
if (enable) {
|
|
18
|
+
const msg = props?.errorMessagePrefix ? `${props.errorMessagePrefix}: ${message}` : message;
|
|
19
|
+
addNotification({ type: "error", message: msg });
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const onUploadStatusChange = (tabId, uploadedFileNames) => {
|
|
23
|
+
props?.onUploadStatusChange?.(tabId, uploadedFileNames);
|
|
24
|
+
if (enable && uploadedFileNames.length > 0) {
|
|
25
|
+
const count = uploadedFileNames.length;
|
|
26
|
+
const msg = props?.successMessage ||
|
|
27
|
+
(count === 1 ? "File uploaded successfully" : `${count} files uploaded successfully`);
|
|
28
|
+
addNotification({ type: "success", message: msg });
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
// Delegate to the core hook with proxied callbacks
|
|
32
|
+
const core = useFileUpload({
|
|
33
|
+
...props,
|
|
34
|
+
onError,
|
|
35
|
+
onUploadStatusChange,
|
|
36
|
+
});
|
|
37
|
+
return core;
|
|
38
|
+
};
|
|
39
|
+
export default useFileUploadWithNotifications;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare const BREAKPOINTS: {
|
|
2
|
+
readonly sm: 640;
|
|
3
|
+
readonly md: 768;
|
|
4
|
+
readonly lg: 1024;
|
|
5
|
+
readonly xl: 1280;
|
|
6
|
+
readonly "2xl": 1536;
|
|
7
|
+
};
|
|
8
|
+
export type Breakpoint = keyof typeof BREAKPOINTS;
|
|
9
|
+
interface ResponsiveState {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
isMobile: boolean;
|
|
13
|
+
isTablet: boolean;
|
|
14
|
+
isDesktop: boolean;
|
|
15
|
+
isLargeDesktop: boolean;
|
|
16
|
+
isExtraLargeDesktop: boolean;
|
|
17
|
+
breakpoint: Breakpoint | "xs";
|
|
18
|
+
}
|
|
19
|
+
interface UseResponsiveOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Debounce delay in milliseconds for resize events
|
|
22
|
+
* @default 150
|
|
23
|
+
*/
|
|
24
|
+
debounceMs?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Whether to initialize immediately or wait for first resize
|
|
27
|
+
* @default true
|
|
28
|
+
*/
|
|
29
|
+
initializeImmediately?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Custom breakpoints to override defaults
|
|
32
|
+
*/
|
|
33
|
+
customBreakpoints?: Partial<typeof BREAKPOINTS>;
|
|
34
|
+
}
|
|
35
|
+
export declare const useResponsive: (options?: UseResponsiveOptions) => ResponsiveState;
|
|
36
|
+
export declare const useIsMobile: (breakpoint?: Breakpoint) => boolean;
|
|
37
|
+
export declare const useBreakpoint: (breakpoint: Breakpoint, direction?: "up" | "down") => boolean;
|
|
38
|
+
export default useResponsive;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useState } from "react";
|
|
3
|
+
// Tailwind CSS breakpoints (in pixels)
|
|
4
|
+
export const BREAKPOINTS = {
|
|
5
|
+
sm: 640,
|
|
6
|
+
md: 768,
|
|
7
|
+
lg: 1024,
|
|
8
|
+
xl: 1280,
|
|
9
|
+
"2xl": 1536,
|
|
10
|
+
};
|
|
11
|
+
export const useResponsive = (options = {}) => {
|
|
12
|
+
const { debounceMs = 150, initializeImmediately = true, customBreakpoints = {}, } = options;
|
|
13
|
+
const breakpoints = { ...BREAKPOINTS, ...customBreakpoints };
|
|
14
|
+
const getScreenDimensions = useCallback(() => {
|
|
15
|
+
if (typeof window === "undefined") {
|
|
16
|
+
return {
|
|
17
|
+
width: 1024,
|
|
18
|
+
height: 768,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
width: window.innerWidth,
|
|
23
|
+
height: window.innerHeight,
|
|
24
|
+
};
|
|
25
|
+
}, []);
|
|
26
|
+
const getBreakpoint = useCallback((width) => {
|
|
27
|
+
if (width >= breakpoints["2xl"])
|
|
28
|
+
return "2xl";
|
|
29
|
+
if (width >= breakpoints.xl)
|
|
30
|
+
return "xl";
|
|
31
|
+
if (width >= breakpoints.lg)
|
|
32
|
+
return "lg";
|
|
33
|
+
if (width >= breakpoints.md)
|
|
34
|
+
return "md";
|
|
35
|
+
if (width >= breakpoints.sm)
|
|
36
|
+
return "sm";
|
|
37
|
+
return "xs";
|
|
38
|
+
}, [breakpoints]);
|
|
39
|
+
const createResponsiveState = useCallback((width, height) => {
|
|
40
|
+
const breakpoint = getBreakpoint(width);
|
|
41
|
+
return {
|
|
42
|
+
width,
|
|
43
|
+
height,
|
|
44
|
+
isMobile: width < breakpoints.sm,
|
|
45
|
+
isTablet: width >= breakpoints.sm && width < breakpoints.lg,
|
|
46
|
+
isDesktop: width >= breakpoints.lg,
|
|
47
|
+
isLargeDesktop: width >= breakpoints.xl,
|
|
48
|
+
isExtraLargeDesktop: width >= breakpoints["2xl"],
|
|
49
|
+
breakpoint,
|
|
50
|
+
};
|
|
51
|
+
}, [breakpoints, getBreakpoint]);
|
|
52
|
+
const initialDimensions = initializeImmediately
|
|
53
|
+
? getScreenDimensions()
|
|
54
|
+
: { width: 1024, height: 768 };
|
|
55
|
+
const [state, setState] = useState(() => createResponsiveState(initialDimensions.width, initialDimensions.height));
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (typeof window === "undefined")
|
|
58
|
+
return;
|
|
59
|
+
let timeoutId;
|
|
60
|
+
const handleResize = () => {
|
|
61
|
+
if (timeoutId) {
|
|
62
|
+
clearTimeout(timeoutId);
|
|
63
|
+
}
|
|
64
|
+
timeoutId = setTimeout(() => {
|
|
65
|
+
const { width, height } = getScreenDimensions();
|
|
66
|
+
const newState = createResponsiveState(width, height);
|
|
67
|
+
setState((prevState) => {
|
|
68
|
+
if (prevState.width === newState.width &&
|
|
69
|
+
prevState.height === newState.height) {
|
|
70
|
+
return prevState;
|
|
71
|
+
}
|
|
72
|
+
return newState;
|
|
73
|
+
});
|
|
74
|
+
}, debounceMs);
|
|
75
|
+
};
|
|
76
|
+
window.addEventListener("resize", handleResize);
|
|
77
|
+
return () => {
|
|
78
|
+
if (timeoutId) {
|
|
79
|
+
clearTimeout(timeoutId);
|
|
80
|
+
}
|
|
81
|
+
window.removeEventListener("resize", handleResize);
|
|
82
|
+
};
|
|
83
|
+
}, [debounceMs, getScreenDimensions, createResponsiveState]);
|
|
84
|
+
return state;
|
|
85
|
+
};
|
|
86
|
+
export const useIsMobile = (breakpoint = "sm") => {
|
|
87
|
+
const { width } = useResponsive({ debounceMs: 100 });
|
|
88
|
+
return width < BREAKPOINTS[breakpoint];
|
|
89
|
+
};
|
|
90
|
+
export const useBreakpoint = (breakpoint, direction = "up") => {
|
|
91
|
+
const { width } = useResponsive({ debounceMs: 100 });
|
|
92
|
+
const breakpointValue = BREAKPOINTS[breakpoint];
|
|
93
|
+
return direction === "up"
|
|
94
|
+
? width >= breakpointValue
|
|
95
|
+
: width < breakpointValue;
|
|
96
|
+
};
|
|
97
|
+
export default useResponsive;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/styles.css
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! tailwindcss v4.1.16 | MIT License | https://tailwindcss.com */
|
|
2
|
+
@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-translate-x:0;--tw-translate-y:0;--tw-translate-z:0;--tw-scale-x:1;--tw-scale-y:1;--tw-scale-z:1;--tw-rotate-x:initial;--tw-rotate-y:initial;--tw-rotate-z:initial;--tw-skew-x:initial;--tw-skew-y:initial;--tw-space-y-reverse:0;--tw-space-x-reverse:0;--tw-divide-y-reverse:0;--tw-border-style:solid;--tw-font-weight:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-backdrop-blur:initial;--tw-backdrop-brightness:initial;--tw-backdrop-contrast:initial;--tw-backdrop-grayscale:initial;--tw-backdrop-hue-rotate:initial;--tw-backdrop-invert:initial;--tw-backdrop-opacity:initial;--tw-backdrop-saturate:initial;--tw-backdrop-sepia:initial;--tw-duration:initial;--tw-ease:initial}}}@layer theme{:root,:host{--font-sans:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--font-mono:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;--color-red-50:oklch(97.1% .013 17.38);--color-red-200:oklch(88.5% .062 18.334);--color-red-500:oklch(63.7% .237 25.331);--color-red-600:oklch(57.7% .245 27.325);--color-green-50:oklch(98.2% .018 155.826);--color-green-200:oklch(92.5% .084 155.995);--color-green-500:oklch(72.3% .219 149.579);--color-blue-50:oklch(97% .014 254.604);--color-blue-100:oklch(93.2% .032 255.585);--color-blue-200:oklch(88.2% .059 254.128);--color-blue-300:oklch(80.9% .105 251.813);--color-blue-400:oklch(70.7% .165 254.624);--color-blue-500:oklch(62.3% .214 259.815);--color-blue-600:oklch(54.6% .245 262.881);--color-blue-700:oklch(48.8% .243 264.376);--color-blue-800:oklch(42.4% .199 265.638);--color-gray-50:oklch(98.5% .002 247.839);--color-gray-100:oklch(96.7% .003 264.542);--color-gray-200:oklch(92.8% .006 264.531);--color-gray-300:oklch(87.2% .01 258.338);--color-gray-400:oklch(70.7% .022 261.325);--color-gray-500:oklch(55.1% .027 264.364);--color-gray-600:oklch(44.6% .03 256.802);--color-gray-700:oklch(37.3% .034 259.733);--color-gray-800:oklch(27.8% .033 256.848);--color-gray-900:oklch(21% .034 264.665);--color-black:#000;--color-white:#fff;--spacing:.25rem;--container-md:28rem;--text-xs:.75rem;--text-xs--line-height:calc(1/.75);--text-sm:.875rem;--text-sm--line-height:calc(1.25/.875);--text-base:1rem;--text-base--line-height:calc(1.5/1);--text-lg:1.125rem;--text-lg--line-height:calc(1.75/1.125);--text-xl:1.25rem;--text-xl--line-height:calc(1.75/1.25);--text-2xl:1.5rem;--text-2xl--line-height:calc(2/1.5);--font-weight-normal:400;--font-weight-medium:500;--font-weight-semibold:600;--font-weight-bold:700;--radius-md:.375rem;--radius-lg:.5rem;--radius-xl:.75rem;--radius-2xl:1rem;--radius-3xl:1.5rem;--ease-out:cubic-bezier(0,0,.2,1);--ease-in-out:cubic-bezier(.4,0,.2,1);--animate-spin:spin 1s linear infinite;--blur-xs:4px;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4,0,.2,1);--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono);--color-primaryblue:var(--primaryblue)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab, red, red)){::placeholder{color:color-mix(in oklab,currentcolor 50%,transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer components;@layer utilities{.pointer-events-none{pointer-events:none}.visible{visibility:visible}.sr-only{clip-path:inset(50%);white-space:nowrap;border-width:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.inset-0{inset:calc(var(--spacing)*0)}.-top-0\.5{top:calc(var(--spacing)*-.5)}.top-1{top:calc(var(--spacing)*1)}.top-1\/2{top:50%}.top-2{top:calc(var(--spacing)*2)}.top-4{top:calc(var(--spacing)*4)}.top-full{top:100%}.right-0{right:calc(var(--spacing)*0)}.right-1{right:calc(var(--spacing)*1)}.right-2{right:calc(var(--spacing)*2)}.right-3{right:calc(var(--spacing)*3)}.right-4{right:calc(var(--spacing)*4)}.left-0\.5{left:calc(var(--spacing)*.5)}.left-2{left:calc(var(--spacing)*2)}.left-5{left:calc(var(--spacing)*5)}.z-12{z-index:12}.z-30{z-index:30}.z-50{z-index:50}.z-\[80\]{z-index:80}.container{width:100%}@media (min-width:40rem){.container{max-width:40rem}}@media (min-width:48rem){.container{max-width:48rem}}@media (min-width:64rem){.container{max-width:64rem}}@media (min-width:80rem){.container{max-width:80rem}}@media (min-width:96rem){.container{max-width:96rem}}.mx-auto{margin-inline:auto}.mt-1{margin-top:calc(var(--spacing)*1)}.mt-2{margin-top:calc(var(--spacing)*2)}.mt-3{margin-top:calc(var(--spacing)*3)}.mt-4{margin-top:calc(var(--spacing)*4)}.mr-2{margin-right:calc(var(--spacing)*2)}.mb-1{margin-bottom:calc(var(--spacing)*1)}.mb-2{margin-bottom:calc(var(--spacing)*2)}.mb-3{margin-bottom:calc(var(--spacing)*3)}.mb-4{margin-bottom:calc(var(--spacing)*4)}.ml-2{margin-left:calc(var(--spacing)*2)}.ml-4{margin-left:calc(var(--spacing)*4)}.block{display:block}.contents{display:contents}.flex{display:flex}.grid{display:grid}.hidden{display:none}.inline{display:inline}.inline-block{display:inline-block}.inline-flex{display:inline-flex}.size-1\.5{width:calc(var(--spacing)*1.5);height:calc(var(--spacing)*1.5)}.size-4{width:calc(var(--spacing)*4);height:calc(var(--spacing)*4)}.size-5{width:calc(var(--spacing)*5);height:calc(var(--spacing)*5)}.size-10{width:calc(var(--spacing)*10);height:calc(var(--spacing)*10)}.size-14{width:calc(var(--spacing)*14);height:calc(var(--spacing)*14)}.size-16{width:calc(var(--spacing)*16);height:calc(var(--spacing)*16)}.size-full{width:100%;height:100%}.h-3{height:calc(var(--spacing)*3)}.h-3\.5{height:calc(var(--spacing)*3.5)}.h-4{height:calc(var(--spacing)*4)}.h-4\.5{height:calc(var(--spacing)*4.5)}.h-5{height:calc(var(--spacing)*5)}.h-6{height:calc(var(--spacing)*6)}.h-8{height:calc(var(--spacing)*8)}.h-10{height:calc(var(--spacing)*10)}.h-12{height:calc(var(--spacing)*12)}.h-13\.5{height:calc(var(--spacing)*13.5)}.h-20{height:calc(var(--spacing)*20)}.h-25{height:calc(var(--spacing)*25)}.h-full{height:100%}.max-h-60{max-height:calc(var(--spacing)*60)}.max-h-\[80vh\]{max-height:80vh}.min-h-\[160px\]{min-height:160px}.w-0{width:calc(var(--spacing)*0)}.w-3{width:calc(var(--spacing)*3)}.w-3\.5{width:calc(var(--spacing)*3.5)}.w-4{width:calc(var(--spacing)*4)}.w-4\.5{width:calc(var(--spacing)*4.5)}.w-5{width:calc(var(--spacing)*5)}.w-6{width:calc(var(--spacing)*6)}.w-8{width:calc(var(--spacing)*8)}.w-9{width:calc(var(--spacing)*9)}.w-10{width:calc(var(--spacing)*10)}.w-12{width:calc(var(--spacing)*12)}.w-full{width:100%}.max-w-96{max-width:calc(var(--spacing)*96)}.max-w-\[120px\]{max-width:120px}.max-w-md{max-width:var(--container-md)}.min-w-48{min-width:calc(var(--spacing)*48)}.min-w-80{min-width:calc(var(--spacing)*80)}.min-w-full{min-width:100%}.flex-1{flex:1}.flex-shrink-0{flex-shrink:0}.translate-x-0{--tw-translate-x:calc(var(--spacing)*0);translate:var(--tw-translate-x)var(--tw-translate-y)}.translate-x-1{--tw-translate-x:calc(var(--spacing)*1);translate:var(--tw-translate-x)var(--tw-translate-y)}.translate-x-4{--tw-translate-x:calc(var(--spacing)*4);translate:var(--tw-translate-x)var(--tw-translate-y)}.translate-x-full{--tw-translate-x:100%;translate:var(--tw-translate-x)var(--tw-translate-y)}.-translate-y-1\/2{--tw-translate-y:calc(calc(1/2*100%)*-1);translate:var(--tw-translate-x)var(--tw-translate-y)}.scale-105{--tw-scale-x:105%;--tw-scale-y:105%;--tw-scale-z:105%;scale:var(--tw-scale-x)var(--tw-scale-y)}.rotate-45{rotate:45deg}.rotate-180{rotate:180deg}.transform{transform:var(--tw-rotate-x,)var(--tw-rotate-y,)var(--tw-rotate-z,)var(--tw-skew-x,)var(--tw-skew-y,)}.animate-spin{animation:var(--animate-spin)}.cursor-not-allowed{cursor:not-allowed}.cursor-pointer{cursor:pointer}.resize{resize:both}.\[appearance\:textfield\]{appearance:textfield}.grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.grid-cols-7{grid-template-columns:repeat(7,minmax(0,1fr))}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.items-center{align-items:center}.items-start{align-items:flex-start}.justify-between{justify-content:space-between}.justify-center{justify-content:center}.justify-end{justify-content:flex-end}.gap-1{gap:calc(var(--spacing)*1)}.gap-2{gap:calc(var(--spacing)*2)}.gap-3{gap:calc(var(--spacing)*3)}.gap-4{gap:calc(var(--spacing)*4)}.gap-6{gap:calc(var(--spacing)*6)}:where(.space-y-2>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*2)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*2)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-3>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*3)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*3)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-6>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*6)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*6)*calc(1 - var(--tw-space-y-reverse)))}.gap-x-2{column-gap:calc(var(--spacing)*2)}:where(.space-x-3>:not(:last-child)){--tw-space-x-reverse:0;margin-inline-start:calc(calc(var(--spacing)*3)*var(--tw-space-x-reverse));margin-inline-end:calc(calc(var(--spacing)*3)*calc(1 - var(--tw-space-x-reverse)))}:where(.divide-y>:not(:last-child)){--tw-divide-y-reverse:0;border-bottom-style:var(--tw-border-style);border-top-style:var(--tw-border-style);border-top-width:calc(1px*var(--tw-divide-y-reverse));border-bottom-width:calc(1px*calc(1 - var(--tw-divide-y-reverse)))}:where(.divide-gray-100>:not(:last-child)){border-color:var(--color-gray-100)}.truncate{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.overflow-hidden{overflow:hidden}.overflow-x-auto{overflow-x:auto}.overflow-y-auto{overflow-y:auto}.rounded{border-radius:.25rem}.rounded-2xl{border-radius:var(--radius-2xl)}.rounded-full{border-radius:3.40282e38px}.rounded-lg{border-radius:var(--radius-lg)}.rounded-md{border-radius:var(--radius-md)}.rounded-xl{border-radius:var(--radius-xl)}.rounded-t-3xl{border-top-left-radius:var(--radius-3xl);border-top-right-radius:var(--radius-3xl)}.border,.border-1{border-style:var(--tw-border-style);border-width:1px}.border-b-2{border-bottom-style:var(--tw-border-style);border-bottom-width:2px}.border-dashed{--tw-border-style:dashed;border-style:dashed}.border-black{border-color:var(--color-black)}.border-blue-200{border-color:var(--color-blue-200)}.border-blue-300{border-color:var(--color-blue-300)}.border-blue-400{border-color:var(--color-blue-400)}.border-blue-500{border-color:var(--color-blue-500)}.border-blue-600{border-color:var(--color-blue-600)}.border-gray-100{border-color:var(--color-gray-100)}.border-gray-200{border-color:var(--color-gray-200)}.border-gray-300{border-color:var(--color-gray-300)}.border-gray-400{border-color:var(--color-gray-400)}.border-green-200{border-color:var(--color-green-200)}.border-red-200{border-color:var(--color-red-200)}.border-red-500{border-color:var(--color-red-500)}.bg-\[\#F1A5C2\]{background-color:#f1a5c2}.bg-black{background-color:var(--color-black)}.bg-black\/40{background-color:#0006}@supports (color:color-mix(in lab, red, red)){.bg-black\/40{background-color:color-mix(in oklab,var(--color-black)40%,transparent)}}.bg-black\/70{background-color:#000000b3}@supports (color:color-mix(in lab, red, red)){.bg-black\/70{background-color:color-mix(in oklab,var(--color-black)70%,transparent)}}.bg-blue-50{background-color:var(--color-blue-50)}.bg-blue-100{background-color:var(--color-blue-100)}.bg-blue-500{background-color:var(--color-blue-500)}.bg-blue-600{background-color:var(--color-blue-600)}.bg-gray-50{background-color:var(--color-gray-50)}.bg-gray-100{background-color:var(--color-gray-100)}.bg-gray-200{background-color:var(--color-gray-200)}.bg-gray-400{background-color:var(--color-gray-400)}.bg-green-50{background-color:var(--color-green-50)}.bg-green-500{background-color:var(--color-green-500)}.bg-primaryblue,.bg-primaryblue\/5{background-color:var(--color-primaryblue)}@supports (color:color-mix(in lab, red, red)){.bg-primaryblue\/5{background-color:color-mix(in oklab,var(--color-primaryblue)5%,transparent)}}.bg-primaryblue\/10{background-color:var(--color-primaryblue)}@supports (color:color-mix(in lab, red, red)){.bg-primaryblue\/10{background-color:color-mix(in oklab,var(--color-primaryblue)10%,transparent)}}.bg-red-50{background-color:var(--color-red-50)}.bg-red-500{background-color:var(--color-red-500)}.bg-white{background-color:var(--color-white)}.object-cover{object-fit:cover}.p-0{padding:calc(var(--spacing)*0)}.p-0\.5{padding:calc(var(--spacing)*.5)}.p-2{padding:calc(var(--spacing)*2)}.p-3{padding:calc(var(--spacing)*3)}.p-3\.5{padding:calc(var(--spacing)*3.5)}.p-4{padding:calc(var(--spacing)*4)}.p-\[2\.5px\]{padding:2.5px}.px-2{padding-inline:calc(var(--spacing)*2)}.px-3{padding-inline:calc(var(--spacing)*3)}.px-4{padding-inline:calc(var(--spacing)*4)}.px-6{padding-inline:calc(var(--spacing)*6)}.py-1{padding-block:calc(var(--spacing)*1)}.py-2{padding-block:calc(var(--spacing)*2)}.py-2\.5{padding-block:calc(var(--spacing)*2.5)}.py-3{padding-block:calc(var(--spacing)*3)}.py-12{padding-block:calc(var(--spacing)*12)}.pt-0{padding-top:calc(var(--spacing)*0)}.pr-12{padding-right:calc(var(--spacing)*12)}.pb-2{padding-bottom:calc(var(--spacing)*2)}.pl-8{padding-left:calc(var(--spacing)*8)}.text-center{text-align:center}.text-left{text-align:left}.text-base{font-size:var(--text-base);line-height:var(--tw-leading,var(--text-base--line-height))}.text-lg{font-size:var(--text-lg);line-height:var(--tw-leading,var(--text-lg--line-height))}.text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.text-xs{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}.text-\[10px\]{font-size:10px}.text-\[11px\]{font-size:11px}.text-\[13px\]{font-size:13px}.font-bold{--tw-font-weight:var(--font-weight-bold);font-weight:var(--font-weight-bold)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.font-normal{--tw-font-weight:var(--font-weight-normal);font-weight:var(--font-weight-normal)}.font-semibold{--tw-font-weight:var(--font-weight-semibold);font-weight:var(--font-weight-semibold)}.text-nowrap{text-wrap:nowrap}.whitespace-nowrap{white-space:nowrap}.text-\[\#011B33\]{color:#011b33}.text-black{color:var(--color-black)}.text-blue-500{color:var(--color-blue-500)}.text-blue-600{color:var(--color-blue-600)}.text-blue-700{color:var(--color-blue-700)}.text-blue-800{color:var(--color-blue-800)}.text-gray-300{color:var(--color-gray-300)}.text-gray-400{color:var(--color-gray-400)}.text-gray-500{color:var(--color-gray-500)}.text-gray-600{color:var(--color-gray-600)}.text-gray-700{color:var(--color-gray-700)}.text-gray-800{color:var(--color-gray-800)}.text-gray-900{color:var(--color-gray-900)}.text-green-500{color:var(--color-green-500)}.text-primaryblue{color:var(--color-primaryblue)}.text-red-500{color:var(--color-red-500)}.text-red-600{color:var(--color-red-600)}.text-white{color:var(--color-white)}.placeholder-gray-300::placeholder{color:var(--color-gray-300)}.placeholder-gray-400::placeholder{color:var(--color-gray-400)}.opacity-0{opacity:0}.opacity-50{opacity:.5}.opacity-100{opacity:1}.shadow-lg{--tw-shadow:0 10px 15px -3px var(--tw-shadow-color,#0000001a),0 4px 6px -4px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-md{--tw-shadow:0 4px 6px -1px var(--tw-shadow-color,#0000001a),0 2px 4px -2px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-xl{--tw-shadow:0 20px 25px -5px var(--tw-shadow-color,#0000001a),0 8px 10px -6px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.ring-1{--tw-ring-shadow:var(--tw-ring-inset,)0 0 0 calc(1px + var(--tw-ring-offset-width))var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.ring-2{--tw-ring-shadow:var(--tw-ring-inset,)0 0 0 calc(2px + var(--tw-ring-offset-width))var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.ring-blue-300{--tw-ring-color:var(--color-blue-300)}.ring-primaryblue,.ring-primaryblue\/30{--tw-ring-color:var(--color-primaryblue)}@supports (color:color-mix(in lab, red, red)){.ring-primaryblue\/30{--tw-ring-color:color-mix(in oklab,var(--color-primaryblue)30%,transparent)}}.backdrop-blur-xs{--tw-backdrop-blur:blur(var(--blur-xs));-webkit-backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,);backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,)}.transition-all{transition-property:all;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-colors{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-opacity{transition-property:opacity;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-transform{transition-property:transform,translate,scale,rotate;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.duration-200{--tw-duration:.2s;transition-duration:.2s}.duration-300{--tw-duration:.3s;transition-duration:.3s}.ease-in-out{--tw-ease:var(--ease-in-out);transition-timing-function:var(--ease-in-out)}.ease-out{--tw-ease:var(--ease-out);transition-timing-function:var(--ease-out)}.outline-none{--tw-outline-style:none;outline-style:none}.select-none{-webkit-user-select:none;user-select:none}@media (hover:hover){.group-hover\:opacity-100:is(:where(.group):hover *){opacity:1}}.first\:rounded-t-xl:first-child{border-top-left-radius:var(--radius-xl);border-top-right-radius:var(--radius-xl)}.last\:rounded-b-xl:last-child{border-bottom-right-radius:var(--radius-xl);border-bottom-left-radius:var(--radius-xl)}.focus-within\:border-gray-300:focus-within{border-color:var(--color-gray-300)}.focus-within\:bg-white:focus-within{background-color:var(--color-white)}@media (hover:hover){.hover\:border-gray-400:hover{border-color:var(--color-gray-400)}.hover\:bg-blue-50:hover{background-color:var(--color-blue-50)}.hover\:bg-blue-100:hover{background-color:var(--color-blue-100)}.hover\:bg-blue-200:hover{background-color:var(--color-blue-200)}.hover\:bg-gray-50:hover{background-color:var(--color-gray-50)}.hover\:bg-gray-100:hover{background-color:var(--color-gray-100)}.hover\:bg-primaryblue\/70:hover{background-color:var(--color-primaryblue)}@supports (color:color-mix(in lab, red, red)){.hover\:bg-primaryblue\/70:hover{background-color:color-mix(in oklab,var(--color-primaryblue)70%,transparent)}}.hover\:bg-red-600:hover{background-color:var(--color-red-600)}.hover\:text-black:hover{color:var(--color-black)}.hover\:text-blue-600:hover{color:var(--color-blue-600)}.hover\:text-gray-600:hover{color:var(--color-gray-600)}.hover\:opacity-100:hover{opacity:1}}.focus\:border-gray-300:focus{border-color:var(--color-gray-300)}.focus\:border-primaryblue:focus{border-color:var(--color-primaryblue)}.focus\:bg-white:focus{background-color:var(--color-white)}.focus\:outline-none:focus{--tw-outline-style:none;outline-style:none}.focus-visible\:ring-2:focus-visible{--tw-ring-shadow:var(--tw-ring-inset,)0 0 0 calc(2px + var(--tw-ring-offset-width))var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.focus-visible\:ring-primaryblue\/60:focus-visible{--tw-ring-color:var(--color-primaryblue)}@supports (color:color-mix(in lab, red, red)){.focus-visible\:ring-primaryblue\/60:focus-visible{--tw-ring-color:color-mix(in oklab,var(--color-primaryblue)60%,transparent)}}.disabled\:cursor-not-allowed:disabled{cursor:not-allowed}.disabled\:opacity-50:disabled{opacity:.5}@media (min-width:40rem){.sm\:left-4{left:calc(var(--spacing)*4)}.sm\:h-\[220px\]{height:220px}.sm\:h-auto{height:auto}.sm\:grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}.sm\:p-3{padding:calc(var(--spacing)*3)}.sm\:p-4{padding:calc(var(--spacing)*4)}.sm\:px-4{padding-inline:calc(var(--spacing)*4)}.sm\:py-6{padding-block:calc(var(--spacing)*6)}.sm\:pl-7{padding-left:calc(var(--spacing)*7)}.sm\:text-2xl{font-size:var(--text-2xl);line-height:var(--tw-leading,var(--text-2xl--line-height))}.sm\:text-base{font-size:var(--text-base);line-height:var(--tw-leading,var(--text-base--line-height))}.sm\:text-lg{font-size:var(--text-lg);line-height:var(--tw-leading,var(--text-lg--line-height))}.sm\:text-xl{font-size:var(--text-xl);line-height:var(--tw-leading,var(--text-xl--line-height))}.sm\:text-xs{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}}@media (min-width:48rem){.md\:size-12{width:calc(var(--spacing)*12);height:calc(var(--spacing)*12)}.md\:size-16{width:calc(var(--spacing)*16);height:calc(var(--spacing)*16)}.md\:size-20{width:calc(var(--spacing)*20);height:calc(var(--spacing)*20)}.md\:grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.md\:gap-4{gap:calc(var(--spacing)*4)}}@media (min-width:80rem){.xl\:grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}}.\[\&\:\:-webkit-inner-spin-button\]\:appearance-none::-webkit-inner-spin-button{appearance:none}.\[\&\:\:-webkit-outer-spin-button\]\:appearance-none::-webkit-outer-spin-button{appearance:none}}.cb-btn{height:calc(var(--spacing)*13.5);cursor:pointer;border-radius:var(--radius-xl);border-style:var(--tw-border-style);border-width:1px;border-color:var(--color-gray-200);background-color:var(--color-primaryblue);width:100%;padding:calc(var(--spacing)*3.5);padding-inline:calc(var(--spacing)*6);color:var(--color-white);--tw-outline-style:none;outline-style:none;font-size:13px}@media (hover:hover){.cb-btn:hover{background-color:var(--color-primaryblue)}@supports (color:color-mix(in lab, red, red)){.cb-btn:hover{background-color:color-mix(in oklab,var(--color-primaryblue)70%,transparent)}}}.cb-btn:focus{border-color:var(--color-primaryblue)}@media (min-width:40rem){.cb-btn{height:auto}}.cb-btn--disabled{cursor:not-allowed;background-color:var(--color-gray-400)}.cb-input{height:calc(var(--spacing)*13.5);border-radius:var(--radius-xl);border-style:var(--tw-border-style);border-width:1px;border-color:var(--color-gray-200);background-color:var(--color-gray-50);width:100%;padding:calc(var(--spacing)*0);padding-inline:calc(var(--spacing)*3);font-size:var(--text-base);line-height:var(--tw-leading,var(--text-base--line-height));color:var(--color-black)}.cb-input::placeholder{color:var(--color-gray-300)}.cb-input{--tw-outline-style:none;outline-style:none}.cb-input:focus{border-color:var(--color-gray-300);background-color:var(--color-white)}@media (min-width:40rem){.cb-input{height:auto;padding:calc(var(--spacing)*4);padding-inline:calc(var(--spacing)*4);font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}}.cb-input--error{border-color:var(--color-red-500)}.cb-input--password{padding-right:calc(var(--spacing)*12)}.cb-checkbox-container{height:calc(var(--spacing)*13.5);border-radius:var(--radius-xl);border-style:var(--tw-border-style);border-width:1px;border-color:var(--color-gray-200);background-color:var(--color-gray-50);width:100%;padding:calc(var(--spacing)*0);padding-inline:calc(var(--spacing)*3);justify-content:space-between;align-items:center;display:flex}.cb-checkbox-container:focus-within{border-color:var(--color-gray-300);background-color:var(--color-white)}@media (min-width:40rem){.cb-checkbox-container{height:auto;padding:calc(var(--spacing)*3)}}.cb-checkbox-label{font-size:var(--text-base);line-height:var(--tw-leading,var(--text-base--line-height));color:var(--color-gray-400)}@media (min-width:40rem){.cb-checkbox-label{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}}.cb-checkbox-box{height:calc(var(--spacing)*6);width:calc(var(--spacing)*6);cursor:pointer;border-radius:var(--radius-lg);border-style:var(--tw-border-style);transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration));border-width:1px;justify-content:center;align-items:center;display:flex}.cb-checkbox-box--checked{border-color:var(--color-black);background-color:var(--color-black)}.cb-checkbox-box--unchecked{border-color:var(--color-gray-300);background-color:var(--color-white)}.cb-checkbox-box--disabled{cursor:not-allowed;opacity:.5}.cb-square-checkbox{cursor:pointer;align-items:center;gap:calc(var(--spacing)*4);-webkit-user-select:none;user-select:none;display:flex}.cb-square-checkbox--disabled{cursor:not-allowed;opacity:.6}.cb-square-checkbox--checked .cb-square-checkbox__label{color:var(--color-gray-800)}.cb-square-checkbox--unchecked .cb-square-checkbox__label{color:var(--color-gray-600)}.cb-square-checkbox__box{height:calc(var(--spacing)*11);width:calc(var(--spacing)*11);border-radius:var(--radius-xl);border-style:var(--tw-border-style);border-width:1px;border-color:var(--color-gray-200);background-color:var(--color-gray-50);--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a),0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow);transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.cb-square-checkbox__box--checked{border-color:var(--color-primaryblue);background-color:var(--color-white);--tw-ring-shadow:var(--tw-ring-inset,)0 0 0 calc(2px + var(--tw-ring-offset-width))var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow);--tw-ring-color:var(--color-primaryblue)}.cb-square-checkbox__box--unchecked{border-color:var(--color-gray-200);background-color:var(--color-gray-50)}.cb-square-checkbox__box--disabled{opacity:.5}.cb-square-checkbox__label{--tw-font-weight:var(--font-weight-medium);font-size:15px;font-weight:var(--font-weight-medium);color:var(--color-gray-600)}@property --tw-translate-x{syntax:"*";inherits:false;initial-value:0}@property --tw-translate-y{syntax:"*";inherits:false;initial-value:0}@property --tw-translate-z{syntax:"*";inherits:false;initial-value:0}@property --tw-scale-x{syntax:"*";inherits:false;initial-value:1}@property --tw-scale-y{syntax:"*";inherits:false;initial-value:1}@property --tw-scale-z{syntax:"*";inherits:false;initial-value:1}@property --tw-rotate-x{syntax:"*";inherits:false}@property --tw-rotate-y{syntax:"*";inherits:false}@property --tw-rotate-z{syntax:"*";inherits:false}@property --tw-skew-x{syntax:"*";inherits:false}@property --tw-skew-y{syntax:"*";inherits:false}@property --tw-space-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-space-x-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-divide-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-font-weight{syntax:"*";inherits:false}@property --tw-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:"*";inherits:false}@property --tw-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:"*";inherits:false}@property --tw-inset-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:"*";inherits:false}@property --tw-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:"*";inherits:false}@property --tw-inset-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:"*";inherits:false}@property --tw-ring-offset-width{syntax:"<length>";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:"*";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-backdrop-blur{syntax:"*";inherits:false}@property --tw-backdrop-brightness{syntax:"*";inherits:false}@property --tw-backdrop-contrast{syntax:"*";inherits:false}@property --tw-backdrop-grayscale{syntax:"*";inherits:false}@property --tw-backdrop-hue-rotate{syntax:"*";inherits:false}@property --tw-backdrop-invert{syntax:"*";inherits:false}@property --tw-backdrop-opacity{syntax:"*";inherits:false}@property --tw-backdrop-saturate{syntax:"*";inherits:false}@property --tw-backdrop-sepia{syntax:"*";inherits:false}@property --tw-duration{syntax:"*";inherits:false}@property --tw-ease{syntax:"*";inherits:false}@keyframes spin{to{transform:rotate(360deg)}}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface RoomCounts {
|
|
2
|
+
sittingRoom?: number;
|
|
3
|
+
bedroom?: number;
|
|
4
|
+
kitchen?: number;
|
|
5
|
+
bathroom?: number;
|
|
6
|
+
toilet?: number;
|
|
7
|
+
parkingSpace?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface PropertyFeatures {
|
|
10
|
+
serviced?: boolean;
|
|
11
|
+
furnished?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface AddressObject {
|
|
14
|
+
address: string;
|
|
15
|
+
latitude?: number;
|
|
16
|
+
longitude?: number;
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type UploadedFileLike = {
|
|
2
|
+
name: string;
|
|
3
|
+
url?: string;
|
|
4
|
+
type?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const isImageFile: (file: File | UploadedFileLike) => boolean;
|
|
7
|
+
export declare const isVideoFile: (file: File | UploadedFileLike) => boolean;
|
|
8
|
+
export declare const validateImageRequirement: (files: (File | UploadedFileLike)[]) => boolean;
|
|
9
|
+
export declare const separateFilesByType: (files: File[]) => {
|
|
10
|
+
imageFiles: File[];
|
|
11
|
+
videoFiles: File[];
|
|
12
|
+
};
|
|
13
|
+
export declare const getFileType: (file: File | UploadedFileLike) => "image" | "video" | "unknown";
|
|
14
|
+
export declare const validateFileCollection: (files: (File | UploadedFileLike)[]) => {
|
|
15
|
+
isValid: boolean;
|
|
16
|
+
hasImages: boolean;
|
|
17
|
+
hasVideos: boolean;
|
|
18
|
+
totalCount: number;
|
|
19
|
+
error?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare const isVideoFileGeneric: (file: File | UploadedFileLike) => boolean;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Shared file validation utilities
|
|
2
|
+
// These utilities work with both native File objects and simple uploaded file-like objects
|
|
3
|
+
const IMAGE_EXTENSIONS = /\.(jpg|jpeg|png|gif|bmp|webp|svg)$/i;
|
|
4
|
+
const VIDEO_EXTENSIONS = /\.(mp4|avi|mov|wmv|flv|webm|mkv)$/i;
|
|
5
|
+
export const isImageFile = (file) => {
|
|
6
|
+
if (typeof file.type === "string") {
|
|
7
|
+
const f = file;
|
|
8
|
+
return f.type.startsWith("image/") || IMAGE_EXTENSIONS.test((f.name || "").toLowerCase());
|
|
9
|
+
}
|
|
10
|
+
const lf = file;
|
|
11
|
+
const fileName = (lf.name || "").toLowerCase();
|
|
12
|
+
const fileUrl = (lf.url || "").toLowerCase();
|
|
13
|
+
return IMAGE_EXTENSIONS.test(fileName) || IMAGE_EXTENSIONS.test(fileUrl);
|
|
14
|
+
};
|
|
15
|
+
export const isVideoFile = (file) => {
|
|
16
|
+
if (typeof file.type === "string") {
|
|
17
|
+
const f = file;
|
|
18
|
+
return f.type.startsWith("video/") || VIDEO_EXTENSIONS.test((f.name || "").toLowerCase());
|
|
19
|
+
}
|
|
20
|
+
const lf = file;
|
|
21
|
+
const fileName = (lf.name || "").toLowerCase();
|
|
22
|
+
const fileUrl = (lf.url || "").toLowerCase();
|
|
23
|
+
return VIDEO_EXTENSIONS.test(fileName) || VIDEO_EXTENSIONS.test(fileUrl);
|
|
24
|
+
};
|
|
25
|
+
export const validateImageRequirement = (files) => {
|
|
26
|
+
return files.some(isImageFile);
|
|
27
|
+
};
|
|
28
|
+
export const separateFilesByType = (files) => {
|
|
29
|
+
const imageFiles = [];
|
|
30
|
+
const videoFiles = [];
|
|
31
|
+
files.forEach((file) => {
|
|
32
|
+
if (isImageFile(file))
|
|
33
|
+
imageFiles.push(file);
|
|
34
|
+
else if (isVideoFile(file))
|
|
35
|
+
videoFiles.push(file);
|
|
36
|
+
});
|
|
37
|
+
return { imageFiles, videoFiles };
|
|
38
|
+
};
|
|
39
|
+
export const getFileType = (file) => {
|
|
40
|
+
if (isImageFile(file))
|
|
41
|
+
return "image";
|
|
42
|
+
if (isVideoFile(file))
|
|
43
|
+
return "video";
|
|
44
|
+
return "unknown";
|
|
45
|
+
};
|
|
46
|
+
export const validateFileCollection = (files) => {
|
|
47
|
+
const totalCount = files.length;
|
|
48
|
+
const hasImages = files.some(isImageFile);
|
|
49
|
+
const hasVideos = files.some(isVideoFile);
|
|
50
|
+
if (totalCount === 0) {
|
|
51
|
+
return {
|
|
52
|
+
isValid: false,
|
|
53
|
+
hasImages: false,
|
|
54
|
+
hasVideos: false,
|
|
55
|
+
totalCount: 0,
|
|
56
|
+
error: "Please upload at least one image or video",
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (!hasImages) {
|
|
60
|
+
return {
|
|
61
|
+
isValid: false,
|
|
62
|
+
hasImages: false,
|
|
63
|
+
hasVideos,
|
|
64
|
+
totalCount,
|
|
65
|
+
error: "At least one image is required. Videos alone are not sufficient.",
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return { isValid: true, hasImages, hasVideos, totalCount };
|
|
69
|
+
};
|
|
70
|
+
export const isVideoFileGeneric = (file) => {
|
|
71
|
+
if (typeof file.type === "string") {
|
|
72
|
+
return isVideoFile(file);
|
|
73
|
+
}
|
|
74
|
+
const lf = file;
|
|
75
|
+
const name = (lf.name || "").toLowerCase();
|
|
76
|
+
const url = (lf.url || "").toLowerCase();
|
|
77
|
+
return (name.includes("video") ||
|
|
78
|
+
url.includes(".mp4") ||
|
|
79
|
+
url.includes(".mov") ||
|
|
80
|
+
url.includes(".avi") ||
|
|
81
|
+
url.includes(".webm"));
|
|
82
|
+
};
|