UNPKG

@macrostrat/column-components

Version:

React rendering primitives for stratigraphic columns

75 lines (74 loc) 1.83 kB
import h from "@macrostrat/hyper"; import { createElement, forwardRef } from "react"; import { expandInnerSize, extractPadding, extractMargin, removeMargin, removePadding } from "@macrostrat/ui-components"; import classNames from "classnames"; import { useColumn } from "../context/column.js"; const SVGNamespaces = { xmlns: "http://www.w3.org/2000/svg", xmlnsXlink: "http://www.w3.org/1999/xlink" }; const SVG = forwardRef( (props, ref) => { const { children, innerRef, ...props1 } = props; const { style, ...rest } = expandInnerSize(props1); const { paddingLeft, paddingTop } = extractPadding(props); const margin = extractMargin(props); const realRest = removeMargin(removePadding(rest)); return h( "svg", { ref, style: { ...margin, ...style }, ...realRest, ...SVGNamespaces }, h( "g", { transform: `translate(${paddingLeft},${paddingTop})` }, children ) ); } ); const ForeignObject = (props) => createElement("foreignObject", props); const ColumnSVG = function(props) { const { children, className, innerRef, style, ...rest } = props; const { pixelHeight } = useColumn(); const nextProps = expandInnerSize({ innerHeight: pixelHeight, ...rest }); const { paddingLeft, paddingTop, innerHeight, innerWidth, height, width, ...remainingProps } = nextProps; return h( SVG, { className: classNames(className, "section"), height, width, innerRef, ...remainingProps, style }, h( "g.backdrop", { transform: `translate(${paddingLeft},${paddingTop})` }, children ) ); }; export { ColumnSVG, ForeignObject, SVG, SVGNamespaces }; //# sourceMappingURL=index.js.map