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";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { ControlType } from "constants/PropertyControlConstants";
|
2019-09-18 10:19:50 +00:00
|
|
|
|
2020-02-18 10:41:52 +00:00
|
|
|
abstract class BaseControl<P extends ControlProps, S = {}> extends Component<
|
|
|
|
|
P,
|
|
|
|
|
S
|
|
|
|
|
> {
|
2019-09-18 10:19:50 +00:00
|
|
|
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;
|
2019-09-18 10:19:50 +00:00
|
|
|
controlType: ControlType;
|
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;
|
2019-11-19 12:44:58 +00:00
|
|
|
isValid: boolean;
|
2020-06-05 08:09:01 +00:00
|
|
|
errorMessage?: string;
|
|
|
|
|
expected: string;
|
2019-12-10 13:30:16 +00:00
|
|
|
validationMessage?: string;
|
2020-06-05 08:09:01 +00:00
|
|
|
dataTreePath: string;
|
2019-09-18 10:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ControlFunctions {
|
|
|
|
|
onPropertyChange?: (propertyName: string, propertyValue: string) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default BaseControl;
|