Refactor: enhance upload file button UI and enhance File and Image preview UI
This commit is contained in:
parent
43ba306b34
commit
40eaa0903b
6 changed files with 50 additions and 20 deletions
|
|
@ -42,10 +42,10 @@ const TextAreaWrapper = ({
|
||||||
|
|
||||||
const fileClass =
|
const fileClass =
|
||||||
files.length > 0
|
files.length > 0
|
||||||
? "rounded-b-md border-t-0 border-border focus:border-t-0 focus:border-ring"
|
? "rounded-b-lg rounded-t-none border-t-0 border-border focus:border-t-0 focus:border-ring"
|
||||||
: "rounded-md border-t-2 border-border focus:border-ring";
|
: "rounded-md border-t-2 border-border focus:border-ring";
|
||||||
|
|
||||||
const additionalClassNames = "form-modal-lockchat pl-10";
|
const additionalClassNames = "form-modal-lockchat pl-14";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Textarea
|
<Textarea
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import ForwardedIconComponent from "../../../../../../../components/genericIconComponent";
|
||||||
|
|
||||||
const UploadFileButton = ({
|
const UploadFileButton = ({
|
||||||
fileInputRef,
|
fileInputRef,
|
||||||
handleFileChange,
|
handleFileChange,
|
||||||
|
|
@ -12,10 +14,10 @@ const UploadFileButton = ({
|
||||||
onChange={handleFileChange}
|
onChange={handleFileChange}
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
className="absolute rounded bg-blue-500 px-4 py-2 font-bold text-white hover:bg-blue-700"
|
className="font-bold text-white transition-all hover:text-muted-foreground"
|
||||||
onClick={handleButtonClick}
|
onClick={handleButtonClick}
|
||||||
>
|
>
|
||||||
Upload File
|
<ForwardedIconComponent name="PaperclipIcon" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
export const getClassNamesFilePreview = (inputFocus) => {
|
export const getClassNamesFilePreview = (inputFocus) => {
|
||||||
return `flex w-full items-center gap-2 rounded-t-md bg-background px-10 py-5 ${
|
return `flex w-full items-center gap-4 rounded-t-lg bg-background px-14 py-5 overflow-auto custom-scroll ${
|
||||||
inputFocus
|
inputFocus
|
||||||
? "border-2 border-b-0 border-ring"
|
? "border-2 border-b-0 border-ring"
|
||||||
: "border border-b-0 border-border"
|
: "border border-b-0 border-border"
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,6 @@ export default function ChatInput({
|
||||||
files={files}
|
files={files}
|
||||||
isDragging={isDragging}
|
isDragging={isDragging}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="form-modal-send-icon-position">
|
<div className="form-modal-send-icon-position">
|
||||||
<ButtonSendWrapper
|
<ButtonSendWrapper
|
||||||
send={send}
|
send={send}
|
||||||
|
|
@ -103,11 +102,13 @@ export default function ChatInput({
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<UploadFileButton
|
<div className="absolute bottom-2 left-4">
|
||||||
fileInputRef={fileInputRef}
|
<UploadFileButton
|
||||||
handleFileChange={handleFileChange}
|
fileInputRef={fileInputRef}
|
||||||
handleButtonClick={handleButtonClick}
|
handleFileChange={handleFileChange}
|
||||||
/>
|
handleButtonClick={handleButtonClick}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{files.length > 0 && (
|
{files.length > 0 && (
|
||||||
<div className={classNameFilePreview}>
|
<div className={classNameFilePreview}>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import IconComponent from "../../../../../components/genericIconComponent";
|
import IconComponent, {
|
||||||
|
ForwardedIconComponent,
|
||||||
|
} from "../../../../../components/genericIconComponent";
|
||||||
|
|
||||||
export default function FilePreview({
|
export default function FilePreview({
|
||||||
error,
|
error,
|
||||||
|
|
@ -12,12 +14,23 @@ export default function FilePreview({
|
||||||
error: boolean;
|
error: boolean;
|
||||||
onDelete: () => void;
|
onDelete: () => void;
|
||||||
}) {
|
}) {
|
||||||
|
const isImage = file.type.toLowerCase().includes("image");
|
||||||
|
|
||||||
const [isHovered, setIsHovered] = useState(false);
|
const [isHovered, setIsHovered] = useState(false);
|
||||||
|
|
||||||
|
const formatFileName = (name) => {
|
||||||
|
const fileExtension = name.split(".").pop(); // Get the file extension
|
||||||
|
const baseName = name.slice(0, name.lastIndexOf(".")); // Get the base name without the extension
|
||||||
|
if (baseName.length > 6) {
|
||||||
|
return `${baseName.slice(0, 10)}...${fileExtension}`;
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative inline-block">
|
<div className="relative inline-block">
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<div className="flex h-24 w-24 items-center justify-center rounded-md border border-ring bg-background ">
|
<div className="flex h-20 w-20 items-center justify-center rounded-md border border-ring bg-background ">
|
||||||
<svg
|
<svg
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
className={`h-10 w-10 animate-spin fill-black text-muted`}
|
className={`h-10 w-10 animate-spin fill-black text-muted`}
|
||||||
|
|
@ -39,19 +52,31 @@ export default function FilePreview({
|
||||||
<div>Error...</div>
|
<div>Error...</div>
|
||||||
) : (
|
) : (
|
||||||
<div
|
<div
|
||||||
className={`relative h-24 w-24 rounded-md border border-ring bg-background transition duration-300 ${
|
className={`relative ${isImage ? "h-20 w-20" : "h-20 w-48"} cursor-pointer rounded-lg border border-ring bg-background transition duration-300 ${
|
||||||
isHovered ? "shadow-md" : ""
|
isHovered ? "shadow-md" : ""
|
||||||
}`}
|
}`}
|
||||||
onMouseEnter={() => setIsHovered(true)}
|
onMouseEnter={() => setIsHovered(true)}
|
||||||
onMouseLeave={() => setIsHovered(false)}
|
onMouseLeave={() => setIsHovered(false)}
|
||||||
>
|
>
|
||||||
<img
|
{isImage ? (
|
||||||
src={URL.createObjectURL(file)}
|
<img
|
||||||
alt="file"
|
src={URL.createObjectURL(file)}
|
||||||
className="block h-full w-full rounded-md border border-border"
|
alt="file"
|
||||||
/>
|
className="block h-full w-full rounded-md border border-border"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="ml-3 flex h-full w-full items-center gap-2 text-sm">
|
||||||
|
<ForwardedIconComponent name="File" className="h-8 w-8" />
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<span className="font-bold">{formatFileName(file.name)}</span>
|
||||||
|
<span>File</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{isHovered && (
|
{isHovered && (
|
||||||
<div className="absolute bottom-20 left-20 flex h-5 w-5 items-center justify-center bg-black bg-opacity-30">
|
<div
|
||||||
|
className={`absolute ${isImage ? "bottom-16 left-16" : "bottom-16 left-44"} flex h-5 w-5 items-center justify-center`}
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
className="flex h-7 w-7 cursor-pointer items-center justify-center rounded-full bg-gray-200 p-2 transition-all"
|
className="flex h-7 w-7 cursor-pointer items-center justify-center rounded-full bg-gray-200 p-2 transition-all"
|
||||||
onClick={onDelete}
|
onClick={onDelete}
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,7 @@ import {
|
||||||
X,
|
X,
|
||||||
XCircle,
|
XCircle,
|
||||||
Zap,
|
Zap,
|
||||||
|
PaperclipIcon,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { FaApple, FaDiscord, FaGithub } from "react-icons/fa";
|
import { FaApple, FaDiscord, FaGithub } from "react-icons/fa";
|
||||||
import { AWSIcon } from "../icons/AWS";
|
import { AWSIcon } from "../icons/AWS";
|
||||||
|
|
@ -526,4 +527,5 @@ export const nodeIconsLucide: iconsType = {
|
||||||
FolderPlusIcon,
|
FolderPlusIcon,
|
||||||
FolderIcon,
|
FolderIcon,
|
||||||
Discord: FaDiscord,
|
Discord: FaDiscord,
|
||||||
|
PaperclipIcon,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue