Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | 545x 149091x 149091x 149091x 149091x 149091x | import { Typography } from "@mui/material";
import { useAppTheme } from "@theme/v2/Provider";
import { TextProps } from "./giveText.types";
import parse from "html-react-parser";
import { convertMarkdown, ALLOWED_TAGS, ALLOWED_ATTR } from "@utils/index";
import DOMPurify from "dompurify";
const GiveText = ({
children = "",
variant = "bodyM",
color = "primary",
useParse,
...rest
}: TextProps) => {
const { palette } = useAppTheme();
const content =
children instanceof Date
? children.toLocaleString()
: useParse && typeof children === "string"
? parse(
DOMPurify.sanitize(convertMarkdown(children), {
USE_PROFILES: { html: true },
ALLOWED_TAGS,
ALLOWED_ATTR,
}),
)
: children;
const textColors = {
primary: palette.text.primary,
secondary: palette.text.secondary,
link: palette.primitive?.blue[100],
success: palette.primitive?.success[50],
error: palette.primitive?.error[50],
default: palette.text.invert,
warning: palette.primitive?.warning?.["100"],
warning1: palette.primitive?.warning?.[50],
success1: palette.primitive?.success?.["100"],
light: palette.text.primary,
error1: palette.primitive?.error?.["100"],
tertiary: palette.text.tertiary,
blue: palette.primitive?.blue[100],
white1: palette?.text?.invert,
white2: palette?.["text-inverted"]?.primary,
dark: palette?.neutral?.[100],
};
const resolvedColor =
typeof color === "string" && color in textColors
? textColors[color as keyof typeof textColors]
: textColors.primary;
return (
<Typography variant={variant} version="two" color={resolvedColor} {...rest}>
{content}
</Typography>
);
};
export default GiveText;
|