mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 19:30:17 +08:00
* 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
20 KiB
20 KiB
UI Component Library Migration Status
Usage Example
// Import components from @cherrystudio/ui
import { Spinner, DividerWithText, InfoTooltip } from '@cherrystudio/ui'
// Use in components
function MyComponent() {
return (
<div>
<Spinner size={24} />
<DividerWithText text="Divider Text" />
<InfoTooltip content="Tooltip message" />
</div>
)
}
Directory Structure
@packages/ui/
├── src/
│ ├── components/ # Main components directory
│ │ ├── base/ # Basic components (buttons, inputs, labels, etc.)
│ │ ├── display/ # Display components (cards, lists, tables, etc.)
│ │ ├── layout/ # Layout components (containers, grids, spacing, etc.)
│ │ ├── icons/ # Icon components
│ │ ├── interactive/ # Interactive components (modals, tooltips, dropdowns, etc.)
│ │ └── composite/ # Composite components (made from multiple base components)
│ ├── hooks/ # Custom React Hooks
│ └── types/ # TypeScript type definitions
Component Classification Guide
When submitting PRs, please place components in the correct directory based on their function:
- base: Most basic UI elements like buttons, inputs, switches, labels, etc.
- display: Components for displaying content like cards, lists, tables, tabs, etc.
- layout: Components for page layout like containers, grid systems, dividers, etc.
- icons: All icon-related components
- interactive: Components requiring user interaction like modals, drawers, tooltips, dropdowns, etc.
- composite: Composite components made from multiple base components
Migration Overview
- Total Components: 236
- Migrated: 34
- Refactored: 18
- Pending Migration: 184
Component Status Table
| Category | Component Name | Migration Status | Refactoring Status | Description |
|---|---|---|---|---|
| base | Base components | |||
| CopyButton | ✅ | ✅ | Copy button | |
| CustomTag | ✅ | ✅ | Custom tag | |
| DividerWithText | ✅ | ✅ | Divider with text | |
| EmojiIcon | ✅ | ✅ | Emoji icon | |
| ErrorBoundary | ✅ | ✅ | Error boundary (decoupled via props) | |
| StatusTag | ✅ | ✅ | Unified status tag (merged ErrorTag, SuccessTag, WarnTag, InfoTag) | |
| IndicatorLight | ✅ | ✅ | Indicator light | |
| Spinner | ✅ | ✅ | Loading spinner | |
| TextBadge | ✅ | ✅ | Text badge | |
| CustomCollapse | ✅ | ✅ | Custom collapse panel | |
| display | Display components | |||
| Ellipsis | ✅ | ✅ | Text ellipsis | |
| ExpandableText | ✅ | ✅ | Expandable text | |
| ThinkingEffect | ✅ | ✅ | Thinking effect animation | |
| EmojiAvatar | ✅ | ✅ | Emoji avatar | |
| ListItem | ✅ | ✅ | List item | |
| MaxContextCount | ✅ | ✅ | Max context count display | |
| ProviderAvatar | ✅ | ✅ | Provider avatar | |
| CodeViewer | ❌ | ❌ | Code viewer (external deps) | |
| OGCard | ❌ | ❌ | OG card | |
| MarkdownShadowDOMRenderer | ❌ | ❌ | Markdown renderer | |
| Preview/* | ❌ | ❌ | Preview components | |
| layout | Layout components | |||
| HorizontalScrollContainer | ✅ | ❌ | Horizontal scroll container | |
| Scrollbar | ✅ | ❌ | Scrollbar | |
| Layout/* | ✅ | ✅ | Layout components | |
| Tab/* | ❌ | ❌ | Tab (Redux dependency) | |
| TopView | ❌ | ❌ | Top view (window.api dependency) | |
| icons | Icon components | |||
| Icon | ✅ | ✅ | Icon factory function and predefined icons (merged CopyIcon, DeleteIcon, EditIcon, RefreshIcon, ResetIcon, ToolIcon, VisionIcon, WebSearchIcon, WrapIcon, UnWrapIcon, OcrIcon) | |
| FileIcons | ✅ | ❌ | File icons (FileSvgIcon, FilePngIcon) | |
| ReasoningIcon | ✅ | ❌ | Reasoning icon | |
| SvgSpinners180Ring | ✅ | ❌ | Spinner loading icon | |
| ToolsCallingIcon | ✅ | ❌ | Tools calling icon | |
| interactive | Interactive components | |||
| InfoTooltip | ✅ | ❌ | Info tooltip | |
| HelpTooltip | ✅ | ❌ | Help tooltip | |
| WarnTooltip | ✅ | ❌ | Warning tooltip | |
| EditableNumber | ✅ | ❌ | Editable number | |
| InfoPopover | ✅ | ❌ | Info popover | |
| CollapsibleSearchBar | ✅ | ❌ | Collapsible search bar | |
| ImageToolButton | ✅ | ❌ | Image tool button | |
| DraggableList | ✅ | ❌ | Draggable list | |
| CodeEditor | ✅ | ❌ | Code editor | |
| EmojiPicker | ❌ | ❌ | Emoji picker (useTheme dependency) | |
| Selector | ✅ | ❌ | Selector (i18n dependency) | |
| ModelSelector | ❌ | ❌ | Model selector (Redux dependency) | |
| LanguageSelect | ❌ | ❌ | Language select | |
| TranslateButton | ❌ | ❌ | Translate button (window.api dependency) | |
| composite | Composite components | |||
| - | - | - | No composite components yet | |
| Uncategorized | Components needing categorization | |||
| Popups/* (16+ files) | ❌ | ❌ | Popup components (business coupled) | |
| RichEditor/* (30+ files) | ❌ | ❌ | Rich text editor | |
| MarkdownEditor/* | ❌ | ❌ | Markdown editor | |
| MinApp/* | ❌ | ❌ | Mini app (Redux dependency) | |
| Avatar/* | ❌ | ❌ | Avatar components | |
| ActionTools/* | ❌ | ❌ | Action tools | |
| CodeBlockView/* | ❌ | ❌ | Code block view (window.api dependency) | |
| ContextMenu | ❌ | ❌ | Context menu (Electron API) | |
| WindowControls | ❌ | ❌ | Window controls (Electron API) | |
| ErrorBoundary | ❌ | ❌ | Error boundary (window.api dependency) |
Migration Steps
Phase 1: Copy Migration (Current Phase)
- Copy components as-is to @packages/ui
- Retain original dependencies (antd, styled-components, etc.)
- Add original path comment at file top
Phase 2: Refactor and Optimize
- Remove antd dependencies, replace with HeroUI
- Remove styled-components, replace with Tailwind CSS
- Optimize component APIs and type definitions
Notes
-
Do NOT migrate components with these dependencies (can be migrated after decoupling):
- window.api calls
- Redux (useSelector, useDispatch, etc.)
- Other external data sources
-
Can migrate but need decoupling later:
- Components using i18n (change i18n to props)
- Components using antd (replace with HeroUI later)
-
Submission Guidelines:
- Each PR should focus on one category of components
- Ensure all migrated components are exported
- Update migration status in this document