import React from 'react'; import cls from 'classnames'; import { Button } from '@toy-box/toybox-ui'; import { IconWidget, TextWidget } from '../../widgets'; import { usePrefix } from '../../hooks'; import './styles.less'; export type CompositePanelProps = { direction?: 'left' | 'right'; defaultOpen?: boolean; defaultPinning?: boolean; defaultActiveKey?: number; activeKey?: number; setActiveKey?: (activeKey: number) => void; visible?: boolean; setVisible?: (isVisible: boolean) => void; }; export type CompositePanelItemProps = { shape?: 'tab' | 'button' | 'link'; title?: string; icon?: React.ReactNode; href?: string; onClick?: (e: React.MouseEvent) => void; extra?: React.ReactNode; }; const parseItems = ( children: React.ReactNode, ): React.PropsWithChildren[] => { const items: any[] = []; React.Children.forEach(children, (child: any) => { if (child['type'] === CompositePanel.Item) { items.push(child['props']); } }); return items; }; export const CompositePanel: React.FC & { Item?: React.FC; } = (props: any) => { const prefix = usePrefix('composite-panel'); const items = parseItems(props.children); return (
{items.map((item, index) => { const takeTab = () => { if (item.href) { return {item.icon}; } return ( } placement="bottom" icon={} /> ); }; const shape = item.shape ?? 'tab'; const Comp = shape === 'link' ? 'a' : 'div'; return ( { if (shape === 'tab') { if (index === props.activeKey) { props.setVisible(!props.visible); } else { props.setVisible(true); } props.setActiveKey(index); } item.onClick?.(e); }} > {takeTab()} ); })}
); }; CompositePanel.Item = () => { return ; };