@cometchat/chat-uikit-react-native
Version:
Ready-to-use Chat UI Components for React Native
34 lines • 1.44 kB
JavaScript
import React, { useMemo } from "react";
import { Text, View } from "react-native";
import { useTheme } from "../../../theme";
import { useCompTheme } from "../../../theme/hook";
import { dateHelperInstance } from "../../helper/dateHelper";
import { deepMerge } from "../../helper/helperFunctions";
/**
* CometChatDate is a component for displaying a formatted date/time.
*
* If a customDateString is provided, it will be displayed instead of the formatted date.
* Otherwise, the component formats the provided timeStamp using the given pattern.
*
* - Props for the component.
* The rendered date view.
*/
export const CometChatDate = (props) => {
const { timeStamp, pattern, customDateString, style = {} } = props;
const theme = useTheme();
const compTheme = useCompTheme();
// Merge theme date styles with component date styles and any custom style overrides.
const dateStyles = useMemo(() => {
return deepMerge(theme.dateStyles, compTheme.dateStyles ?? {}, style);
}, [theme.dateStyles, style, compTheme.dateStyles]);
return (<View style={[dateStyles.containerStyle]}>
<Text style={[dateStyles.textStyle]} numberOfLines={1}>
{timeStamp
? customDateString
? customDateString
: pattern && dateHelperInstance.getFormattedDate(timeStamp, pattern)
: ""}
</Text>
</View>);
};
//# sourceMappingURL=CometChatDate.js.map