PromucFlow_constructor/app/client/src/widgets/ImageWidget.tsx

72 lines
2.0 KiB
TypeScript
Raw Normal View History

import * as React from "react";
import BaseWidget, { WidgetProps, WidgetState } from "./BaseWidget";
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,
} from "utils/ValidationFactory";
2019-11-22 13:12:39 +00:00
import { VALIDATION_TYPES } from "constants/WidgetValidation";
import * as Sentry from "@sentry/react";
import { EventType } from "constants/ActionConstants";
import { TriggerPropertiesMap } from "utils/WidgetFactory";
2019-09-12 08:11:25 +00:00
class ImageWidget extends BaseWidget<ImageWidgetProps, WidgetState> {
constructor(props: ImageWidgetProps) {
super(props);
this.onImageClick = this.onImageClick.bind(this);
}
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,
};
}
static getTriggerPropertyMap(): TriggerPropertiesMap {
return {
onClick: true,
};
}
2019-09-12 08:11:25 +00:00
getPageView() {
2019-11-05 05:09:50 +00:00
return (
<ImageComponent
widgetId={this.props.widgetId}
imageUrl={this.props.image}
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
}
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 {
return "IMAGE_WIDGET";
2019-09-12 08:11:25 +00:00
}
}
export type ImageShape = "RECTANGLE" | "CIRCLE" | "ROUNDED";
2019-09-12 08:11:25 +00:00
export interface ImageWidgetProps extends WidgetProps {
image: string;
imageShape: ImageShape;
defaultImage: string;
onClick?: string;
2019-09-12 08:11:25 +00:00
}
export default ImageWidget;
export const ProfiledImageWidget = Sentry.withProfiler(ImageWidget);