import React, { useEffect, useState } from 'react'; import cls from 'classnames'; import { isValid } from '@designable/shared'; import { IconWidget, TextWidget } from '../../widgets'; import { usePrefix } from '../../hooks'; import './styles.less'; export type CompositePanelContentItemProps = { shape?: 'tab' | 'button' | 'link'; title?: React.ReactNode; icon?: React.ReactNode; href?: string; onClick?: (e: React.MouseEvent) => void; extra?: React.ReactNode; }; export type CompositePanelContentProps = { direction?: 'left' | 'right'; activeKey?: number; visible?: boolean; onClose?: () => void; }; const parseItems = ( children: React.ReactNode, ): React.PropsWithChildren[] => { const items: any[] = []; React.Children.forEach(children, (child: any) => { if (child['type'] === CompositePanelContent.Item) { items.push(child['props']); } }); return items; }; export const CompositePanelContent: React.FC & { Item?: React.FC; } = ({ direction, activeKey, visible, onClose, children }) => { const prefix = usePrefix('composite-panel-content'); const items = parseItems(children); const currentItem = activeKey !== undefined ? items?.[activeKey] : undefined; const content = currentItem?.children; const renderContent = () => { if (!currentItem || !visible) return; return (
{currentItem.title}
{currentItem.extra}
{content}
); }; return {renderContent()}; }; CompositePanelContent.Item = () => { return ; };