import { ALink, colors, Link, utils as sharedUtils } from '@0x/react-shared'; import { ObjectMap } from '@0x/types'; import * as _ from 'lodash'; import * as React from 'react'; import { Button } from 'ts/components/ui/button'; import { Text } from 'ts/components/ui/text'; import { ScreenWidths } from 'ts/types'; export interface NestedSidebarMenuProps { sectionNameToLinks: ObjectMap; sidebarHeader?: React.ReactNode; shouldReformatMenuItemNames?: boolean; screenWidth: ScreenWidths; } export const NestedSidebarMenu = (props: NestedSidebarMenuProps) => { const navigation = _.map(props.sectionNameToLinks, (links: ALink[], sectionName: string) => { const finalSectionName = sharedUtils.convertCamelCaseToSpaces(sectionName); const menuItems = _.map(links, (link, i) => { const menuItemTitle = props.shouldReformatMenuItemNames ? _.capitalize(sharedUtils.convertDashesToSpaces(link.title)) : link.title; const finalLink = { ...link, title: menuItemTitle, }; return ; }); // tslint:disable-next-line:no-unused-variable return (
{finalSectionName.toUpperCase()} {menuItems}
); }); return (
{props.sidebarHeader}
{navigation}
); }; export interface MenuItemProps { link: ALink; screenWidth: ScreenWidths; } export interface MenuItemState { isActive: boolean; } export class MenuItem extends React.Component { constructor(props: MenuItemProps) { super(props); const isActive = window.location.hash.slice(1) === props.link.to; this.state = { isActive, }; } public render(): React.ReactNode { const isActive = this.state.isActive; return ( ); } private _onActivityChanged(isActive: boolean): void { this.setState({ isActive, }); } }