Skip to content

Commit

Permalink
animate on props changed
Browse files Browse the repository at this point in the history
  • Loading branch information
NGR-NP committed Mar 7, 2024
1 parent 48fdb89 commit 576fa01
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tapShareFrontend/src/components/DynamicFileTypeIcon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { useState, useEffect } from "react";
import { PiFile } from "react-icons/pi";

const iconMap = {
export const iconMap = {
mp3: "PiFileAudio",
archive: "PiFileArchive",
code: "PiFileCode",
Expand All @@ -15,14 +15,15 @@ const iconMap = {
webp: "PiFileImage",
jpg: "PiFileJpg",
js: "PiFileJs",
javascript: "PiFileJs",
jsx: "PiFileJsx",
pdf: "PiFilePdf",
png: "PiFilePng",
ppt: "PiFilePpt",
pptx: "PiFilePpt",
sql: "PiFileSql",
svg: "PiFileSvg",
text: "PiFileText",
plain: "PiFileText",
txt: "PiFileText",
ts: "PiFileTs",
tsx: "PiFileTsx",
Expand All @@ -39,6 +40,8 @@ const iconMap = {
const DynamicIcon = ({ name }) => {
const [IconComponent, setIconComponent] = useState(null);
const iconName = name.split(".").pop().toLowerCase();
const key = name.split(".").length > 1 && iconName.length > 1;

useEffect(() => {
const importIcon = async () => {
try {
Expand All @@ -55,7 +58,7 @@ const DynamicIcon = ({ name }) => {
importIcon();
}, [iconName]);

return IconComponent ? <IconComponent /> : <PiFile />;
return IconComponent ? <IconComponent key={name} className="animate-[scale_300ms]" /> : <PiFile key={key ? iconName : key} className={`${!key ? "hidden": !iconMap[iconName] ? "animate-shake" : "animate-[scale_300ms]"}`} />;
};

export default DynamicIcon;

0 comments on commit 576fa01

Please sign in to comment.