Spaces:
Running
Running
File size: 2,295 Bytes
77fd7a1 20a6709 77fd7a1 20a6709 77fd7a1 20a6709 77fd7a1 20a6709 b3ee86d 20a6709 3f6aba6 77fd7a1 20a6709 77fd7a1 20a6709 b3ee86d 3f6aba6 20a6709 77fd7a1 20a6709 77fd7a1 20a6709 77fd7a1 20a6709 77fd7a1 | 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 86 87 88 89 90 91 92 93 | import styles from "./Text.module.css";
import React from "react";
type TextElement =
| "p"
| "span"
| "div"
| "h1"
| "h2"
| "h3"
| "h4"
| "h5"
| "h6"
| "li";
type TextAlign = "left" | "center" | "right" | "justify";
type TextTransform = "none" | "capitalize" | "uppercase" | "lowercase";
type DisplayType = "inline" | "block" | "inline-block";
type FontWeight = "regular" | "bold";
type FontSize = "small" | "medium" | "large" | "huge";
type ColorVariant = "default" | "primary" | "secondary" | "button" | "hover";
interface TextProps {
as?: TextElement;
children: React.ReactNode;
fontWeight?: FontWeight;
fontSize?: FontSize;
colorVariant?: ColorVariant;
interactable?: boolean;
textAlign?: TextAlign;
textTransform?: TextTransform;
display?: DisplayType;
className?: string;
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;
style?: React.CSSProperties;
}
function Text(props: Readonly<TextProps>) {
const {
children,
fontSize = "medium",
fontWeight = "regular",
colorVariant = "default",
interactable = false,
onClick,
textTransform = "none", // Default textTransform
display, // Destructure display
className, // Additional class names
style, // Additional inline styles
as = "p",
} = props;
const Component = as;
const fontSizeClass = {
small: styles.fontSizeSmall,
medium: styles.fontSizeMedium,
large: styles.fontSizeLarge,
huge: styles.fontSizeHuge,
}[fontSize];
const colorClass = {
default: "",
primary: styles.colorPrimary,
secondary: styles.colorSecondary,
button: styles.colorButton,
hover: styles.colorHover,
}[colorVariant];
const classes = [styles.text, className, colorClass, fontSizeClass]
.filter(Boolean)
.join(" ");
const inlineStyles: React.CSSProperties = {
fontWeight: fontWeight === "bold" ? "bold" : "regular",
userSelect: interactable ? "auto" : "none",
WebkitUserSelect: interactable ? "auto" : "none",
MozUserSelect: interactable ? "auto" : "none",
textTransform: textTransform,
display: display,
...style,
};
return (
<Component className={classes} style={inlineStyles} onClick={onClick}>
{children}
</Component>
);
}
export default Text;
|