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

53 lines
1.6 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";
import { EditorTheme } from "components/editorComponents/CodeEditor/EditorConfig";
import { PropertyPaneControlConfig } from "constants/PropertyControlConstants";
// eslint-disable-next-line @typescript-eslint/ban-types
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);
}
deleteProperties(propertyPaths: string[]) {
if (this.props.deleteProperties) {
this.props.deleteProperties(propertyPaths);
}
}
}
export interface ControlBuilder<T extends ControlProps> {
buildPropertyControl(controlProps: T): JSX.Element;
}
export interface ControlProps extends ControlData, ControlFunctions {
key?: string;
additionalAutoComplete?: Record<string, Record<string, unknown>>;
}
export interface ControlData
extends Omit<PropertyPaneControlConfig, "additionalAutoComplete"> {
propertyValue?: any;
2019-11-19 12:44:58 +00:00
isValid: boolean;
2020-06-04 13:49:22 +00:00
errorMessage?: string;
expected: string;
2020-06-05 16:20:23 +00:00
evaluatedValue: any;
2019-12-10 13:30:16 +00:00
validationMessage?: string;
widgetProperties: any;
useValidationMessage?: boolean;
}
export interface ControlFunctions {
onPropertyChange?: (propertyName: string, propertyValue: string) => void;
openNextPanel: (props: any) => void;
deleteProperties: (propertyPaths: string[]) => void;
theme: EditorTheme;
}
export default BaseControl;