Skip to content

Commit

Permalink
Allow setting a custom format for the day in the grid list (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
mweimerskirch authored Aug 24, 2023
1 parent ae13583 commit 09a5155
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Inspired by [FullCalendar](https://fullcalendar.io/), implements similar options
- [filterResourcesWithEvents](#filterresourceswithevents)
- [firstDay](#firstday)
- [flexibleSlotTimeLimits](#flexibleslottimelimits)
- [gridDayFormat](#griddayformat)
- [headerToolbar](#headertoolbar)
- [height](#height)
- [hiddenDays](#hiddendays)
Expand Down Expand Up @@ -1392,6 +1393,29 @@ The function must return `true` to have this event counted, or `false` to ignore
</tr>
</table>

### gridDayFormat
- Type `object` or `function`
- Default `{day: 'numeric'}`

Defines the day-text that is displayed on the grid view.

This value can be either an object with options for the native JavaScript [Intl.DateTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat) object, or a callback function that returns formatted string:

```js
function (date) {
// return formatted date string
}
```
<table>
<tr>
<td>

`date`
</td>
<td>JavaScript Date object that needs to be formatted</td>
</tr>
</table>

### headerToolbar
- Type `object`
- Default `{start: 'title', center: '', end: 'today prev,next'}`
Expand Down
4 changes: 2 additions & 2 deletions packages/day-grid/src/Day.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
export let iChunks = [];
let {date: currentDate, dayMaxEvents, highlightedDates, moreLinkContent, theme,
_hiddenEvents, _popupDate, _popupChunks, _interaction, _queue} = getContext('state');
_hiddenEvents, _intlGridDayFormat, _popupDate, _popupChunks, _interaction, _queue} = getContext('state');
let el;
let dayChunks;
Expand Down Expand Up @@ -111,7 +111,7 @@
on:pointerleave={$_interaction.pointer?.leave}
on:pointerdown={$_interaction.action?.select}
>
<div class="{$theme.dayHead}">{date.getUTCDate()}</div>
<div class="{$theme.dayHead}">{$_intlGridDayFormat.format(date)}</div>
<!-- Pointer -->
{#if iChunks[1] && datesEqual(iChunks[1].date, date)}
<div class="{$theme.events}">
Expand Down
2 changes: 2 additions & 0 deletions packages/day-grid/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default {
// Common options
options.buttonText.dayGridMonth = 'month';
options.buttonText.close = 'Close';
options.gridDayFormat = {day: 'numeric'};
options.theme.uniform = 'ec-uniform';
options.theme.dayFoot = 'ec-day-foot';
options.theme.popup = 'ec-popup';
Expand All @@ -29,6 +30,7 @@ export default {
createStores(state) {
state._days = days(state);
state._intlDayPopover = intl(state.locale, state.dayPopoverFormat);
state._intlGridDayFormat = intl(state.locale, state.gridDayFormat);
state._hiddenEvents = writable({});
state._popupDate = writable(null);
state._popupChunks = writable([]);
Expand Down

0 comments on commit 09a5155

Please sign in to comment.