lukasbach / react-complex-tree

Unopinionated Accessible Tree Component with Multi-Select and Drag-And-Drop
https://rct.lukasbach.com
MIT License
915 stars 72 forks source link

Expose treeItem internals #313

Closed keegan-lillo closed 6 months ago

keegan-lillo commented 7 months ago

Is your feature request related to a problem? Please describe. I've been creating a solution to #263 for my own usage and I managed to get something that works pretty well using a few custom renderers, however I have had to reach into the lib directory and import TreeItem.

import { TreeItem } from 'react-complex-tree/lib/cjs/treeItem/TreeItem'

This isn't a huge issue, however I have had to also update all my other imports to use 'react-complex-tree/lib/cjs' since NextJS/Webpack switches between the CJS and ESM versions depending on client/server builds so React context gets lost.

Describe the solution you'd like Expose TreeItem or useTreeItemRenderContext to the main package. If they are still "unstable", maybe expose them under a __UNSTABLE constant?

// src/index.ts
import { useTreeItemRenderContext } from './treeItem/useTreeItemRenderContext';
import { TreeItem } from './treeItem/TreeItem';

export * from './controlledEnvironment/ControlledTreeEnvironment';
export * from './tree/Tree';
export * from './uncontrolledEnvironment/UncontrolledTreeEnvironment';
export * from './uncontrolledEnvironment/StaticTreeDataProvider';
export * from './types';
export * from './renderers';

export const __UNSTABLE = {
  useTreeItemRenderContext,
  TreeItem,
};

Describe alternatives you've considered

Additional context

lukasbach commented 6 months ago

Hey, thanks for the suggestion. The TreeItem component isn't actually that unstable, but I'd still consider it an implementation detail that doesn't make sense to expose directly. But I did expose it as part of a "INTERNALS" export that I added now in v2.3.3, similar to what you suggested. Note that I renamed TreeItem to TreeItemElement to avoid confusion with the type of the same name TreeItem, which refers to the data field.

For the hook you mentioned, I can actually see realistic use cases for that and it makes more sense to use in normal applications, so I exposed the hook also in v2.3.3 as normal export.