import React, { useId, useMemo, useState } from 'react'; import cx from 'classnames'; import PropTypes from 'prop-types'; import { ChevronLeft } from 'react-bootstrap-icons'; import { NavLink, useLocation } from 'react-router-dom'; import { Collapse } from 'reactstrap'; import Icon from '../../Icon/Icon'; import s from './LinksGroup.module.scss'; const LinksGroup = ({ childrenLinks, className, glyph, header, headerLink }) => { const location = useLocation(); const panelId = useId(); const hasChildren = Boolean(childrenLinks?.length); const isGroupActive = useMemo(() => { if (!headerLink) { return false; } return location.pathname === headerLink || location.pathname.startsWith(`${headerLink}/`); }, [headerLink, location.pathname]); const [isOpen, setIsOpen] = useState(isGroupActive); const panelOpen = isOpen || isGroupActive; if (!hasChildren) { return (
  • (isActive ? s.headerLinkActive : undefined)} end to={headerLink} >
    {glyph ? : null} {header}
  • ); } return (
  • ); }; LinksGroup.propTypes = { header: PropTypes.node.isRequired, headerLink: PropTypes.string, childrenLinks: PropTypes.arrayOf( PropTypes.shape({ name: PropTypes.string.isRequired, link: PropTypes.string.isRequired, }) ), glyph: PropTypes.string, className: PropTypes.string, }; LinksGroup.defaultProps = { headerLink: null, childrenLinks: null, className: '', glyph: null, }; export default LinksGroup;