PromucFlow_constructor/app/client/src/components/propertyControls/BaseControl.tsx

43 lines
1.3 KiB
TypeScript
Raw Normal View History

/***
* Controls are rendered in the property panel from the property config
* Controls are higher order components that update a widgets property
*/
import { Component } from "react";
import _ from "lodash";
2019-11-05 05:09:50 +00:00
import { ControlType } from "../../constants/PropertyControlConstants";
2019-11-14 09:28:51 +00:00
import { ErrorCode } from "../../constants/validationErrorCodes";
abstract class BaseControl<T extends ControlProps> extends Component<T> {
updateProperty(propertyName: string, propertyValue: any) {
if (!_.isNil(this.props.onPropertyChange))
this.props.onPropertyChange(propertyName, propertyValue);
}
abstract getControlType(): ControlType;
}
export interface ControlBuilder<T extends ControlProps> {
buildPropertyControl(controlProps: T): JSX.Element;
}
export interface ControlProps extends ControlData, ControlFunctions {
key?: string;
}
export interface ControlData {
id: string;
label: string;
propertyName: string;
controlType: ControlType;
propertyValue?: any;
2019-11-14 09:28:51 +00:00
propertyError?: ErrorCode;
}
export interface ControlFunctions {
onPropertyChange?: (propertyName: string, propertyValue: string) => void;
2019-11-14 09:28:51 +00:00
getDynamicValue: (dynamicBinding: string) => any;
setPropertyValidation: (propertyName: string, errorCode: ErrorCode) => void;
}
export default BaseControl;