([
- {
- 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);
- }
+// ─── Stories ──────────────────────────────────────────────────────────────────
- return (
- <>
-
- Enable Drag
- {
- setDraggable(true);
- }}
- />
- True
- {
- setDraggable(false);
- }}
- />
- False
-
+export const Flat: StoryObj = {
+ render: (args) => {
+ const [data, setData] = useState(flatData);
+ return (
{
- console.log("selected item:", item);
- setSelectedId(item.id ?? undefined);
+ onChange={(updated) => {
+ setData(updated);
+ args.onChange(updated);
}}
- 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("");
+// Custom args type for the styling story so controls map to itemOptions fields
+type CustomStyleArgs = {
+ draggable: boolean;
+ focusedOutlineColor: string;
+ focusedOutlineWidth: number;
+ focusedBorderRadius: number;
+ focusedBackgroundColor: string;
+ arrow: string;
+ onSelected: (...args: unknown[]) => void;
+ onDrop: (...args: unknown[]) => void;
+ onChange: (...args: unknown[]) => void;
+};
- 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 },
- ],
+export const CustomStyles: StoryObj = {
+ args: {
+ draggable: true,
+ focusedOutlineColor: "rgba(255, 0, 0, 0.5)",
+ focusedOutlineWidth: 1,
+ focusedBorderRadius: 50,
+ focusedBackgroundColor: "rgba(255, 0, 0, 0.1)",
+ arrow: "▸",
+ },
+ argTypes: {
+ draggable: { control: "boolean" },
+ focusedOutlineColor: {
+ control: "color",
+ description: "Color of the focus outline",
},
- ]);
-
- 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,
- }}
- />
- );
+ focusedOutlineWidth: {
+ control: { type: "range", min: 0, max: 8, step: 1 },
+ description: "Width of the focus outline in px",
+ },
+ focusedBorderRadius: {
+ control: { type: "range", min: 0, max: 50, step: 1 },
+ description: "Border radius of the focused item in px",
+ },
+ focusedBackgroundColor: {
+ control: "color",
+ description: "Background color of the focused item",
+ },
+ arrow: {
+ control: "text",
+ description: "Arrow character for items with children",
+ },
+ },
+ render: ({
+ draggable,
+ focusedOutlineColor,
+ focusedOutlineWidth,
+ focusedBorderRadius,
+ focusedBackgroundColor,
+ arrow,
+ onSelected,
+ onDrop,
+ onChange,
+ }) => {
+ const [data, setData] = useState(nestedData);
+ return (
+ {
+ setData(updated);
+ onChange(updated);
+ }}
+ onSelected={onSelected as (item: ReactTreeListItemType) => void}
+ onDrop={onDrop as (...args: unknown[]) => void}
+ itemDefaults={{ open: true, arrow }}
+ itemOptions={{
+ focusedOutlineColor,
+ focusedOutlineWidth,
+ focusedBorderRadius,
+ focusedBackgroundColor,
+ }}
+ />
+ );
+ },
};