tattali / CalendarBundle

Provides event calendar for your Symfony project. Compatible with API like Google Calendar.
https://packagist.org/packages/tattali/calendar-bundle
MIT License
147 stars 22 forks source link

Twig Component and Stimulus #63

Open tacman opened 1 year ago

tacman commented 1 year ago

One of the goals of this bundle could be to be able to customize fullcalendar without ever writing javascript. That is, to replace the section https://github.com/tattali/CalendarBundle#basic-functionalities with some twig calls.

Stimulus is the obvious choice, and could be wrapped in a twig component to make it even easier.

Brainstorming about the format.

{# events is an array of events, event contains at a minimum keys of title and start) #}
<div {{ stimulus_controller('calendar', {
        events: events
    })) }}>
</div>

OR

<twig:Calendar :events="events" />

Both of these work in the demo app at https://github.com/tacman/micro-calendar

image

Obviously, we'll want to move the twig component and stimulus controller to the bundle, but it's considerably easier to work in the demo app first. But when that happens, the developer simply needs to create events, e.g.

        $dt = new \DateTime(); // for the demo, start with the current date
        $events = [];
        $events[] = ['title' => 'now()', 'start' => $dt->format('c')];
        $events[] = ['title' => 'Set Goals', 'start' => $dt->format("Y-m-01")];
        $events[] = ['title' => 'Reflect', 'start' => $dt->format("Y-m-t")];

And pass them to the twig template, and in twig, call the component. ZERO JAVASCRIPT from the developer! Even what libraries to load will be hidden, since the bundle auto-registers everything, as long as the base loads the assets:

        {% block javascripts %}
            {{ importmap() }}
        {% endblock %}

So before moving the stimulus controller and twig component to the bundle, what are the options we want to expose via attributes? Obviously events and initialView, which for my application was actually enough to be usable. But fullcalendar has TONS of options, I imagine we'll start with the easy ones. I'm working on the icalendar plugin first.

tacman commented 1 year ago

This probably makes more sense as a discussion rather than an issue, but I don't think discussions are enabled.