year-calendar / js-year-calendar

A fully customizable year calendar widget
https://year-calendar.github.io/
Apache License 2.0
193 stars 70 forks source link

JS Calendar: How Does it Set Date Highlight Color? #19

Open sam-thecoder opened 4 years ago

sam-thecoder commented 4 years ago

I'm tinkering with JS Calendar and I have this codepen example:

https://codepen.io/thecoderr254/pen/wvvJqaY

let tooltip = null;

const calendar = new Calendar('#calendar', {
dataSource: function(year) {
    // Load data from GitHub API
    return fetch(`https://api.github.com/search/issues?q=repo:Paul-DS/bootstrap-year-calendar%20created:${year}-01-01..${year}-12-31`)
    .then(result => result.json())
    .then(result => {
        if (result.items) {
        return result.items.map(r => ({
            startDate: new Date(r.created_at),
            endDate: new Date(r.created_at),
        }));
        }

        return [];
    });
},
}).setStyle('background', 'red');

The interesting part is each "Date Range" has its own color code, this rule isn't set on the js or css code and I haven't seen a way to set that in the documentation. A standard color is important in my case, preferably red to indicate a booked date.

Paul-DS commented 4 years ago

You can specify a color parameter for each dataSource item:

{
    startDate: new Date(r.created_at),
    endDate: new Date(r.created_at),
    color: "yellow"
}

If no color is specified, the calendar automatically assign one color to each datasource item

sam-thecoder commented 4 years ago

Excellent, there's also one where you set a background color, how do you do that?

Paul-DS commented 4 years ago

The color of the datasource item is display depending of the style option of the calendar.

If you set it to border, the days will be display like that: image

If you set it to background, the days will be displayed like that: image

boutmos commented 3 years ago

Is color property can be an hexadecimal, RGB or HSL format ?

Thank you

EDIT: these 3 formats work but need to be quoted : "#DC143", etc ..

AndrewMiroshn1chenko commented 2 years ago

How could i highlight public holidays at this calendar if i have an array of dates of them?

Sanu-pr commented 1 year ago

how can i mark a color before the event date and after the event date ?

Batrbekk commented 1 year ago

Hello how can I change text color for saturday and sunday ?