utopia-ui/src/Components/AppShell/SidebarSubmenu.tsx
Anton Tranelis 54f464ef02
fix(source): removed tw-elements (#175)
* rollup - fail when typescript has warnings or errors

Currently this is detected when building the docu. Since the developer
rarely does that the problem is detected on github.
This change allows the developer to discover the error early by failing
the build.

* 3.0.75

* removed tw-elements

* removed tw-elements package

* found userType artefacts and removed it

* fixed linting

* 3.0.76

* adjust sidebar size and transition

---------

Co-authored-by: Ulf Gebhardt <ulf.gebhardt@webcraft-media.de>
2025-03-04 23:35:10 +01:00

72 lines
2.0 KiB
TypeScript

import ChevronDownIcon from '@heroicons/react/24/outline/ChevronDownIcon'
import { useEffect, useState } from 'react'
import { Link, useLocation } from 'react-router-dom'
import type { Route } from './SideBar'
function SidebarSubmenu({
submenu,
name,
icon,
}: {
path: string
icon: JSX.Element
name: string
submenu?: Route[]
}) {
const location = useLocation()
const [isExpanded, setIsExpanded] = useState(false)
/** Open Submenu list if path found in routes, this is for directly loading submenu routes first time */
useEffect(() => {
if (
submenu?.filter((m) => {
return m.path === location.pathname
})[0]
)
setIsExpanded(true)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
return (
<div className='flex-col'>
{/** Route header */}
<div className='w-full' onClick={() => setIsExpanded(!isExpanded)}>
{icon} <span>{name} </span>
<ChevronDownIcon
className={
'w-5 h-5 mt-1 float-right delay-400 duration-500 transition-all ' +
(isExpanded ? 'rotate-180' : '')
}
/>
</div>
{/** Submenu list */}
<div className={' w-full' + (isExpanded ? '' : 'hidden')}>
<ul className={'menu menu-compact'}>
{submenu?.map((m, k) => {
return (
<li key={k}>
<Link to={m.path} className=''>
{m.icon}
<span className='' data-te-sidenav-slim='false'>
{m.name}
</span>
{location.pathname === m.path ? (
<span
className='absolute mt-1 mb-1 inset-y-0 left-0 w-1 rounded-tr-md rounded-br-md bg-primary '
aria-hidden='true'
></span>
) : null}
</Link>
</li>
)
})}
</ul>
</div>
</div>
)
}
export default SidebarSubmenu