Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(VCalendar): Add eventHandlers and slots #19568

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

blalan05
Copy link
Member

@blalan05 blalan05 commented Apr 9, 2024

<template>
  <v-app>
    <v-main>
      <v-container>
        <v-row>
          <v-col>
            <v-calendar v-model="thisDate" :events="events">
              <template #title="title">
                <span>{{ title }}</span>
              </template>
              <template #event="{ event }">
                {{ `Test ${event.title}` }}
              </template>
            </v-calendar>
          </v-col>
        </v-row>
      </v-container>
    </v-main>
  </v-app>
</template>
<script setup>
  import { ref } from 'vue'

  const thisDate = ref([new Date()])

  const events = ref([
    {
      start: new Date(),
      end: new Date(),
      title: 'Event 1',
    },
  ])
</script>

@blalan05 blalan05 self-assigned this Apr 9, 2024
@blalan05 blalan05 added the C: VCalendar VCalendar label Apr 9, 2024
@blalan05
Copy link
Member Author

blalan05 commented Apr 9, 2024

@nekosaur I started this code a few weeks ago, but wasn't able to get it working. I've tried to match what you PR'd in #19555. But I still don't see the slots overriding content. This PRs also addresses the missing event handling and more slots.

@blalan05 blalan05 added the labs label Apr 9, 2024
@nekosaur
Copy link
Member

Is there support for <slot> in jsx?

@KaelWD
Copy link
Member

KaelWD commented Apr 10, 2024

No.

events={ props.events?.filter(e => adapter.isSameDay(e.start, day.date) || adapter.isSameDay(e.end, day.date)) }
></VCalendarDay>
daysInWeek.value.map((day, i) =>
slots.intervalDay?.({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: what's the difference between day and intervalDay slots?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

day is the replacement for MonthDay, and intervalDay would be the week/day view "day". The props and display is completely different.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the slot names be improved? It's not immediately clear what they do and when you should use which

packages/vuetify/src/labs/VCalendar/VCalendarDay.tsx Outdated Show resolved Hide resolved
packages/vuetify/src/labs/VCalendar/VCalendarDay.tsx Outdated Show resolved Hide resolved
packages/vuetify/src/labs/VCalendar/VCalendarInterval.tsx Outdated Show resolved Hide resolved
packages/vuetify/src/labs/VCalendar/VCalendarInterval.tsx Outdated Show resolved Hide resolved
packages/vuetify/src/labs/VCalendar/VCalendarInterval.tsx Outdated Show resolved Hide resolved
packages/vuetify/src/labs/VCalendar/VCalendarInterval.tsx Outdated Show resolved Hide resolved
day={ day }
title={ day ? adapter.format(day.date, 'dayOfMonth') : 'NaN' }
events={ props.events?.filter(e => adapter.isSameDay(day.date, e.start) || adapter.isSameDay(day.date, e.end)) }
{ ...getPrefixedEventHandlers(attrs, ':day', () => ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: I'm assuming the dynamic nature of this means that the events can't be documented in/through code? @KaelWD

Copy link
Member

@KaelWD KaelWD Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have a genPrefixedEventProps<T>(':day') too but it would have to add every single dom event as a prop which would be a huge mess. v2 got around it by manually defining <event>:row in the overrides file but v3 doesn't have that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah.. might need that override again

packages/vuetify/src/labs/VCalendar/VCalendar.tsx Outdated Show resolved Hide resolved
@Jang-Eun-Ji
Copy link

Jang-Eun-Ji commented Apr 19, 2024

Here is my solution for #19624 :
I just count the 'v-chip__content' (in month-day format) on the screen.
When you fetch monthly data from the server, if you retrieve it sorted by date and time,
you can know which event you are currently clicking on.
This is the code to find the index of the event on the screen and print it with console.log.
Just you know, my current code is a temporary solution until Vuetify further develops the data format for the calendar.

findElementIndex(event) {
      const clickedElement = event.target.closest('.v-chip__content');
      if (!clickedElement) {
        console.log('Clicked element is not a .v-chip__content element');
        return;
      }
      const allElements = Array.from(document.querySelectorAll('.v-chip__content'));
      const elementIndex = allElements.indexOf(clickedElement);
      console.log('Clicked .v-chip__content Element Index:', elementIndex);
    }

@nekosaur nekosaur force-pushed the feat/v3-calendar-slots-events branch from c19160d to 4e06468 Compare April 27, 2024 08:55
@nekosaur
Copy link
Member

I rebased and pushed some changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] output event information when you click on the event (for details of the event)
4 participants