UNPKG

react-native-full-calendars

Version:

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

65 lines (64 loc) 1.82 kB
"use strict"; import { addDays, addMonths, eachDayOfInterval, eachWeekOfInterval, lastDayOfMonth } from 'date-fns'; import React, { useContext, useMemo } from 'react'; import { StyleSheet, View } from 'react-native'; import { CalendarContext } from '../../store'; import { DayLabels } from '../day/DayLabel'; import { Header } from '../header/Header'; import Week from '../week/Week'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; export const Month = /*#__PURE__*/React.memo(({ index }) => { const { initialDate, weekStartDay, height, width } = useContext(CalendarContext); const firstDayOfMonth = useMemo(() => addMonths(initialDate, index), [initialDate, index]); firstDayOfMonth.setDate(1); const lastDayOfMo = useMemo(() => lastDayOfMonth(firstDayOfMonth), [firstDayOfMonth]); const weekStarts = useMemo(() => eachWeekOfInterval({ start: firstDayOfMonth, end: lastDayOfMo }, { weekStartsOn: weekStartDay }), [firstDayOfMonth, lastDayOfMo, weekStartDay]); const weeks = useMemo(() => weekStarts.map(week => { return eachDayOfInterval({ start: week, end: addDays(week, 6) }); }), [weekStarts]); const monthStyle = [styleSheet.flex]; if (height) { monthStyle.push({ height }); } if (width) { monthStyle.push({ width }); } return /*#__PURE__*/_jsxs(View, { style: monthStyle, children: [/*#__PURE__*/_jsx(Header, { index: index }), /*#__PURE__*/_jsx(DayLabels, { datesOfWeek: weeks[0] }), weeks.map(week => { return /*#__PURE__*/_jsx(Week, { days: week, firstDayOfMonth: firstDayOfMonth }, week[0]?.toISOString()); })] }); }); const styleSheet = StyleSheet.create({ flex: { flex: 1 } }); //# sourceMappingURL=Month.js.map