mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 03:10:08 +08:00
* feat(input): add new input component and update eslint config
Add new custom input component to replace antd and heroui inputs
Update eslint config to enforce using the new input component
* feat(input): refactor input component to support compound pattern
Add new Input component with support for Password and Button variants through compound pattern. Move input implementation to new directory structure and enhance with label and caption support. Remove old input implementation.
* refactor(input): consolidate input components and update exports
Move input component files to lowercase directory and simplify structure
Remove unused button and password input components
Update exports in components index file
* refactor: replace antd Input with @cherrystudio/ui Input across components
* feat(primitives): add textarea component to ui primitives
* feat(primitives): add input-group component with variants and controls
build: update @radix-ui/react-slot dependency to v1.2.4
* refactor(ui): simplify input component and update usage
Remove complex Input component implementation and replace with simpler version
Update components to use new Input and Textarea components from ui package
* feat(ui): add composite input component and utility functions
- Introduce new CompositeInput component with variants and password toggle
- Add utility functions for null/undefined conversion
- Export new components and types from index
- Update input props interface and usage in input-group
* feat(Input): refactor CompositeInput component and add stories
- Refactor CompositeInput component with improved variants and styling
- Add comprehensive Storybook stories for Input, InputGroup and CompositeInput components
- Implement password toggle functionality and button variants
- Include accessibility features and interactive examples
* feat(input): improve disabled state styling and behavior
- Add disabled state variants for input components
- Ensure password toggle button respects disabled state
- Update disabled styling for better visual consistency
- Add storybook examples for disabled password inputs
* feat(input): add validation states and form examples
- Implement validation states for input components
- Add real-time validation examples
- Create form validation demos for different input types
- Update styling for disabled and invalid states
* feat(input): add prefix support for email variant input
Add prefix variants styling and prefix prop to CompositeInput component to support email inputs with fixed prefixes. Update stories to demonstrate various prefix use cases and interactive examples.
* refactor(Input): simplify content rendering logic by removing useMemo hooks
The startContent and endContent memoized values were removed and their logic was inlined directly in the JSX. This makes the code more straightforward and removes unnecessary memoization overhead since the calculations are simple.
* feat(Input): add select variant to CompositeInput component
Add new 'select' variant to CompositeInput component with support for select dropdown groups and items. Includes styling variants, type exports, and comprehensive storybook examples demonstrating various use cases like currency input, URL with protocol, phone with country code, and temperature with unit selectors.
* Revert "refactor: replace antd Input with @cherrystudio/ui Input across components"
This reverts commit
|
||
|---|---|---|
| .. | ||
| .storybook | ||
| design-reference | ||
| icons | ||
| scripts | ||
| src | ||
| stories | ||
| .gitignore | ||
| components.json | ||
| MIGRATION_STATUS.md | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
| tsdown.config.ts | ||
@cherrystudio/ui
Cherry Studio UI 组件库 - 为 Cherry Studio 设计的 React 组件集合
✨ 特性
- 🎨 设计系统: 完整的 CherryStudio 设计令牌(17种颜色 × 11个色阶 + 语义化主题)
- 🌓 Dark Mode: 开箱即用的深色模式支持
- 🚀 Tailwind v4: 基于最新 Tailwind CSS v4 构建
- 📦 灵活导入: 2种样式导入方式,满足不同使用场景
- 🔷 TypeScript: 完整的类型定义和智能提示
- 🎯 零冲突: CSS 变量隔离,不覆盖用户主题
🚀 快速开始
安装
npm install @cherrystudio/ui
# peer dependencies
npm install framer-motion react react-dom tailwindcss
两种使用方式
方式 1:完整覆盖 ✨
使用完整的 CherryStudio 设计系统,所有 Tailwind 类名映射到设计系统。
/* app.css */
@import '@cherrystudio/ui/styles/theme.css';
特点:
- ✅ 直接使用标准 Tailwind 类名(
bg-primary、bg-red-500、p-md、rounded-lg) - ✅ 所有颜色使用设计师定义的值
- ✅ 扩展的 Spacing 系统(
p-5xs~p-8xl,共 16 个语义化尺寸) - ✅ 扩展的 Radius 系统(
rounded-4xs~rounded-3xl,共 11 个圆角) - ⚠️ 会完全覆盖 Tailwind 默认主题
示例:
<Button className="bg-primary text-red-500 p-md rounded-lg">
{/* bg-primary → 品牌色(lime-500) */}
{/* text-red-500 → 设计师定义的红色 */}
{/* p-md → 2.5rem(spacing-md) */}
{/* rounded-lg → 2.5rem(radius-lg) */}
</Button>
{/* 扩展的工具类 */}
<div className="p-5xs">最小间距 (0.5rem)</div>
<div className="p-xs">超小间距 (1rem)</div>
<div className="p-sm">小间距 (1.5rem)</div>
<div className="p-md">中等间距 (2.5rem)</div>
<div className="p-lg">大间距 (3.5rem)</div>
<div className="p-xl">超大间距 (5rem)</div>
<div className="p-8xl">最大间距 (15rem)</div>
<div className="rounded-4xs">最小圆角 (0.25rem)</div>
<div className="rounded-xs">小圆角 (1rem)</div>
<div className="rounded-md">中等圆角 (2rem)</div>
<div className="rounded-xl">大圆角 (3rem)</div>
<div className="rounded-round">完全圆角 (999px)</div>
方式 2:选择性覆盖 🎯
只导入设计令牌(CSS 变量),手动选择要覆盖的部分。
/* app.css */
@import 'tailwindcss';
@import '@cherrystudio/ui/styles/tokens.css';
/* 只使用部分设计系统 */
@theme {
--color-primary: var(--cs-primary); /* 使用 CS 的主色 */
--color-red-500: oklch(...); /* 使用自己的红色 */
--spacing-md: var(--cs-size-md); /* 使用 CS 的间距 */
--radius-lg: 1rem; /* 使用自己的圆角 */
}
特点:
- ✅ 不覆盖任何 Tailwind 默认主题
- ✅ 通过 CSS 变量访问所有设计令牌(
var(--cs-primary)、var(--cs-red-500)) - ✅ 精细控制哪些使用 CS、哪些保持原样
- ✅ 适合有自己设计系统但想借用部分 CS 设计令牌的场景
示例:
{/* 通过 CSS 变量使用 CS 设计令牌 */}
<button style={{ backgroundColor: 'var(--cs-primary)' }}>
使用 CherryStudio 品牌色
</button>
{/* 保持原有的 Tailwind 类名不受影响 */}
<div className="bg-red-500">
使用 Tailwind 默认的红色
</div>
{/* 可用的 CSS 变量 */}
<div style={{
color: 'var(--cs-primary)', // 品牌色
backgroundColor: 'var(--cs-red-500)', // 红色-500
padding: 'var(--cs-size-md)', // 间距
borderRadius: 'var(--cs-radius-lg)' // 圆角
}} />
Provider 配置
在你的 App 根组件中添加 HeroUI Provider:
import { HeroUIProvider } from '@heroui/react'
function App() {
return (
<HeroUIProvider>
{/* 你的应用内容 */}
</HeroUIProvider>
)
}
使用
基础组件
import { Button, Input } from '@cherrystudio/ui'
function App() {
return (
<div>
<Button variant="primary" size="md">
点击我
</Button>
<Input
type="text"
placeholder="请输入内容"
onChange={(value) => console.log(value)}
/>
</div>
)
}
分模块导入
// 只导入组件
import { Button } from '@cherrystudio/ui/components'
// 只导入工具函数
import { cn, formatFileSize } from '@cherrystudio/ui/utils'
开发
# 安装依赖
yarn install
# 开发模式(监听文件变化)
yarn dev
# 构建
yarn build
# 类型检查
yarn type-check
# 运行测试
yarn test
目录结构
src/
├── components/ # React 组件
│ ├── Button/ # 按钮组件
│ ├── Input/ # 输入框组件
│ └── index.ts # 组件导出
├── hooks/ # React Hooks
├── utils/ # 工具函数
├── types/ # 类型定义
└── index.ts # 主入口文件
组件列表
Button 按钮
支持多种变体和尺寸的按钮组件。
Props:
variant: 'primary' | 'secondary' | 'outline' | 'ghost' | 'danger'size: 'sm' | 'md' | 'lg'loading: booleanfullWidth: booleanleftIcon/rightIcon: React.ReactNode
Input 输入框
带有错误处理和密码显示切换的输入框组件。
Props:
type: 'text' | 'password' | 'email' | 'number'error: booleanerrorMessage: stringonChange: (value: string) => void
Hooks
useDebounce
防抖处理,延迟执行状态更新。
useLocalStorage
本地存储的 React Hook 封装。
useClickOutside
检测点击元素外部区域。
useCopyToClipboard
复制文本到剪贴板。
工具函数
cn(...inputs)
基于 clsx 的类名合并工具,支持条件类名。
formatFileSize(bytes)
格式化文件大小显示。
debounce(func, delay)
防抖函数。
throttle(func, delay)
节流函数。
许可证
MIT