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

65 lines
1.8 KiB
TypeScript
Raw Normal View History

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 ButtonComponent from "components/designSystems/blueprint/ButtonComponent";
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-18 13:50:24 +00:00
2019-09-09 09:08:54 +00:00
class ButtonWidget extends BaseWidget<ButtonWidgetProps, WidgetState> {
2019-10-30 10:23:20 +00:00
onButtonClickBound: (event: React.MouseEvent<HTMLElement>) => void;
constructor(props: ButtonWidgetProps) {
super(props);
this.onButtonClickBound = this.onButtonClick.bind(this);
}
2019-11-22 13:12:39 +00:00
static getPropertyValidationMap(): WidgetPropertyValidationType {
return {
text: VALIDATION_TYPES.TEXT,
isDisabled: VALIDATION_TYPES.BOOLEAN,
isVisible: VALIDATION_TYPES.BOOLEAN,
buttonStyle: VALIDATION_TYPES.TEXT,
};
}
onButtonClick() {
super.executeAction(this.props.onClick);
}
getPageView() {
2019-03-18 13:50:24 +00:00
return (
<ButtonComponent
2019-10-31 05:28:11 +00:00
buttonStyle={this.props.buttonStyle}
2019-03-18 13:50:24 +00:00
widgetId={this.props.widgetId}
key={this.props.widgetId}
2019-11-05 05:09:50 +00:00
widgetName={this.props.widgetName}
text={this.props.text}
disabled={this.props.isDisabled}
2019-10-30 10:23:20 +00:00
onClick={this.onButtonClickBound}
2019-12-03 04:41:10 +00:00
isLoading={this.props.isLoading}
2019-03-18 13:50:24 +00:00
/>
2019-09-09 09:08:54 +00:00
);
2019-03-18 13:50:24 +00:00
}
getWidgetType(): WidgetType {
2019-09-09 09:08:54 +00:00
return "BUTTON_WIDGET";
2019-03-18 13:50:24 +00:00
}
}
export type ButtonStyle =
| "PRIMARY_BUTTON"
| "SECONDARY_BUTTON"
| "SUCCESS_BUTTON"
| "DANGER_BUTTON";
2019-09-12 08:11:25 +00:00
2019-09-09 09:08:54 +00:00
export interface ButtonWidgetProps extends WidgetProps {
2019-08-29 11:22:09 +00:00
text?: string;
buttonStyle?: ButtonStyle;
onClick?: ActionPayload[];
isDisabled?: boolean;
isVisible?: boolean;
2019-03-18 13:50:24 +00:00
}
2019-09-09 09:08:54 +00:00
export default ButtonWidget;