Files
Genarrative/src/components/common/PlatformModalCloseButton.tsx
T
kdletters 7ea463ed08 退役旧创作模板业务并保留数据壳
保留 SpacetimeDB 历史表、迁移白名单与最小兼容读取定义
移除旧创作前后端、worker、业务过程及纯业务 crate 的编译依赖
恢复现役创作、项目、我的入口及桌面移动导航
收紧 Vite、TypeScript、ESLint、Vitest 与静态资源退役边界
补齐开发栈、网关、原生壳和文档退役约束
2026-07-18 22:02:22 +08:00

91 lines
2.4 KiB
TypeScript

import { X } from 'lucide-react';
import type {
ButtonHTMLAttributes,
MouseEvent as ReactMouseEvent,
ReactNode,
} from 'react';
type PlatformModalCloseButtonVariant =
| 'profile'
| 'profileCompact'
| 'floating'
| 'floatingPlain'
| 'platformIcon'
| 'editorDark';
type PlatformModalCloseButtonPlacement = 'absolute' | 'inline';
type PlatformModalCloseButtonProps = Omit<
ButtonHTMLAttributes<HTMLButtonElement>,
'children'
> & {
label: string;
variant?: PlatformModalCloseButtonVariant;
icon?: ReactNode;
placement?: PlatformModalCloseButtonPlacement;
stopPropagation?: boolean;
};
const PLATFORM_MODAL_CLOSE_BUTTON_CLASS_BY_VARIANT: Record<
PlatformModalCloseButtonVariant,
string
> = {
profile:
'platform-modal-close flex h-9 w-9 items-center justify-center rounded-full',
profileCompact:
'platform-profile-icon-button flex h-8 w-8 items-center justify-center rounded-full',
floating:
'absolute right-3 top-3 z-10 flex h-8 w-8 items-center justify-center rounded-full bg-white/80 text-[#ff4056] shadow-sm',
floatingPlain:
'absolute right-3 top-2 z-10 flex h-8 w-8 items-center justify-center rounded-full text-[#ff4056]',
platformIcon:
'platform-icon-button disabled:cursor-not-allowed disabled:opacity-45',
editorDark:
'platform-modal-close-button--editor-dark rounded-full border border-white/10 bg-white/5 p-2 text-zinc-300 transition hover:bg-white/10 hover:text-white',
};
/**
* 平台弹窗关闭按钮。
* 收口个人中心和平台浮层里重复的关闭 aria、尺寸和视觉样式。
*/
export function PlatformModalCloseButton({
label,
variant = 'profile',
icon = <X className="h-4 w-4" />,
className,
type = 'button',
placement = 'absolute',
stopPropagation = false,
onClick,
title,
...buttonProps
}: PlatformModalCloseButtonProps) {
const handleClick = (event: ReactMouseEvent<HTMLButtonElement>) => {
if (stopPropagation) {
event.preventDefault();
event.stopPropagation();
}
onClick?.(event);
};
return (
<button
{...buttonProps}
type={type}
aria-label={label}
title={title ?? label}
onClick={handleClick}
className={[
PLATFORM_MODAL_CLOSE_BUTTON_CLASS_BY_VARIANT[variant],
placement === 'inline' ? 'relative shrink-0' : null,
className,
]
.filter(Boolean)
.join(' ')}
>
{icon}
</button>
);
}