import React, { useMemo } from 'react' import useTheme from '../use-theme' import TreeFileIcon from './tree-file-icon' import { useTreeContext } from './tree-context' import TreeIndents from './tree-indents' import { makeChildPath, stopPropagation } from './tree-help' interface Props { name: string extra?: string parentPath?: string level?: number className?: string } const defaultProps = { level: 0, className: '', parentPath: '', } type NativeAttrs = Omit, keyof Props> export type TreeFileProps = Props & NativeAttrs const TreeFile: React.FC> = ({ name, parentPath, level, extra, className, ...props }: React.PropsWithChildren & typeof defaultProps) => { const theme = useTheme() const { onFileClick } = useTreeContext() const currentPath = useMemo(() => makeChildPath(name, parentPath), []) const clickHandler = (event: React.MouseEvent) => { stopPropagation(event) onFileClick && onFileClick(currentPath) } return (
{name} {extra && {extra}}
) } TreeFile.defaultProps = defaultProps TreeFile.displayName = 'GeistTreeFile' export default TreeFile