roko-date-picker
Version:
A simple single/multi date picker
106 lines (105 loc) • 4 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_native_1 = require("react-native");
const react_1 = __importStar(require("react"));
const format_1 = __importDefault(require("date-fns/format"));
const indicator_today_1 = __importDefault(require("../indicators/indicator.today"));
const hooks_1 = require("../../../../features/hooks");
const container_1 = __importDefault(require("../../container"));
const constants_1 = require("../../../../features/domain/constants");
const BORDER_SIZE = 2;
const Cell = ({ item, selected, sameMonth, theme, blocked, index, weekNumber, onChange, }) => {
// #region functions
const handleOnChange = () => onChange(item);
// #endregion
// #region variables
const customStyles = (0, hooks_1.useStyles)(styles, theme);
const calculatedPadding = {
6: constants_1.sizes.minuscule,
5: constants_1.sizes.petite,
4: constants_1.sizes.medium,
};
// #endregion
return (<container_1.default index={index} activeOpacity={1} disabled={blocked} style={[customStyles.root, { padding: calculatedPadding[weekNumber] }]} onPress={handleOnChange}>
<react_native_1.View style={[customStyles.container, selected && customStyles.selectedContainer]}>
<react_native_1.Text numberOfLines={1} allowFontScaling={true} style={[
customStyles.text,
selected && customStyles.selectedText,
!sameMonth && !selected && customStyles.differentMonth,
blocked && customStyles.blocked,
]}>
{(0, format_1.default)(item, "dd")}
</react_native_1.Text>
<indicator_today_1.default {...{ selected, item }}/>
</react_native_1.View>
</container_1.default>);
};
exports.default = (0, react_1.memo)(Cell);
Cell.displayName = "Cell";
const styles = (theme) => react_native_1.StyleSheet.create({
root: {
flex: 1,
alignItems: "center",
justifyContent: "center",
},
container: {
flexGrow: 1,
alignItems: "center",
justifyContent: "center",
},
selectedContainer: {
elevation: 3,
aspectRatio: 1,
shadowRadius: 2.22,
shadowOpacity: 0.22,
borderWidth: BORDER_SIZE,
borderRadius: 50,
borderColor: theme.colors.onPrimary,
backgroundColor: theme.colors.primary,
shadowColor: "#000",
shadowOffset: {
width: -2,
height: 2,
},
},
text: {
textTransform: "capitalize",
fontFamily: theme.font?.family,
color: theme.colors.onBackground,
},
selectedText: {
color: theme.colors.onPrimary,
},
differentMonth: {
color: theme.colors.onSecondary,
},
blocked: {
color: theme.colors.disabled,
},
});