2019-11-11 11:34:42 +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-04 10:57:19 +00:00
|
|
|
import RadioGroupComponent from "../components/designSystems/blueprint/RadioGroupComponent";
|
2019-09-13 11:59:45 +00:00
|
|
|
import { ActionPayload } from "../constants/ActionConstants";
|
2019-03-21 12:10:32 +00:00
|
|
|
|
2019-09-13 10:45:49 +00:00
|
|
|
class RadioGroupWidget extends BaseWidget<RadioGroupWidgetProps, WidgetState> {
|
2019-03-21 12:10:32 +00:00
|
|
|
getPageView() {
|
|
|
|
|
return (
|
|
|
|
|
<RadioGroupComponent
|
|
|
|
|
style={this.getPositionStyle()}
|
|
|
|
|
widgetId={this.props.widgetId}
|
2019-10-31 09:04:19 +00:00
|
|
|
onRadioSelectionChange={this.onRadioSelectionChange}
|
2019-03-21 12:10:32 +00:00
|
|
|
key={this.props.widgetId}
|
|
|
|
|
label={this.props.label}
|
2019-10-31 09:04:19 +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-10-31 09:04:19 +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-10-31 09:04:19 +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 {
|
2019-09-13 10:45:49 +00:00
|
|
|
label: string;
|
|
|
|
|
value: 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;
|
2019-09-13 10:45:49 +00:00
|
|
|
options: RadioOption[];
|
2019-10-31 09:04:19 +00:00
|
|
|
selectedOptionValue: string;
|
2019-11-06 12:12:41 +00:00
|
|
|
onSelectionChange?: ActionPayload[];
|
2019-03-21 12:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-13 10:45:49 +00:00
|
|
|
export default RadioGroupWidget;
|