mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-09 06:49:02 +08:00
- Added new components including CodeEditor, CollapsibleSearchBar, and DraggableList. - Removed obsolete components such as Button, CustomCollapse, and StatusTag. - Updated migration status documentation and adjusted component exports. - Enhanced package.json dependencies for better compatibility.
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
// Original: src/renderer/src/components/ExpandableText.tsx
|
|
import { Button } from '@heroui/react'
|
|
import { memo, useCallback, useState } from 'react'
|
|
|
|
interface ExpandableTextProps {
|
|
text: string
|
|
style?: React.CSSProperties
|
|
className?: string
|
|
expandText?: string
|
|
collapseText?: string
|
|
lineClamp?: number
|
|
ref?: React.RefObject<HTMLDivElement>
|
|
}
|
|
|
|
const ExpandableText = ({
|
|
text,
|
|
style,
|
|
className = '',
|
|
expandText = 'Expand',
|
|
collapseText = 'Collapse',
|
|
lineClamp = 1,
|
|
ref
|
|
}: ExpandableTextProps) => {
|
|
const [isExpanded, setIsExpanded] = useState(false)
|
|
|
|
const toggleExpand = useCallback(() => {
|
|
setIsExpanded((prev) => !prev)
|
|
}, [])
|
|
|
|
return (
|
|
<div
|
|
ref={ref}
|
|
className={`flex ${isExpanded ? 'flex-col' : 'flex-row items-center'} gap-2 ${className}`}
|
|
style={style}>
|
|
<div
|
|
className={`overflow-hidden ${
|
|
isExpanded ? '' : lineClamp === 1 ? 'text-ellipsis whitespace-nowrap' : `line-clamp-${lineClamp}`
|
|
} ${isExpanded ? '' : 'flex-1'}`}>
|
|
{text}
|
|
</div>
|
|
<Button size="sm" variant="light" color="primary" onClick={toggleExpand} className="min-w-fit px-2">
|
|
{isExpanded ? collapseText : expandText}
|
|
</Button>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
ExpandableText.displayName = 'ExpandableText'
|
|
|
|
export default memo(ExpandableText)
|