update choice widget to add radio buttons option.

This commit is contained in:
Mike Molinari 2022-10-25 03:49:34 +00:00 committed by Val Erastov
parent da6a462864
commit 7b5807089b

View file

@ -3,6 +3,10 @@ import React from "react";
import {FieldBasicProps, fieldToSchemaGeneric} from "cad/mdf/ui/field";
import {Types} from "cad/craft/schema/types";
import {ComboBoxOption} from "ui/components/controls/ComboBoxControl";
import {RadioButton} from 'ui/components/controls/RadioButtons';
import {RadioButtonsField} from '../../craft/wizard/components/form/Fields';
type ValueDef = [string, string] | string;
@ -18,7 +22,6 @@ export interface ChoiceWidgetProps extends FieldBasicProps {
export function ChoiceWidget(props: ChoiceWidgetProps) {
if (!props.style || props.style === 'dropdown') {
return <ComboBoxField name={props.name} defaultValue={props.defaultValue} label={props.label} includeNonExistent>
{props.values.map((value: any) => {
let val, name;
@ -31,9 +34,20 @@ export function ChoiceWidget(props: ChoiceWidgetProps) {
return <ComboBoxOption value={val} key={val}>{name}</ComboBoxOption>
})}
</ComboBoxField>;
} else {
throw 'implement me';
}
if (props.style === 'radio'){
return <RadioButtonsField name={props.name} defaultValue={props.defaultValue} label={props.label} includeNonExistent>
{props.values.map((value: any) => {
let val, name;
if (Array.isArray(value)) {
[val, name] = value;
} else {
val = value;
name = value;
}
return <RadioButton value={val} key={val}>{name}</RadioButton>
})}
</RadioButtonsField>;
}
}