2019-09-18 10:19:50 +00:00
|
|
|
/***
|
|
|
|
|
* 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";
|
2021-03-15 12:17:56 +00:00
|
|
|
import { EditorTheme } from "components/editorComponents/CodeEditor/EditorConfig";
|
2021-02-16 10:29:08 +00:00
|
|
|
import { PropertyPaneControlConfig } from "constants/PropertyControlConstants";
|
|
|
|
|
|
2020-11-03 13:05:40 +00:00
|
|
|
// 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
|
|
|
|
|
> {
|
2021-02-25 14:00:02 +00:00
|
|
|
updateProperty(propertyName: string, propertyValue: any) {
|
2019-09-18 10:19:50 +00:00
|
|
|
if (!_.isNil(this.props.onPropertyChange))
|
2021-02-25 14:00:02 +00:00
|
|
|
this.props.onPropertyChange(propertyName, propertyValue);
|
2021-02-16 10:29:08 +00:00
|
|
|
}
|
|
|
|
|
deleteProperties(propertyPaths: string[]) {
|
|
|
|
|
if (this.props.deleteProperties) {
|
|
|
|
|
this.props.deleteProperties(propertyPaths);
|
|
|
|
|
}
|
2019-09-18 10:19:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ControlBuilder<T extends ControlProps> {
|
|
|
|
|
buildPropertyControl(controlProps: T): JSX.Element;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ControlProps extends ControlData, ControlFunctions {
|
|
|
|
|
key?: string;
|
2021-02-19 04:49:54 +00:00
|
|
|
additionalAutoComplete?: Record<string, Record<string, unknown>>;
|
2019-09-18 10:19:50 +00:00
|
|
|
}
|
2021-02-19 04:49:54 +00:00
|
|
|
export interface ControlData
|
|
|
|
|
extends Omit<PropertyPaneControlConfig, "additionalAutoComplete"> {
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
propertyValue?: any;
|
2020-06-04 13:49:22 +00:00
|
|
|
errorMessage?: string;
|
2021-05-26 12:32:43 +00:00
|
|
|
expected?: string;
|
2020-06-05 16:20:23 +00:00
|
|
|
evaluatedValue: any;
|
2021-02-16 10:29:08 +00:00
|
|
|
widgetProperties: any;
|
2021-03-24 12:12:24 +00:00
|
|
|
useValidationMessage?: boolean;
|
2021-05-26 12:32:43 +00:00
|
|
|
parentPropertyName: string;
|
|
|
|
|
parentPropertyValue: unknown;
|
|
|
|
|
additionalDynamicData: Record<string, Record<string, unknown>>;
|
2019-09-18 10:19:50 +00:00
|
|
|
}
|
|
|
|
|
export interface ControlFunctions {
|
2021-02-25 14:00:02 +00:00
|
|
|
onPropertyChange?: (propertyName: string, propertyValue: string) => void;
|
2021-02-16 10:29:08 +00:00
|
|
|
openNextPanel: (props: any) => void;
|
|
|
|
|
deleteProperties: (propertyPaths: string[]) => void;
|
2021-03-15 12:17:56 +00:00
|
|
|
theme: EditorTheme;
|
2021-04-23 05:43:13 +00:00
|
|
|
hideEvaluatedValue?: boolean;
|
2019-09-18 10:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default BaseControl;
|