2019-10-31 05:28:11 +00:00
|
|
|
import * as React from "react";
|
2021-04-01 08:30:33 +00:00
|
|
|
import { Text } from "@blueprintjs/core";
|
2019-10-31 05:28:11 +00:00
|
|
|
import styled from "styled-components";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { ComponentProps } from "components/designSystems/appsmith/BaseComponent";
|
2021-04-01 08:30:33 +00:00
|
|
|
import { TextAlign } from "widgets/TextWidget";
|
2020-01-08 12:30:16 +00:00
|
|
|
import Interweave from "interweave";
|
|
|
|
|
import { UrlMatcher, EmailMatcher } from "interweave-autolink";
|
2021-04-01 08:30:33 +00:00
|
|
|
import {
|
|
|
|
|
FontStyleTypes,
|
|
|
|
|
TextSize,
|
|
|
|
|
TEXT_SIZES,
|
|
|
|
|
} from "constants/WidgetConstants";
|
2019-10-31 05:28:11 +00:00
|
|
|
type TextStyleProps = {
|
2019-11-28 07:08:39 +00:00
|
|
|
accent: "primary" | "secondary" | "error";
|
2019-10-31 05:28:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const BaseText = styled(Text)<TextStyleProps>``;
|
|
|
|
|
|
2020-01-14 09:48:01 +00:00
|
|
|
/*
|
|
|
|
|
Note:
|
|
|
|
|
-webkit-line-clamp may seem like a wierd way to doing this
|
|
|
|
|
however, it is getting more and more useful with more browser support.
|
|
|
|
|
It suffices for our target browsers
|
|
|
|
|
More info: https://css-tricks.com/line-clampin/
|
|
|
|
|
*/
|
2020-01-21 12:48:42 +00:00
|
|
|
|
|
|
|
|
export const TextContainer = styled.div`
|
|
|
|
|
&& {
|
|
|
|
|
height: 100%;
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
`;
|
2020-05-11 14:19:58 +00:00
|
|
|
export const StyledText = styled(Text)<{
|
|
|
|
|
scroll: boolean;
|
|
|
|
|
textAlign: string;
|
2021-04-01 08:30:33 +00:00
|
|
|
backgroundColor?: string;
|
|
|
|
|
textColor?: string;
|
|
|
|
|
fontStyle?: string;
|
|
|
|
|
fontSize?: TextSize;
|
2020-05-11 14:19:58 +00:00
|
|
|
}>`
|
2020-01-21 12:48:42 +00:00
|
|
|
height: 100%;
|
2020-12-24 04:32:25 +00:00
|
|
|
overflow-y: ${(props) => (props.scroll ? "auto" : "hidden")};
|
2020-01-21 12:48:42 +00:00
|
|
|
text-overflow: ellipsis;
|
2020-12-24 04:32:25 +00:00
|
|
|
text-align: ${(props) => props.textAlign.toLowerCase()};
|
2020-01-21 12:48:42 +00:00
|
|
|
display: flex;
|
|
|
|
|
width: 100%;
|
|
|
|
|
justify-content: flex-start;
|
2020-12-24 04:32:25 +00:00
|
|
|
align-items: ${(props) => (props.scroll ? "flex-start" : "center")};
|
2021-04-01 08:30:33 +00:00
|
|
|
background: ${(props) => props?.backgroundColor};
|
|
|
|
|
color: ${(props) => props?.textColor};
|
|
|
|
|
font-style: ${(props) =>
|
|
|
|
|
props?.fontStyle?.includes(FontStyleTypes.ITALIC) ? "italic" : ""};
|
|
|
|
|
text-decoration: ${(props) =>
|
|
|
|
|
props?.fontStyle?.includes(FontStyleTypes.UNDERLINE) ? "underline" : ""};
|
|
|
|
|
font-weight: ${(props) =>
|
|
|
|
|
props?.fontStyle?.includes(FontStyleTypes.BOLD) ? "bold" : "normal"};
|
|
|
|
|
font-size: ${(props) => props?.fontSize && TEXT_SIZES[props?.fontSize]};
|
2020-05-11 14:19:58 +00:00
|
|
|
span {
|
|
|
|
|
width: 100%;
|
2021-04-28 05:43:03 +00:00
|
|
|
line-height: 1.2;
|
2020-05-11 14:19:58 +00:00
|
|
|
}
|
2020-01-14 09:48:01 +00:00
|
|
|
`;
|
|
|
|
|
|
2019-10-31 05:28:11 +00:00
|
|
|
export interface TextComponentProps extends ComponentProps {
|
|
|
|
|
text?: string;
|
2020-05-11 14:19:58 +00:00
|
|
|
textAlign: TextAlign;
|
2019-10-31 05:28:11 +00:00
|
|
|
ellipsize?: boolean;
|
2021-04-01 08:30:33 +00:00
|
|
|
fontSize?: TextSize;
|
2019-12-03 04:41:10 +00:00
|
|
|
isLoading: boolean;
|
2020-01-28 08:21:22 +00:00
|
|
|
shouldScroll?: boolean;
|
2021-04-01 08:30:33 +00:00
|
|
|
backgroundColor?: string;
|
|
|
|
|
textColor?: string;
|
|
|
|
|
fontStyle?: string;
|
2019-10-31 05:28:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class TextComponent extends React.Component<TextComponentProps> {
|
|
|
|
|
render() {
|
2021-04-01 08:30:33 +00:00
|
|
|
const {
|
2021-05-13 08:35:39 +00:00
|
|
|
backgroundColor,
|
2021-04-01 08:30:33 +00:00
|
|
|
ellipsize,
|
|
|
|
|
fontSize,
|
2021-05-13 08:35:39 +00:00
|
|
|
fontStyle,
|
|
|
|
|
text,
|
|
|
|
|
textAlign,
|
2021-04-01 08:30:33 +00:00
|
|
|
textColor,
|
|
|
|
|
} = this.props;
|
2020-01-08 12:30:16 +00:00
|
|
|
return (
|
2020-01-21 12:48:42 +00:00
|
|
|
<TextContainer>
|
|
|
|
|
<StyledText
|
2021-04-28 10:28:39 +00:00
|
|
|
backgroundColor={backgroundColor}
|
|
|
|
|
className={this.props.isLoading ? "bp3-skeleton" : "bp3-ui-text"}
|
2020-01-21 12:48:42 +00:00
|
|
|
ellipsize={ellipsize}
|
2021-04-28 10:28:39 +00:00
|
|
|
fontSize={fontSize}
|
2021-04-01 08:30:33 +00:00
|
|
|
fontStyle={fontStyle}
|
2021-04-28 10:28:39 +00:00
|
|
|
scroll={!!this.props.shouldScroll}
|
|
|
|
|
textAlign={textAlign}
|
2021-04-01 08:30:33 +00:00
|
|
|
textColor={textColor}
|
2020-01-21 12:48:42 +00:00
|
|
|
>
|
|
|
|
|
<Interweave
|
|
|
|
|
content={text}
|
|
|
|
|
matchers={[new UrlMatcher("url"), new EmailMatcher("email")]}
|
|
|
|
|
/>
|
|
|
|
|
</StyledText>
|
|
|
|
|
</TextContainer>
|
2020-01-08 12:30:16 +00:00
|
|
|
);
|
2019-10-31 05:28:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default TextComponent;
|