PromucFlow_constructor/app/client/src/widgets/RadioGroupWidget.tsx

49 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-11-07 10:15:33 +00:00
import React from "react";
2019-09-09 09:08:54 +00:00
import BaseWidget, { WidgetProps, WidgetState } from "./BaseWidget";
import { WidgetType } from "../constants/WidgetConstants";
2019-11-05 05:09:50 +00:00
import RadioGroupComponent from "../components/designSystems/blueprint/RadioGroupComponent";
import { ActionPayload } from "../constants/ActionConstants";
2019-03-21 12:10:32 +00:00
class RadioGroupWidget extends BaseWidget<RadioGroupWidgetProps, WidgetState> {
2019-03-21 12:10:32 +00:00
getPageView() {
return (
<RadioGroupComponent
widgetId={this.props.widgetId}
2019-11-05 05:09:50 +00:00
onRadioSelectionChange={this.onRadioSelectionChange}
2019-03-21 12:10:32 +00:00
key={this.props.widgetId}
label={this.props.label}
2019-11-05 05:09:50 +00:00
selectedOptionValue={this.props.selectedOptionValue}
2019-03-21 12:10:32 +00:00
options={this.props.options}
/>
2019-09-09 09:08:54 +00:00
);
2019-03-21 12:10:32 +00:00
}
2019-11-05 05:09:50 +00:00
onRadioSelectionChange = (updatedValue: string) => {
this.context.updateWidgetProperty(
this.props.widgetId,
"selectedOptionValue",
updatedValue,
);
2019-11-06 12:12:41 +00:00
super.executeAction(this.props.onSelectionChange);
2019-11-05 05:09:50 +00:00
};
2019-03-21 12:10:32 +00:00
getWidgetType(): WidgetType {
2019-09-09 09:08:54 +00:00
return "RADIO_GROUP_WIDGET";
2019-03-21 12:10:32 +00:00
}
}
2019-09-12 08:11:25 +00:00
export interface RadioOption {
label: string;
value: string;
id: string;
2019-09-12 08:11:25 +00:00
}
2019-09-09 09:08:54 +00:00
export interface RadioGroupWidgetProps extends WidgetProps {
2019-08-29 11:22:09 +00:00
label: string;
options: RadioOption[];
2019-11-05 05:09:50 +00:00
selectedOptionValue: string;
2019-11-06 12:12:41 +00:00
onSelectionChange?: ActionPayload[];
2019-03-21 12:10:32 +00:00
}
export default RadioGroupWidget;