2020-04-14 05:35:16 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import BaseWidget, { WidgetProps, WidgetState } from "./BaseWidget";
|
|
|
|
|
import { WidgetType, WidgetTypes } from "constants/WidgetConstants";
|
2020-08-24 05:42:19 +00:00
|
|
|
import styled from "styled-components";
|
2020-04-14 05:35:16 +00:00
|
|
|
import IconComponent, {
|
|
|
|
|
IconType,
|
|
|
|
|
} from "components/designSystems/appsmith/IconComponent";
|
|
|
|
|
import { EventType, ExecutionResult } from "constants/ActionConstants";
|
2020-08-28 17:23:07 +00:00
|
|
|
import * as Sentry from "@sentry/react";
|
2020-04-14 05:35:16 +00:00
|
|
|
|
2020-08-24 05:42:19 +00:00
|
|
|
const IconWrapper = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: flex-end;
|
|
|
|
|
`;
|
2020-04-14 05:35:16 +00:00
|
|
|
class IconWidget extends BaseWidget<IconWidgetProps, WidgetState> {
|
2021-02-24 10:29:19 +00:00
|
|
|
static getPropertyPaneConfig() {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
2020-04-14 05:35:16 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
|
|
|
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
|
|
|
handleActionResult = (result: ExecutionResult) => {};
|
|
|
|
|
|
|
|
|
|
onClick = () => {
|
|
|
|
|
if (this.props.onClick) {
|
|
|
|
|
super.executeAction({
|
|
|
|
|
dynamicString: this.props.onClick,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_CLICK,
|
|
|
|
|
callback: this.handleActionResult,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getPageView() {
|
|
|
|
|
return (
|
2020-08-24 05:42:19 +00:00
|
|
|
<IconWrapper>
|
|
|
|
|
<IconComponent
|
|
|
|
|
iconName={this.props.iconName}
|
|
|
|
|
disabled={this.props.disabled}
|
|
|
|
|
iconSize={this.props.iconSize}
|
|
|
|
|
color={this.props.color}
|
|
|
|
|
onClick={this.onClick}
|
|
|
|
|
/>
|
|
|
|
|
</IconWrapper>
|
2020-04-14 05:35:16 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getWidgetType(): WidgetType {
|
|
|
|
|
return WidgetTypes.ICON_WIDGET;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const IconSizes: { [key: string]: number } = {
|
|
|
|
|
LARGE: 32,
|
|
|
|
|
SMALL: 12,
|
|
|
|
|
DEFAULT: 16,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type IconSize = typeof IconSizes[keyof typeof IconSizes] | undefined;
|
|
|
|
|
|
|
|
|
|
export interface IconWidgetProps extends WidgetProps {
|
|
|
|
|
iconName: IconType;
|
|
|
|
|
onClick: string;
|
|
|
|
|
iconSize: IconSize;
|
|
|
|
|
color: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default IconWidget;
|
2020-08-28 17:23:07 +00:00
|
|
|
export const ProfiledIconWidget = Sentry.withProfiler(IconWidget);
|