-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
e92e794
commit 4cc33eb
Showing
7 changed files
with
1,853 additions
and
1,792 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useMemo } from 'react'; | ||
|
||
type Flattened<T extends object> = T & { level: number }; | ||
|
||
function flattenTree<T extends object>( | ||
tree: T[], | ||
getChildren: (node: T) => T[] | undefined, | ||
level: number = 0 | ||
): Flattened<T>[] { | ||
console.log('CALLED'); | ||
return tree.reduce((acc: Flattened<T>[], node: T) => { | ||
const children = getChildren(node); | ||
acc.push({ ...node, level }); | ||
|
||
if (children && children.length > 0) { | ||
acc.push(...flattenTree(children, getChildren, level + 1)); | ||
} | ||
|
||
return acc; | ||
}, []); | ||
} | ||
|
||
|
||
export function useTreeFlatten<T extends object>( | ||
tree: T[], | ||
getChildren: (node: T) => T[] | undefined | ||
): Flattened<T>[] { | ||
|
||
const flattenedTree = useMemo(() => ( | ||
flattenTree(tree, getChildren) | ||
), [ tree, getChildren ]); | ||
|
||
return flattenedTree; | ||
} |
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 { useListData } from 'react-stately'; | ||
import { NavigationProps } from './Navigation.types'; | ||
import { Tabs, TabList, Tab } from 'react-aria-components'; | ||
import { useTreeFlatten } from '@do-ob/ui/hooks'; | ||
|
||
export function NavigationMenu({ | ||
base, | ||
}: { base: NavigationProps }) { | ||
|
||
const { | ||
links = [], | ||
} = base; | ||
|
||
const linksFlat = useTreeFlatten( | ||
links, | ||
(item) => item.links, | ||
); | ||
|
||
const linkList = useListData({ | ||
initialItems: linksFlat, | ||
getKey: (item) => item.url, | ||
}); | ||
|
||
console.log({ | ||
linksFlat, | ||
linkList: linkList.items | ||
}); | ||
|
||
return ( | ||
<Tabs | ||
orientation="vertical" | ||
keyboardActivation="manual" | ||
> | ||
<TabList | ||
items={linkList.items} | ||
> | ||
{(link) => ( | ||
<Tab id={link.url}>{link.title}</Tab> | ||
)} | ||
</TabList> | ||
</Tabs> | ||
); | ||
} |
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
Oops, something went wrong.