import { Drawer, Tabs } from 'antd'; import { AiOutlineMenuUnfold } from 'react-icons/ai'; import React, { useCallback, useState } from 'react'; import { useResponsive } from 'ahooks'; import { PicexTool } from '../tools/types'; import { usePicexCtx, usePicexDispatch } from '../core/context'; import './ToolBar.css'; import { cn } from '@/utils/cn'; export interface PicexToolBarProps { tools: PicexTool[]; value?: null | string; onChange?: (key: string) => void; style?: React.CSSProperties; className?: string; activeToolKey?: string; } /** * 左侧工具栏 * @description 根据配置初始化并渲染工具栏 */ export function PicexToolBar({ tools, value, activeToolKey, onChange, style, className, }: PicexToolBarProps) { const ctx = usePicexCtx(); const dispatch = usePicexDispatch(); const sizes = useResponsive(); const [flags, setFlags] = useState>({}); const onToolChange = useCallback( (v: string) => { onChange?.(v); setFlags((prev) => { return { ...prev, [v]: true, }; }); }, [onChange], ); return ( { return { key: tool.key, label: ( {tool.renderIcon?.({ ctx, dispatch })} {tool.name} ), children: sizes.lg ? ( tool.renderPanel?.({ ctx, dispatch }) ) : ( <> setFlags((prev) => ({ ...prev, [tool.key]: false })) } > {tool.renderPanel?.({ ctx, dispatch })} ), disabled: tool.disabled, }; })} /> ); }