|
| 1 | +import useCalendar from '@veccu/react-calendar' |
| 2 | +import cx from 'classnames' |
| 3 | +import { format, getDate } from 'date-fns' |
| 4 | +import React from 'react' |
| 5 | + |
| 6 | +export default function Calendar() { |
| 7 | + const { calendar, headers, body, view, navigation } = useCalendar() |
| 8 | + |
| 9 | + return ( |
| 10 | + <> |
| 11 | + <table className="table-fixed border-collapse border border-gray-100 w-full rounded-sm"> |
| 12 | + <caption> |
| 13 | + <div className="flex flex-row justify-between items-center pb-4"> |
| 14 | + <div className="flex flex-row space space-x-2"> |
| 15 | + <button |
| 16 | + onClick={() => view.showMonthView()} |
| 17 | + className={cx('btn bg-blue-50', { |
| 18 | + 'bg-blue-200': view.isMonthView, |
| 19 | + })} |
| 20 | + > |
| 21 | + M |
| 22 | + </button> |
| 23 | + <button |
| 24 | + onClick={() => view.showWeekView()} |
| 25 | + className={cx('btn bg-blue-50', { |
| 26 | + 'bg-blue-200': view.isWeekView, |
| 27 | + })} |
| 28 | + > |
| 29 | + W |
| 30 | + </button> |
| 31 | + <button |
| 32 | + onClick={() => view.showDayView()} |
| 33 | + className={cx('btn bg-blue-50', { |
| 34 | + 'bg-blue-200': view.isDayView, |
| 35 | + })} |
| 36 | + > |
| 37 | + D |
| 38 | + </button> |
| 39 | + </div> |
| 40 | + <div className="text-2xl font-black"> |
| 41 | + {format(calendar.cursorDate, 'yyyy.MM')} |
| 42 | + </div> |
| 43 | + <div className="flex flex-row space space-x-2"> |
| 44 | + <button |
| 45 | + onClick={() => navigation.toPrev()} |
| 46 | + className={cx('btn bg-blue-50')} |
| 47 | + > |
| 48 | + {'<'} |
| 49 | + </button> |
| 50 | + <button |
| 51 | + onClick={() => navigation.setToday()} |
| 52 | + className={cx('btn bg-blue-500 text-white')} |
| 53 | + > |
| 54 | + TODAY |
| 55 | + </button> |
| 56 | + <button |
| 57 | + onClick={() => navigation.toNext()} |
| 58 | + className={cx('btn bg-blue-50')} |
| 59 | + > |
| 60 | + {'>'} |
| 61 | + </button> |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + </caption> |
| 65 | + <thead className="border-b-1"> |
| 66 | + <tr> |
| 67 | + {headers.weekDays.map(({ key, value }) => { |
| 68 | + return ( |
| 69 | + <th className="border border-gray-100 p-3" key={key}> |
| 70 | + {format(value, 'E')} |
| 71 | + </th> |
| 72 | + ) |
| 73 | + })} |
| 74 | + </tr> |
| 75 | + </thead> |
| 76 | + <tbody> |
| 77 | + {body.value.map((week) => { |
| 78 | + const { key, value: days } = week |
| 79 | + |
| 80 | + return ( |
| 81 | + <tr key={key}> |
| 82 | + {days.map((day) => { |
| 83 | + const { key, value, isCurrentDate, isCurrentMonth } = day |
| 84 | + |
| 85 | + return ( |
| 86 | + <td |
| 87 | + key={key} |
| 88 | + className={cx( |
| 89 | + 'border border-gray-100 p-6 text-center text-xl', |
| 90 | + { |
| 91 | + 'bg-blue-200 animate-pulse': isCurrentDate, |
| 92 | + 'opacity-20': !isCurrentMonth, |
| 93 | + }, |
| 94 | + )} |
| 95 | + > |
| 96 | + {getDate(value)} |
| 97 | + </td> |
| 98 | + ) |
| 99 | + })} |
| 100 | + </tr> |
| 101 | + ) |
| 102 | + })} |
| 103 | + </tbody> |
| 104 | + </table> |
| 105 | + |
| 106 | + <button |
| 107 | + onClick={() => { |
| 108 | + window.location.href = '/getting-started/overview' |
| 109 | + }} |
| 110 | + className="block mt-20 mx-auto p-4 rounded bg-gradient-to-r from-indigo-400 via-purple-500 to-blue-500 text-white" |
| 111 | + > |
| 112 | + Go to <span className="italic font-bold">Getting Started</span> |
| 113 | + </button> |
| 114 | + </> |
| 115 | + ) |
| 116 | +} |
0 commit comments