mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-30 07:39:06 +08:00
refactor(ui): update utility imports to use internal lib
- Changed utility imports from '@cherrystudio/ui/utils' to '@cherrystudio/ui/lib/utils' across multiple components for better organization. - Introduced a new internal utility module for class name merging, ensuring consistent usage across the UI components. - Updated relevant components to reflect the new import paths, enhancing maintainability and clarity.
This commit is contained in:
parent
6feb322be8
commit
05c26fbff2
@ -5,7 +5,7 @@
|
||||
"hooks": "@cherrystudio/ui/hooks",
|
||||
"lib": "@cherrystudio/ui/lib",
|
||||
"ui": "@cherrystudio/ui/components/primitives",
|
||||
"utils": "@cherrystudio/ui/utils"
|
||||
"utils": "@cherrystudio/ui/lib/utils"
|
||||
},
|
||||
"iconLibrary": "lucide",
|
||||
"rsc": false,
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
// Original: src/renderer/src/components/Ellipsis/index.tsx
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import type { HTMLAttributes } from 'react'
|
||||
|
||||
import { cn } from '../../../utils'
|
||||
|
||||
type Props = {
|
||||
maxLine?: number
|
||||
className?: string
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import React from 'react'
|
||||
|
||||
import { cn } from '../../../utils'
|
||||
|
||||
export interface BoxProps extends React.ComponentProps<'div'> {}
|
||||
|
||||
export const Box = ({ children, className, ...props }: BoxProps & { children?: React.ReactNode }) => {
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { cn, toUndefinedIfNull } from '@cherrystudio/ui/utils'
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import { toUndefinedIfNull } from '@cherrystudio/ui/utils/index'
|
||||
import type { VariantProps } from 'class-variance-authority'
|
||||
import { cva } from 'class-variance-authority'
|
||||
import { Edit2Icon, EyeIcon, EyeOffIcon } from 'lucide-react'
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
// Original path: src/renderer/src/components/ListItem/index.tsx
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import { Tooltip } from '@heroui/react'
|
||||
import type { ReactNode } from 'react'
|
||||
|
||||
import { cn } from '../../../utils'
|
||||
|
||||
interface ListItemProps {
|
||||
active?: boolean
|
||||
icon?: ReactNode
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import type { DraggableSyntheticListeners } from '@dnd-kit/core'
|
||||
import type { Transform } from '@dnd-kit/utilities'
|
||||
import { CSS } from '@dnd-kit/utilities'
|
||||
import React, { useEffect } from 'react'
|
||||
import styled from 'styled-components'
|
||||
|
||||
import { cn } from '../../../utils'
|
||||
import type { RenderItemType } from './types'
|
||||
|
||||
interface ItemRendererProps<T> {
|
||||
|
||||
@ -7,12 +7,12 @@
|
||||
*/
|
||||
|
||||
// Original path: src/renderer/src/components/ThinkingEffect.tsx
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import { isEqual } from 'lodash'
|
||||
import { ChevronRight, Lightbulb } from 'lucide-react'
|
||||
import { motion } from 'motion/react'
|
||||
import React, { useEffect, useMemo, useState } from 'react'
|
||||
|
||||
import { cn } from '../../../utils'
|
||||
import { lightbulbVariants } from './defaultVariants'
|
||||
|
||||
interface ThinkingEffectProps {
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import React, { memo } from 'react'
|
||||
|
||||
import { cn } from '../../../utils'
|
||||
|
||||
interface EmojiAvatarProps {
|
||||
children: string
|
||||
size?: number
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import type { AvatarProps as HeroUIAvatarProps } from '@heroui/react'
|
||||
import { Avatar as HeroUIAvatar, AvatarGroup as HeroUIAvatarGroup } from '@heroui/react'
|
||||
|
||||
import { cn } from '../../../utils'
|
||||
import EmojiAvatar from './EmojiAvatar'
|
||||
|
||||
export interface AvatarProps extends Omit<HeroUIAvatarProps, 'size'> {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { cn } from '@cherrystudio/ui/utils/index'
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import { Slot } from '@radix-ui/react-slot'
|
||||
import { cva, type VariantProps } from 'class-variance-authority'
|
||||
import * as React from 'react'
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { cn } from '@cherrystudio/ui/utils/index'
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import { Slot } from '@radix-ui/react-slot'
|
||||
import { ChevronRight, MoreHorizontal } from 'lucide-react'
|
||||
import * as React from 'react'
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { cn } from '@cherrystudio/ui/utils/index'
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import { Slot } from '@radix-ui/react-slot'
|
||||
import { cva, type VariantProps } from 'class-variance-authority'
|
||||
import { Loader } from 'lucide-react'
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { cn } from '@cherrystudio/ui/utils/index'
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import * as CheckboxPrimitive from '@radix-ui/react-checkbox'
|
||||
import { cva, type VariantProps } from 'class-variance-authority'
|
||||
import { CheckIcon } from 'lucide-react'
|
||||
|
||||
@ -10,7 +10,7 @@ import {
|
||||
CommandList
|
||||
} from '@cherrystudio/ui/components/primitives/command'
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@cherrystudio/ui/components/primitives/popover'
|
||||
import { cn } from '@cherrystudio/ui/utils/index'
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import { cva, type VariantProps } from 'class-variance-authority'
|
||||
import { Check, ChevronDown, X } from 'lucide-react'
|
||||
import * as React from 'react'
|
||||
|
||||
@ -5,7 +5,7 @@ import {
|
||||
DialogHeader,
|
||||
DialogTitle
|
||||
} from '@cherrystudio/ui/components/primitives/dialog'
|
||||
import { cn } from '@cherrystudio/ui/utils'
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import { Command as CommandPrimitive } from 'cmdk'
|
||||
import { SearchIcon } from 'lucide-react'
|
||||
import * as React from 'react'
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { cn } from '@cherrystudio/ui/utils/index'
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import * as DialogPrimitive from '@radix-ui/react-dialog'
|
||||
import { XIcon } from 'lucide-react'
|
||||
import * as React from 'react'
|
||||
|
||||
@ -3,7 +3,7 @@ import type { InputProps } from '@cherrystudio/ui/components/primitives/input'
|
||||
import { Input } from '@cherrystudio/ui/components/primitives/input'
|
||||
import type { TextareaInputProps } from '@cherrystudio/ui/components/primitives/textarea'
|
||||
import * as Textarea from '@cherrystudio/ui/components/primitives/textarea'
|
||||
import { cn } from '@cherrystudio/ui/utils/index'
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import { cva, type VariantProps } from 'class-variance-authority'
|
||||
import * as React from 'react'
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { cn } from '@cherrystudio/ui/utils'
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import * as React from 'react'
|
||||
|
||||
interface InputProps extends React.ComponentProps<'input'> {}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { cn } from '@cherrystudio/ui/utils/index'
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
|
||||
function Kbd({ className, ...props }: React.ComponentProps<'kbd'>) {
|
||||
return (
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import type { Button } from '@cherrystudio/ui/components/primitives/button'
|
||||
import { buttonVariants } from '@cherrystudio/ui/components/primitives/button'
|
||||
import { cn } from '@cherrystudio/ui/utils/index'
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import { ChevronLeftIcon, ChevronRightIcon, MoreHorizontalIcon } from 'lucide-react'
|
||||
import * as React from 'react'
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import { cn } from '@cherrystudio/ui/utils'
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import * as PopoverPrimitive from '@radix-ui/react-popover'
|
||||
import * as React from 'react'
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { cn } from '@cherrystudio/ui/utils/index'
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import * as RadioGroupPrimitive from '@radix-ui/react-radio-group'
|
||||
import { cva, type VariantProps } from 'class-variance-authority'
|
||||
import { CircleIcon } from 'lucide-react'
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { cn } from '@cherrystudio/ui/utils/index'
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import * as SelectPrimitive from '@radix-ui/react-select'
|
||||
import { cva, type VariantProps } from 'class-variance-authority'
|
||||
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from 'lucide-react'
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import { Button } from '@cherrystudio/ui/components/primitives/button'
|
||||
import { cn } from '@cherrystudio/ui/utils/index'
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import { UploadIcon } from 'lucide-react'
|
||||
import type { ReactNode } from 'react'
|
||||
import { createContext, use } from 'react'
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { cn } from '@cherrystudio/ui/utils'
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import * as SwitchPrimitive from '@radix-ui/react-switch'
|
||||
import { cva } from 'class-variance-authority'
|
||||
import * as React from 'react'
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { cn } from '@cherrystudio/ui/utils/index'
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import * as TabsPrimitive from '@radix-ui/react-tabs'
|
||||
import { cva } from 'class-variance-authority'
|
||||
import * as React from 'react'
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { cn } from '@cherrystudio/ui/utils/index'
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import { composeEventHandlers } from '@radix-ui/primitive'
|
||||
import { useCallbackRef } from '@radix-ui/react-use-callback-ref'
|
||||
import { useControllableState } from '@radix-ui/react-use-controllable-state'
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { cn } from '@cherrystudio/ui/utils/index'
|
||||
import { cn } from '@cherrystudio/ui/lib/utils'
|
||||
import * as TooltipPrimitive from '@radix-ui/react-tooltip'
|
||||
import * as React from 'react'
|
||||
|
||||
|
||||
23
packages/ui/src/lib/utils.ts
Normal file
23
packages/ui/src/lib/utils.ts
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Internal utilities for UI components.
|
||||
*
|
||||
* This module is for INTERNAL use only and should NOT be exposed to external consumers.
|
||||
* External utilities should be placed in `utils/` instead.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
|
||||
import { type ClassValue, clsx } from 'clsx'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
|
||||
/**
|
||||
* Merges Tailwind CSS class names with conflict resolution.
|
||||
* Combines clsx for conditional classes and tailwind-merge for deduplication.
|
||||
*
|
||||
* @example
|
||||
* cn('px-2 py-1', 'px-4') // => 'py-1 px-4'
|
||||
* cn('text-red-500', isActive && 'text-blue-500')
|
||||
*/
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
@ -1,13 +1,11 @@
|
||||
import { type ClassValue, clsx } from 'clsx'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
|
||||
/**
|
||||
* Merge class names with tailwind-merge
|
||||
* This utility combines clsx and tailwind-merge for optimal class name handling
|
||||
* Public utility functions for external consumers.
|
||||
*
|
||||
* This module is part of the PUBLIC API and can be imported via `@cherrystudio/ui/utils`.
|
||||
* For internal-only utilities (e.g., Tailwind class merging), use `lib/` instead.
|
||||
*
|
||||
* @module utils
|
||||
*/
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts `null` to `undefined`, otherwise returns the input value.
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import type { AvatarProps } from '@cherrystudio/ui'
|
||||
import { Avatar, cn } from '@cherrystudio/ui'
|
||||
import { Avatar } from '@cherrystudio/ui'
|
||||
import { getModelLogo } from '@renderer/config/models'
|
||||
import type { Model } from '@renderer/types'
|
||||
import { cn } from '@renderer/utils'
|
||||
import { first } from 'lodash'
|
||||
import type { FC } from 'react'
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { Button, cn } from '@cherrystudio/ui'
|
||||
import { Button } from '@cherrystudio/ui'
|
||||
import { cn } from '@renderer/utils'
|
||||
import React, { memo } from 'react'
|
||||
|
||||
interface ActionIconButtonProps extends Omit<React.ComponentProps<'button'>, 'ref'> {
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import { Avatar, cn } from '@cherrystudio/ui'
|
||||
import { Avatar } from '@cherrystudio/ui'
|
||||
import { PoeLogo } from '@renderer/components/Icons'
|
||||
import { getProviderLogo } from '@renderer/config/providers'
|
||||
import type { Provider } from '@renderer/types'
|
||||
import { cn } from '@renderer/utils'
|
||||
import { generateColorFromChar, getFirstCharacter, getForegroundColor } from '@renderer/utils'
|
||||
import React from 'react'
|
||||
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import { FormOutlined } from '@ant-design/icons'
|
||||
import { Button, cn } from '@cherrystudio/ui'
|
||||
import { Button } from '@cherrystudio/ui'
|
||||
import { useTheme } from '@renderer/context/ThemeProvider'
|
||||
import { EventEmitter } from '@renderer/services/EventService'
|
||||
import { EVENT_NAMES } from '@renderer/services/EventService'
|
||||
import { cn } from '@renderer/utils'
|
||||
import { ThemeMode } from '@shared/data/preference/preferenceTypes'
|
||||
import type { FC } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { Button, cn } from '@cherrystudio/ui'
|
||||
import { Button } from '@cherrystudio/ui'
|
||||
import { cn } from '@renderer/utils'
|
||||
import { PlusIcon } from 'lucide-react'
|
||||
|
||||
const AddButton = ({ children, className, ...props }) => {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { cn } from '@cherrystudio/ui'
|
||||
import { cn } from '@renderer/utils'
|
||||
import type { ThemeMode } from '@shared/data/preference/preferenceTypes'
|
||||
import { Divider } from 'antd'
|
||||
import Link from 'antd/es/typography/Link'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user