react-native-full-calendars
Version:
React Native Full Calendar (RNFC) is an intuitive and powerful calendar component library designed for React Native.
96 lines (95 loc) • 2.78 kB
JavaScript
"use strict";
import { format } from 'date-fns';
import { isEqual } from 'lodash';
import React, { useMemo } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { computedWeeksOfMonth } from '../../utils/computed-weeks';
import { Item } from './Item';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export const Day = /*#__PURE__*/React.memo(({
date,
isDisabled,
isToday,
items,
weekStartDay,
theme,
renderMoreItemText,
maxVisibleCount,
isSelected
}) => {
const weeks = computedWeeksOfMonth(date, isDisabled);
const renderDayText = () => {
const dayNumberTextStyle = [{
fontSize: 48 / weeks
}, theme.dayNumberTextStyle];
const dayNumberStyle = [styleSheet.dayNumberStyle, theme.dayNumberStyle];
if (isToday) {
dayNumberTextStyle.push(theme.dayTodayTextStyle);
dayNumberStyle.push(theme.dayTodayStyle);
}
return /*#__PURE__*/_jsx(View, {
style: dayNumberStyle,
children: /*#__PURE__*/_jsx(Text, {
style: dayNumberTextStyle,
children: format(date, theme.dayTextForamt)
})
});
};
const dayContainerStyle = [styleSheet.dayContainerStyle, theme.dayContainerStyle];
const isOverFlow = useMemo(() => items.length >= maxVisibleCount + 1, [maxVisibleCount, items.length]);
if (isDisabled) {
dayContainerStyle.push({
opacity: theme.disableOpacity
});
}
if (isSelected) {
dayContainerStyle.push(theme.daySelectedStyle);
}
return /*#__PURE__*/_jsxs(View, {
style: dayContainerStyle,
children: [renderDayText(), items.map((item, index) => {
if (index >= maxVisibleCount) {
return null;
}
return /*#__PURE__*/_jsx(Item, {
date: date,
isDisabled: isDisabled,
theme: theme,
item: item,
index: index,
weekStartDay: weekStartDay,
maxVisibleCount: maxVisibleCount
}, item?.id ? item?.id : index);
}), isOverFlow ? renderMoreItemText ? renderMoreItemText({
count: items.slice(maxVisibleCount).filter(v => v).length
}) : /*#__PURE__*/_jsxs(Text, {
style: [styleSheet.moreItemText, {
fontSize: 48 / weeks
}],
children: ["+", items.slice(maxVisibleCount).filter(v => v).length || '0']
}) : null]
});
}, (prev, next) => {
return isEqual(prev, next);
});
const styleSheet = StyleSheet.create({
dayContainerStyle: {
flex: 1,
borderColor: '#F5F5F5',
borderTopWidth: 1,
borderBottomWidth: 1
},
dayNumberStyle: {
justifyContent: 'center',
alignItems: 'center',
alignSelf: 'center',
height: '16%',
width: '40%',
marginVertical: '1%'
},
moreItemText: {
paddingStart: 4,
textAlign: 'center'
}
});
//# sourceMappingURL=Day.js.map