import React from 'react' import Path from '../Path' import Point from '../Point' import Snippet from '../Snippet' import { getProps } from '../utils' const Part = (props) => { const focusPoint = (point, i) => { const p = props.part.points[point] const pathString = `M ${p.x} ${props.part.topLeft.y} ` + `L ${p.x} ${props.part.bottomRight.y} ` + `M ${props.part.topLeft.x} ${p.y} ` + `L ${props.part.bottomRight.x} ${p.y} ` const classes = 'focus point c' + (i % 8) // Cycle through 8 colors return ( props.raiseEvent('clearFocus', { part: props.name, type: 'points', name: point }) } /> ) } const focusCoords = (p, i) => { let pathString = `M ${p.x} ${props.part.topLeft.y} ` pathString += `L ${p.x} ${props.part.bottomRight.y} ` pathString += `M ${props.part.topLeft.x} ${p.y} ` pathString += `L ${props.part.bottomRight.x} ${p.y} ` let classes = 'focus coords c' + (i % 4) // Cycle through 4 CSS classes return ( props.raiseEvent('clearFocus', { part: props.name, type: 'coords', data: p }) } /> ) } let grid = props.paperless ? ( ) : null let focus = [] if (props.develop) { if (props.focus && typeof props.focus[props.name] !== 'undefined') { for (let i in props.focus[props.name].points) focus.push(focusPoint(props.focus[props.name].points[i], i)) for (let i in props.focus[props.name].paths) { let name = props.focus[props.name].paths[i] focus.push( props.raiseEvent('clearFocus', { part: props.name, type: 'paths', name }) } /> ) } for (let i in props.focus[props.name].coords) focus.push(focusCoords(props.focus[props.name].coords[i], i)) } } return ( {grid} {Object.keys(props.part.paths).map((name) => ( ))} {Object.keys(props.part.points).map((name) => ( ))} {Object.keys(props.part.snippets).map((name) => ( ))} {focus} ) } export default Part