Skip to content

Commit e756a75

Browse files
committed
Updated column selection preview
1 parent 27a7325 commit e756a75

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

packages/column-views/src/column.module.sass

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
.column
1212
display: flex
1313
flex-direction: row
14+
position: relative
1415

1516
.age-axis-label
1617
writing-mode: vertical-lr

packages/column-views/src/selection-popover.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function UnitDetailsPopover({
2525
},
2626
h(
2727
Popover,
28-
{ content, isOpen: true, usePortal: false, boundary },
28+
{ content, isOpen: true, usePortal: false, boundary, position: "right" },
2929
h("span.popover-target")
3030
)
3131
);
@@ -52,13 +52,26 @@ export function LegendPanelHeader({ title, id, onClose }) {
5252
}
5353

5454
export function UnitSelectionPopover(props) {
55+
const { position } = props;
5556
const unit = useSelectedUnit();
5657
if (unit == null) {
5758
return null;
5859
}
5960

6061
return h(
6162
"div.unit-popover-container",
62-
h(UnitDetailsPopover, h(JSONView, { data: unit, showRoot: false }))
63+
h(
64+
UnitDetailsPopover,
65+
{
66+
style: {
67+
position: "absolute",
68+
top: position?.y,
69+
width: position?.width,
70+
left: position?.x,
71+
height: position?.height,
72+
},
73+
},
74+
h(JSONView, { data: unit, showRoot: false })
75+
)
6376
);
6477
}

packages/column-views/src/units/boxes.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import styles from "./boxes.module.sass";
2525

2626
const h = hyper.styled(styles);
2727

28-
interface RectBounds {
28+
export interface RectBounds {
2929
x: number;
3030
y: number;
3131
width: number;
@@ -115,9 +115,6 @@ function Unit(props: UnitProps) {
115115
ref,
116116
...bounds,
117117
fill,
118-
onMouseOver() {
119-
console.log(d);
120-
},
121118
onClick,
122119
}),
123120
h.if(selected)("rect.selection-overlay", bounds),
@@ -135,7 +132,6 @@ function useUnitSelectionManager(
135132

136133
const onClick = useCallback(
137134
(evt: Event) => {
138-
console.log(ref.current, evt);
139135
selectUnit(ref.current, evt);
140136
},
141137
[unit, ref, selectUnit]

packages/column-views/stories/column.stories.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { PatternProvider } from "@macrostrat/column-components/stories/base-sect
1818
import "@macrostrat/style-system";
1919
import { UnitSelectionPopover } from "../src/selection-popover";
2020
import { createRef, DOMElement, useEffect, useState } from "react";
21+
import { RectBounds } from "../src/units/boxes";
2122

2223
const h = hyper.styled(styles);
2324

@@ -144,17 +145,10 @@ export function WithBasicUnitSelection() {
144145
);
145146
}
146147

147-
interface ItemPosition {
148-
x: number;
149-
y: number;
150-
width: number;
151-
height: number;
152-
}
153-
154148
export function WithUnitSelectionPopover() {
155149
const ref = createRef<HTMLElement>();
156150
// Selected item position
157-
const [position, setPosition] = useState<ItemPosition | null>(null);
151+
const [position, setPosition] = useState<RectBounds | null>(null);
158152

159153
useEffect(() => {
160154
if (position == null) return;
@@ -183,7 +177,7 @@ export function WithUnitSelectionPopover() {
183177
},
184178
},
185179
h(BasicColumn, { id: 432, showLabelColumn: true, columnRef: ref }, [
186-
h(UnitSelectionPopover),
180+
h(UnitSelectionPopover, { position }),
187181
])
188182
);
189183
}

0 commit comments

Comments
 (0)