收口标准泥点确认弹窗

新增 PlatformMudPointConfirmDialog 统一承接标准泥点消耗确认壳层
迁移拼图与抓大鹅创作工作台复用共享泥点确认弹窗
迁移拼图与抓大鹅结果页素材生成流程复用共享泥点确认弹窗
补充共享组件测试并更新 PlatformUiKit 收口文档与决策记录
This commit is contained in:
2026-06-10 21:57:49 +08:00
parent a33914aa5a
commit dbfdb9b99b
8 changed files with 138 additions and 41 deletions

View File

@@ -0,0 +1,53 @@
/* @vitest-environment jsdom */
import { fireEvent, render, screen, within } from '@testing-library/react';
import { expect, test, vi } from 'vitest';
import { PlatformMudPointConfirmDialog } from './PlatformMudPointConfirmDialog';
test('renders standard mud point confirmation copy and forwards confirm', () => {
const onClose = vi.fn();
const onConfirm = vi.fn();
render(
<PlatformMudPointConfirmDialog
open
points={8}
onClose={onClose}
onConfirm={onConfirm}
portal={false}
/>,
);
const dialog = screen.getByRole('dialog', { name: '确认消耗泥点' });
expect(within(dialog).getByText('消耗 8 泥点')).toBeTruthy();
fireEvent.click(within(dialog).getByRole('button', { name: '确定' }));
expect(onConfirm).toHaveBeenCalledTimes(1);
});
test('supports extra detail copy and close button override', () => {
const onClose = vi.fn();
render(
<PlatformMudPointConfirmDialog
open
points={7}
title="保存正式素材"
description="角色形象"
onClose={onClose}
onConfirm={vi.fn()}
showCloseButton={false}
portal={false}
>
</PlatformMudPointConfirmDialog>,
);
const dialog = screen.getByRole('dialog', { name: '保存正式素材' });
expect(within(dialog).getByText('消耗 7 泥点')).toBeTruthy();
expect(within(dialog).getByText('本次会覆盖当前待确认素材。')).toBeTruthy();
expect(screen.queryByRole('button', { name: '关闭' })).toBeNull();
});

View File

@@ -0,0 +1,64 @@
import type { ReactNode } from 'react';
import { UnifiedConfirmDialog } from './UnifiedConfirmDialog';
type PlatformMudPointConfirmDialogProps = {
open: boolean;
points: number;
onClose: () => void;
onConfirm: () => void;
confirmDisabled?: boolean;
confirmLabel?: string;
title?: string;
description?: ReactNode;
children?: ReactNode;
showCloseButton?: boolean;
portal?: boolean;
size?: 'sm' | 'md';
overlayClassName?: string;
panelClassName?: string;
};
/**
* 平台泥点消耗确认弹窗。
* 统一承接“确认消耗泥点 + 消耗 N 泥点”的标准确认壳层,业务侧只保留点数与确认动作。
*/
export function PlatformMudPointConfirmDialog({
open,
points,
onClose,
onConfirm,
confirmDisabled = false,
confirmLabel = '确定',
title = '确认消耗泥点',
description,
children,
showCloseButton = true,
portal = true,
size = 'sm',
overlayClassName,
panelClassName,
}: PlatformMudPointConfirmDialogProps) {
return (
<UnifiedConfirmDialog
open={open}
title={title}
description={description}
onClose={onClose}
onConfirm={onConfirm}
confirmLabel={confirmLabel}
confirmDisabled={confirmDisabled}
showCancel
showCloseButton={showCloseButton}
portal={portal}
size={size}
overlayClassName={overlayClassName}
panelClassName={panelClassName}
>
<div className="space-y-2">
<div className="font-semibold"> {points} </div>
{children}
</div>
</UnifiedConfirmDialog>
);
}