import { useState } from 'react' import ClearIcon from 'shared/components/icons/clear.js' import EditIcon from 'shared/components/icons/edit.js' import { formatMm, round } from 'shared/utils.js' import { useTranslation } from 'next-i18next' const EditOption = props => (
) const DesignOptionPctDeg = props => { const { t } = useTranslation(['app']) const suffix = props.type === 'deg' ? '°' : '%' const factor = props.type === 'deg' ? 1 : 100 const { max, min } = props.pattern.config.options[props.option] const dflt = props.pattern.config.options[props.option][props.type || 'pct'] const val = (typeof props.gist?.options?.[props.option] === 'undefined') ? dflt : props.gist.options[props.option] * factor const [value, setValue] = useState(val) const [editOption, setEditOption] = useState(false) const handleChange = (evt) => { const newVal = evt.target.value setValue(newVal) props.updateGist(['options', props.option], newVal/factor) } const reset = () => { setValue(dflt) props.unsetGist(['options', props.option]) } return (

{t(`options:${props.pattern.config.name}.${props.option}.description`, props.app.locale)}

{editOption ? : ( <> {round(min)}{suffix} {round(val)}{suffix} {round(max)}{suffix} ) }
{props.pattern.config.options[props.option]?.toAbs ? formatMm(props.pattern.config.options[props.option].toAbs(value/100, props.gist)) : ' ' }
) } export default DesignOptionPctDeg