wip: Fix all design option inputs
This commit is contained in:
parent
899b323563
commit
e78864f274
4 changed files with 76 additions and 25 deletions
|
@ -1,20 +1,73 @@
|
|||
import React from 'react'
|
||||
import { mergeOptions } from '@freesewing/core'
|
||||
import { designOptionType, set, orderBy } from '@freesewing/utils'
|
||||
import { i18n } from '@freesewing/collection'
|
||||
import { linkClasses } from '@freesewing/utils'
|
||||
|
||||
export function menuDesignOptionsStructure(options, settings, asFullList = false) {
|
||||
const DesignDocsLink = ({ design, item }) => (
|
||||
<a
|
||||
href={`/docs/designs/${design}/options/#${item.toLowerCase()}`}
|
||||
className={`${linkClasses} tw-px-2`}
|
||||
target="_BLANK"
|
||||
>
|
||||
Learn more
|
||||
</a>
|
||||
)
|
||||
|
||||
export function menuDesignOptionsStructure(design, options, settings, asFullList = false) {
|
||||
if (!options) return options
|
||||
const sorted = {}
|
||||
for (const [name, option] of Object.entries(options)) {
|
||||
if (typeof option === 'object') sorted[name] = { ...option, name }
|
||||
if (typeof option === 'object') {
|
||||
sorted[name] = {
|
||||
...option,
|
||||
name,
|
||||
title: i18n[design].en.o[name].t,
|
||||
about: (
|
||||
<span>
|
||||
{i18n[design].en.o[name].d}
|
||||
<DesignDocsLink item={name} design={design} />
|
||||
</span>
|
||||
),
|
||||
dense: true,
|
||||
sideBySide: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const menu = {}
|
||||
// Fixme: One day we should sort this based on the translation
|
||||
for (const option of orderBy(sorted, ['order', 'menu', 'name'], ['asc', 'asc', 'asc'])) {
|
||||
if (typeof option === 'object') {
|
||||
const oType = designOptionType(option)
|
||||
option.dflt = option.dflt || option[oType]
|
||||
// Percentage option tweaks
|
||||
if (oType === 'pct') option.dflt /= 100
|
||||
// List option tweaks
|
||||
else if (oType === 'list') {
|
||||
option.valueTitles = {}
|
||||
option.choiceTitles = {}
|
||||
option.choiceDescriptions = {}
|
||||
for (const entry of option.list) {
|
||||
option.choiceTitles[entry] = i18n[design].en.o[`${option.name}.${entry}`].t
|
||||
option.choiceDescriptions[entry] = i18n[design].en.o[`${option.name}.${entry}`].d
|
||||
option.valueTitles[entry] = i18n[design].en.o[`${option.name}.${entry}`].t
|
||||
}
|
||||
}
|
||||
// Bool option tweaks
|
||||
else if (oType === 'bool') {
|
||||
option.list = [false, true]
|
||||
option.valueTitles = {}
|
||||
option.choiceTitles = {}
|
||||
option.choiceDescriptions = {}
|
||||
for (const entry of option.list) {
|
||||
option.choiceTitles.false = i18n[design].en.o[`${option.name}No`].t
|
||||
option.choiceDescriptions.false = i18n[design].en.o[`${option.name}No`].d
|
||||
option.valueTitles.false = 'No'
|
||||
option.choiceTitles.true = i18n[design].en.o[`${option.name}Yes`].t
|
||||
option.choiceDescriptions.true = i18n[design].en.o[`${option.name}Yes`].d
|
||||
option.valueTitles.true = 'Yes'
|
||||
}
|
||||
}
|
||||
if (typeof option.menu === 'function')
|
||||
option.menu = asFullList
|
||||
? 'conditional'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue