upvote-button.md
基本信息
- 类型: React Client 组件
- 路径:
./src/components/prompts/upvote-button.tsx
功能描述
投票按钮组件,用于对Prompt进行投票/取消投票。支持多种尺寸样式(默认、小尺寸、圆形),包含未登录提示弹窗。
导出内容
UpvoteButton- 主组件UpvoteButtonProps- Props接口
Props 接口
| 属性 | 类型 | 说明 | ||
|---|---|---|---|---|
| promptId | string | Prompt ID | ||
| initialVoted | boolean | 初始投票状态 | ||
| initialCount | number | 初始投票数 | ||
| isLoggedIn | boolean | 用户是否登录 | ||
| size | "sm" \ | "default" \ | "circular" | 按钮尺寸 |
| showLabel | boolean | 是否显示标签文本 |
尺寸样式
default- 默认按钮样式sm- 小尺寸文本链接样式circular- 圆形大按钮样式
依赖
react- React核心next-intl- 国际化next/link- Next.js链接lucide-react- 图标库@/components/ui/button- 按钮组件@/components/ui/dialog- 对话框组件sonner- Toast通知@/lib/utils- 工具函数@/lib/analytics- 分析工具
API端点
- POST
/api/prompts/{id}/vote- 投票 - DELETE
/api/prompts/{id}/vote- 取消投票
相关组件
PromptCard- 集成投票按钮PromptList- Prompt列表