继续扩展共享组件并收口入口页面
新增 PlatformBackActionButton 共享返回动作与行为测试 迁移登录、绑定手机号和世界实体目录的共享组件直引 扩展示展示页示例并同步组件库文档与决策记录
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/* @vitest-environment jsdom */
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { expect, test } from 'vitest';
|
||||
|
||||
import { PlatformBackActionButton } from './index';
|
||||
|
||||
test('renders compact back action button by default', () => {
|
||||
render(<PlatformBackActionButton />);
|
||||
|
||||
const button = screen.getByRole('button', { name: '返回' });
|
||||
|
||||
expect(button.className).toContain('platform-button--ghost');
|
||||
expect(button.className).toContain('min-h-0');
|
||||
expect(button.className).toContain('text-[11px]');
|
||||
expect(button.className).toContain('gap-1.5');
|
||||
expect(button.querySelector('svg')?.className.baseVal).toContain('h-3.5');
|
||||
expect(button.getAttribute('type')).toBe('button');
|
||||
});
|
||||
|
||||
test('supports regular variant and editor dark surface', () => {
|
||||
render(
|
||||
<PlatformBackActionButton
|
||||
label="返回编辑"
|
||||
variant="regular"
|
||||
surface="editorDark"
|
||||
/>,
|
||||
);
|
||||
|
||||
const button = screen.getByRole('button', { name: '返回编辑' });
|
||||
|
||||
expect(button.className).toContain('platform-action-button--editor-dark');
|
||||
expect(button.className).toContain('text-sm');
|
||||
expect(button.className).toContain('gap-2');
|
||||
expect(button.querySelector('svg')?.className.baseVal).toContain('h-4');
|
||||
});
|
||||
@@ -0,0 +1,53 @@
|
||||
import { ArrowLeft } from 'lucide-react';
|
||||
import type { ButtonHTMLAttributes } from 'react';
|
||||
|
||||
import { PlatformActionButton } from './PlatformActionButton';
|
||||
import type { PlatformActionButtonSurface } from './platformActionButtonModel';
|
||||
|
||||
export type PlatformBackActionButtonVariant = 'compact' | 'regular';
|
||||
|
||||
export type PlatformBackActionButtonProps = Omit<
|
||||
ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
'children'
|
||||
> & {
|
||||
label?: string;
|
||||
variant?: PlatformBackActionButtonVariant;
|
||||
surface?: PlatformActionButtonSurface;
|
||||
};
|
||||
|
||||
const VARIANT_CLASS: Record<PlatformBackActionButtonVariant, string> = {
|
||||
compact: 'gap-1.5 py-1.5 text-[11px]',
|
||||
regular: 'gap-2 py-2 text-sm',
|
||||
};
|
||||
|
||||
const ICON_CLASS: Record<PlatformBackActionButtonVariant, string> = {
|
||||
compact: 'h-3.5 w-3.5',
|
||||
regular: 'h-4 w-4',
|
||||
};
|
||||
|
||||
/**
|
||||
* 平台轻量返回动作按钮。
|
||||
* 统一结果页、工作台等白底场景里的“左箭头 + 返回文案”按钮骨架。
|
||||
*/
|
||||
export function PlatformBackActionButton({
|
||||
label = '返回',
|
||||
variant = 'compact',
|
||||
surface = 'platform',
|
||||
className,
|
||||
...buttonProps
|
||||
}: PlatformBackActionButtonProps) {
|
||||
return (
|
||||
<PlatformActionButton
|
||||
{...buttonProps}
|
||||
surface={surface}
|
||||
tone="ghost"
|
||||
size="xs"
|
||||
className={['min-h-0 self-start', VARIANT_CLASS[variant], className]
|
||||
.filter(Boolean)
|
||||
.join(' ')}
|
||||
>
|
||||
<ArrowLeft className={ICON_CLASS[variant]} />
|
||||
{label}
|
||||
</PlatformActionButton>
|
||||
);
|
||||
}
|
||||
@@ -10,6 +10,11 @@ export { PlatformActionButton } from './PlatformActionButton';
|
||||
export { getPlatformActionButtonClassName } from './platformActionButtonModel';
|
||||
export type { PlatformAsyncStatePanelProps } from './PlatformAsyncStatePanel';
|
||||
export { PlatformAsyncStatePanel } from './PlatformAsyncStatePanel';
|
||||
export type {
|
||||
PlatformBackActionButtonProps,
|
||||
PlatformBackActionButtonVariant,
|
||||
} from './PlatformBackActionButton';
|
||||
export { PlatformBackActionButton } from './PlatformBackActionButton';
|
||||
export type { PlatformBadgeProps, PlatformBadgeTone } from './PlatformBadge';
|
||||
export { PlatformBadge } from './PlatformBadge';
|
||||
export type {
|
||||
|
||||
Reference in New Issue
Block a user