-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/numericinput-edge-cases
- Loading branch information
Showing
47 changed files
with
1,330 additions
and
827 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,6 @@ dist-ssr | |
!.yarn/versions | ||
|
||
vite.config.ts.timestamp-* | ||
coverage/ | ||
coverage/ | ||
# Local Netlify folder | ||
.netlify |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
export const NavCollapseMenu = ({ | ||
link, | ||
disabled, | ||
button, | ||
children, | ||
ariaControls, | ||
activeSelection, | ||
onClick, | ||
}: { | ||
link: string; | ||
disabled?: boolean; | ||
button: JSX.Element | null; | ||
children: JSX.Element | null; | ||
ariaControls?: string; | ||
activeSelection?: string | null; | ||
onClick: (link: string | null) => void; | ||
}) => { | ||
const isItemActive = !!activeSelection && activeSelection === link; | ||
|
||
const handleOnClick = () => { | ||
onClick(isItemActive ? null : link); | ||
}; | ||
|
||
return ( | ||
<section className={`collapse ${disabled ? 'disabled' : 'collapse-arrow'} ${isItemActive ? 'collapse-open' : ''} `}> | ||
<button | ||
type="button" | ||
className={`nav-item collapse-btn collapse-title ${isItemActive ? 'active' : ''}`} | ||
aria-controls={ariaControls} | ||
aria-disabled={disabled} | ||
aria-expanded={isItemActive} | ||
onClick={handleOnClick} | ||
> | ||
{button} | ||
</button> | ||
<div className="collapse-content p-0">{children}</div> | ||
</section> | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { NavLink } from 'react-router-dom'; | ||
import { LinkItem } from '../../links'; | ||
|
||
const isExternalLink = (link: string) => { | ||
try { | ||
const parsedUrl = new URL(link); | ||
return ['http:', 'https:'].includes(parsedUrl.protocol); | ||
} catch { | ||
return false; | ||
} | ||
}; | ||
|
||
export const NavItem = ({ | ||
item, | ||
onClick, | ||
isSubNavItem = false, | ||
}: { | ||
item: LinkItem; | ||
onClick?: () => void; | ||
isSubNavItem?: boolean; | ||
}) => { | ||
const { link, prefix, suffix, title, props, hidden } = item; | ||
if (hidden) return null; | ||
const isExternal = isExternalLink(link); | ||
|
||
const linkUi = ( | ||
<> | ||
{prefix} | ||
<span>{title}</span> | ||
{suffix} | ||
</> | ||
); | ||
const cls = `nav-item font-outfit ${props?.className?.() || ''} ${isSubNavItem ? 'text-sm' : ''}`; | ||
return isExternal ? ( | ||
<a href={link} {...props} className={cls} onClick={onClick}> | ||
{linkUi} | ||
</a> | ||
) : ( | ||
<NavLink to={link} {...props} onClick={onClick} className={cls}> | ||
{linkUi} | ||
</NavLink> | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { memo, useEffect, useMemo, useState } from 'preact/compat'; | ||
import { useLocation } from 'react-router-dom'; | ||
import { useGlobalState } from '../../../GlobalStateProvider'; | ||
import { NavCollapseButtonContent } from '../NavCollapseButtonContent'; | ||
import { createLinks, LinkItem } from '../links'; | ||
import { NavItem } from './NavItem'; | ||
import { NavCollapseMenu } from './NavCollapseMenu'; | ||
|
||
const getActiveLink = (pathname: string): string | null => { | ||
const [path] = pathname.split('?'); | ||
const paths = path.split('/').filter(Boolean); | ||
return paths.length > 1 ? `/${paths[1]}` : null; | ||
}; | ||
|
||
export type NavProps = { | ||
onClick?: () => void; | ||
}; | ||
|
||
const Nav = memo(({ onClick }: NavProps) => { | ||
const state = useGlobalState(); | ||
|
||
const [isPlaying, setIsPlaying] = useState(false); | ||
const [links, setLinks] = useState<LinkItem[]>([]); | ||
|
||
const { pathname } = useLocation(); | ||
const activeLink = useMemo(() => getActiveLink(pathname), [pathname]); | ||
const [activeSelection, setActiveSelection] = useState<null | string>(activeLink); | ||
|
||
const handleMouseEnter = () => { | ||
setIsPlaying(true); | ||
}; | ||
|
||
useEffect(() => { | ||
const [defaultLinks, loadedLinksPromise] = createLinks(state.tenantName); | ||
setLinks(defaultLinks); | ||
|
||
loadedLinksPromise.then(setLinks).catch((error) => console.error("Couldn't load links", error)); | ||
}, [state.tenantName]); | ||
|
||
return ( | ||
<nav> | ||
{links.map((item, i) => { | ||
if (item.hidden) return; | ||
|
||
return item.submenu ? ( | ||
<div onMouseEnter={handleMouseEnter} className="my-2.5"> | ||
<NavCollapseMenu | ||
key={i} | ||
disabled={item.disabled} | ||
ariaControls="submenu" | ||
button={<NavCollapseButtonContent item={item} isPlaying={isPlaying} />} | ||
activeSelection={activeSelection} | ||
link={item.link} | ||
onClick={setActiveSelection} | ||
> | ||
<ul className="submenu" id={`submenu-${i}`}> | ||
{item.submenu.map((subItem, j) => ( | ||
<li key={`${i}-${j}`} className="ml-[3px]"> | ||
<NavItem item={subItem} onClick={onClick} isSubNavItem={true} /> | ||
</li> | ||
))} | ||
</ul> | ||
</NavCollapseMenu> | ||
</div> | ||
) : ( | ||
<NavItem | ||
key={i} | ||
item={item} | ||
onClick={() => { | ||
setActiveSelection(item.link); | ||
onClick && onClick(); | ||
}} | ||
/> | ||
); | ||
})} | ||
</nav> | ||
); | ||
}); | ||
|
||
export default Nav; |
Oops, something went wrong.