myjourney/components/ThemedText.tsx
2025-06-21 14:53:56 -07:00

67 lines
1.3 KiB
TypeScript

import { StyleSheet, Text, type TextProps } from 'react-native';
import { useTheme } from 'react-native-paper';
export type ThemedTextProps = TextProps & {
lightColor?: string;
darkColor?: string;
type?: 'default' | 'title' | 'defaultSemiBold' | 'subtitle' | 'link';
};
export function ThemedText({
style,
lightColor,
darkColor,
type = 'default',
...rest
}: ThemedTextProps) {
const theme = useTheme();
// Only use override colors if provided
let color = theme.colors.onSurface; // default
if (lightColor || darkColor) {
color = theme.dark ? (darkColor || lightColor || color) : (lightColor || darkColor || color);
}
// Special case for link type
if (type === 'link') {
color = lightColor || darkColor || theme.colors.primary;
}
return (
<Text
style={[
{ color },
styles[type],
style,
]}
{...rest}
/>
);
}
const styles = StyleSheet.create({
default: {
fontSize: 16,
lineHeight: 24,
},
defaultSemiBold: {
fontSize: 16,
lineHeight: 24,
fontWeight: '600',
},
title: {
fontSize: 32,
fontWeight: 'bold',
lineHeight: 40,
},
subtitle: {
fontSize: 20,
fontWeight: 'bold',
},
link: {
lineHeight: 30,
fontSize: 16,
color: '#0a7ea4',
},
});