import React, { useState, useCallback, useEffect } from 'react'; import { Step } from '@douyinfe/semi-foundation/aiChatDialogue/foundation'; import Collapsible from '../../../collapsible'; import { cssClasses } from '@douyinfe/semi-foundation/aiChatDialogue/constants'; import { IconStoryStroked, IconChevronDown, IconChevronUp, IconMore, IconSearch } from '@douyinfe/semi-icons'; const prefixCls = cssClasses.PREFIX_STEP; const { PREFIX_CONTENT } = cssClasses; export interface DialogueStepWidgetProps { steps: Step[] } export const DialogueStepWidget = (props: DialogueStepWidgetProps) => { const [openIndexes, setOpenIndexes] = useState>(() => new Set(props.steps.map((_, i) => i))); useEffect(() => { setOpenIndexes(new Set(props.steps.map((_, i) => i))); }, [props.steps]); const toggleOpen = useCallback((idx: number) => { setOpenIndexes(prev => { const next = new Set(prev); if (next.has(idx)) { next.delete(idx); } else { next.add(idx); } return next; }); }, []); const completedIcon = () => { return ; }; const loadingIcon = () => { return ; }; return (
{props.steps.map((item: Step, index) => { const { summary, status, actions } = item; const isOpen = openIndexes.has(index); const actionsLength = actions?.length; return (
toggleOpen(index)} onKeyDown={e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); toggleOpen(index); } }} >
{ status === 'completed' ? completedIcon() : loadingIcon() }
{summary}
{ actionsLength > 0 && (
{isOpen ? : }
) }
{actions?.map((action, i) => (
{action.summary}
{action.icon} {action.description}
))}
); })}
); };