2019-09-09 09:08:54 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import BaseWidget, { WidgetProps, WidgetState } from "./BaseWidget";
|
|
|
|
|
import { WidgetType } from "../constants/WidgetConstants";
|
2019-11-04 10:57:19 +00:00
|
|
|
import CheckboxComponent from "../components/designSystems/blueprint/CheckboxComponent";
|
2019-09-13 11:59:45 +00:00
|
|
|
import { ActionPayload } from "../constants/ActionConstants";
|
2019-11-19 12:44:58 +00:00
|
|
|
import { VALIDATION_TYPES } from "../constants/WidgetValidation";
|
|
|
|
|
import { WidgetPropertyValidationType } from "../utils/ValidationFactory";
|
2019-03-21 12:10:32 +00:00
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
class CheckboxWidget extends BaseWidget<CheckboxWidgetProps, WidgetState> {
|
2019-11-19 12:44:58 +00:00
|
|
|
static getPropertyValidationMap(): WidgetPropertyValidationType {
|
|
|
|
|
return {
|
|
|
|
|
isDisabled: VALIDATION_TYPES.BOOLEAN,
|
|
|
|
|
label: VALIDATION_TYPES.TEXT,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-21 12:10:32 +00:00
|
|
|
getPageView() {
|
|
|
|
|
return (
|
|
|
|
|
<CheckboxComponent
|
2019-09-12 08:11:25 +00:00
|
|
|
defaultCheckedState={this.props.defaultCheckedState}
|
|
|
|
|
label={this.props.label}
|
2019-03-21 12:10:32 +00:00
|
|
|
widgetId={this.props.widgetId}
|
|
|
|
|
key={this.props.widgetId}
|
2019-10-31 09:04:19 +00:00
|
|
|
isDisabled={this.props.isDisabled}
|
|
|
|
|
onCheckChange={this.onCheckChange}
|
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-10-31 09:04:19 +00:00
|
|
|
onCheckChange = (isChecked: boolean) => {
|
|
|
|
|
this.context.updateWidgetProperty(
|
|
|
|
|
this.props.widgetId,
|
|
|
|
|
"isChecked",
|
|
|
|
|
isChecked,
|
|
|
|
|
);
|
2019-11-06 12:12:41 +00:00
|
|
|
super.executeAction(this.props.onCheckChange);
|
2019-10-31 09:04:19 +00:00
|
|
|
};
|
|
|
|
|
|
2019-03-21 12:10:32 +00:00
|
|
|
getWidgetType(): WidgetType {
|
2019-09-13 10:45:49 +00:00
|
|
|
return "CHECKBOX_WIDGET";
|
2019-03-21 12:10:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
export interface CheckboxWidgetProps extends WidgetProps {
|
2019-09-13 10:45:49 +00:00
|
|
|
label: string;
|
|
|
|
|
defaultCheckedState: boolean;
|
2019-10-31 09:04:19 +00:00
|
|
|
isChecked?: boolean;
|
|
|
|
|
isDisabled?: boolean;
|
2019-09-13 11:59:45 +00:00
|
|
|
onCheckChange?: ActionPayload[];
|
2019-03-21 12:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
export default CheckboxWidget;
|