Toggle.tsx 1022 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { Tree } from "antd";
  2. import { Children } from "react";
  3. interface IToggleCtlWidget {
  4. children?: React.ReactNode | React.ReactNode[];
  5. }
  6. const ToggleCtl = ({ children }: IToggleCtlWidget) => {
  7. const arrayChildren = Children.toArray(children);
  8. if (arrayChildren.length === 0) {
  9. return <></>;
  10. } else {
  11. return (
  12. <Tree
  13. treeData={[
  14. {
  15. title: arrayChildren[0],
  16. key: "root",
  17. children: Children.map(arrayChildren, (child, index) => {
  18. if (index === 0) {
  19. return undefined;
  20. } else {
  21. return {
  22. title: child as React.ReactElement,
  23. key: index,
  24. };
  25. }
  26. }),
  27. },
  28. ]}
  29. />
  30. );
  31. }
  32. };
  33. interface IWidget {
  34. props?: string;
  35. children?: React.ReactNode | React.ReactNode[];
  36. }
  37. const ToggleWidget = ({ children }: IWidget) => {
  38. return <ToggleCtl>{children}</ToggleCtl>;
  39. };
  40. export default ToggleWidget;