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

Allow setting styles on date cell #35

Merged
merged 1 commit into from
Feb 12, 2019
Merged

Allow setting styles on date cell #35

merged 1 commit into from
Feb 12, 2019

Conversation

jordanwallwork
Copy link

Added a simple option to allow specifying cell styles

@GramThanos
Copy link
Owner

Why not just use CSS to do so?

.jsCalendar tbody td:nth-child(1), .jsCalendar tbody td:nth-child(7) {
    font-weight: bold;
}

or if you have Monday first

.jsCalendar tbody td:nth-child(6), .jsCalendar tbody td:nth-child(7) {
    font-weight: bold;
}

In order to allow UI tweaks through Javascript, I am considering implementing an extension system for version 2 to allow pre-render and post-render modifications.

@jordanwallwork
Copy link
Author

I just used making dates bold as an example to show how it's used. I'm using it alongside a backing event store to indicate things happening on certain dates. My code looks more like:

getCellStyle: function (date) {
    var summary = eventStore.getEventSummaryForDate(date);
    if (summary.hasImportant) return "font-weight:bold;color:#f00";
    else if (summary.events.count > 1) return "font-weight:bold";
}

@GramThanos
Copy link
Owner

GramThanos commented Feb 12, 2019

Ok, now I get it. But I feel like getCellStyle is too specific.

I think I am going to merge this and convert it to something like

function onDateRender(date, cell) {
    // We will also give access to `this` as the jsCalendar instance

    var summary = eventStore.getEventSummaryForDate(date);
    if (summary.hasImportant) {
        cell.style.fontWeight = 'bold';
        cell.style.color= '#f00';
    }
    else if (summary.events.count > 1) {
        cell.style.fontWeight = 'bold';
    }

    // We will be able to alter the contents too, maybe add the number of events
    if (summary.events.count > 0) {
        let span = document.createElement('span');
        span.className = 'date-events';
        span.textContent = summary.events.count;
        cell.appendChild(span);
    }
}

So that it can cover more applications.

What do you think?

@jordanwallwork
Copy link
Author

Yeah that makes total sense. That's actually what I started with and then I made it more specific to fit my requirements, I hadn't anticipated submitting a PR but then decided I may as well in case someone else found it useful

@GramThanos GramThanos merged commit 7c58e2d into GramThanos:master Feb 12, 2019
GramThanos added a commit that referenced this pull request Feb 12, 2019
Removed option `getCellStyle`.
Added option `monthRenderHandler`.
Added method `setMonthRenderHandler`.
Added option `dayRenderHandler`.
Added method `setDayRenderHandler`.
Added option `dateRenderHandler`.
Added method `setDateRenderHandler`.
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants