react-native-dates-picker
Version:
Customizable date picker for React Native
86 lines (85 loc) • 2.95 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _CalendarContext = require("../CalendarContext");
var _utils = require("../utils");
const YearSelector = () => {
const {
currentDate,
currentYear,
onSelectYear,
theme
} = (0, _CalendarContext.useCalendarContext)();
const selectedYear = (0, _utils.getDateYear)(currentDate);
const generateCells = (0, _react.useCallback)(() => {
const years = (0, _utils.getYearRange)(currentYear);
const activeYear = (0, _utils.getDateYear)(currentDate);
const column = years.map(year => {
const activeItemStyle = year === selectedYear ? {
borderColor: (theme === null || theme === void 0 ? void 0 : theme.selectedItemColor) || '#0047FF',
backgroundColor: (theme === null || theme === void 0 ? void 0 : theme.selectedItemColor) || '#0047FF'
} : year === activeYear ? {
borderColor: (theme === null || theme === void 0 ? void 0 : theme.selectedItemColor) || '#0047FF'
} : {};
const textStyle = year === selectedYear ? {
color: '#fff',
...(theme === null || theme === void 0 ? void 0 : theme.selectedTextStyle)
} : year === activeYear ? {
color: (theme === null || theme === void 0 ? void 0 : theme.selectedItemColor) || '#0047FF',
fontWeight: 'bold'
} : {
...(theme === null || theme === void 0 ? void 0 : theme.calendarTextStyle)
};
return /*#__PURE__*/React.createElement(_reactNative.Pressable, {
key: year,
onPress: () => onSelectYear(year),
style: styles.yearCell,
accessibilityRole: "button",
accessibilityLabel: year.toString()
}, /*#__PURE__*/React.createElement(_reactNative.View, {
style: [styles.year, theme === null || theme === void 0 ? void 0 : theme.yearContainerStyle, activeItemStyle]
}, /*#__PURE__*/React.createElement(_reactNative.Text, {
key: year,
style: textStyle
}, year)));
});
return column;
}, [onSelectYear, selectedYear, currentYear, currentDate, theme]);
return /*#__PURE__*/React.createElement(_reactNative.View, {
style: styles.container
}, /*#__PURE__*/React.createElement(_reactNative.View, {
style: styles.years
}, generateCells()));
};
const styles = _reactNative.StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
margin: 5,
width: '100%'
},
yearCell: {
width: '33.3%'
},
years: {
flexDirection: 'row',
flexWrap: 'wrap',
width: '100%'
},
year: {
paddingVertical: 15,
margin: 2,
alignItems: 'center',
borderWidth: 1,
borderRadius: 8,
borderColor: '#E5E5E5',
backgroundColor: '#FFFFFF'
}
});
var _default = exports.default = YearSelector;
//# sourceMappingURL=YearSelector.js.map