traintrape-moi/client/hooks/useThemeColor.ts

22 lines
530 B
TypeScript
Raw Normal View History

2024-12-01 11:29:47 +00:00
/**
* Learn more about light and dark modes:
* https://docs.expo.dev/guides/color-schemes/
*/
2024-12-07 09:24:41 +00:00
import { Colors } from '@/constants/Colors'
import { useColorScheme } from '@/hooks/useColorScheme'
2024-12-01 11:29:47 +00:00
export function useThemeColor(
props: { light?: string; dark?: string },
colorName: keyof typeof Colors.light & keyof typeof Colors.dark
) {
2024-12-07 09:24:41 +00:00
const theme = useColorScheme() ?? 'light'
const colorFromProps = props[theme]
2024-12-01 11:29:47 +00:00
if (colorFromProps) {
2024-12-07 09:24:41 +00:00
return colorFromProps
2024-12-01 11:29:47 +00:00
} else {
2024-12-07 09:24:41 +00:00
return Colors[theme][colorName]
2024-12-01 11:29:47 +00:00
}
}