components.regions.ScrollSpy.Menu.jsx Maven / Gradle / Ivy
The newest version!
import React, { useState } from 'react'
import classNames from 'classnames'
import { Divider } from '../../snippets/Divider/Divider'
import { ScrollSpyTypes } from './ScrollSpyTypes'
import { Title } from './Title'
import { hasVisibleWidget } from './utils'
export function Menu({
items,
widgets,
active,
setActive,
isOpen = true,
nested = false,
}) {
return (
)
}
Menu.propTypes = {
...ScrollSpyTypes,
}
function MenuList({ items, active, setActive, widgets }) {
return items.map(({ title, id, menu: items, content, group = null, headline = false }) => {
if (!group) {
return (
)
}
const isGroupVisible = group.some(item => hasVisibleWidget(item, widgets))
if (!isGroupVisible) {
return null
}
return (
{headline && }
)
})
}
MenuList.propTypes = ScrollSpyTypes
function MenuItem({
id,
title,
items = [],
active,
setActive,
content,
widgets,
}) {
const isActive = id === active
if (items.length > 0) {
return (
)
}
const itemVisible = hasVisibleWidget(content, widgets)
return (
setActive(id)}
visible={itemVisible}
/>
)
}
MenuItem.propTypes = ScrollSpyTypes
function DropdownMenuItem({ title, active, setActive, widgets, items = [], nested = false }) {
const [isOpen, setOpen] = useState(false)
const isDropdownVisible = items.some(item => hasVisibleWidget(item, widgets))
if (!isDropdownVisible) {
return false
}
const toggle = () => setOpen(!isOpen)
const hasActive = items.some(({ id }) => id === active)
return (
)
}
DropdownMenuItem.propTypes = ScrollSpyTypes