2019-08-29 11:22:09 +00:00
|
|
|
import React from "react";
|
2019-09-09 09:08:54 +00:00
|
|
|
import BaseWidget, { WidgetProps, WidgetState } from "./BaseWidget";
|
2021-04-01 08:30:33 +00:00
|
|
|
import { WidgetType, TextSize } from "constants/WidgetConstants";
|
2019-11-25 05:07:27 +00:00
|
|
|
import TextComponent from "components/designSystems/blueprint/TextComponent";
|
2021-07-26 05:50:46 +00:00
|
|
|
import { ValidationTypes } from "constants/WidgetValidation";
|
2020-06-09 12:04:38 +00:00
|
|
|
import { DerivedPropertiesMap } from "utils/WidgetFactory";
|
2020-08-28 17:23:07 +00:00
|
|
|
import * as Sentry from "@sentry/react";
|
2019-02-10 14:14:58 +00:00
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
class TextWidget extends BaseWidget<TextWidgetProps, WidgetState> {
|
2021-02-16 10:29:08 +00:00
|
|
|
static getPropertyPaneConfig() {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
sectionName: "General",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "text",
|
|
|
|
|
helpText: "Sets the text of the widget",
|
|
|
|
|
label: "Text",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
2021-09-09 08:18:16 +00:00
|
|
|
placeholderText: "Enter text",
|
2021-02-16 10:29:08 +00:00
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: { type: ValidationTypes.TEXT },
|
2021-02-16 10:29:08 +00:00
|
|
|
},
|
|
|
|
|
{
|
2021-04-01 08:30:33 +00:00
|
|
|
propertyName: "shouldScroll",
|
|
|
|
|
label: "Enable Scroll",
|
|
|
|
|
helpText: "Allows scrolling text instead of truncation",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isVisible",
|
|
|
|
|
helpText: "Controls the visibility of the widget",
|
|
|
|
|
label: "Visible",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
2021-04-01 08:30:33 +00:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Styles",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "backgroundColor",
|
|
|
|
|
label: "Cell Background",
|
|
|
|
|
controlType: "COLOR_PICKER",
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "textColor",
|
|
|
|
|
label: "Text Color",
|
|
|
|
|
controlType: "COLOR_PICKER",
|
2021-07-02 07:09:17 +00:00
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
2021-04-01 08:30:33 +00:00
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.TEXT,
|
|
|
|
|
params: {
|
|
|
|
|
regex: /^(?![<|{{]).+/,
|
|
|
|
|
},
|
|
|
|
|
},
|
2021-04-01 08:30:33 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "fontSize",
|
|
|
|
|
label: "Text Size",
|
2021-02-16 10:29:08 +00:00
|
|
|
controlType: "DROP_DOWN",
|
|
|
|
|
options: [
|
|
|
|
|
{
|
2021-04-01 08:30:33 +00:00
|
|
|
label: "Heading 1",
|
|
|
|
|
value: "HEADING1",
|
|
|
|
|
subText: "24px",
|
|
|
|
|
icon: "HEADING_ONE",
|
2021-02-16 10:29:08 +00:00
|
|
|
},
|
|
|
|
|
{
|
2021-04-01 08:30:33 +00:00
|
|
|
label: "Heading 2",
|
|
|
|
|
value: "HEADING2",
|
|
|
|
|
subText: "18px",
|
|
|
|
|
icon: "HEADING_TWO",
|
2021-02-16 10:29:08 +00:00
|
|
|
},
|
|
|
|
|
{
|
2021-04-01 08:30:33 +00:00
|
|
|
label: "Heading 3",
|
|
|
|
|
value: "HEADING3",
|
|
|
|
|
subText: "16px",
|
|
|
|
|
icon: "HEADING_THREE",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Paragraph",
|
|
|
|
|
value: "PARAGRAPH",
|
|
|
|
|
subText: "14px",
|
|
|
|
|
icon: "PARAGRAPH",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Paragraph 2",
|
|
|
|
|
value: "PARAGRAPH2",
|
|
|
|
|
subText: "12px",
|
|
|
|
|
icon: "PARAGRAPH_TWO",
|
2021-02-16 10:29:08 +00:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
2021-04-01 08:30:33 +00:00
|
|
|
propertyName: "fontStyle",
|
|
|
|
|
label: "Font Style",
|
|
|
|
|
controlType: "BUTTON_TABS",
|
2021-02-16 10:29:08 +00:00
|
|
|
options: [
|
|
|
|
|
{
|
2021-04-01 08:30:33 +00:00
|
|
|
icon: "BOLD_FONT",
|
|
|
|
|
value: "BOLD",
|
2021-02-16 10:29:08 +00:00
|
|
|
},
|
|
|
|
|
{
|
2021-04-01 08:30:33 +00:00
|
|
|
icon: "ITALICS_FONT",
|
|
|
|
|
value: "ITALIC",
|
2021-02-16 10:29:08 +00:00
|
|
|
},
|
|
|
|
|
],
|
2021-07-16 12:29:53 +00:00
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
2021-02-16 10:29:08 +00:00
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: { type: ValidationTypes.TEXT },
|
2021-02-16 10:29:08 +00:00
|
|
|
},
|
|
|
|
|
{
|
2021-04-01 08:30:33 +00:00
|
|
|
propertyName: "textAlign",
|
|
|
|
|
label: "Text Align",
|
|
|
|
|
controlType: "ICON_TABS",
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
icon: "LEFT_ALIGN",
|
|
|
|
|
value: "LEFT",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
icon: "CENTER_ALIGN",
|
|
|
|
|
value: "CENTER",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
icon: "RIGHT_ALIGN",
|
|
|
|
|
value: "RIGHT",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
defaultValue: "LEFT",
|
2021-07-16 12:29:53 +00:00
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
2021-02-16 10:29:08 +00:00
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: { type: ValidationTypes.TEXT },
|
2021-02-16 10:29:08 +00:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
}
|
2019-11-19 12:44:58 +00:00
|
|
|
|
2019-03-18 15:10:30 +00:00
|
|
|
getPageView() {
|
2019-02-10 14:14:58 +00:00
|
|
|
return (
|
2019-10-31 05:28:11 +00:00
|
|
|
<TextComponent
|
2021-04-01 08:30:33 +00:00
|
|
|
backgroundColor={this.props.backgroundColor}
|
2021-04-28 10:28:39 +00:00
|
|
|
fontSize={this.props.fontSize}
|
|
|
|
|
fontStyle={this.props.fontStyle}
|
2019-12-03 04:41:10 +00:00
|
|
|
isLoading={this.props.isLoading}
|
2021-04-28 10:28:39 +00:00
|
|
|
key={this.props.widgetId}
|
2020-01-28 08:21:22 +00:00
|
|
|
shouldScroll={this.props.shouldScroll}
|
2021-04-28 10:28:39 +00:00
|
|
|
text={this.props.text}
|
|
|
|
|
textAlign={this.props.textAlign ? this.props.textAlign : "LEFT"}
|
|
|
|
|
textColor={this.props.textColor}
|
|
|
|
|
widgetId={this.props.widgetId}
|
2019-02-10 14:14:58 +00:00
|
|
|
/>
|
2019-03-21 12:10:32 +00:00
|
|
|
);
|
2019-02-10 14:14:58 +00:00
|
|
|
}
|
|
|
|
|
|
2020-06-09 12:04:38 +00:00
|
|
|
static getDerivedPropertiesMap(): DerivedPropertiesMap {
|
|
|
|
|
return {
|
|
|
|
|
value: `{{ this.text }}`,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-10 14:14:58 +00:00
|
|
|
getWidgetType(): WidgetType {
|
2019-03-21 12:10:32 +00:00
|
|
|
return "TEXT_WIDGET";
|
2019-02-10 14:14:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 14:19:58 +00:00
|
|
|
export type TextAlign = "LEFT" | "CENTER" | "RIGHT" | "JUSTIFY";
|
2019-09-12 08:11:25 +00:00
|
|
|
|
2021-04-01 08:30:33 +00:00
|
|
|
export interface TextStyles {
|
|
|
|
|
backgroundColor?: string;
|
|
|
|
|
textColor?: string;
|
|
|
|
|
fontStyle?: string;
|
|
|
|
|
fontSize?: TextSize;
|
|
|
|
|
textAlign?: TextAlign;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface TextWidgetProps extends WidgetProps, TextStyles {
|
2019-03-21 12:10:32 +00:00
|
|
|
text?: string;
|
2019-12-03 04:41:10 +00:00
|
|
|
isLoading: boolean;
|
2020-01-28 08:21:22 +00:00
|
|
|
shouldScroll: boolean;
|
2019-02-10 14:14:58 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-21 12:10:32 +00:00
|
|
|
export default TextWidget;
|
2020-08-28 17:23:07 +00:00
|
|
|
export const ProfiledTextWidget = Sentry.withProfiler(TextWidget);
|