duoyun-ui
Version:
A lightweight desktop UI component library, implemented using Gem
32 lines (31 loc) • 1.1 kB
JavaScript
import React from 'react';
import { forwardRef, useImperativeHandle, useRef, useLayoutEffect } from 'react';
export * from '../elements/tree';
export const DyTree = forwardRef(function (props, ref) {
const elementRef = useRef(null);
useImperativeHandle(ref, () => {
return {
isExpand(...args) {
return elementRef.current.isExpand(...args);
},
expandToItems(...args) {
return elementRef.current.expandToItems(...args);
},
collapseItems(...args) {
return elementRef.current.collapseItems(...args);
},
iterateCollapseItem(...args) {
return elementRef.current.iterateCollapseItem(...args);
},
};
}, []);
// React Bug?
useLayoutEffect(() => {
const element = elementRef.current;
["data", "items", "highlights"].map(name => {
element[name] = props[name];
});
}, []);
return React.createElement("dy-tree", { ref: elementRef, ...props });
});
export default DyTree;