import React, { useMemo, memo } from 'react'; import { View, Pressable, Text, TextStyle } from 'react-native'; import { useThemeFactory } from '../Theme'; import type { CalendarDayProps } from './type'; import { createDayStyle } from './style'; const CalendarDay = (props: CalendarDayProps): JSX.Element => { const { item, color, rowHeight, topInfoRender, bottomInfoRender, index, offset } = props; const { type, topInfo, bottomInfo, text } = item; const { styles } = useThemeFactory(createDayStyle); const style = useMemo(() => { const iternalStyle: TextStyle = {}; if (rowHeight) { iternalStyle.height = rowHeight; } if (item.type === 'placeholder') { iternalStyle.width = '100%'; return iternalStyle; } if (index === 0) { iternalStyle.marginLeft = `${(100 * offset!) / 7}%`; } if (color) { switch (item.type) { case 'end': case 'start': case 'start-end': case 'multiple-middle': case 'multiple-selected': iternalStyle.backgroundColor = color; break; case 'middle': iternalStyle.color = color; break; default: break; } } return iternalStyle; }, [item, index, color, offset, rowHeight]); const renderContent = () => { const Nodes = ( <> {(topInfo || topInfoRender) && ( {topInfoRender ? topInfoRender(item) : topInfo} )} {text} {(bottomInfo || bottomInfoRender) && ( {bottomInfoRender ? bottomInfoRender(item) : bottomInfo} )} ); if (type === 'selected') { return ( {Nodes} ); } return Nodes; }; if (type === 'placeholder') { return ; } return ( props.onClick?.(item)} > {renderContent()} ); }; export default memo(CalendarDay);