2019-09-13 10:45:49 +00:00
|
|
|
import * as React from "react";
|
|
|
|
|
import BaseWidget, { WidgetProps, WidgetState } from "./BaseWidget";
|
2020-09-18 10:12:57 +00:00
|
|
|
import { WidgetType, RenderModes } from "constants/WidgetConstants";
|
2019-11-25 05:07:27 +00:00
|
|
|
import ImageComponent from "components/designSystems/appsmith/ImageComponent";
|
2020-03-16 07:59:07 +00:00
|
|
|
import {
|
|
|
|
|
WidgetPropertyValidationType,
|
|
|
|
|
BASE_WIDGET_VALIDATION,
|
2020-10-21 04:25:32 +00:00
|
|
|
} from "utils/WidgetValidation";
|
2019-11-22 13:12:39 +00:00
|
|
|
import { VALIDATION_TYPES } from "constants/WidgetValidation";
|
2020-08-28 17:23:07 +00:00
|
|
|
import * as Sentry from "@sentry/react";
|
2020-09-18 10:12:57 +00:00
|
|
|
import { EventType } from "constants/ActionConstants";
|
|
|
|
|
import { TriggerPropertiesMap } from "utils/WidgetFactory";
|
2019-09-12 08:11:25 +00:00
|
|
|
|
2019-09-13 10:45:49 +00:00
|
|
|
class ImageWidget extends BaseWidget<ImageWidgetProps, WidgetState> {
|
2020-09-18 10:12:57 +00:00
|
|
|
constructor(props: ImageWidgetProps) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.onImageClick = this.onImageClick.bind(this);
|
|
|
|
|
}
|
2021-02-16 10:29:08 +00:00
|
|
|
static getPropertyPaneConfig() {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
sectionName: "General",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
helpText: "Renders the url or Base64 in the widget",
|
|
|
|
|
propertyName: "image",
|
|
|
|
|
label: "Image",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
|
|
|
|
placeholderText: "Enter URL / Base64",
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
helpText: "Renders the url or Base64 when no image is provided",
|
|
|
|
|
propertyName: "defaultImage",
|
|
|
|
|
label: "Default Image",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
|
|
|
|
placeholderText: "Enter URL / Base64",
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
helpText: "Controls the visibility of the widget",
|
|
|
|
|
propertyName: "isVisible",
|
|
|
|
|
label: "Visible",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
helpText: "Controls the max zoom of the widget",
|
|
|
|
|
propertyName: "maxZoomLevel",
|
|
|
|
|
label: "Max Zoom Level",
|
|
|
|
|
controlType: "DROP_DOWN",
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
label: "1x (No Zoom)",
|
|
|
|
|
value: 1,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "2x",
|
|
|
|
|
value: 2,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "4x",
|
|
|
|
|
value: 4,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "8x",
|
|
|
|
|
value: 8,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "16x",
|
|
|
|
|
value: 16,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Actions",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
helpText:
|
|
|
|
|
"Triggers an action when a user changes the selected option",
|
|
|
|
|
propertyName: "onClick",
|
|
|
|
|
label: "onClick",
|
|
|
|
|
controlType: "ACTION_SELECTOR",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: true,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
}
|
2019-11-22 13:12:39 +00:00
|
|
|
static getPropertyValidationMap(): WidgetPropertyValidationType {
|
|
|
|
|
return {
|
2020-03-16 07:59:07 +00:00
|
|
|
...BASE_WIDGET_VALIDATION,
|
2019-11-22 13:12:39 +00:00
|
|
|
image: VALIDATION_TYPES.TEXT,
|
|
|
|
|
imageShape: VALIDATION_TYPES.TEXT,
|
|
|
|
|
defaultImage: VALIDATION_TYPES.TEXT,
|
2020-10-29 11:14:39 +00:00
|
|
|
maxZoomLevel: VALIDATION_TYPES.NUMBER,
|
2019-11-22 13:12:39 +00:00
|
|
|
};
|
|
|
|
|
}
|
2020-09-18 10:12:57 +00:00
|
|
|
static getTriggerPropertyMap(): TriggerPropertiesMap {
|
|
|
|
|
return {
|
|
|
|
|
onClick: true,
|
|
|
|
|
};
|
|
|
|
|
}
|
2019-09-12 08:11:25 +00:00
|
|
|
getPageView() {
|
2020-10-29 11:14:39 +00:00
|
|
|
const { maxZoomLevel } = this.props;
|
2019-11-05 05:09:50 +00:00
|
|
|
return (
|
|
|
|
|
<ImageComponent
|
2020-10-29 11:14:39 +00:00
|
|
|
disableDrag={(disable: boolean) => {
|
|
|
|
|
this.disableDrag(disable);
|
|
|
|
|
}}
|
|
|
|
|
maxZoomLevel={maxZoomLevel}
|
2019-11-05 05:09:50 +00:00
|
|
|
widgetId={this.props.widgetId}
|
2020-10-06 06:36:57 +00:00
|
|
|
imageUrl={this.props.image || ""}
|
2020-09-18 10:12:57 +00:00
|
|
|
onClick={this.props.onClick ? this.onImageClick : undefined}
|
|
|
|
|
showHoverPointer={this.props.renderMode === RenderModes.PAGE}
|
2019-11-05 05:09:50 +00:00
|
|
|
defaultImageUrl={this.props.defaultImage}
|
2019-12-03 04:41:10 +00:00
|
|
|
isLoading={this.props.isLoading}
|
2019-11-05 05:09:50 +00:00
|
|
|
/>
|
|
|
|
|
);
|
2019-09-12 08:11:25 +00:00
|
|
|
}
|
|
|
|
|
|
2020-09-18 10:12:57 +00:00
|
|
|
onImageClick() {
|
|
|
|
|
if (this.props.onClick) {
|
|
|
|
|
super.executeAction({
|
|
|
|
|
dynamicString: this.props.onClick,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_CLICK,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-12 08:11:25 +00:00
|
|
|
getWidgetType(): WidgetType {
|
2019-09-13 10:45:49 +00:00
|
|
|
return "IMAGE_WIDGET";
|
2019-09-12 08:11:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-13 10:45:49 +00:00
|
|
|
export type ImageShape = "RECTANGLE" | "CIRCLE" | "ROUNDED";
|
2019-09-12 08:11:25 +00:00
|
|
|
|
2019-09-13 10:45:49 +00:00
|
|
|
export interface ImageWidgetProps extends WidgetProps {
|
|
|
|
|
image: string;
|
|
|
|
|
imageShape: ImageShape;
|
|
|
|
|
defaultImage: string;
|
2020-10-29 11:14:39 +00:00
|
|
|
maxZoomLevel: number;
|
2020-09-18 10:12:57 +00:00
|
|
|
onClick?: string;
|
2019-09-12 08:11:25 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-13 10:45:49 +00:00
|
|
|
export default ImageWidget;
|
2020-08-28 17:23:07 +00:00
|
|
|
export const ProfiledImageWidget = Sentry.withProfiler(ImageWidget);
|