# Pika 其他组件开发计划与规范 > 基于 Pika 设计规范,参照 Ant Design 剩余组件体系,构建专为 AI 代码生成优化的其他组件库。 --- ## 一、组件总览 Pika 其他组件分为以下几类: | 类别 | 组件 | antd 对标 | 优先级 | |------|------|-----------|--------| | **通用组件** | Affix, Anchor, App, ConfigProvider, BackTop, Watermark | Ant Design 通用组件 | P0-P1 | | **容器组件** | Drawer | Ant Design 抽屉 | P1 | | **数据展示** | List | Ant Design 列表 | P1 | --- ## 二、核心设计原则(与根规范一致) ### 2.1 AI 优先设计原则 | 原则 | 说明 | |------|------| | **零歧义** | Props 名称自解释,无简称、无隐式行为 | | **零默认假设** | 所有视觉行为显式声明 | | **一致性** | 相同概念用相同 prop 名 | | **扁平化** | 最多一层嵌套 | | **确定性** | 相同输入始终产生相同输出 | ### 2.2 统一尺寸体系 所有组件使用统一的三级尺寸体系: | 级别 | 说明 | 常用值 | |------|------|-------| | **small** | 小尺寸 | 紧凑列表、表格内 | | **middle** | 中尺寸(默认) | 默认使用 | | **large** | 大尺寸 | 突出显示、重点元素 | --- ## 三、通用组件 ### 3.1 Affix 固钉 #### 组件定位 将页面元素固定在可视区域内,常用于导航栏、侧边栏、回到顶部按钮等。 #### Props 定义 ```tsx export interface AffixProps { /** 距离窗口顶部达到指定偏移量后触发 */ offsetTop?: number; /** 距离窗口底部达到指定偏移量后触发 */ offsetBottom?: number; /** 指定 Affix 挂载的 HTML 节点 */ target?: () => HTMLElement | null; /** 监听滚动事件的容器 */ getContainer?: () => HTMLElement | Window; /** 固定状态改变时触发的回调 */ onChange?: (isAffixed: boolean) => void; /** 子元素 */ children?: ReactNode; /** 样式类名 */ className?: string; /** 自定义样式 */ style?: React.CSSProperties; } ``` #### 使用示例 ```tsx import { Affix, Button } from '@Pika/ui/affix'; // 基本使用 ; // 固钉在底部 ; // 自定义容器 document.getElementById('scroll-container')} offsetTop={10}> ; ``` #### Design Token ```css --nv-affix-z-index: 10; ``` #### 开发优先级:P1 --- ### 3.2 Anchor 锚点 #### 组件定位 用于跳转到页面指定位置,或显示当前滚动位置。 #### Props 定义 ```tsx export interface AnchorProps { /** 锚点方向 */ direction?: 'vertical' | 'horizontal'; /** 当前激活的锚点链接 */ activeLink?: string; /** 锚点滚动偏移量 */ targetOffset?: number; /** 点击锚点链接的回调 */ onClick?: ( e: React.MouseEvent, link: { href: string; title: ReactNode } ) => void; /** 锚点链接改变时的回调 */ onChange?: (currentActiveLink: string) => void; /** 获取锚点容器 */ getContainer?: () => HTMLElement | Window; /** 是否改变 hash */ hash?: boolean; /** 子元素 */ children?: ReactNode; /** 样式类名 */ className?: string; /** 自定义样式 */ style?: React.CSSProperties; } export interface AnchorLinkProps { /** 锚点链接 */ href: string; /** 锚点文本 */ title: ReactNode; /** 子元素 */ children?: ReactNode; } ``` #### 使用示例 ```tsx import { Anchor } from '@Pika/ui/anchor'; // 基本使用 ; ``` #### Design Token ```css --nv-anchor-link-height: 32px; --nv-anchor-link-color: var(--nv-text-color-secondary); --nv-anchor-link-active-color: var(--nv-color-primary); --nv-anchor-link-active-width: 2px; --nv-anchor-wrapper-padding: 4px 0; ``` #### 开发优先级:P1 --- ### 3.3 App 包裹组件 #### 组件定位 提供全局上下文,用于 Message、Modal、Notification 等组件的静态方法调用。 #### Props 定义 ```tsx export interface AppProps { /** 子元素 */ children?: ReactNode; } export interface AppContextProps { message: MessageStatic; modal: ModalStatic; notification: NotificationStatic; } export declare function useApp(): AppContextProps; ``` #### 使用示例 ```tsx import { App, Button } from '@Pika/ui/app'; // 基本使用 function AppDemo() { const { message, modal, notification } = App.useApp(); const showMessage = () => { message.success('操作成功'); }; const showModal = () => { modal.info({ title: '提示', content: '这是一条提示信息' }); }; return ( ); } ``` #### 开发优先级:P0 --- ### 3.4 ConfigProvider 全局配置 #### 组件定位 为组件提供统一的全局配置,包括主题、语言、国际化等。 #### Props 定义 ```tsx export interface ConfigProviderProps { /** 主题配置 */ theme?: { token?: Record; components?: Record; algorithm?: 'default' | 'dark' | 'compact' | Array<'default' | 'dark' | 'compact'>; }; /** 语言包 */ locale?: Record; /** 全局 zIndex */ zIndex?: number; /** 设置主题色 */ colorPrimary?: string; /** 设置图标前缀 */ iconPrefixCls?: string; /** 设置组件类名前缀 */ prefixCls?: string; /** 设置弹框的默认渲染容器 */ getPopupContainer?: (node: HTMLElement) => HTMLElement; /** 子元素 */ children?: ReactNode; } ``` #### 使用示例 ```tsx import { ConfigProvider, Button } from '@Pika/ui/config-provider'; // 基本使用 ; ``` #### Design Token 与根设计规范中的 Token 一致。 #### 开发优先级:P0 --- ### 3.5 BackTop 回到顶部 #### 组件定位 提供快速回到页面顶部的功能。 #### Props 定义 ```tsx export interface BackTopProps { /** 距离顶部多少像素时显示 */ visibilityHeight?: number; /** 点击回调 */ onClick?: () => void; /** 监听滚动的容器 */ target?: () => HTMLElement | Window; /** 子元素 */ children?: ReactNode; /** 样式类名 */ className?: string; /** 自定义样式 */ style?: React.CSSProperties; } ``` #### 使用示例 ```tsx import { BackTop } from '@Pika/ui/back-top'; // 基本使用 ; // 自定义图标
UP
; ``` #### Design Token ```css --nv-back-top-size: 40px; --nv-back-top-z-index: 10; --nv-back-top-color: var(--nv-color-primary); --nv-back-top-hover-color: var(--nv-color-primary-hover); ``` #### 开发优先级:P1 --- ### 3.6 Watermark 水印 #### 组件定位 为页面或元素添加水印,防止截图泄露或证明来源。(注意:在 FEEDBACK_COMPONENTS.md 中已有定义,这里补充完整) #### Props 定义 ```tsx export interface WatermarkProps { /** 水印文字 */ content?: string | string[]; /** 自定义图片水印 */ image?: string; /** 水印宽度(文字模式时为单个文字宽度) */ width?: number; /** 水印高度(文字模式时为单个文字高度) */ height?: number; /** 旋转角度 */ rotate?: number; /** 水印之间的水平间距 */ gap?: [number, number]; /** 水印在 canvas 上绘制时的偏移量 */ offset?: [number, number]; /** 文字样式 */ font?: { color?: string; fontSize?: number; fontFamily?: string; fontWeight?: 'normal' | 'light' | 'weight' | number; }; /** 水印层级 */ zIndex?: number; /** 子元素 */ children?: ReactNode; } ``` #### 使用示例 ```tsx import { Watermark, Card } from '@Pika/ui/watermark'; // 基本使用

这是一些内容,会有水印覆盖

; // 多行水印
内容
; // 自定义样式
内容
; ``` #### Design Token ```css --nv-watermark-font-size: 14px; --nv-watermark-font-color: rgba(0, 0, 0, 0.08); --nv-watermark-rotate: -22deg; --nv-watermark-gap: [100, 100]; --nv-watermark-z-index: 9; ``` #### 开发优先级:P3 --- ## 四、容器组件 ### 4.1 Drawer 抽屉 #### 组件定位 抽屉组件,用于从屏幕边缘滑出内容面板,常用于详情页、表单页、筛选页等。 #### Props 定义 ```tsx export type DrawerPlacement = 'top' | 'right' | 'bottom' | 'left'; export type DrawerSize = 'small' | 'middle' | 'large' | number | string; export interface DrawerProps { /** 抽屉是否可见 */ open: boolean; /** 抽屉标题 */ title?: ReactNode; /** 抽屉宽度(placement 为 left/right 时生效) */ width?: number | string; /** 抽屉高度(placement 为 top/bottom 时生效) */ height?: number | string; /** 抽屉尺寸预设 */ size?: DrawerSize; /** 抽屉放置位置 */ placement?: DrawerPlacement; /** 是否显示遮罩 */ mask?: boolean; /** 点击遮罩是否关闭 */ maskClosable?: boolean; /** 是否显示右上角关闭按钮 */ closable?: boolean; /** 自定义关闭图标 */ closeIcon?: ReactNode; /** 点击关闭图标的回调 */ onClose?: () => void; /** 抽屉打开后的回调 */ afterOpenChange?: (open: boolean) => void; /** 抽屉的容器 */ getContainer?: HTMLElement | (() => HTMLElement) | null; /** 预渲染,防止抖动 */ forceRender?: boolean; /** 关闭时销毁 Drawer 里的子元素 */ destroyOnClose?: boolean; /** 抽屉的样式 */ style?: React.CSSProperties; /** 抽屉标题的样式 */ headerStyle?: React.CSSProperties; /** 抽屉内容的样式 */ bodyStyle?: React.CSSProperties; /** 自定义遮罩样式 */ maskStyle?: React.CSSProperties; /** 抽屉的类名 */ className?: string; /** 抽屉根元素的类名 */ rootClassName?: string; /** 是否支持键盘 esc 关闭 */ keyboard?: boolean; /** 子元素 */ children?: ReactNode; /** 抽屉页脚 */ footer?: ReactNode; /** 页脚的样式 */ footerStyle?: React.CSSProperties; /** 是否显示页脚 */ footer?: ReactNode | null; } ``` #### 使用示例 ```tsx import { Drawer, Button, Form, Input } from '@Pika/ui/drawer'; function DrawerDemo() { const [open, setOpen] = useState(false); return ( <> setOpen(false)} >

这是抽屉的内容

可以放置任何内容

); } // 表单抽屉 function FormDrawer() { const [open, setOpen] = useState(false); return ( <> setOpen(false)} footer={
} >