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

99 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-06-02 09:41:00 -05:00
import { optionsMenuStructure, optionType } from 'shared/utils.mjs'
import { values } from './values.mjs'
import { inputs } from './inputs.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']
// Emojis for option groups :)
const emojis = {
advanced: '🤓',
fit: '👕',
style: '💃🏽',
dflt: '🕹️',
groupDflt: '📁',
}
2023-05-31 17:42:16 -05:00
/**
* A wrapper for {@see MenuItem} to handle design option-specific business
* @param {Object} options.config the config for the item
* @param {Object} options.settings core settings
* @param {Object} options.rest the rest of the props
*/
2023-06-02 09:41:00 -05:00
const DesignOption = ({ config, settings, control, ...rest }) => {
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-06-02 09:41:00 -05:00
const allowToggle =
(control > 3 && type === 'bool') || (type == 'list' && config.list.length === 2)
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
{...{
config,
2023-06-02 09:41:00 -05:00
control,
2023-05-31 17:42:16 -05:00
...rest,
2023-05-26 18:16:48 -05:00
Input,
Value,
allowOverride,
2023-06-02 09:41:00 -05:00
allowToggle,
2023-05-26 18:16:48 -05:00
}}
/>
2023-05-11 19:14:48 +02:00
)
}
2023-05-31 17:42:16 -05:00
/**
* The design options menu
* @param {String} options.design the name of the design
* @param {Object} options.patternConfig the configuration from the pattern
* @param {Object} options.settings core settings
* @param {Object} options.update settings and ui update functions
* @param {String} options.language the menu language
* @param {Object} options.account the user account data
* @param {Boolean|React.component} options.DynamicDocs A docs component
*/
export const DesignOptions = ({
design,
patternConfig,
settings,
update,
language,
2023-05-26 18:16:48 -05:00
account,
2023-06-03 11:31:40 -05:00
isFirst = true,
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,
2023-06-03 11:31:40 -05:00
isFirst,
name: 'design-options:designOptions',
language,
ns: menuNs,
passProps: { settings },
2023-06-04 09:59:47 -05:00
updateFunc: (name, value) => update.settings(['options', ...name], value),
2023-05-26 18:16:48 -05:00
}}
/>
2023-05-11 19:14:48 +02:00
)
}