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

47 lines
1.2 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-25 05:07:27 +00:00
import { ControlType } from "constants/PropertyControlConstants";
2020-02-18 10:41:52 +00:00
abstract class BaseControl<P extends ControlProps, S = {}> extends Component<
P,
S
> {
updateProperty(propertyName: string, propertyValue: any) {
if (!_.isNil(this.props.onPropertyChange))
this.props.onPropertyChange(propertyName, propertyValue);
}
}
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;
2020-03-19 13:22:01 +00:00
helpText?: string;
2020-03-16 07:59:07 +00:00
isJSConvertible?: boolean;
controlType: ControlType;
propertyValue?: any;
2019-11-19 12:44:58 +00:00
isValid: boolean;
errorMessage?: string;
expected: string;
2019-12-10 13:30:16 +00:00
validationMessage?: string;
dataTreePath: string;
}
export interface ControlFunctions {
onPropertyChange?: (propertyName: string, propertyValue: string) => void;
}
export default BaseControl;