Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. import React from 'react';
  2. import { View, Text, StyleSheet, TouchableOpacity, Image } from 'react-native';
  3. import PropTypes from 'prop-types';
  4.  
  5. const weekDaysNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
  6.  
  7. class CalendarDayComponent extends React.PureComponent {
  8. constructor(props) {
  9. super(props);
  10. this.onDayPress = this.onDayPress.bind(this);
  11. }
  12.  
  13. getContentStyle() {
  14. const { state, marking = {} } = this.props;
  15. const style= {
  16. content: {},
  17. text: {
  18. color: '#181c26'
  19. }
  20. };
  21.  
  22. if (state === 'disabled') {
  23. style.text.color = '#c1c2c1';
  24. } else {
  25. if (marking.partiallyBlocked) {
  26. style.content.borderColor = '#c1c2c1';
  27. style.content.borderRadius = 50;
  28. style.content.borderWidth = 1;
  29. } else if (marking.partiallySoldOut) {
  30. style.content.borderColor = '#e35052';
  31. style.content.borderRadius = 50;
  32. style.content.borderWidth = 1;
  33. }
  34.  
  35. if (marking.selected) {
  36. style.text.color = '#fff';
  37. style.content.backgroundColor = '#216bc9';
  38. style.content.borderRadius = 50;
  39. } else if (marking.fullyBlocked) {
  40. style.text.color = '#fff';
  41. style.content.backgroundColor = '#c1c2c1';
  42. style.content.borderRadius = 50;
  43. } else if (marking.fullySoldOut) {
  44. style.text.color = '#fff';
  45. style.content.backgroundColor = '#e35052';
  46. style.content.borderRadius = 50;
  47. }
  48. }
  49.  
  50. return style;
  51. }
  52.  
  53. getFooterTextStyle() {
  54. const { marking = {}, state } = this.props;
  55. const style = {
  56. color: '#c1c2c1'
  57. };
  58.  
  59. if (marking.inventory > 0 && state !== 'disabled') {
  60. style.color = '#4caf50';
  61. }
  62. return style;
  63. }
  64.  
  65. getInventoryCount() {
  66. const { marking = {}, state } = this.props;
  67. if (typeof marking === 'object' && state !== 'disabled') {
  68. if (marking.inventory >= 0) {
  69. return marking.inventory;
  70. }
  71. }
  72. if (state === 'disabled') {
  73. return '';
  74. } else {
  75. return 'NA';
  76. }
  77. }
  78.  
  79. onDayPress() {
  80. this.props.onPress(this.props.date);
  81. }
  82.  
  83. render() {
  84. const contentStyle = this.getContentStyle();
  85. const highDemandImage = require('../../images/high-demand.png');
  86.  
  87. return (
  88. <View style={styles.container}>
  89. <View style={styles.header}>
  90. {
  91. this.props.horizontal ?
  92. <Text style={styles.weekName} numberOfLines={1}>
  93. {
  94. weekDaysNames[this.props.date.weekDay].toUpperCase()
  95. }
  96. </Text>
  97. :
  98. null
  99. }
  100. </View>
  101. <TouchableOpacity
  102. style={[styles.content, contentStyle.content]}
  103. onPress={this.onDayPress}
  104. >
  105. <Text style={[styles.contentText, contentStyle.text]}>
  106. {String(this.props.children)}
  107. </Text>
  108. {
  109. (this.props.marking.highDemand && this.props.state !== 'disabled') ?
  110. <Image source={highDemandImage} style={styles.smallIcon} />
  111. : null
  112. }
  113. </TouchableOpacity>
  114. <View style={styles.footer}>
  115. <Text style={this.getFooterTextStyle()}>
  116. {this.getInventoryCount()}
  117. </Text>
  118. </View>
  119. </View>
  120. );
  121. }
  122. }
  123.  
  124. CalendarDayComponent.propTypes = {
  125. children: PropTypes.any,
  126. state: PropTypes.string,
  127. marking: PropTypes.any,
  128. horizontal: PropTypes.bool,
  129. date: PropTypes.object,
  130. onPress: PropTypes.func.isRequired,
  131. current: PropTypes.string
  132. };
  133.  
  134. const styles = StyleSheet.create({
  135. container: {
  136. justifyContent: 'center',
  137. alignItems: 'center',
  138. marginLeft: 7,
  139. marginRight: 7
  140. },
  141. weekName: {
  142. width: 32,
  143. textAlign: 'center',
  144. fontSize: 12,
  145. fontWeight: 'bold',
  146. color: '#7c7c7c'
  147. },
  148. content: {
  149. width: 36,
  150. height: 36,
  151. justifyContent: 'center',
  152. alignItems: 'center'
  153. },
  154. contentText: {
  155. fontSize: 20
  156. },
  157. footer: {
  158. flexDirection: 'row'
  159. },
  160. smallIcon: {
  161. width: 12,
  162. height: 12,
  163. position: 'absolute',
  164. top: -1,
  165. right: -1
  166. }
  167. });
  168.  
  169. export default CalendarDayComponent;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement