From 026c7adcd2ec0a03bdcb66678264abeed2e2b11a Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Sat, 18 Jun 2022 17:02:19 +0200 Subject: [PATCH] feat(lab): Hover info for parts --- .../components/workbench/draft/part/index.js | 65 ++++++++++++++++--- .../components/workbench/draft/path/index.js | 8 +-- 2 files changed, 61 insertions(+), 12 deletions(-) diff --git a/sites/shared/components/workbench/draft/part/index.js b/sites/shared/components/workbench/draft/part/index.js index 883f9a5350a..2aec3ae500a 100644 --- a/sites/shared/components/workbench/draft/part/index.js +++ b/sites/shared/components/workbench/draft/part/index.js @@ -3,6 +3,8 @@ import Path from '../path' import Point from '../point' import Snippet from '../snippet' import { getProps } from '../utils' +import { round } from 'shared/utils' +import { Tr, KeyTd, ValTd, Attributes, pointCoords } from '../path/index' class ErrorBoundary extends React.Component { constructor(props) { @@ -27,12 +29,56 @@ class ErrorBoundary extends React.Component { } } +const partInfo = (props) => { + + return ( +
+
Part info
+ + + + Name + {props.partName} + + + Width + {round(props.part.width,2)}mm + + + Height + {round(props.part.height,2)}mm + + + Top Left + {pointCoords(props.part.topLeft)} + + + Bottom Right + {pointCoords(props.part.bottomRight)} + + + Attributes + + + +
+ {props.gist?.only && props.gist.only.length > 0 + ? ( + + ) : ( + + )} +
+ ) +} + const XrayPart = props => { - // Don't bother if this is the only part on display - if (props.gist.only && props.gist.only.length === 1) return null - const i = props.gist._state?.xray?.reveal - ? Object.keys(props.gist._state.xray.reveal).indexOf(props.partName)%10 - : 0 const { topLeft, bottomRight } = props.part return ( @@ -42,7 +88,11 @@ const XrayPart = props => { L ${topLeft.x} ${bottomRight.y} L ${bottomRight.x} ${bottomRight.y} L ${bottomRight.x} ${topLeft.y} - z`} className={`fill-color-${i} opacity-10`} /> + z + `} className={`peer stroke-note lashed opacity-30 hover:opacity-90 fill-fabric hover:cursor-pointer hover:stroke-mark`} + style={{ fillOpacity: 0}} + onClick={(evt) => { evt.stopPropagation(); props.showInfo(partInfo(props)) }} + /> ) } @@ -66,8 +116,7 @@ const Part = props => { {grid} { props.gist?._state?.xray?.enabled && - props.gist?._state?.xray?.reveal?.[partName] - && + } {Object.keys(part.paths).map((pathName) => ( {chil export const KeyTd = ({ children }) => {children}: export const ValTd = ({ children }) => {children} -const TextAlongPath = ({id, size, fill="var(--pattern-note)", txt}) => ( +export const TextAlongPath = ({id, size, fill="var(--pattern-note)", txt}) => ( ( ) -const PointCircle = ({ point, size, className="stroke-neutral-content" }) => ( +export const PointCircle = ({ point, size, className="stroke-neutral-content" }) => ( { } } -const Defs = () => ( +export const Defs = () => ( @@ -87,7 +87,7 @@ const Defs = () => ( ) -const svgProps = { +export const svgProps = { xmlns: "http://www.w3.org/2000/svg", xmlnsSvg: "http://www.w3.org/2000/svg", xmlnsXlink: "http://www.w3.org/1999/xlink",