import React, { useMemo } from 'react' import withDefaults from '../utils/with-defaults' import useTheme from '../use-theme' import TreeLeafIcon from './tree-leaf-icon' import { useTreeContext } from './tree-context' import TreeIndents from './tree-indents' import { makeLeafPath, 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 TreeLeafProps = Props & typeof defaultProps & NativeAttrs const TreeLeaf: React.FC> = ({ name, parentPath, level, extra, className, ...props }) => { const theme = useTheme() const { onLeafClick } = useTreeContext() const currentPath = useMemo(() => makeLeafPath(name, parentPath), []) const clickHandler = (event: React.MouseEvent) => { stopPropagation(event) onLeafClick && onLeafClick(currentPath) } return (
{name} {extra && {extra}}
) } export default withDefaults(TreeLeaf, defaultProps)