import Link from 'next/link'
import orderBy from 'lodash.orderby'
import {
RssIcon,
TutorialIcon,
GuideIcon,
HelpIcon,
DocsIcon,
DesignIcon,
BoxIcon,
CogIcon,
UserIcon,
CommunityIcon,
ShowcaseIcon,
} from 'shared/components/icons.mjs'
// Don't show children for blog and showcase posts
const keepClosed = ['blog', 'showcase']
// List of icons matched to top-level slug
const icons = {
accessories: (className = '') => ,
account: (className = '') => ,
blocks: (className = '') => ,
blog: (className = '') => ,
community: (className = '') => ,
designs: (className = '') => ,
docs: (className = '') => ,
garments: (className = '') => ,
guides: (className = '') => ,
howtos: (className = '') => ,
reference: (className = '') => ,
showcase: (className = '') => ,
tutorials: (className = '') => ,
utilities: (className = '') => ,
}
/* helper method to order nav entries */
const order = (obj) => orderBy(obj, ['__order', '__title'], ['asc', 'asc'])
// Component for the collapse toggle
// Exported for re-use
export const Chevron = ({ w = 8, m = 2 }) => (
)
// Helper method to filter out the real children
const currentChildren = (current) =>
Object.values(order(current)).filter((entry) => typeof entry === 'object')
// Shared classes for links
// Exported for re-use
export const linkClasses = `text-lg lg:text-xl
py-1
text-base-content sm:text-base-content
hover:text-secondary
sm:hover:text-secondary
`
// Figure out whether a page is on the path to the active page
const isActive = (slug, active) => {
if (slug === active) return true
let result = true
const slugParts = slug.split('/')
const activeParts = active.split('/')
for (const i in slugParts) {
if (slugParts[i] !== activeParts[i]) result = false
}
return result
}
// Component that renders a sublevel of navigation
const SubLevel = ({ nodes = {}, active }) => (
{currentChildren(nodes).map((child) =>
Object.keys(child).length > 4 ? (
-
{child.__slug === active ? <>•> : <>°>}
{child.__linktitle || child.__title}
) : (
-
{child.__slug === active ? <>•> : <>°>}
{child.__linktitle || child.__title}
)
)}
)
// Component that renders a toplevel of navigation
const TopLevel = ({ icon, title, current, slug, hasChildren = false, active }) => (
{icon}
{title}
{hasChildren && }
{hasChildren && }
)
const Navigation = ({ app, active, className = '' }) => {
if (!app.navigation) return null
const output = []
for (const page of order(app.navigation))
output.push(
°
)
}
title={page.__title}
slug={page.__slug}
hasChildren={keepClosed.indexOf(page.__slug) === -1}
nav={app.navigation}
current={order(app.navigation[page.__slug])}
active={active}
/>
)
return {output}
}
export const Icons = ({
app,
ulClasses = '',
liClasses = '',
linkClasses = `grow text-lg lg:text-xl py-1 text-base-content sm:text-base-content
hover:text-secondary sm:hover:text-secondary hover:cursor-pointer
flex flex-col items-center`,
linkStyle = {},
}) => {
if (!app.navigation) return null
const output = []
for (const page of order(app.navigation)) {
output.push(
{icons[page.__slug] ? icons[page.__slug]('w-14 h-14') : }
{page.__title}
)
}
return
}
export const PrimaryNavigation = ({ app, active, before = [], after = [] }) => (
)