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

56 lines
1.8 KiB
JavaScript
Raw Normal View History

2023-05-11 19:14:48 +02:00
import { formatMm, formatPercentage } from 'shared/utils.mjs'
2023-05-31 17:42:16 -05:00
import { ListValue, HighlightedValue, PlainValue, BoolValue } from '../shared/values'
import { mergeOptions } from '@freesewing/core'
2023-05-31 17:42:16 -05:00
/** Displays the current percentatge value, and the absolute value if configured */
export const PctOptionValue = ({ config, current, settings, changed, patternConfig }) => {
const val = changed ? current : config.pct / 100
2023-05-11 19:14:48 +02:00
return (
<HighlightedValue changed={changed}>
2023-05-11 19:14:48 +02:00
{formatPercentage(val)}
{config.toAbs && settings.measurements
? ` | ${formatMm(
config.toAbs(val, settings, mergeOptions(settings, patternConfig.options))
)}`
: null}
</HighlightedValue>
2023-05-11 19:14:48 +02:00
)
}
2023-05-31 17:42:16 -05:00
/** Displays a count value*/
export const CountOptionValue = ({ config, current, changed }) => (
<PlainValue {...{ current, changed, dflt: config.count }} />
)
2023-05-11 19:14:48 +02:00
2023-05-31 17:42:16 -05:00
/** Displays a list option value */
export const ListOptionValue = (props) => (
<ListValue {...props} t={(input) => props.t(`${props.name}.o.${input}`)} />
)
2023-05-11 19:14:48 +02:00
2023-05-31 17:42:16 -05:00
/** Displays a degree value */
export const DegOptionValue = ({ config, current, changed }) => (
<HighlightedValue changed={changed}> {changed ? current : config.deg}&deg;</HighlightedValue>
)
2023-05-11 19:14:48 +02:00
2023-05-31 17:42:16 -05:00
/** Displays the MmOptions are not supported */
2023-05-11 19:14:48 +02:00
export const MmOptionValue = () => (
2023-05-31 17:42:16 -05:00
<span className="text-error">FIXME: No Mm Options are not supported</span>
2023-05-11 19:14:48 +02:00
)
2023-05-31 17:42:16 -05:00
/** Displays that constant values are not implemented in the front end */
2023-05-11 19:14:48 +02:00
export const ConstantOptionValue = () => (
<span className="text-error">FIXME: No ConstantOptionvalue implemented</span>
)
2023-06-02 09:41:00 -05:00
// Facilitate lookup of the value component
export const values = {
bool: BoolValue,
constant: ConstantOptionValue,
count: CountOptionValue,
deg: DegOptionValue,
list: ListOptionValue,
mm: MmOptionValue,
pct: PctOptionValue,
}