[WIP] Import Plans
This commit is contained in:
@@ -83,7 +83,7 @@ function NavListSub({ list }: NavListSubProps) {
|
||||
|
||||
const { pathname } = useLocation();
|
||||
|
||||
const active = getActive(list.path, pathname);
|
||||
const active = getActive(list.path, pathname, list.openWhen);
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@ export function isExternalLink(path: string) {
|
||||
return path.includes('http');
|
||||
}
|
||||
|
||||
export function getActive(path: string, pathname: string) {
|
||||
return path ? !!matchPath({ path: path, end: false }, pathname) : false;
|
||||
export function getActive(path: string, pathname: string, openWhen?: string[]) {
|
||||
const listPathWhenActive = [ ...openWhen ?? [], path ];
|
||||
|
||||
return listPathWhenActive.includes(pathname);
|
||||
// return path ? !!matchPath({ path: path, end: false }, pathname) : false;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ export type NavListProps = {
|
||||
path: string;
|
||||
icon?: ReactElement;
|
||||
info?: ReactElement;
|
||||
openWhen? : string[];
|
||||
children?: {
|
||||
title: string;
|
||||
path: string;
|
||||
|
||||
@@ -18,7 +18,7 @@ type NavListRootProps = {
|
||||
export function NavListRoot({ list, isCollapse }: NavListRootProps) {
|
||||
const { pathname } = useLocation();
|
||||
|
||||
const active = getActive(list.path, pathname);
|
||||
const active = getActive(list.path, pathname, list.openWhen);
|
||||
|
||||
const [open, setOpen] = useState(active);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user