2019-10-31 05:28:11 +00:00
|
|
|
import * as React from "react";
|
|
|
|
|
import { Text, Classes } from "@blueprintjs/core";
|
|
|
|
|
import styled from "styled-components";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { ComponentProps } from "components/designSystems/appsmith/BaseComponent";
|
|
|
|
|
import { TextStyle } from "widgets/TextWidget";
|
2020-01-08 12:30:16 +00:00
|
|
|
import Interweave from "interweave";
|
|
|
|
|
import { UrlMatcher, EmailMatcher } from "interweave-autolink";
|
2020-01-28 08:21:22 +00:00
|
|
|
import { labelStyle } from "constants/DefaultTheme";
|
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-01-28 08:21:22 +00:00
|
|
|
export const StyledText = styled(Text)<{ scroll: boolean }>`
|
2020-01-21 12:48:42 +00:00
|
|
|
height: 100%;
|
2020-01-28 08:21:22 +00:00
|
|
|
overflow-y: ${props => (props.scroll ? "auto" : "hidden")};
|
2020-01-21 12:48:42 +00:00
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
display: flex;
|
|
|
|
|
width: 100%;
|
|
|
|
|
justify-content: flex-start;
|
2020-01-28 11:46:04 +00:00
|
|
|
align-items: ${props => (props.scroll ? "flex-start" : "center")};
|
2020-01-28 08:21:22 +00:00
|
|
|
&.bp3-heading {
|
|
|
|
|
font-weight: ${props => props.theme.fontWeights[3]};
|
|
|
|
|
font-size: ${props => props.theme.fontSizes[4]}px;
|
|
|
|
|
}
|
|
|
|
|
&.bp3-ui-text {
|
|
|
|
|
${labelStyle}
|
2020-01-20 08:07:00 +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;
|
|
|
|
|
ellipsize?: boolean;
|
|
|
|
|
textStyle?: TextStyle;
|
2019-12-03 04:41:10 +00:00
|
|
|
isLoading: boolean;
|
2020-01-28 08:21:22 +00:00
|
|
|
shouldScroll?: boolean;
|
2019-10-31 05:28:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class TextComponent extends React.Component<TextComponentProps> {
|
|
|
|
|
getTextClass(textStyle?: TextStyle) {
|
2020-01-14 09:48:01 +00:00
|
|
|
const className = [];
|
|
|
|
|
|
|
|
|
|
if (this.props.isLoading) {
|
|
|
|
|
className.push("bp3-skeleton");
|
|
|
|
|
}
|
2019-10-31 05:28:11 +00:00
|
|
|
switch (textStyle) {
|
|
|
|
|
case "HEADING":
|
2020-01-28 08:21:22 +00:00
|
|
|
className.push(Classes.HEADING);
|
2019-12-03 04:41:10 +00:00
|
|
|
break;
|
2019-10-31 05:28:11 +00:00
|
|
|
case "BODY":
|
2020-01-14 09:48:01 +00:00
|
|
|
className.push(Classes.RUNNING_TEXT);
|
2019-12-03 04:41:10 +00:00
|
|
|
break;
|
|
|
|
|
case "LABEL":
|
2020-01-28 08:21:22 +00:00
|
|
|
className.push(Classes.UI_TEXT);
|
2019-12-03 04:41:10 +00:00
|
|
|
break;
|
2019-10-31 05:28:11 +00:00
|
|
|
default:
|
2019-12-03 04:41:10 +00:00
|
|
|
break;
|
2019-10-31 05:28:11 +00:00
|
|
|
}
|
2019-12-03 04:41:10 +00:00
|
|
|
|
2020-01-14 09:48:01 +00:00
|
|
|
return className.join(" ");
|
2019-10-31 05:28:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2020-01-08 12:30:16 +00:00
|
|
|
const { textStyle, text, ellipsize } = this.props;
|
|
|
|
|
return (
|
2020-01-21 12:48:42 +00:00
|
|
|
<TextContainer>
|
|
|
|
|
<StyledText
|
2020-01-28 08:21:22 +00:00
|
|
|
scroll={!!this.props.shouldScroll}
|
2020-01-21 12:48:42 +00:00
|
|
|
className={this.getTextClass(textStyle)}
|
|
|
|
|
ellipsize={ellipsize}
|
|
|
|
|
>
|
|
|
|
|
<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;
|