cherry-studio/packages/ui/MIGRATION_STATUS.md
Phantom 4f746842a5
refactor: migrate Flex from antd to custom Flex component (#10083)
* refactor(components): rename HStack and VStack to RowFlex and ColFlex for clarity

rename HStack to RowFlex and VStack to ColFlex across all components to better reflect their purpose as flex containers with row and column directions. This improves code readability and maintainability while keeping the same functionality. All references to these components have been updated accordingly.

* refactor(layout): migrate layout components from .ts to .tsx

The layout components have been moved from TypeScript (.ts) to TypeScript with JSX (.tsx) to better support JSX syntax and improve type safety. The functionality remains unchanged.

* refactor(Layout): convert styled Box component to functional component

Improve maintainability by converting styled-component to a functional component with explicit style props. This provides better type safety through CSSProperties interface and makes the component easier to debug.

* refactor(Layout): restructure Box component and convert styled components to functional

- Replace styled-components with functional components for Stack and Center
- Rename style variable to _style in Box component to avoid naming conflict
- Add style prop to Box component to allow external style overrides

* refactor(components): rename HSpaceBetweenStack to SpaceBetweenRowFlex for clarity

* refactor(Layout): pass through props in Stack components

Allow additional props to be passed to Stack and its variants for better flexibility. Convert RowFlex from styled component to regular component for consistency.

* refactor(Layout): convert SpaceBetweenRowFlex from styled to component

Improve maintainability by converting styled component to a regular component that explicitly passes justifyContent prop

* refactor(Layout): convert ColFlex to component and type RowFlex props

Improve type safety by explicitly omitting flexDirection from StackProps and convert ColFlex from styled component to regular component for consistency

* refactor(Layout): convert BaseTypography from styled to component

Improve type safety and maintainability by converting styled component to regular React component with TypeScript interface

* refactor(Layout): remove unused BaseTypography component

* refactor(Layout): remove unused Container component and interface

* refactor(layout): rename Stack to Flex and use CSSProperties types

The Stack component was renamed to Flex to better reflect its purpose and align with common naming conventions. The interface properties were also updated to use CSSProperties types for better type safety and consistency with CSS standards.

* refactor(Layout): move FlexProps interface and comment out unused ButtonProps

Clean up component interfaces by moving FlexProps closer to its usage and commenting out unused ButtonProps interface to reduce clutter

* refactor(layout): standardize flex props from alignItems/justifyContent to align/justify

The changes standardize the flex-related props in the Layout component and across multiple files from using alignItems/justifyContent to the shorter align/justify. This improves consistency and reduces verbosity in the codebase while maintaining the same functionality.

All instances of alignItems have been replaced with align and justifyContent with justify in Flex, RowFlex, ColFlex and related components. The changes are purely syntactic and do not affect the actual layout behavior.

This refactoring makes the code more maintainable by using a consistent naming convention for flex properties throughout the application.

* refactor(Layout): extend BoxProps with React div props

* feat(Layout): add flexWrap prop to Flex component interface

Add flexWrap property to FlexProps interface to support CSS flex-wrap functionality. Also replace antd Flex with custom Flex component in TagFilterSection.

* refactor(components): replace antd Flex with custom Layout components

Consolidate Flex component usage across multiple files by replacing antd's Flex with custom Layout components (Flex, ColFlex, RowFlex) for better maintainability and consistency

* refactor(components):  migrate antd Flex tu custom Flex

* refactor(components): update layout component usage for consistency

replace RowFlex with ColFlex where appropriate and align prop names

* refactor(tests): rename HStack to RowFlex in test components

Update test snapshots and mock components to reflect the component name change from HStack to RowFlex
Remove unused data-vertical attribute from preview container

* refactor(Layout): pass through props and merge styles in Box and Flex components

Improve component flexibility by allowing additional props to pass through and properly merging style objects in both Box and Flex components

* refactor(Layout): make Flex component props optional with undefined defaults

* test: update TagFilterSection snapshot to include wrap style

* perf(Layout): optimize Box component style calculation with useMemo

* docs: fix typo in Layout component comment

* refactor(Layout): update BoxProps to use CSSProperties types

Standardize prop types by using CSSProperties for style-related props to improve type safety and consistency with React's style system

* feat(Layout): add wrap prop to Flex component

* style(TagFilterSection): update snapshot styling to use flex-wrap property

* refactor(Layout): simplify layout components by using Tailwind CSS classes

Remove custom style calculations and props in favor of Tailwind utility classes

* refactor: replace inline styles with Tailwind CSS classes for consistent styling

style: update spacing and alignment utilities across components

* refactor(tests): update test snapshots to use tailwind classes

Replace inline styles with tailwind classes in test snapshots and update test assertions to match. This improves consistency with the codebase's styling approach.

* style: adjust spacing and gaps in UI components for consistency

* style: replace inline styles with tailwind classes for consistency

Refactor various components to use tailwind classes instead of inline styles to maintain consistency and improve readability. Changes include:
- Replacing style attributes with tailwind classes for spacing, margins, and padding
- Standardizing gap sizes across components
- Using tailwind for width, height, and other layout properties
- Updating test files to match new class names

* style(settings): replace inline styles with tailwind classes for consistency

Refactor settings components to use tailwind gap utility instead of inline styles for better maintainability and consistency across the codebase

* refactor(styles): replace inline styles with tailwind classes for consistency

* feat(eslint): add rule to restrict antd Flex imports

Enforce using custom Layout components instead of antd's Flex by adding a restricted import rule

* refactor: migrate flex layout from antd props to tailwind classes

- Replace antd Flex component props with tailwind classes for consistency
- Update gap and alignment values to use tailwind's spacing scale
- Remove unused antd Flex imports to clean up dependencies

* style(settings): adjust spacing and layout in various settings components

- Add gap spacing between elements in multiple settings components
- Remove redundant flex class in some components
- Standardize gap sizes across related components

* refactor(ui): replace inline styles with tailwind classes for consistency

Replace various inline style attributes with equivalent tailwind classes across multiple components to maintain consistent styling approach. Changes include margin, padding, width, and flex properties.

- Convert style attributes to tailwind classes
- Standardize spacing values using tailwind's spacing scale
- Improve maintainability by using utility classes

* style(ui): adjust spacing in model list group header

* style(css): wrap base styles in @layer for better organization

* style(css): fix indentation and nesting in global styles

* style(settings): adjust spacing in model list and convert subtitle to cn

Refactor SettingSubtitle to use cn utility for better className handling
Add gap spacing between model list items for improved layout

* style(css): move some styles from base layer to outer in index.css

* refactor(components): replace HStack with RowFlex for consistency

Update layout components to use RowFlex instead of HStack to maintain consistent naming

* style: reorder imports in useAppInit and BaseApiClient files

* fix(MinAppTabsPool): wrong import path

* refactor: update style file extensions from scss to css

Update file extensions and comments to reflect the change from SCSS to CSS stylesheets

* feat(layout): add Flex component and its variants

Introduce new Flex component with Box, RowFlex, SpaceBetweenRowFlex, ColFlex and Center variants to provide reusable layout components

* refactor: migrate layout components to @cherrystudio/ui package

This commit updates all imports of layout components (Box, Flex, RowFlex, ColFlex, etc.) from '@renderer/components/Layout' to '@cherrystudio/ui' across the codebase. The change also includes updating related test files and eslint configuration to reflect this migration. This refactoring aims to centralize layout components in a shared package for better maintainability and consistency.

* docs(eslint): update comment and restricted imports rule

Update comment to clarify the purpose of the rule and add a TODO note for future migration

* docs(ui): update migration status for layout components

Mark Layout/* components as migrated and refactored in both Chinese and English documentation

* docs: update migration status for Layout components
2025-09-17 18:17:17 +08:00

19 KiB
Raw Blame History

UI 组件库迁移状态

使用示例

// 从 @cherrystudio/ui 导入组件
import { Spinner, DividerWithText, InfoTooltip, CustomTag } from '@cherrystudio/ui'

// 在组件中使用
function MyComponent() {
  return (
    <div>
      <Spinner size={24} />
      <DividerWithText text="分隔文本" />
      <InfoTooltip content="提示信息" />
      <CustomTag color="var(--color-primary)">标签</CustomTag>
    </div>
  )
}

目录结构说明

@packages/ui/
├── src/
│   ├── components/         # 组件主目录
│   │   ├── base/           # 基础组件(按钮、输入框、标签等)
│   │   ├── display/        # 显示组件(卡片、列表、表格等)
│   │   ├── layout/         # 布局组件(容器、网格、间距等)
│   │   ├── icons/          # 图标组件
│   │   ├── interactive/    # 交互组件(弹窗、提示、下拉等)
│   │   └── composite/      # 复合组件(多个基础组件组合而成)
│   ├── hooks/              # 自定义 React Hooks
│   └── types/              # TypeScript 类型定义

组件分类指南

提交 PR 时,请根据组件功能将其放入正确的目录:

  • base: 最基础的 UI 元素,如按钮、输入框、开关、标签等
  • display: 用于展示内容的组件,如卡片、列表、表格、标签页等
  • layout: 用于页面布局的组件,如容器、网格系统、分隔符等
  • icons: 所有图标相关的组件
  • interactive: 需要用户交互的组件,如模态框、抽屉、提示框、下拉菜单等
  • composite: 复合组件,由多个基础组件组合而成

迁移概览

  • 总组件数: 236
  • 已迁移: 34
  • 已重构: 18
  • 待迁移: 184

组件状态表

Category Component Name Migration Status Refactoring Status Description
base 基础组件
CopyButton 复制按钮
CustomTag 自定义标签
DividerWithText 带文本的分隔线
EmojiIcon 表情图标
ErrorBoundary 错误边界 (通过 props 解耦)
StatusTag 统一状态标签(合并了 ErrorTag、SuccessTag、WarnTag、InfoTag
IndicatorLight 指示灯
Spinner 加载动画
TextBadge 文本徽标
CustomCollapse 自定义折叠面板
display 显示组件
Ellipsis 文本省略
ExpandableText 可展开文本
ThinkingEffect 思考效果动画
EmojiAvatar 表情头像
ListItem 列表项
MaxContextCount 最大上下文数显示
ProviderAvatar 提供者头像
CodeViewer 代码查看器 (外部依赖)
OGCard OG 卡片
MarkdownShadowDOMRenderer Markdown 渲染器
Preview/* 预览组件
layout 布局组件
HorizontalScrollContainer 水平滚动容器
Scrollbar 滚动条
Layout/* 布局组件
Tab/* 标签页 (Redux 依赖)
TopView 顶部视图 (window.api 依赖)
icons 图标组件
Icon 图标工厂函数和预定义图标(合并了 CopyIcon、DeleteIcon、EditIcon、RefreshIcon、ResetIcon、ToolIcon、VisionIcon、WebSearchIcon、WrapIcon、UnWrapIcon、OcrIcon
FileIcons 文件图标 (FileSvgIcon、FilePngIcon)
ReasoningIcon 推理图标
SvgSpinners180Ring 旋转加载图标
ToolsCallingIcon 工具调用图标
interactive 交互组件
InfoTooltip 信息提示
HelpTooltip 帮助提示
WarnTooltip 警告提示
EditableNumber 可编辑数字
InfoPopover 信息弹出框
CollapsibleSearchBar 可折叠搜索栏
ImageToolButton 图片工具按钮
DraggableList 可拖拽列表
CodeEditor 代码编辑器
EmojiPicker 表情选择器 (useTheme 依赖)
Selector 选择器 (i18n 依赖)
ModelSelector 模型选择器 (Redux 依赖)
LanguageSelect 语言选择
TranslateButton 翻译按钮 (window.api 依赖)
composite 复合组件
- - - 暂无复合组件
未分类 需要分类的组件
Popups/* (16+ 文件) 弹窗组件 (业务耦合)
RichEditor/* (30+ 文件) 富文本编辑器
MarkdownEditor/* Markdown 编辑器
MinApp/* 迷你应用 (Redux 依赖)
Avatar/* 头像组件
ActionTools/* 操作工具
CodeBlockView/* 代码块视图 (window.api 依赖)
ContextMenu 右键菜单 (Electron API)
WindowControls 窗口控制 (Electron API)
ErrorBoundary 错误边界 (window.api 依赖)

迁移步骤

第一阶段:复制迁移(当前阶段)

  • 将组件原样复制到 @packages/ui
  • 保留原有依赖antd、styled-components 等)
  • 在文件顶部添加原路径注释

第二阶段:重构优化

  • 移除 antd 依赖,替换为 HeroUI
  • 移除 styled-components替换为 Tailwind CSS
  • 优化组件 API 和类型定义

注意事项

  1. 不迁移包含以下依赖的组件(解耦后可迁移):

    • window.api 调用
    • ReduxuseSelector、useDispatch 等)
    • 其他外部数据源
  2. 可迁移但需要后续解耦的组件:

    • 使用 i18n 的组件(将 i18n 改为 props 传入)
    • 使用 antd 的组件(后续替换为 HeroUI
  3. 提交规范

    • 每次 PR 专注于一个类别的组件
    • 确保所有迁移的组件都有导出
    • 更新此文档的迁移状态