You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
1.9 KiB

  1. <template>
  2. <div>
  3. <h1>
  4. {{ new Date(date).toLocaleString("default", { month: "long" }) }}
  5. </h1>
  6. <ul class="calendar">
  7. <li
  8. v-for="dow in daysOfWeek"
  9. :key="dow"
  10. :class="['calendar__day', 'calendar__day--dow']"
  11. >
  12. {{ dow }}
  13. </li>
  14. <li
  15. v-for="index in getDayOfWeekOffset(date)"
  16. :key="index + 'o'"
  17. class="calendar__day"
  18. >
  19. <span class="day__date--blank" />
  20. </li>
  21. <li
  22. v-for="day in getDaysInMonth(date)"
  23. :key="day.toString()"
  24. class="calendar__day"
  25. >
  26. <span class="day__date"> {{ day.getDate() }} </span>
  27. <button
  28. v-if="selectedDays.find( sched => sched['num'] == day.getDay() )"
  29. @click="book(day)"
  30. >
  31. book
  32. </button>
  33. </li>
  34. </ul>
  35. </div>
  36. </template>
  37. <script>
  38. export default {
  39. props: {
  40. date: {
  41. type: [Date],
  42. default () {
  43. return new Date()
  44. }
  45. },
  46. selectedDays: {
  47. type: [Array],
  48. default () {
  49. return []
  50. }
  51. }
  52. },
  53. data () {
  54. return {
  55. daysOfWeek: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']
  56. }
  57. },
  58. methods: {
  59. getDayOfWeekOffset (thisDate) {
  60. const dow = new Date(thisDate.getFullYear(), thisDate.getMonth(), 1).getDay()
  61. return dow
  62. },
  63. getDaysInMonth (thisDate) {
  64. const daysInMonth = new Date(thisDate.getFullYear(), thisDate.getMonth() + 1, 0).getDate()
  65. const days = []
  66. for (let index = 1; index < daysInMonth + 1; index++) {
  67. days.push(new Date(thisDate.getFullYear(), thisDate.getMonth(), index))
  68. }
  69. return days
  70. },
  71. book (thisDate) {
  72. this.$emit('book', thisDate)
  73. }
  74. }
  75. }
  76. </script>
  77. <style>
  78. .calendar {
  79. display: grid;
  80. width: 300px;
  81. grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
  82. grid-template-rows: 1fr 1fr 1fr 1fr 1fr 1fr;
  83. }
  84. </style>