Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions src/chat-action/action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,42 @@ export const renderActions = (

const arrayActions: TdChatActionItem[] =
Array.isArray(actionBar) && actionBar.length > 0
? actionBar.map((action) => presetActions().find((item) => item.name === action))
? actionBar.map((action) => {
// 兼容preset的旧逻辑
if (typeof action === 'string') {
return presetActions().find((item) => item.name === action);
}
return action;
})
: presetActions();

return (
<div className={className}>
{arrayActions.map((item, index) =>
item.name === 'replay' && index + 1 !== arrayActions.length ? (
<div class={`${className}__refresh`}>
{item.render}
<span class={`${className}__refresh-line`} />
</div>
) : (
item.render
),
)}
{arrayActions.map((item, index) => {
if (!item) return null;
if (item.name === 'replay' && index + 1 !== arrayActions.length) {
return (
<div class={`${className}__refresh`}>
{item.render}
<span class={`${className}__refresh-line`} />
</div>
);
}
// preset action
if (item.render) return item.render;
// custom action
if (item.name) {
if (item.ignoreWrapper) {
return <slot name={item.name} />;
}
return (
<span class={`${className}__item__wrapper`}>
<slot name={item.name} />
</span>
);
}
return null;
})}
</div>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/chat-action/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type TdChatActionsName = 'copy' | 'good' | 'bad' | 'replay' | 'share';
export type TdChatActionItem = {
name: TdChatActionsName;
render: TNode;
ignoreWrapper?: boolean;
};

interface ChatActionProps {
Expand Down