Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(platform): Add SVGs to projectTabs #673

Merged
merged 4 commits into from
Jan 30, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions apps/platform/src/components/ui/line-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { motion } from 'framer-motion'
import React, { useCallback } from 'react'
import type { ReadonlyURLSearchParams } from 'next/navigation'
import { usePathname, useRouter, useSearchParams } from 'next/navigation'
import { EnvironmentSVG, SecretSVG, VariableSVG } from '@public/svg/dashboard'
import { cn } from '@/lib/utils'

interface TabProps {
Expand All @@ -11,14 +12,16 @@ interface TabProps {
// setSelected: React.Dispatch<React.SetStateAction<string>>
searchParams: ReadonlyURLSearchParams
customID: string
icon?: React.ReactNode
}

function Tab({
text,
selected,
// setSelected,
searchParams,
customID
customID,
icon
}: TabProps): React.JSX.Element {
const router = useRouter()
const pathname = usePathname()
Expand Down Expand Up @@ -46,14 +49,17 @@ function Tab({
}}
type="button"
>
<span className="relative z-10">{text}</span>
<span className="relative z-10 flex items-center gap-2">
{icon && <span className={'h-4 w-4'}>{icon}</span>}
{text}
</span>
{selected ? (
<motion.div
className="absolute left-0 top-0 flex size-full items-end justify-center"
layoutId={`${customID}linetab`}
transition={{ type: 'spring', duration: 0.4, bounce: 0, delay: 0.1 }}
>
<span className="z-0 h-[3px] w-[60%] rounded-t-full bg-white" />
<span className="z-0 h-[3px] w-[70%] rounded-t-full bg-white" />
</motion.div>
) : null}
</button>
Expand All @@ -69,6 +75,22 @@ function LineTab({ customID, tabs }: LineTabsProps): React.JSX.Element {
// const [selected, setSelected] = useState(tabs[0])
const searchParams = useSearchParams()
const search = searchParams.get('tab')
const pathname = usePathname()

const getIcon = (tab: string): React.ReactNode => {
if (pathname.split('/')[1] !== 'project') return null

switch (tab.toLowerCase()) {
case 'secret':
return <SecretSVG />
case 'variable':
return <VariableSVG />
case 'environment':
return <EnvironmentSVG />
default:
return null
}
}

return (
<div
Expand All @@ -77,6 +99,7 @@ function LineTab({ customID, tabs }: LineTabsProps): React.JSX.Element {
{tabs.map((tab) => (
<Tab
customID={customID}
icon={getIcon(tab)}
key={tab}
searchParams={searchParams}
selected={search?.toLocaleLowerCase() === tab.toLocaleLowerCase()}
Expand Down
Loading