import React, { useState, useCallback } from 'react'; import Icon from '@components/icons'; import Arrow from '@components/icons/arrow'; interface SearchFileTitleProps { title: string; onExpanded?: (expanded: boolean) => void; } const SearchFileTitle: React.FC = (props) => { const { title, onExpanded } = props; // 默认展开 const [expanded, setExpanded] = useState(true); const renderTitle = (titleText: string) => { const fileName = titleText.split('/').pop(); const fileDir = titleText.split('/').slice(0, -1).join('/'); let fileType; if (fileName && fileName.indexOf('.') !== -1) { fileType = `file_type_${fileName.split('.').slice(-1)}`; } else { fileType = 'default_file'; } return (
{fileName} {fileDir}
); }; const toggleExpand = useCallback(() => { setExpanded((prevExpanded) => !prevExpanded); onExpanded && onExpanded(!expanded); }, [expanded, onExpanded]); return (
{renderTitle(title)}
); }; export default SearchFileTitle;