UNPKG

@macrostrat/column-components

Version:

React rendering primitives for stratigraphic columns

71 lines (70 loc) 1.83 kB
import { useContext, forwardRef } from "react"; import h from "../hyper.js"; import { NoteLayoutContext } from "./layout.js"; import { HeightRangeAnnotation } from "./height-range.js"; import { ForeignObject } from "../util/index.js"; const NotePositioner = forwardRef(function(props, ref) { let { offsetY, noteHeight, onClick, children } = props; const { width, paddingLeft } = useContext(NoteLayoutContext); if (noteHeight == null) { noteHeight = 0; } const outerPad = 5; let y = offsetY - noteHeight / 2 - outerPad; return h( ForeignObject, { width: width - paddingLeft + 2 * outerPad, x: paddingLeft - outerPad, y, height: noteHeight + 2 * outerPad, overflow: "visible", style: { overflowY: "visible" } }, [ h( "div.note-inner", { ref, onClick }, children ) ] ); }); const findIndex = function(note) { const { notes } = useContext(NoteLayoutContext); return notes.indexOf(note); }; const NoteConnector = function(props) { let { note, node, deltaConnectorAttachment, index } = props; if (index == null) { index = findIndex(note); } const { nodes, columnIndex, generatePath } = useContext(NoteLayoutContext); const { height, top_height } = note; if (node == null) { node = nodes[note.id]; } if (node != null && deltaConnectorAttachment != null) { node.currentPos += deltaConnectorAttachment; } const offsetX = (columnIndex[index] || 0) * 5; return h([ h(HeightRangeAnnotation, { offsetX, height, top_height }), h("path.link.col-note-link", { d: generatePath(node, offsetX), transform: `translate(${offsetX})` }) ]); }; export { NoteConnector, NotePositioner }; //# sourceMappingURL=connector.js.map