import { Button, SideSheet, Tag } from '@douyinfe/semi-ui'; import { useId, useLayoutEffect, type ReactNode } from 'react'; export type WorkspaceSideSheetAction = { label: string; onClick: () => void; disabled?: boolean; loading?: boolean; theme?: 'solid' | 'light' | 'borderless'; type?: 'primary' | 'secondary' | 'tertiary' | 'warning' | 'danger'; }; export type WorkspaceSideSheetSummaryItem = { label: string; value: ReactNode; detail?: ReactNode; tone?: 'neutral' | 'primary' | 'success' | 'warning' | 'danger'; }; export type WorkspaceSideSheetBadgeColor = 'blue' | 'green' | 'orange' | 'red' | 'grey'; export type WorkspaceSideSheetProps = { className?: string; variant?: 'config' | 'detail' | 'task' | 'editor' | 'help' | 'action'; visible: boolean; ariaLabel: string; closeLabel?: string; dialogId?: string; title: ReactNode; description: ReactNode; icon?: ReactNode; badge?: ReactNode; badgeColor?: WorkspaceSideSheetBadgeColor; placement?: 'left' | 'right' | 'top' | 'bottom'; width?: string | number; height?: string | number; summaryItems?: WorkspaceSideSheetSummaryItem[]; footerNote?: ReactNode; secondaryActions?: WorkspaceSideSheetAction[]; primaryAction?: WorkspaceSideSheetAction; onCancel: () => void; children: ReactNode; }; export function WorkspaceSideSheet({ className = '', variant = 'config', visible, ariaLabel, closeLabel = `关闭${ariaLabel}`, dialogId, title, description, icon, badge, badgeColor = 'blue', placement = 'right', width = 460, height, summaryItems = [], footerNote, secondaryActions = [], primaryAction, onCancel, children }: WorkspaceSideSheetProps) { const sheetId = useId(); const sheetClassName = [`v2-workspace-${variant}-sidesheet`, className].filter(Boolean).join(' '); const hasFooter = Boolean(footerNote || secondaryActions.length || primaryAction); useLayoutEffect(() => { if (!visible) return; const apply = () => { const dialog = document.querySelector(`[data-workspace-sheet-id="${sheetId}"] .semi-sidesheet-inner`); dialog?.setAttribute('aria-label', ariaLabel); if (dialogId) dialog?.setAttribute('id', dialogId); dialog?.querySelector('.semi-sidesheet-close')?.setAttribute('aria-label', closeLabel); }; apply(); const frame = window.requestAnimationFrame(apply); return () => window.cancelAnimationFrame(frame); }, [ariaLabel, closeLabel, dialogId, sheetId, visible]); return {icon ? : null} {title}{description} {badge ? {badge} : null} } onCancel={onCancel} footer={hasFooter ?
{footerNote}
{secondaryActions.map((action) => )} {primaryAction ? : null}
: null} >
{summaryItems.length ?
{summaryItems.map((item) => {item.label} {item.value} {item.detail ? {item.detail} : null} )}
: null}
{children}
; }