2022-01-29 18:24:36 +01:00
|
|
|
import { Chevron } from 'shared/components/navigation/primary.js'
|
2022-01-26 13:41:40 +01:00
|
|
|
import PctDegOption from 'shared/components/workbench/inputs/design-option-pct-deg'
|
2022-01-26 10:04:15 +01:00
|
|
|
import CountOption from 'shared/components/workbench/inputs/design-option-count'
|
|
|
|
import ListOption from 'shared/components/workbench/inputs/design-option-list'
|
2022-01-25 18:14:31 +01:00
|
|
|
import { formatMm, formatPercentage, optionType } from 'shared/utils.js'
|
2022-01-29 18:24:36 +01:00
|
|
|
import { Li, Ul, Details, Summary, SumButton, SumDiv, Deg } from 'shared/components/workbench/menu'
|
2022-02-08 20:49:19 +01:00
|
|
|
import { useTranslation } from 'next-i18next'
|
2022-01-25 18:14:31 +01:00
|
|
|
|
|
|
|
const values = {
|
|
|
|
pct: props => {
|
|
|
|
const val = (typeof props.gist?.options?.[props.option] === 'undefined')
|
|
|
|
? props.pattern.config.options[props.option].pct/100
|
|
|
|
: props.gist.options[props.option]
|
|
|
|
return (
|
|
|
|
<span className={
|
|
|
|
val=== props.pattern.config.options[props.option].pct/100
|
|
|
|
? 'text-secondary'
|
|
|
|
: 'text-accent'
|
|
|
|
}>
|
|
|
|
{formatPercentage(val)}
|
|
|
|
{props.pattern.config.options[props.option]?.toAbs
|
|
|
|
? ' | ' +formatMm(props.pattern.config.options[props.option]?.toAbs(val, props.gist))
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
</span>
|
|
|
|
)
|
2022-01-26 09:38:47 +01:00
|
|
|
},
|
|
|
|
bool: props => {
|
|
|
|
const dflt = props.pattern.config.options[props.option].bool
|
|
|
|
const current = props.gist?.options?.[props.option]
|
|
|
|
return (
|
|
|
|
<span className={
|
|
|
|
(dflt==current || typeof current === 'undefined')
|
|
|
|
? 'text-secondary'
|
|
|
|
: 'text-accent'
|
|
|
|
}>
|
|
|
|
{props.gist?.options?.[props.option]
|
2022-02-08 20:49:19 +01:00
|
|
|
? props.t('app.yes')
|
|
|
|
: props.t('app.no')
|
2022-01-26 09:38:47 +01:00
|
|
|
}
|
|
|
|
</span>
|
|
|
|
)
|
|
|
|
},
|
|
|
|
count: props => {
|
2022-01-26 10:04:15 +01:00
|
|
|
const dflt = props.pattern.config.options[props.option].count
|
|
|
|
const current = props.gist?.options?.[props.option]
|
|
|
|
return (dflt==current || typeof current === 'undefined')
|
|
|
|
? <span className="text-secondary">{dflt}</span>
|
2022-01-26 11:53:43 +01:00
|
|
|
: <span className="text-accent">{current}</span>
|
2022-01-26 09:38:47 +01:00
|
|
|
},
|
|
|
|
list: props => {
|
2022-01-26 11:53:43 +01:00
|
|
|
const dflt = props.pattern.config.options[props.option].dflt
|
|
|
|
const current = props.gist?.options?.[props.option]
|
|
|
|
const prefix = `options.${props.pattern.config.name}.${props.option}.options.`
|
|
|
|
return (dflt==current || typeof current === 'undefined')
|
2022-02-08 20:49:19 +01:00
|
|
|
? <span className="text-secondary">{props.t(prefix+dflt)}</span>
|
|
|
|
: <span className="text-accent">{props.t(prefix+current)}</span>
|
2022-01-26 11:53:43 +01:00
|
|
|
},
|
|
|
|
deg: props => {
|
2022-01-26 13:41:40 +01:00
|
|
|
const dflt = props.pattern.config.options[props.option].deg
|
|
|
|
const current = props.gist?.options?.[props.option]
|
|
|
|
return (dflt==current || typeof current === 'undefined')
|
|
|
|
? <span className="text-secondary">{dflt}°</span>
|
|
|
|
: <span className="text-accent">{current}°</span>
|
2022-01-26 09:38:47 +01:00
|
|
|
},
|
|
|
|
mm: props => {
|
2022-01-26 11:53:43 +01:00
|
|
|
return <p>No mm val yet</p>
|
2022-01-26 09:38:47 +01:00
|
|
|
},
|
|
|
|
constant: props => {
|
2022-01-26 11:53:43 +01:00
|
|
|
return <p>No constant val yet</p>
|
2022-01-26 09:38:47 +01:00
|
|
|
},
|
2022-01-25 18:14:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const Tmp = props => <p>not yet</p>
|
|
|
|
|
|
|
|
const inputs = {
|
2022-01-26 13:41:40 +01:00
|
|
|
pct: PctDegOption,
|
2022-01-26 10:04:15 +01:00
|
|
|
count: CountOption,
|
2022-01-26 13:41:40 +01:00
|
|
|
deg: props => <PctDegOption {...props} type='deg' />,
|
2022-01-26 10:04:15 +01:00
|
|
|
list: ListOption,
|
2022-01-26 13:41:40 +01:00
|
|
|
mm: <p>Mm options are not supported. Please report this.</p>,
|
2022-01-25 18:14:31 +01:00
|
|
|
constant: Tmp,
|
|
|
|
}
|
|
|
|
|
2022-01-25 12:39:29 +01:00
|
|
|
|
|
|
|
const Option = props => {
|
2022-02-08 20:49:19 +01:00
|
|
|
const { t } = useTranslation(['app'])
|
2022-01-25 18:14:31 +01:00
|
|
|
const type = optionType(props.pattern.config.options[props.option])
|
|
|
|
const Input = inputs[type]
|
|
|
|
const Value = values[type]
|
|
|
|
|
2022-01-26 09:38:47 +01:00
|
|
|
const toggleBoolean = () => {
|
|
|
|
const dflt = props.pattern.config.options[props.option].bool
|
|
|
|
const current = props.gist?.options?.[props.option]
|
|
|
|
if (typeof current === 'undefined')
|
|
|
|
props.updateGist(['options', props.option], !dflt)
|
|
|
|
else props.unsetGist(['options', props.option])
|
|
|
|
}
|
|
|
|
|
2022-01-29 18:24:36 +01:00
|
|
|
return (type === 'bool')
|
|
|
|
? (
|
|
|
|
<Li>
|
|
|
|
<SumButton onClick={toggleBoolean}>
|
|
|
|
<SumDiv>
|
|
|
|
<Deg />
|
2022-01-25 12:39:29 +01:00
|
|
|
<span>
|
2022-02-08 20:49:19 +01:00
|
|
|
{ t(`options.${props.pattern.config.name}.${props.option}.title`) }
|
2022-01-25 12:39:29 +01:00
|
|
|
</span>
|
2022-01-29 18:24:36 +01:00
|
|
|
</SumDiv>
|
2022-02-08 20:49:19 +01:00
|
|
|
<Value type={type} {...props} t={t} />
|
2022-01-29 18:24:36 +01:00
|
|
|
</SumButton>
|
|
|
|
</Li>
|
|
|
|
) : (
|
|
|
|
<Li>
|
|
|
|
<Details>
|
|
|
|
<Summary>
|
|
|
|
<SumDiv>
|
|
|
|
<Deg />
|
|
|
|
<span>
|
2022-02-08 20:49:19 +01:00
|
|
|
{ t(`options.${props.pattern.config.name}.${props.option}.title`) }
|
2022-01-29 18:24:36 +01:00
|
|
|
</span>
|
|
|
|
</SumDiv>
|
2022-02-08 20:49:19 +01:00
|
|
|
<Value type={type} {...props} t={t} />
|
2022-01-29 18:24:36 +01:00
|
|
|
<Chevron w={6} m={3}/>
|
|
|
|
</Summary>
|
|
|
|
<Input {...props} />
|
|
|
|
</Details>
|
|
|
|
</Li>
|
|
|
|
)
|
2022-01-25 12:39:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Option
|