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'
|
2023-06-11 14:10:17 +02:00
|
|
|
import { mergeOptions } from '@freesewing/core'
|
2023-05-31 17:42:16 -05:00
|
|
|
|
|
|
|
/** Displays the current percentatge value, and the absolute value if configured */
|
2023-06-11 14:10:17 +02:00
|
|
|
export const PctOptionValue = ({ config, current, settings, changed, patternConfig }) => {
|
2023-05-29 22:34:33 -05:00
|
|
|
const val = changed ? current : config.pct / 100
|
2023-05-11 19:14:48 +02:00
|
|
|
|
|
|
|
return (
|
2023-05-29 13:35:04 -05:00
|
|
|
<HighlightedValue changed={changed}>
|
2023-05-11 19:14:48 +02:00
|
|
|
{formatPercentage(val)}
|
2023-06-11 14:10:17 +02:00
|
|
|
{config.toAbs && settings.measurements
|
|
|
|
? ` | ${formatMm(
|
|
|
|
config.toAbs(val, settings, mergeOptions(settings, patternConfig.options))
|
|
|
|
)}`
|
|
|
|
: null}
|
2023-05-29 13:35:04 -05:00
|
|
|
</HighlightedValue>
|
2023-05-11 19:14:48 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-05-31 17:42:16 -05:00
|
|
|
/** Displays a count value*/
|
2023-05-29 13:35:04 -05:00
|
|
|
export const CountOptionValue = ({ config, current, changed }) => (
|
2023-05-29 22:34:33 -05:00
|
|
|
<PlainValue {...{ current, changed, dflt: config.count }} />
|
2023-05-29 13:35:04 -05:00
|
|
|
)
|
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 */
|
2023-05-29 13:35:04 -05:00
|
|
|
export const DegOptionValue = ({ config, current, changed }) => (
|
|
|
|
<HighlightedValue changed={changed}> {changed ? current : config.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,
|
|
|
|
}
|