Giter VIP home page Giter VIP logo

Comments (7)

fschon avatar fschon commented on June 26, 2024 1

from vaadin-minicalendar.

downdrown avatar downdrown commented on June 26, 2024

Hey @fschon! I do get 1 and 2 (so I think 😅) but you'd need to elaborate on your 3rd suggestion.
Do you wish to have a specific styling for some days?

from vaadin-minicalendar.

fschon avatar fschon commented on June 26, 2024

Yes. In my use case, each available day should have a different styling to non available days. So only two different styles necessary - available or not available styles.

But I thought that maybe someone would have a need for more than one styling option for days, therefore the "list of lists of stylings". So maybe:

  • a list of available styled days
  • a list of not available styled days
  • and a list of public holiday styled days.

Of course some kind of styling priority would have to be defined - maybe last one wins?

Thanks in advance for updating the component.

from vaadin-minicalendar.

downdrown avatar downdrown commented on June 26, 2024

Hey @fschon, thanks for your suggestions.

I just checked the Vaadin internal com.vaadin.flow.component.datepicker.DatePicker but I could not find a constructor allowing you to define the valid range (a.k.a. setMin(LocalDate) and setMax(LocalDate)).
image

(As a side note: I updated the AddOn to Vaadin to 24.3.9)

MiniCalendar provides a setDayEnabledProvider(SerializablePredicate<LocalDate>) method to dynamically en- or disable days for selection. This could also be a more complex predicate like the following:

miniCalendar.setDayEnabledProvider(date -> 
    date.isAfter(LocalDate.of(2024, Month.APRIL, 1)) && 
    date.isBefore(LocalDate.of(2024, Month.MAY, 1)) &&
    isNoPublicHoliday(date)
);

Same goes for adding styles to your days. You can simply use setDayStyleProvider(SerializableFunction<LocalDate, List<String>>) to dynamically add (multiple) styles to a certain date:

List<LocalDate> publicHolidays = gatherYourLocalHolidays();
miniCalendar.setDayStyleProvider(day -> {
    if (publicHolidays.contains(day)) {
        return List.of("public-holiday", "some-other-spicy-style");
    }
    return null;
});

Regarding the public holidays you mentioned I am not quite sure what you mean. Holidays differ by country and there's no easy way (that I know of) to trustworthy check for them using the standard Java LocalDate API. I'd like to not include any 3rd party libraries into the AddOn if not really necessary.

That's the reason I tried to make it quite flexible in the first place.

If your request adresses convenience I can surely provide an additional constructor in which you can directly pass a dayEnabledProvider and a dayStyleProvider.

Please let me know if this helps you already or if you still need a change 🙂

from vaadin-minicalendar.

downdrown avatar downdrown commented on June 26, 2024

Hey @fschon, thanks for clarification.

I think I understand better what you mean now.
The component does not actually make server roundtrips for the styles to be applied, it happens server side before the component gets "drawn".

I just adapted my showcase sample to add styles to each day and just increment a counter, so that the data is dynamic, see below screen capture:

MiniCalendar_StyleProvider.mp4

So if you already have static information about the stylings you wish to apply, you've basically already won.
My warning in the documentation refers to heavy db operations in these callbacks, which is really (really) a bad thing to do.
If you e.g. load the data on view creation, store the reference in a local var and use that var in the style provider you should be fine.

If you experience this differently it would be super nice to have a minimalist sample project to play around, or maybe also a short screencast of the roundtrips you're experiencing.

Please don't get me wrong, I'm really not trying to "not do that change" for you, I'm just trying to figure out what the best solution could be 😅

I also was thinking about adding the actual date as a css class to the span of the days. In this way you could simply inject CSS into your page and you'd also be ready 2 go.

However I'm still debating with myself whether I like this or not 😆

from vaadin-minicalendar.

fschon avatar fschon commented on June 26, 2024

from vaadin-minicalendar.

downdrown avatar downdrown commented on June 26, 2024

Yep, there are no client-server roundtrips per day. The creation of the layout happens server side and before the component gets attached. As I said, it's just not a good idea to have some heavy computation in these callbacks as they can get called quite a few times when you navigate through the calendar.

I'm closing this issue now but please do let me know when you really have some performance issues and see any possible enhancements. 🙂

from vaadin-minicalendar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.