react-native-full-calendars
Version:
React Native Full Calendar (RNFC) is an intuitive and powerful calendar component library designed for React Native.
95 lines (94 loc) • 3.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Item = void 0;
var _dateFns = require("date-fns");
var _react = _interopRequireDefault(require("react"));
var _reactNative = require("react-native");
var _computedWeeks = require("../../utils/computed-weeks");
var _date = require("../../utils/date");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const Item = ({
date,
isDisabled,
item,
weekStartDay,
theme,
index,
maxVisibleCount
}) => {
const weeks = (0, _computedWeeks.computedWeeksOfMonth)(date, isDisabled);
const daysRemaining = (0, _date.getDaysRemaining)(date);
const isFirstWeekDay = (0, _date.isSameStartOfWeek)(date, {
weekStartDay
});
const isFirstMonthDay = (0, _date.isSameStartOfMonth)(date);
const dayItemStyle = [styleSheet.dayItem, {
height: `${Math.floor(100 / (maxVisibleCount + 2))}%`
}];
if (item === null) {
if (theme.dayItemStyle) {
dayItemStyle.push(theme.dayItemStyle);
}
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.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 = (0, _dateFns.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__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
style: dayItemStyle,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
style: [textStyle, theme.dayItemTextStyle],
numberOfLines: 1,
children: isShowContents ? item.content : ''
})
});
};
exports.Item = Item;
const styleSheet = _reactNative.StyleSheet.create({
dayItem: {
alignItems: 'flex-start',
marginVertical: '2%',
justifyContent: 'center'
}
});
//# sourceMappingURL=Item.js.map