2023-06-01 18:28:22 +02:00
|
|
|
import React from 'react'
|
|
|
|
import { withinPartBounds } from './utils.mjs'
|
|
|
|
|
2025-05-25 16:29:57 +02:00
|
|
|
/**
|
|
|
|
* A component to render a FreeSewing Point in a pattern
|
|
|
|
*
|
|
|
|
* @component
|
|
|
|
* @param {object} props - All component props
|
|
|
|
* @param {string} props.stackName - The name of the stack the part belongs to
|
|
|
|
* @param {string} props.partName - The name of the part
|
|
|
|
* @param {string} props.pointName - The name of the point
|
|
|
|
* @param {object} props.point - The point object itself
|
|
|
|
* @param {object} props.components - An object holding the pattern compnents to use
|
|
|
|
* @param {object} props.strings - An object holding translations
|
|
|
|
* @returns {JSX.Element}
|
|
|
|
*/
|
2025-04-01 16:15:20 +02:00
|
|
|
export const Point = ({ stackName, partName, pointName, part, point, components, strings }) => {
|
2023-09-13 11:58:00 +02:00
|
|
|
/*
|
|
|
|
* Don't include points outside the part bounding box
|
|
|
|
* Unless the `data-render-always` attribute is set
|
2025-05-25 16:29:57 +02:00
|
|
|
*
|
|
|
|
* FIXME: This is undocumented
|
2023-09-13 11:58:00 +02:00
|
|
|
*/
|
|
|
|
if (!withinPartBounds(point, part) && !point.attributes.list['data-render-always']) return null
|
2023-06-01 18:28:22 +02:00
|
|
|
|
|
|
|
// Get potentially swizzled components
|
|
|
|
const { Circle, Text } = components
|
|
|
|
|
|
|
|
return point.attributes ? (
|
|
|
|
<>
|
2025-04-01 16:15:20 +02:00
|
|
|
{point.attributes.text ? (
|
|
|
|
<Text {...{ point, pointName, partName, stackName, strings }} />
|
|
|
|
) : null}
|
2023-06-01 18:28:22 +02:00
|
|
|
{point.attributes.circle ? <Circle point={point} /> : null}
|
|
|
|
</>
|
|
|
|
) : null
|
|
|
|
}
|