项目作者: nipunravisara

项目描述 :
🌿 React-native-calendar-date-picker component.
高级语言: JavaScript
项目地址: git://github.com/nipunravisara/react-native-calendarview-datepicker.git
创建时间: 2020-07-31T16:57:45Z
项目社区:https://github.com/nipunravisara/react-native-calendarview-datepicker

开源协议:MIT License

下载


React-native-calendarview-datepicker

GitHub top language GitHub code size in bytes npm GitHub tag (latest by date) Hits
banner-image

📦 Installation

  1. npm i react-native-calendarview-datepicker

or

  1. yarn add react-native-calendarview-datepicker

📺 Preview

banner-image banner-image

🚀 Basic Usage

Default

You can simply add date-picker as follows. It shows minimal default calendar. But you can customize as you wish.

  1. import DatePickerCalendar from 'react-native-calendarview-datepicker';
  2. import Moment from 'moment';
  3. ...
  4. const App = () => {
  5. const [date, setDate] = useState(moment());
  6. return (
  7. <DatePickerCalendar date={date} onChange={(selectedDate) => setDate(selectedDate)}/>
  8. );
  9. };

Customized

You can have full control of calendar picker. Pass your own calendar header and condition styles for darkmode.

  1. import DatePickerCalendar from 'react-native-calendarview-datepicker';
  2. import Moment from 'moment';
  3. ...
  4. const App = () => {
  5. const [date, setDate] = useState(moment());
  6. //Custom datepicker header
  7. const customHeader = (date, month, year, setMonth, setYear) => {
  8. return (
  9. <View style={{flexDirection: "row", justifyContent: 'space-between'}}>
  10. <View>
  11. <View>
  12. <Text style={{color: "#fff", fontSize: 18, opacity: 0.5, marginBottom: 4}}>{year}</Text>
  13. </View>
  14. <View>
  15. <Text style={{
  16. color: "#fff",
  17. fontSize: 25,
  18. fontWeight: 'bold'
  19. }}>{moment(date).format("MMMM Do YYYY")}</Text>
  20. </View>
  21. </View>
  22. <View style={{flexDirection: "row", alignItems: 'center'}}>
  23. <TouchableOpacity style={{
  24. alignItems: 'center',
  25. justifyContent: 'center',
  26. marginRight: 10,
  27. height: 40,
  28. width: 40,
  29. backgroundColor: "#155B3C",
  30. borderRadius: 100
  31. }} onPress={() => setMonth(month - 1)}>
  32. <Text style={{color: "#18D183", fontSize: 30, marginBottom: 5}}>{'‹'}</Text>
  33. </TouchableOpacity>
  34. <TouchableOpacity style={{
  35. alignItems: 'center',
  36. justifyContent: 'center',
  37. height: 40,
  38. width: 40,
  39. backgroundColor: "#155B3C",
  40. borderRadius: 100
  41. }} onPress={() => setMonth(month + 1)}>
  42. <Text style={{color: "#18D183", fontSize: 30, marginBottom: 5}}>{'›'}</Text>
  43. </TouchableOpacity>
  44. </View>
  45. </View>
  46. )
  47. }
  48. return (
  49. <DatePickerCalendar
  50. date={date}
  51. onChange={(selectedDate) => setDate(selectedDate)}
  52. placeholder="Select date"
  53. placeholderStyles={{color: "#04e37d"}}
  54. fieldButtonStylesDateFormat="MMM Do YY"
  55. fieldButtonStyles={{width: '95%', backgroundColor: "#1D323E", borderRadius: 12, borderWidth: 2, borderColor: "#18D183", paddingLeft: 20}}
  56. fieldButtonTextStyles={{color: "#18D183"}}
  57. modalBackgroundColor={"#1D323E"}
  58. weekHeaderTextColor={"#18D183"}
  59. datesColor={"#fff"}
  60. selectedDateColor={"#1D323E"}
  61. selectedDateHighlightColor={"#18D183"}
  62. selectedDateHighlightRadius={5}
  63. customHeader={(date, month, year, setMonth, setYear) => customHeader(date, month, year, setMonth, setYear)}
  64. headerStyles={{padding: 0}}
  65. />
  66. );
  67. };

📑 API Reference

Props Type Description
date Moment If your need to show placeholder on initial load just pass undefined, else for default value pass moment() object
onChange Function Callback triggered on date select (Required)
placeholder String Custom placeholder text
placeholderStyles Object Placeholder text styles
modalBackgroundColor String Calendar modal background color
headerStyles Object Header wrapper styles
customHeader Function Function should return a component. Args: (date, month, year, setMonth, setYear)
weekHeaderTextColor String Week days names text color
selectedDateHighlightColor String Selected date highlight marker color
selectedDateHighlightRadius Number Selected date highlight marker radius
datesColor String Calendar date color
selectedDateColor String Selected calendar date color
fieldButtonStylesDateFormat String Selected date showing format. Available formats
fieldButtonStyles Object Field button styles
fieldButtonTextStyles Object Field button text styles

🗞 License

React-native-calendarview-datepicker is licensed under the MIT License