-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
74 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,56 @@ | ||
"use client"; | ||
"use client" | ||
|
||
import { useState } from "react"; | ||
import { motion } from "framer-motion"; | ||
import { cn } from "@/lib/utils"; | ||
import { useState } from "react" | ||
import { cn } from "@/lib/utils" | ||
|
||
type Tab = { | ||
title: string; | ||
value: string; | ||
content?: string | React.ReactNode | any; | ||
}; | ||
title: string | ||
value: string | ||
content?: string | React.ReactNode | any | ||
} | ||
|
||
export const Tabs = ({ | ||
export function Tabs({ | ||
tabs: propTabs, | ||
containerClassName, | ||
activeTabClassName, | ||
tabClassName, | ||
contentClassName, | ||
}: { | ||
tabs: Tab[]; | ||
containerClassName?: string; | ||
activeTabClassName?: string; | ||
tabClassName?: string; | ||
contentClassName?: string; | ||
}) => { | ||
const [active, setActive] = useState<Tab>(propTabs[0]); | ||
const [tabs, setTabs] = useState<Tab[]>(propTabs); | ||
|
||
const moveSelectedTabToTop = (idx: number) => { | ||
const newTabs = [...propTabs]; | ||
const selectedTab = newTabs.splice(idx, 1); | ||
newTabs.unshift(selectedTab[0]); | ||
setTabs(newTabs); | ||
setActive(newTabs[0]); | ||
}; | ||
|
||
const [hovering, setHovering] = useState(false); | ||
tabs: Tab[] | ||
containerClassName?: string | ||
activeTabClassName?: string | ||
tabClassName?: string | ||
contentClassName?: string | ||
}) { | ||
const [activeTab, setActiveTab] = useState<Tab>(propTabs[0]) | ||
|
||
return ( | ||
<> | ||
<div | ||
className={cn( | ||
"flex flex-row items-center justify-start [perspective:1000px] relative overflow-x-auto sm:overflow-visible no-visible-scrollbar max-w-full w-full", | ||
"flex flex-row items-center justify-start overflow-x-auto sm:overflow-visible no-visible-scrollbar max-w-full w-full", | ||
containerClassName | ||
)} | ||
> | ||
{propTabs.map((tab, idx) => ( | ||
{propTabs.map((tab) => ( | ||
<button | ||
key={tab.title} | ||
onClick={() => { | ||
moveSelectedTabToTop(idx); | ||
}} | ||
onMouseEnter={() => setHovering(true)} | ||
onMouseLeave={() => setHovering(false)} | ||
key={tab.value} | ||
onClick={() => setActiveTab(tab)} | ||
className={cn( | ||
"relative px-2 py-1 sm:px-3 sm:py-2 md:px-4 md:py-2 rounded-full text-xs sm:text-sm md:text-base whitespace-nowrap", | ||
tabClassName | ||
tabClassName, | ||
activeTab.value === tab.value && activeTabClassName | ||
)} | ||
style={{ | ||
transformStyle: "preserve-3d", | ||
}} | ||
> | ||
{active.value === tab.value && ( | ||
<motion.div | ||
layoutId="clickedbutton" | ||
transition={{ type: "spring", bounce: 0.3, duration: 0.6 }} | ||
className={cn( | ||
"absolute inset-0 bg-gray-200 dark:bg-zinc-800 rounded-full", | ||
activeTabClassName | ||
)} | ||
/> | ||
)} | ||
|
||
<span className="relative block text-black dark:text-white"> | ||
{tab.title} | ||
</span> | ||
</button> | ||
))} | ||
</div> | ||
<FadeInDiv | ||
tabs={tabs} | ||
active={active} | ||
key={active.value} | ||
hovering={hovering} | ||
className={cn("mt-8 sm:mt-16 md:mt-24 lg:mt-32", contentClassName)} | ||
/> | ||
<div className={cn("mt-8 sm:mt-16 md:mt-24 lg:mt-32", contentClassName)}> | ||
{activeTab.content} | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export const FadeInDiv = ({ | ||
className, | ||
tabs, | ||
hovering, | ||
}: { | ||
className?: string; | ||
key?: string; | ||
tabs: Tab[]; | ||
active: Tab; | ||
hovering?: boolean; | ||
}) => { | ||
const isActive = (tab: Tab) => { | ||
return tab.value === tabs[0].value; | ||
}; | ||
return ( | ||
<div className="relative w-full h-full"> | ||
{tabs.map((tab, idx) => ( | ||
<motion.div | ||
key={tab.value} | ||
layoutId={tab.value} | ||
style={{ | ||
scale: 1 - idx * 0.1, | ||
top: hovering ? idx * -50 : 0, | ||
zIndex: -idx, | ||
opacity: idx < 3 ? 1 - idx * 0.1 : 0, | ||
}} | ||
animate={{ | ||
y: isActive(tab) ? [0, 40, 0] : 0, | ||
}} | ||
className={cn("w-full h-full absolute top-0 left-0", className)} | ||
> | ||
{tab.content} | ||
</motion.div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
890c4a6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
avm-care – ./
avm-care-sinans-projects-8d312afe.vercel.app
avm-care-git-main-sinans-projects-8d312afe.vercel.app
avm-care.vercel.app