1
0
Fork 0
freesewing/sites/shared/components/workbench/menus/design-options/index.mjs

129 lines
2.7 KiB
JavaScript
Raw Normal View History

// Components
2023-05-29 23:22:26 -05:00
import { OptionsIcon } from 'shared/components/icons.mjs'
2023-05-11 19:14:48 +02:00
import { optionsMenuStructure } from 'shared/utils.mjs'
import { optionType } from 'shared/utils.mjs'
import {
2023-05-26 18:16:48 -05:00
BoolInput,
ConstantInput,
SliderInput,
DegInput,
ListInput,
PctInput,
} from '../shared/inputs.mjs'
2023-05-11 19:14:48 +02:00
import {
BoolOptionValue,
ConstantOptionValue,
CountOptionValue,
DegOptionValue,
ListOptionValue,
MmOptionValue,
PctOptionValue,
} from './values.mjs'
2023-05-29 23:22:26 -05:00
import { WorkbenchMenu } from '../shared/index.mjs'
import { MenuItem } from '../shared/menu-item.mjs'
2023-05-11 19:14:48 +02:00
export const ns = ['design-options']
2023-05-11 19:14:48 +02:00
// Facilitate lookup of the input component
const inputs = {
2023-05-26 18:16:48 -05:00
bool: BoolInput,
constant: ConstantInput,
count: SliderInput,
deg: DegInput,
list: ListInput,
mm: () => <span>FIXME: Mm options are deprecated. Please report this </span>,
2023-05-26 18:16:48 -05:00
pct: PctInput,
2023-05-11 19:14:48 +02:00
}
// Facilitate lookup of the value component
const values = {
bool: BoolOptionValue,
constant: ConstantOptionValue,
count: CountOptionValue,
deg: DegOptionValue,
list: ListOptionValue,
mm: MmOptionValue,
pct: PctOptionValue,
}
// Emojis for option groups :)
const emojis = {
advanced: '🤓',
fit: '👕',
style: '💃🏽',
dflt: '🕹️',
groupDflt: '📁',
}
export const DesignOption = ({
name,
current,
config,
settings,
updateFunc,
t,
loadDocs,
changed = false,
}) => {
2023-05-11 19:14:48 +02:00
const type = optionType(config)
const Input = inputs[type]
const Value = values[type]
2023-05-26 18:16:48 -05:00
const allowOverride = ['pct', 'count', 'deg'].includes(type)
2023-05-11 19:14:48 +02:00
// Hide option?
if (config?.hide || (typeof config?.hide === 'function' && config.hide(settings))) return null
return (
2023-05-26 18:16:48 -05:00
<MenuItem
{...{
name,
config,
current,
updateFunc,
2023-05-26 18:16:48 -05:00
t,
changed,
loadDocs,
Input,
Value,
allowOverride,
passProps: { settings },
2023-05-26 18:16:48 -05:00
}}
/>
2023-05-11 19:14:48 +02:00
)
}
export const DesignOptions = ({
design,
patternConfig,
settings,
update,
language,
2023-05-26 18:16:48 -05:00
account,
DynamicDocs = false,
}) => {
2023-05-26 18:16:48 -05:00
const menuNs = [`o_${design}`, ...ns]
2023-05-11 19:14:48 +02:00
const optionsMenu = optionsMenuStructure(patternConfig.options)
2023-05-26 18:16:48 -05:00
const getDocsPath = (option) =>
`patterns/${design}/options${option ? '/' + option.toLowerCase() : ''}`
2023-05-11 19:14:48 +02:00
return (
2023-05-26 18:16:48 -05:00
<WorkbenchMenu
{...{
config: optionsMenu,
2023-05-29 23:22:26 -05:00
control: account.control,
2023-05-26 18:16:48 -05:00
currentValues: settings.options,
DynamicDocs,
emojis,
2023-05-26 18:16:48 -05:00
getDocsPath,
Icon: OptionsIcon,
Item: DesignOption,
name: 'design-options:designOptions',
language,
ns: menuNs,
passProps: { settings },
updateFunc: (name, value) => update.settings(['options', name], value),
2023-05-26 18:16:48 -05:00
}}
/>
2023-05-11 19:14:48 +02:00
)
}