1
0
Fork 0
freesewing/packages/freesewing.shared/components/workbench/menu/design-options/option.js

162 lines
4.4 KiB
JavaScript
Raw Normal View History

2022-01-25 12:39:29 +01:00
import { linkClasses, Chevron } from 'shared/components/navigation/primary.js'
import PercentOption from 'shared/components/workbench/inputs/design-option-percentage'
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'
import { formatMm, formatPercentage, optionType } from 'shared/utils.js'
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]
? props.app.t('app.yes')
: props.app.t('app.no')
}
</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>
: <span className="text-secondary">{current}</span>
2022-01-26 09:38:47 +01:00
},
deg: props => {
return <p>No val yet</p>
},
list: props => {
return <p>No val yet</p>
},
mm: props => {
return <p>No val yet</p>
},
constant: props => {
return <p>No val yet</p>
},
}
const Tmp = props => <p>not yet</p>
const inputs = {
pct: PercentOption,
2022-01-26 10:04:15 +01:00
count: CountOption,
deg: Tmp,
2022-01-26 10:04:15 +01:00
list: ListOption,
mm: Tmp,
constant: Tmp,
}
2022-01-25 12:39:29 +01:00
const Option = props => {
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])
}
if (type === 'bool') return (
<li className="flex flex-row">
<button className={`
flex flex-row
w-full
justify-between
px-2
text-left
text-base-content
sm:text-neutral-content
items-center
pr-6
`} onClick={toggleBoolean}>
<div className={`
grow pl-2 border-l-2
${linkClasses}
hover:border-secondary
sm:hover:border-secondary-focus
text-base-content sm:text-neutral-content
`}>
<span className={`
text-3xl mr-2 inline-block p-0 leading-3
translate-y-3
`}>
<>&deg;</>
</span>
<span>
{ props.app.t(`options.${props.pattern.config.name}.${props.option}.title`) }
</span>
</div>
<Value type={type} {...props} />
</button>
</li>
)
2022-01-25 12:39:29 +01:00
return (
<li className="flex flex-row">
<details className="grow">
<summary className={`
flex flex-row
px-2
text-base-content
sm:text-neutral-content
hover:cursor-row-resize
items-center
`}>
<div className={`
grow pl-2 border-l-2
${linkClasses}
hover:border-secondary
sm:hover:border-secondary-focus
text-base-content sm:text-neutral-content
`}>
<span className={`
text-3xl mr-2 inline-block p-0 leading-3
translate-y-3
`}>
<>&deg;</>
</span>
<span>
{ props.app.t(`options.${props.pattern.config.name}.${props.option}.title`) }
</span>
</div>
<Value type={type} {...props} />
2022-01-25 12:39:29 +01:00
<Chevron w={6} m={3}/>
</summary>
<Input {...props} />
2022-01-25 12:39:29 +01:00
</details>
</li>
)
}
export default Option