forked from SLoh4137/umcp-tase
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathText.tsx
executable file
·85 lines (75 loc) · 1.79 KB
/
Text.tsx
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import React from "react"
import {
Typography,
TypographyProps,
Theme,
createStyles,
withStyles,
WithStyles,
} from "@material-ui/core"
import clsx from "clsx"
const styles = (theme: Theme) =>
createStyles({
white: {
color: "#ffffff",
},
success: {
color: theme.palette.success.main,
},
heading: {
fontFamily: [
"Readex Pro",
"Roboto Slab",
"Times New Roman",
"serif",
].join(","),
},
})
export interface TextColorOptions {
color?: TypographyProps["color"] | "white" | "success"
className?: string
}
type Props = WithStyles<typeof styles> &
Omit<TypographyProps, "color"> &
TextColorOptions & {
heading?: boolean
}
/**
* Custom text component that wraps Material-UI typography
* @param props
*/
function Text(props: Props, ref: React.Ref<HTMLElement>) {
const {
classes,
className = "",
color = "initial",
heading = false,
...rest
} = props
let textClassName = clsx({
[className]: true,
[classes.heading]: heading,
})
let passedColor = color
switch (color) {
case "white":
textClassName = clsx(textClassName, classes.white)
passedColor = "initial"
break
case "success":
textClassName = clsx(textClassName, classes.white)
passedColor = "initial"
break
default:
passedColor = color
}
return (
<Typography
className={textClassName}
color={passedColor}
ref={ref}
{...rest}
/>
)
}
export default withStyles(styles)(React.forwardRef(Text))