2019-08-29 11:22:09 +00:00
|
|
|
import React from "react";
|
2021-09-16 04:21:31 +00:00
|
|
|
import { pick } from "lodash";
|
|
|
|
|
import WidgetStyleContainer, {
|
|
|
|
|
WidgetStyleContainerProps,
|
|
|
|
|
} from "components/designSystems/appsmith/WidgetStyleContainer";
|
2021-09-09 15:10:22 +00:00
|
|
|
|
|
|
|
|
import { TextSize } from "constants/WidgetConstants";
|
2022-04-15 14:03:38 +00:00
|
|
|
import { countOccurrences } from "workers/helpers";
|
2021-09-09 15:10:22 +00:00
|
|
|
|
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";
|
2021-09-09 15:10:22 +00:00
|
|
|
|
|
|
|
|
import BaseWidget, { WidgetProps, WidgetState } from "widgets/BaseWidget";
|
|
|
|
|
import TextComponent, { TextAlign } from "../component";
|
2021-12-07 04:54:19 +00:00
|
|
|
import { AutocompleteDataType } from "utils/autocomplete/TernServer";
|
2022-03-31 04:48:51 +00:00
|
|
|
import { OverflowTypes } from "../constants";
|
2019-02-10 14:14:58 +00:00
|
|
|
|
2022-04-15 14:03:38 +00:00
|
|
|
const MAX_HTML_PARSING_LENGTH = 5000;
|
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-20 10:43:44 +00:00
|
|
|
placeholderText: "Name:",
|
2021-02-16 10:29:08 +00:00
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2022-03-12 05:42:56 +00:00
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.TEXT,
|
|
|
|
|
params: { limitLineBreaks: true },
|
|
|
|
|
},
|
2021-02-16 10:29:08 +00:00
|
|
|
},
|
|
|
|
|
{
|
2022-03-31 04:48:51 +00:00
|
|
|
propertyName: "overflow",
|
|
|
|
|
label: "Overflow",
|
|
|
|
|
helpText: "Controls the text behavior when length of text exceeds",
|
|
|
|
|
controlType: "DROP_DOWN",
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
label: "Scroll contents",
|
|
|
|
|
value: OverflowTypes.SCROLL,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Truncate text",
|
|
|
|
|
value: OverflowTypes.TRUNCATE,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "No overflow",
|
|
|
|
|
value: OverflowTypes.NONE,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
defaultValue: OverflowTypes.NONE,
|
2022-01-04 06:21:02 +00:00
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
2021-04-01 08:30:33 +00:00
|
|
|
{
|
|
|
|
|
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
|
|
|
},
|
2021-12-14 07:55:58 +00:00
|
|
|
{
|
|
|
|
|
propertyName: "animateLoading",
|
|
|
|
|
label: "Animate Loading",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
helpText: "Controls the loading of the widget",
|
|
|
|
|
defaultValue: true,
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
},
|
2021-09-27 06:00:40 +00:00
|
|
|
{
|
|
|
|
|
propertyName: "disableLink",
|
|
|
|
|
helpText: "Controls parsing text as Link",
|
|
|
|
|
label: "Disable Link",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
},
|
2021-04-01 08:30:33 +00:00
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Styles",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "backgroundColor",
|
2022-01-11 05:38:17 +00:00
|
|
|
label: "Cell Background Color",
|
2021-04-01 08:30:33 +00:00
|
|
|
controlType: "COLOR_PICKER",
|
2021-09-20 10:43:44 +00:00
|
|
|
isJSConvertible: true,
|
2021-12-07 04:54:19 +00:00
|
|
|
isBindProperty: true,
|
2021-04-01 08:30:33 +00:00
|
|
|
isTriggerProperty: false,
|
2021-12-07 04:54:19 +00:00
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.TEXT,
|
|
|
|
|
params: {
|
|
|
|
|
regex: /^((?![<|{{]).+){0,1}/,
|
|
|
|
|
expected: {
|
|
|
|
|
type: "string (HTML color name or HEX value)",
|
|
|
|
|
example: `red | #9C0D38`,
|
|
|
|
|
autocompleteDataType: AutocompleteDataType.STRING,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2021-04-01 08:30:33 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
},
|
2022-01-04 06:21:02 +00:00
|
|
|
{
|
|
|
|
|
propertyName: "truncateButtonColor",
|
|
|
|
|
label: "Truncate Button Color",
|
|
|
|
|
controlType: "COLOR_PICKER",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.TEXT,
|
|
|
|
|
params: {
|
|
|
|
|
regex: /^(?![<|{{]).+/,
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-03-31 04:48:51 +00:00
|
|
|
dependencies: ["overflow"],
|
2022-01-04 06:21:02 +00:00
|
|
|
hidden: (props: TextWidgetProps) => {
|
2022-03-31 04:48:51 +00:00
|
|
|
return props.overflow !== OverflowTypes.TRUNCATE;
|
2022-01-04 06:21:02 +00:00
|
|
|
},
|
|
|
|
|
},
|
2021-09-16 04:21:31 +00:00
|
|
|
{
|
|
|
|
|
helpText: "Use a html color name, HEX, RGB or RGBA value",
|
|
|
|
|
placeholderText: "#FFFFFF / Gray / rgb(255, 99, 71)",
|
|
|
|
|
propertyName: "borderColor",
|
2022-01-11 05:38:17 +00:00
|
|
|
label: "Border Color",
|
2021-09-16 04:21:31 +00:00
|
|
|
controlType: "COLOR_PICKER",
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
helpText:
|
|
|
|
|
"Enter value for border width which can also use as margin",
|
|
|
|
|
propertyName: "borderWidth",
|
|
|
|
|
label: "Border Width",
|
|
|
|
|
placeholderText: "Enter value in px",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.NUMBER },
|
|
|
|
|
},
|
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
|
|
|
},
|
|
|
|
|
],
|
2021-09-20 10:43:44 +00:00
|
|
|
isJSConvertible: true,
|
2021-12-07 04:54:19 +00:00
|
|
|
isBindProperty: true,
|
2021-02-16 10:29:08 +00:00
|
|
|
isTriggerProperty: false,
|
2021-12-07 04:54:19 +00:00
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.TEXT,
|
|
|
|
|
params: {
|
|
|
|
|
allowedValues: [
|
|
|
|
|
"HEADING1",
|
|
|
|
|
"HEADING2",
|
|
|
|
|
"HEADING3",
|
|
|
|
|
"PARAGRAPH",
|
|
|
|
|
"PARAGRAPH2",
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
2021-02-16 10:29:08 +00:00
|
|
|
},
|
|
|
|
|
{
|
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
|
|
|
|
2022-04-15 14:03:38 +00:00
|
|
|
/**
|
|
|
|
|
* Disable html parsing for long continuous texts
|
|
|
|
|
* @returns boolean
|
|
|
|
|
*/
|
|
|
|
|
shouldDisableLink = (): boolean => {
|
|
|
|
|
const text = this.props.text || "";
|
|
|
|
|
const count: number = countOccurrences(text, "\n", false);
|
|
|
|
|
return count === 0 && text.length > MAX_HTML_PARSING_LENGTH;
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-18 15:10:30 +00:00
|
|
|
getPageView() {
|
2022-04-15 14:03:38 +00:00
|
|
|
const disableLink: boolean = this.props.disableLink
|
|
|
|
|
? true
|
|
|
|
|
: this.shouldDisableLink();
|
2019-02-10 14:14:58 +00:00
|
|
|
return (
|
2021-09-16 04:21:31 +00:00
|
|
|
<WidgetStyleContainer
|
|
|
|
|
{...pick(this.props, [
|
|
|
|
|
"widgetId",
|
|
|
|
|
"containerStyle",
|
|
|
|
|
"borderColor",
|
|
|
|
|
"borderWidth",
|
|
|
|
|
])}
|
|
|
|
|
>
|
|
|
|
|
<TextComponent
|
|
|
|
|
backgroundColor={this.props.backgroundColor}
|
2022-01-04 06:21:02 +00:00
|
|
|
bottomRow={this.props.bottomRow}
|
2022-04-15 14:03:38 +00:00
|
|
|
disableLink={disableLink}
|
2021-09-16 04:21:31 +00:00
|
|
|
fontSize={this.props.fontSize}
|
|
|
|
|
fontStyle={this.props.fontStyle}
|
|
|
|
|
isLoading={this.props.isLoading}
|
|
|
|
|
key={this.props.widgetId}
|
2022-01-04 06:21:02 +00:00
|
|
|
leftColumn={this.props.leftColumn}
|
2022-03-31 04:48:51 +00:00
|
|
|
overflow={this.props.overflow}
|
2022-01-04 06:21:02 +00:00
|
|
|
rightColumn={this.props.rightColumn}
|
2021-09-16 04:21:31 +00:00
|
|
|
text={this.props.text}
|
|
|
|
|
textAlign={this.props.textAlign ? this.props.textAlign : "LEFT"}
|
|
|
|
|
textColor={this.props.textColor}
|
2022-01-04 06:21:02 +00:00
|
|
|
topRow={this.props.topRow}
|
|
|
|
|
truncateButtonColor={this.props.truncateButtonColor}
|
2021-09-16 04:21:31 +00:00
|
|
|
widgetId={this.props.widgetId}
|
|
|
|
|
/>
|
|
|
|
|
</WidgetStyleContainer>
|
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 }}`,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-09 15:10:22 +00:00
|
|
|
static getWidgetType() {
|
2019-03-21 12:10:32 +00:00
|
|
|
return "TEXT_WIDGET";
|
2019-02-10 14:14:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-01 08:30:33 +00:00
|
|
|
export interface TextStyles {
|
|
|
|
|
backgroundColor?: string;
|
|
|
|
|
textColor?: string;
|
|
|
|
|
fontStyle?: string;
|
|
|
|
|
fontSize?: TextSize;
|
|
|
|
|
textAlign?: TextAlign;
|
2022-01-04 06:21:02 +00:00
|
|
|
truncateButtonColor?: string;
|
2021-04-01 08:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
2021-09-16 04:21:31 +00:00
|
|
|
export interface TextWidgetProps
|
|
|
|
|
extends WidgetProps,
|
|
|
|
|
TextStyles,
|
|
|
|
|
WidgetStyleContainerProps {
|
2019-03-21 12:10:32 +00:00
|
|
|
text?: string;
|
2019-12-03 04:41:10 +00:00
|
|
|
isLoading: boolean;
|
2021-09-27 06:00:40 +00:00
|
|
|
disableLink: boolean;
|
2022-03-31 04:48:51 +00:00
|
|
|
overflow: OverflowTypes;
|
2019-02-10 14:14:58 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-21 12:10:32 +00:00
|
|
|
export default TextWidget;
|