-
Notifications
You must be signed in to change notification settings - Fork 569
/
Copy pathColumns.tsx
50 lines (46 loc) · 1.52 KB
/
Columns.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { JSONHeroPath } from "@jsonhero/path";
import { memo, useMemo } from "react";
import { useJson } from "~/hooks/useJson";
import {
useJsonColumnViewAPI,
useJsonColumnViewState,
} from "~/hooks/useJsonColumnView";
import { ColumnDefinition } from "~/useColumnView";
import { BlankColumn } from "./BlankColumn";
import { Column } from "./Column";
import { ColumnItem } from "./ColumnItem";
function ColumnsElement({ columns }: { columns: ColumnDefinition[] }) {
const [json] = useJson();
const { selectedPath, highlightedPath, highlightedNodeId } =
useJsonColumnViewState();
const highlightedItemIsValue = useMemo<boolean>(() => {
if (highlightedNodeId == null) {
return false;
}
const path = new JSONHeroPath(highlightedNodeId);
let item = path.first(json);
return typeof item !== "object";
}, [highlightedPath, json]);
return (
<div className="columns flex flex-grow overflow-x-auto no-scrollbar focus:outline-none">
{columns.map((column) => {
return (
<Column
key={column.id}
id={column.id}
title={column.title}
icon={column.icon}
hasHighlightedElement={
highlightedPath[highlightedPath.length - 2] === column.id
}
selectedPath={selectedPath}
highlightedPath={highlightedPath}
items={column.items}
/>
);
})}
{highlightedItemIsValue ? <BlankColumn /> : null}
</div>
);
}
export const Columns = memo(ColumnsElement);