react-folder-tree icon indicating copy to clipboard operation
react-folder-tree copied to clipboard

Use custom icons per file/folder

Open antrikshmisri opened this issue 3 years ago • 2 comments

Is there a way to use custom icons per file folder preferably defining them within the initData itself, like this:-

const initData = {
name: "node",
isOpen: true,
children: [],
icon: SomeComponent
}

antrikshmisri avatar Nov 05 '21 18:11 antrikshmisri

Hi, we currently don't support defining custom icon in the data, but we can achieve similar behavior by returning different icons with conditions. For example for file icon:

  const initData = {
    name: "node",
    iconName: 'SomeComponent',
    ...
  }

  const FileIcon = ({ onClick: defaultOnClick, nodeData }) => {
    const SomeComponent = getMyComponent(nodeData.iconName);

    return <SomeComponent onClick={ defaultOnClick } />;
  };

shunjizhan avatar Nov 06 '21 07:11 shunjizhan

actually, the way you suggest might work, maybe we could actually carry that Icon itself in the data, it is just a function after all. Try it out!

  const initData = {
    name: "node",
    icon: SomeComponent,
    ...
  }

  const FileIcon = ({ onClick: defaultOnClick, nodeData }) => {
    const SomeComponent = nodeData.icon;

    return <SomeComponent onClick={ defaultOnClick } />;
  };

UPDATE: ummm there seems to be a bug that nodeData will lost the key whose value is a method, wii investigate this issue later. Passing a string name and get correspodning component (as mentioned above above) should work

shunjizhan avatar Nov 06 '21 07:11 shunjizhan