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";
|
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/
|
|
|
|
|
*/
|
|
|
|
|
export const StyledText = styled(Text)<{ lines: number }>`
|
2020-01-20 08:07:00 +00:00
|
|
|
span {
|
|
|
|
|
display: -webkit-box;
|
|
|
|
|
-webkit-box-orient: vertical;
|
|
|
|
|
-webkit-line-clamp: ${props => props.lines - 1};
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
}
|
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-14 09:48:01 +00:00
|
|
|
lines: number;
|
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-14 09:48:01 +00:00
|
|
|
className.push(Classes.TEXT_LARGE);
|
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":
|
|
|
|
|
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-14 09:48:01 +00:00
|
|
|
<StyledText
|
|
|
|
|
className={this.getTextClass(textStyle)}
|
|
|
|
|
ellipsize={ellipsize}
|
|
|
|
|
lines={this.props.lines}
|
|
|
|
|
>
|
2020-01-08 12:30:16 +00:00
|
|
|
<Interweave
|
|
|
|
|
content={text}
|
|
|
|
|
matchers={[new UrlMatcher("url"), new EmailMatcher("email")]}
|
2020-01-03 13:40:31 +00:00
|
|
|
/>
|
2020-01-14 09:48:01 +00:00
|
|
|
</StyledText>
|
2020-01-08 12:30:16 +00:00
|
|
|
);
|
2019-10-31 05:28:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default TextComponent;
|