import React, { useMemo } from 'react' import withDefaults from '../utils/with-defaults' import useTheme from '../styles/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 & typeof defaultProps & NativeAttrs const TreeFile: React.FC> = ({ name, parentPath, level, extra, className, ...props }) => { const theme = useTheme() const { onFileClick } = useTreeContext() const currentPath = useMemo(() => makeChildPath(name, parentPath), []) const clickHandler = (event: React.MouseEvent) => { stopPropagation(event) onFileClick(currentPath) } return (
{name}{extra && {extra}}
) } export default withDefaults(TreeFile, defaultProps)