import React, { useState } from "react";
import { Meta } from "@storybook/react";
import {
Title,
Subtitle,
Description,
Primary,
Stories,
} from "@storybook/addon-docs/blocks";
import { rgba } from "polished";
import { ReactTreeList, ReactTreeListProps } from "../src";
import { getRandomEmoji } from "./utils/getRandomEmoji";
import { ReactTreeListItemType } from "../build";
export default {
title: "Tree List",
component: ReactTreeList,
parameters: {
docs: {
page: () => (
<>
>
),
},
},
argTypes: {
label: { control: "text" },
},
} as Meta;
export const withEmojis = () => {
const [selectedId, setSelectedId] =
useState("");
const [data, setData] = useState([
{
id: "1",
label: "none",
open: true,
icon: getRandomEmoji(),
children: [
{
id: "2",
label: "Heyo",
open: true,
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [{ label: "Heyo" }],
},
],
},
{
id: "3",
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [{ label: "Heyo" }],
},
],
},
],
},
],
},
],
},
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [{ label: "Heyo" }],
},
],
},
{
label: "Heyo",
open: true,
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [{ label: "Heyo" }],
},
],
},
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [{ label: "Heyo" }],
},
],
},
],
},
],
},
],
},
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{ label: "Heyo" },
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [{ label: "Heyo" }],
},
],
},
],
},
],
},
],
},
],
},
],
},
],
},
{
label: "none",
open: true,
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
open: true,
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [{ label: "Heyo" }],
},
],
},
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [{ label: "Heyo" }],
},
],
},
],
},
],
},
],
},
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [{ label: "Heyo" }],
},
],
},
{
label: "Heyo",
open: true,
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [{ label: "Heyo" }],
},
],
},
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [{ label: "Heyo" }],
},
],
},
],
},
],
},
],
},
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{ label: "Heyo" },
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [
{
label: "Heyo",
icon: getRandomEmoji(),
children: [{ label: "Heyo" }],
},
],
},
],
},
],
},
],
},
],
},
],
},
],
},
]);
const [draggable, setDraggable] = useState(true);
function onDrop(
dragingNode: ReactTreeListItemType,
dragNode: ReactTreeListItemType,
drogType: string
) {
console.log("dragingNode:", dragingNode);
console.log("dragNode:", dragNode);
console.log("drogType:", drogType);
}
return (
<>
Enable Drag
{
setDraggable(true);
}}
/>
True
{
setDraggable(false);
}}
/>
False
{
console.log("selected item:", item);
setSelectedId(item.id ?? undefined);
}}
onChange={setData}
itemDefaults={{ open: false, arrow: "▸", icon: getRandomEmoji() }}
/>
>
);
};
export const withCustomStyles = () => {
const blockIcon = (
);
const textIcon = (
);
const divLabel = (
Div
);
const spanLabel = (
Span
);
const [selectedId, setSelectedId] =
useState("");
const [data, setData] = useState([
{
label: divLabel,
open: true,
children: [
{
label: divLabel,
open: true,
children: [
{
label: divLabel,
children: [{ label: spanLabel, icon: textIcon }],
},
],
},
{ label: spanLabel, icon: textIcon },
{
label: divLabel,
children: [
{
label: divLabel,
children: [{ label: divLabel }],
},
],
},
{
label: divLabel,
open: true,
},
{ label: divLabel },
{ label: divLabel },
],
},
]);
return (
{
setSelectedId(item.id ?? undefined);
}}
onChange={setData}
itemOptions={{
focusedOutlineColor: rgba("red", 0.5),
focusedOutlineWidth: 1,
focusedBorderRadius: 50,
focusedBackgroundColor: rgba("red", 0.1),
}}
itemDefaults={{
open: false,
arrow: (
),
icon: blockIcon,
}}
/>
);
};