f-react-native-schedule
Version:
Flexible scheduling library with more built-in features and enhanced customization options
96 lines (92 loc) • 2.72 kB
JavaScript
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import dayjs from 'dayjs';
import React, { useContext } from 'react';
import { TouchableOpacity, View, Text, StyleSheet } from 'react-native';
import ScheduleContext from '../ScheduleContext';
function getSchedulingHeight(startTime, endTime, height) {
const time = dayjs(endTime).diff(dayjs(startTime), 'hours', true);
return height * time;
}
const Scheduling = _ref => {
let {
date,
scheduling,
style: styleProp,
...props
} = _ref;
const {
cellDimensions,
schedulingSettings,
onSchedulingPress,
onSchedulingLongPress
} = useContext(ScheduleContext);
const {
fields,
render,
style
} = schedulingSettings;
const {
subject: {
name: subjectFieldName,
style: subjectStyle
},
startTime: {
name: startTimeFieldName
},
endTime: {
name: endTimeFieldName
}
} = fields;
const {
[subjectFieldName]: subject,
[startTimeFieldName]: startTime,
[endTimeFieldName]: endTime
} = scheduling;
const {
height: cellHeight
} = cellDimensions;
const touchableOpacityProps = { ...(typeof onSchedulingPress === 'function' && {
onPress: event => onSchedulingPress(scheduling, event)
}),
...(typeof onSchedulingLongPress === 'function' && {
onLongPress: event => onSchedulingLongPress(scheduling, event)
})
};
return /*#__PURE__*/React.createElement(TouchableOpacity, _extends({
style: [styles.container, styleProp, {
height: getSchedulingHeight(startTime, endTime, cellHeight)
}]
}, touchableOpacityProps, props), render && render(scheduling, date), !render && /*#__PURE__*/React.createElement(View, {
style: [styles.content, style]
}, /*#__PURE__*/React.createElement(Text, {
numberOfLines: 2,
style: [styles.subject, subjectStyle]
}, subject), /*#__PURE__*/React.createElement(Text, {
numberOfLines: 1,
style: styles.time
}, dayjs(startTime).format('HH:mm'), " -", ' ', dayjs(endTime).format('HH:mm'))));
};
const styles = StyleSheet.create({
container: {
position: 'absolute',
height: 80,
width: 100,
zIndex: 999,
elevation: 4
},
content: {
flex: 1,
borderRadius: 4,
backgroundColor: '#fff',
zIndex: 999
},
subject: {
color: '#464e5f'
},
time: {
fontSize: 11,
color: '#464e5f'
}
});
export default Scheduling;
//# sourceMappingURL=Scheduling.js.map