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

65 lines
1.8 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";
2019-11-25 05:07:27 +00:00
import { WidgetType } from "constants/WidgetConstants";
import RadioGroupComponent from "components/designSystems/blueprint/RadioGroupComponent";
import { ActionPayload } from "constants/ActionConstants";
2019-11-22 13:12:39 +00:00
import { WidgetPropertyValidationType } from "utils/ValidationFactory";
import { VALIDATION_TYPES } from "constants/WidgetValidation";
2019-03-21 12:10:32 +00:00
class RadioGroupWidget extends BaseWidget<RadioGroupWidgetProps, WidgetState> {
2019-11-22 13:12:39 +00:00
static getPropertyValidationMap(): WidgetPropertyValidationType {
return {
label: VALIDATION_TYPES.TEXT,
options: VALIDATION_TYPES.ARRAY,
selectedOptionValue: VALIDATION_TYPES.TEXT,
};
}
2020-01-17 09:28:26 +00:00
static getDerivedPropertiesMap() {
return {
selectedOption:
"{{_.find(this.options, { value: this.selectedOptionValue })}}",
};
}
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-12-03 04:41:10 +00:00
isLoading={this.props.isLoading}
2019-03-21 12:10:32 +00:00
/>
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;