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";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { WidgetType } from "constants/WidgetConstants";
|
|
|
|
|
import TextComponent from "components/designSystems/blueprint/TextComponent";
|
|
|
|
|
import { VALIDATION_TYPES } from "constants/WidgetValidation";
|
2020-03-16 07:59:07 +00:00
|
|
|
import {
|
|
|
|
|
WidgetPropertyValidationType,
|
|
|
|
|
BASE_WIDGET_VALIDATION,
|
2020-10-21 04:25:32 +00:00
|
|
|
} from "utils/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
|
|
|
|
2020-01-14 09:48:01 +00:00
|
|
|
const LINE_HEIGHTS: { [key in TextStyle]: number } = {
|
|
|
|
|
// The following values are arrived at by multiplying line-height with font-size
|
|
|
|
|
BODY: 1.5 * 14,
|
|
|
|
|
HEADING: 1.28581 * 16,
|
|
|
|
|
LABEL: 1.28581 * 14,
|
|
|
|
|
SUB_TEXT: 1.28581 * 12,
|
|
|
|
|
};
|
|
|
|
|
|
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",
|
|
|
|
|
placeholderText: "Enter text",
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "textAlign",
|
|
|
|
|
helpText: "Sets the alignments of the text",
|
|
|
|
|
label: "Text Align",
|
|
|
|
|
controlType: "DROP_DOWN",
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
label: "Left",
|
|
|
|
|
value: "LEFT",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Center",
|
|
|
|
|
value: "CENTER",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Right",
|
|
|
|
|
value: "RIGHT",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "textStyle",
|
|
|
|
|
helpText: "Sets the font and style of the text",
|
|
|
|
|
label: "Text Style",
|
|
|
|
|
controlType: "DROP_DOWN",
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
label: "Heading",
|
|
|
|
|
value: "HEADING",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Label",
|
|
|
|
|
value: "LABEL",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Body",
|
|
|
|
|
value: "BODY",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
}
|
2019-11-19 12:44:58 +00:00
|
|
|
static getPropertyValidationMap(): WidgetPropertyValidationType {
|
|
|
|
|
return {
|
2020-03-16 07:59:07 +00:00
|
|
|
...BASE_WIDGET_VALIDATION,
|
2019-11-19 12:44:58 +00:00
|
|
|
text: VALIDATION_TYPES.TEXT,
|
2019-11-22 13:12:39 +00:00
|
|
|
textStyle: VALIDATION_TYPES.TEXT,
|
2020-03-16 07:59:07 +00:00
|
|
|
shouldScroll: VALIDATION_TYPES.BOOLEAN,
|
2019-11-19 12:44:58 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-14 09:48:01 +00:00
|
|
|
getNumberOfLines() {
|
|
|
|
|
const height = (this.props.bottomRow - this.props.topRow) * 40;
|
|
|
|
|
const lineHeight = LINE_HEIGHTS[this.props.textStyle];
|
|
|
|
|
return Math.floor(height / lineHeight);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-18 15:10:30 +00:00
|
|
|
getPageView() {
|
2020-01-21 12:48:42 +00:00
|
|
|
// const lines = this.getNumberOfLines();
|
2019-02-10 14:14:58 +00:00
|
|
|
return (
|
2019-10-31 05:28:11 +00:00
|
|
|
<TextComponent
|
2019-02-11 18:22:23 +00:00
|
|
|
widgetId={this.props.widgetId}
|
|
|
|
|
key={this.props.widgetId}
|
2019-10-31 05:28:11 +00:00
|
|
|
textStyle={this.props.textStyle}
|
2019-02-11 18:22:23 +00:00
|
|
|
text={this.props.text}
|
2020-05-11 14:19:58 +00:00
|
|
|
textAlign={this.props.textAlign ? this.props.textAlign : "LEFT"}
|
2019-12-03 04:41:10 +00:00
|
|
|
isLoading={this.props.isLoading}
|
2020-01-28 08:21:22 +00:00
|
|
|
shouldScroll={this.props.shouldScroll}
|
2020-01-21 12:48:42 +00:00
|
|
|
// lines={lines}
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-13 10:45:49 +00:00
|
|
|
export type TextStyle = "BODY" | "HEADING" | "LABEL" | "SUB_TEXT";
|
2020-05-11 14:19:58 +00:00
|
|
|
export type TextAlign = "LEFT" | "CENTER" | "RIGHT" | "JUSTIFY";
|
2019-09-12 08:11:25 +00:00
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
export interface TextWidgetProps extends WidgetProps {
|
2019-03-21 12:10:32 +00:00
|
|
|
text?: string;
|
2019-10-31 05:28:11 +00:00
|
|
|
textStyle: TextStyle;
|
2019-12-03 04:41:10 +00:00
|
|
|
isLoading: boolean;
|
2020-05-11 14:19:58 +00:00
|
|
|
textAlign: TextAlign;
|
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);
|