UNPKG

react-native-full-calendars

Version:

React Native Full Calendar (RNFC) is an intuitive and powerful calendar component library designed for React Native.

89 lines (88 loc) 2.71 kB
"use strict"; import { differenceInDays } from 'date-fns'; import React from 'react'; import { StyleSheet, Text, View } from 'react-native'; import { computedWeeksOfMonth } from '../../utils/computed-weeks'; import { getDaysRemaining, isSameStartOfMonth, isSameStartOfWeek } from '../../utils/date'; import { jsx as _jsx } from "react/jsx-runtime"; export const Item = ({ date, isDisabled, item, weekStartDay, theme, index, maxVisibleCount }) => { const weeks = computedWeeksOfMonth(date, isDisabled); const daysRemaining = getDaysRemaining(date); const isFirstWeekDay = isSameStartOfWeek(date, { weekStartDay }); const isFirstMonthDay = isSameStartOfMonth(date); const dayItemStyle = [styleSheet.dayItem, { height: `${Math.floor(100 / (maxVisibleCount + 2))}%` }]; if (item === null) { if (theme.dayItemStyle) { dayItemStyle.push(theme.dayItemStyle); } return /*#__PURE__*/_jsx(View, { style: dayItemStyle }, index); } const datesInRange = item.metadata.datesInRange; let scheduleDaysRemaining = daysRemaining; if (datesInRange.length) { const endDate = datesInRange[datesInRange.length - 1]; const startDate = date; const daysDifference = differenceInDays(endDate, startDate); if (daysDifference < daysRemaining) { scheduleDaysRemaining = daysDifference + 1; } } const isShowContents = item.metadata.isStart || isFirstWeekDay || isFirstMonthDay; let width = isShowContents ? (datesInRange.length > scheduleDaysRemaining ? scheduleDaysRemaining : datesInRange.length) * 100 : 0; dayItemStyle.push({ backgroundColor: item.color }); if (item.metadata.isStart) { dayItemStyle.push({ marginStart: theme.itemStartMargin, borderTopLeftRadius: theme.itemStartBorderRadius, borderBottomLeftRadius: theme.itemStartBorderRadius }); } if (item.metadata.isEnd) { dayItemStyle.push({ marginEnd: theme.itemEndMargin, borderTopRightRadius: theme.itemEndBorderRadius, borderBottomRightRadius: theme.itemEndBorderRadius }); } if (theme.dayItemStyle) { dayItemStyle.push(theme.dayItemStyle); } const textStyle = { fontSize: 48 / weeks, color: 'white', left: isShowContents ? 2 : 0, width: `${width}%` }; return /*#__PURE__*/_jsx(View, { style: dayItemStyle, children: /*#__PURE__*/_jsx(Text, { style: [textStyle, theme.dayItemTextStyle], numberOfLines: 1, children: isShowContents ? item.content : '' }) }); }; const styleSheet = StyleSheet.create({ dayItem: { alignItems: 'flex-start', marginVertical: '2%', justifyContent: 'center' } }); //# sourceMappingURL=Item.js.map