Skip to content

headerItems

Places of your own in the header — a menu, a filter, a badge — named in headerToolbar.

TypeReadonly<Record<string, ElementHooks<HeaderItemCtx>>>
Defaultnot set
Live update (update())Yes
Declared inpackages/dom/src/calendar.ts

Each key is a place’s name, put in headerToolbar like a button; each value draws it, as a render hook does: content(ctx, el) (a string or a node), class, didMount({ el, ctx }) (once, after it is in the page; it may return its clean-up) and willUnmount. Its context holds name, view and title, and content is asked again when they change: return the same node to keep a control’s value and focus.

The frameworks draw it with their own templates: Angular’s <ng-template dzHeaderItem="filter" let-ctx>, React’s headerItems prop (a node, or a function of the context), Vue’s #header-item-filter slot.

import { createCalendar } from '@dzcalendar/dom';
const select = document.createElement('select');
select.append(new Option('All doctors', ''), new Option('Dr Benali', 'benali'));
createCalendar(element, {
timeZone: 'Europe/Paris',
headerToolbar: { start: 'prev,next today', center: 'title', end: 'filter' },
headerItems: {
filter: {
// The same node each time: content is asked again when the view or the title changes.
content: () => select,
didMount: ({ el }) => {
const onChange = () => console.log('filter', (el.querySelector('select') as HTMLSelectElement).value);
el.addEventListener('change', onChange);
return () => el.removeEventListener('change', onChange);
},
},
},
});

In plain JavaScript it is an option; in the frameworks, the templates above.