Skip to content

Commit dab1f94

Browse files
authored
Add vscode-style structure lines for the cities demo (#94)
1 parent b7ee21d commit dab1f94

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

packages/showcase/pages/cities.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Link from "next/link";
1111
type Data = { id: string; name: string; children?: Data[] };
1212

1313
const data = sortData(cities);
14+
const INDENT_STEP = 15;
1415

1516
export default function Cities() {
1617
const [tree, setTree] = useState<TreeApi<Data> | null | undefined>(null);
@@ -45,7 +46,7 @@ export default function Cities() {
4546
rowClassName={styles.row}
4647
padding={15}
4748
rowHeight={30}
48-
indent={15}
49+
indent={INDENT_STEP}
4950
overscanCount={8}
5051
onSelect={(selected) => setSelectedCount(selected.length)}
5152
onActivate={(node) => setActive(node.data)}
@@ -168,13 +169,20 @@ export default function Cities() {
168169

169170
function Node({ node, style, dragHandle }: NodeRendererProps<Data>) {
170171
const Icon = node.isInternal ? BsMapFill : BsGeoFill;
172+
const indentSize = Number.parseFloat(`${style.paddingLeft || 0}`);
173+
171174
return (
172175
<div
173176
ref={dragHandle}
174177
style={style}
175178
className={clsx(styles.node, node.state)}
176179
onClick={() => node.isInternal && node.toggle()}
177180
>
181+
<div className={styles.indentLines}>
182+
{new Array(indentSize / INDENT_STEP).fill(0).map((_, index) => {
183+
return <div key={index}></div>;
184+
})}
185+
</div>
178186
<FolderArrow node={node} />
179187
<Icon className={styles.icon} />{" "}
180188
<span className={styles.text}>

packages/showcase/styles/cities.module.css

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
}
114114

115115
.node {
116+
position: relative;
116117
border-radius: 8px;
117118
display: flex;
118119
align-items: center;
@@ -125,7 +126,7 @@
125126
}
126127

127128
.node:global(.isSelected) {
128-
background: rgb(20, 127, 250);
129+
background: rgb(20, 127, 250, 0.5);
129130
color: white;
130131
border-radius: 0;
131132
}
@@ -142,6 +143,28 @@
142143
border-radius: 8px;
143144
}
144145

146+
.tree:hover .indentLines {
147+
display: flex;
148+
}
149+
150+
.indentLines {
151+
--indent-size: 15px;
152+
153+
position: absolute;
154+
top: 0;
155+
left: 0;
156+
z-index: -1;
157+
display: none;
158+
align-items: flex-start;
159+
height: 100%;
160+
}
161+
162+
.indentLines > div {
163+
height: 100%;
164+
padding-left: 10px;
165+
border-right: 1px solid #ccc;
166+
margin-right: calc(var(--indent-size) - 10px - 1px);
167+
}
145168

146169
.row:focus-visible {
147170
outline: none;

0 commit comments

Comments
 (0)