DataTable.js
5 years ago
DatePicker.js
5 years ago
OverviewPanel.js
5 years ago
TopUsers.js
3 years ago
TopVideos.js
3 years ago
TotalVideoViewsByUser.js
4 years ago
TotalViewsGraph.js
4 years ago
TotalWatchGraph.js
4 years ago
VideoAverageWatchTime.js
4 years ago
VideoAverageWatchTimeByUser.js
4 years ago
VideoTimeline.js
4 years ago
VideoTotalWatchTimeByUser.js
4 years ago
VideoViews.js
5 years ago
DatePicker.js
54 lines
| 1 | const { __ } = wp.i18n; |
| 2 | const { useRef, useEffect, useState } = wp.element; |
| 3 | |
| 4 | import Litepicker from "litepicker"; |
| 5 | import "litepicker/dist/plugins/ranges"; |
| 6 | |
| 7 | export default ({ startDate, setStartDate, endDate, setEndDate }) => { |
| 8 | const dateRef = useRef(); |
| 9 | const [inputSize, setInputSize] = useState(25); |
| 10 | |
| 11 | let datepicker; |
| 12 | useEffect(() => { |
| 13 | datepicker = new Litepicker({ |
| 14 | element: dateRef?.current, |
| 15 | singleMode: false, |
| 16 | format: "MMMM D YYYY", |
| 17 | autoApply: false, |
| 18 | plugins: ["ranges"], |
| 19 | maxDate: new Date(), |
| 20 | numberOfMonths: 2, |
| 21 | buttonText: { |
| 22 | apply: __("Apply", "presto-player"), |
| 23 | cancel: __("Cancel", "presto-player"), |
| 24 | }, |
| 25 | dropdowns: { |
| 26 | minYear: 1990, |
| 27 | maxYear: null, |
| 28 | months: true, |
| 29 | years: true, |
| 30 | }, |
| 31 | setup: (picker) => { |
| 32 | picker.setDateRange(startDate, endDate); |
| 33 | picker.on("button:apply", (start, end) => { |
| 34 | setStartDate(start.dateInstance); |
| 35 | setEndDate(end.dateInstance); |
| 36 | setInputSize(dateRef.current.value.length); |
| 37 | }); |
| 38 | }, |
| 39 | }); |
| 40 | }, [dateRef]); |
| 41 | |
| 42 | return ( |
| 43 | <div className="component-base-control"> |
| 44 | <div className="components-base-control__field"> |
| 45 | <input |
| 46 | className="components-text-control__input presto-settings__date-select" |
| 47 | ref={dateRef} |
| 48 | size={inputSize} |
| 49 | /> |
| 50 | </div> |
| 51 | </div> |
| 52 | ); |
| 53 | }; |
| 54 |