You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Mobile/components/ui/Text.tsx

55 lines
1.2 KiB

import React from "react";
import { Text, TextProps } from "react-native";
import {
Color,
Position,
Size,
toTextColor,
toTextPosition,
toTextSize,
toTextWeight,
Weight,
} from "../Constants";
export interface ExtendedTextProps extends TextProps {
position?: Position;
color?: Color;
size?: Size;
weight?: Weight;
isLink?: boolean;
}
export default React.forwardRef<any, ExtendedTextProps>(
(
{ position, color, size, weight, isLink, className, children, ...props },
ref
): React.ReactElement => {
const buildClassName = () => {
const textSize = toTextSize(size ?? "lg");
const textColor = toTextColor(color ?? "black");
const textWeight = toTextWeight(weight ?? "normal");
const textPosition = toTextPosition(position ?? "left");
return (
textSize +
" " +
textPosition +
" " +
textColor +
" " +
textWeight +
" " +
(isLink ? "text-orange-500 underline" : "") +
" " +
className
);
};
return (
<Text className={buildClassName()} {...ref} {...props}>
{children}
</Text>
);
}
);