Customization

The MultiViewCalendar enables the user to render custom components instead of the default ones and, in this way, to customize most of the child MultiViewCalendar components which are otherwise inaccessible.

The user can replace the following MultiViewCalendar components with custom ones:

Cells inside the View

You can customize or completely replace with a custom component each individual cell inside the MultiViewCalendar view by passing a cell property to the MultiViewCalendar. The cell property accepts either a Class or Function React Component. Both Class and Function receive relevant information about the state of the cell through the props of the Calendar.

Modifying the Cells

To modify an individual cell inside the MultiViewCalendar view, use the CalendarCell component from the @progress/kendo-date-dateinputs package. CalendarCell will acquire custom behavior and will modify only some of the cells.

For the CalendarCell component to work properly, pass back all properties.

import { MultiViewCalendar, CalendarCell } from '@progress/kendo-react-dateinputs';
const customCell = (props) => {
    const style = props.isWeekend ? { opacity: '.7' } : { fontWeight: 'bold' };

    return (
        <CalendarCell {...props} style={style} />
    )
}

class App extends React.Component {
    render() {
        return (
            <MultiViewCalendar cell={customCell} />
        )
    }
}
ReactDOM.render(
    <App />,
    document.querySelector('my-app')
)

Overriding the Default Properties

The cell property allows you to pass any <td /> element as a CalendarCell. This approach is useful for gaining full control over the cell because the CalendarCell component will render additional elements for the default styling.

For the custom cell to allow date selection, manually pass or handle the onClick event.

import * as React from 'react';
import * as ReactDOM from 'react-dom';

import { MultiViewCalendar } from '@progress/kendo-react-dateinputs';
import { Tooltip } from '@progress/kendo-react-tooltip';
import { classNames } from '@progress/kendo-react-common';

class CustomCell extends React.Component {
    title = "We're closed on the weekends!"
    handleClick = () => {
        if (!this.props.isWeekend) {
            this.props.onClick(this.props.value);
        }
    }

    render() {
        const style = {
            cursor: 'pointer',
            opacity: this.props.isWeekend ? .6 : 1
        };

        const className = classNames({
            'k-state-selected': this.props.isSelected,
            'k-state-focused': this.props.isFocused
        });

        return (
            <td
                onClick={this.handleClick}
                className={className}
                style={style}
            >
                <span className="k-link" title={this.props.isWeekend && this.title}>
                    {this.props.children}
                </span>
            </td>
        );
    }
}

class App extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            value: null
        };
    }

    handleChange = (event) => {
        const dayOfWeek = event.value.getDay();

        // 0 = Sunday, 6 = Saturday
        if (dayOfWeek !== 0 && dayOfWeek !== 6) {
            this.setState({ value: event.value });
        }
    }

    render() {
        return (
            <Tooltip anchorElement="target" position="top">
                <MultiViewCalendar
                    cell={CustomCell}
                    value={this.state.value}
                    onChange={this.handleChange}
                />
            </Tooltip>
        );
    }
}
ReactDOM.render(
    <App />,
    document.querySelector('my-app')
);

Other Child Components

Similar to the cell property, the MultiViewCalendar allows you to modify or override other child element through its weekCell, headerTitle.

import {
       CalendarCell,
       CalendarWeekCell,
       CalendarHeaderTitle
   } from '@progress/kendo-react-dateinputs';

Cells inside the Week Column

The CalendarWeekCell component represents the week number. CalendarWeekCell is only visible in the month view of the MultiViewCalendar and if the weekNumber property is set to true. CalendarWeekCell will receive relevant information about its state through the CalendarWeekCellProps.

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { MultiViewCalendar } from '@progress/kendo-react-dateinputs';
import { CustomWeekCell } from './customWeekCell.jsx';

class App extends React.Component {
    render() {
        return (
            <MultiViewCalendar
                weekNumber={true}
                weekCell={CustomWeekCell}
            />
        );
    }
}

ReactDOM.render(
    <App />,
    document.querySelector('my-app')
);
import * as React from 'react';

import { CalendarWeekCell } from '@progress/kendo-react-dateinputs';
import { convertToRoman } from './customProvider.js';

export class CustomWeekCell extends React.Component {
    render() {
        return (
            <CalendarWeekCell {...this.props} >
                {convertToRoman(this.props.value)}
            </CalendarWeekCell>
        );
    }
}
export const convertToRoman = function(tmp) {
    const Decimal = [ 1, 5, 10, 50, 100, 500, 1000 ];
    const Roman = [ 'I', 'V', 'X', 'L', 'C', 'D', 'M' ];

    let value = Math.min(2000, tmp);
    let text = '';
    for (let i = 6; i >= 0; i--) {
        while (value >= Decimal[i]) {
            text += Roman[i];
            value -= Decimal[i];
        }
        const leftIndex = i + i % 2 - 2;
        if (leftIndex >= 0 && value >= Decimal[i] - Decimal[leftIndex]) {
            text += Roman[leftIndex] + Roman[i];
            value -= Decimal[i] - Decimal[leftIndex];
        }
    }
    return text;
};

Titles of Current Views

The CalendarHeaderTitle component represents the title of the current MultiViewCalendar view and also functions as a button for changing the current view. CalendarHeaderTitle will receive relevant information about its state through the CalendarHeaderTitleProps.

For the CalendarHeaderTitle component to work properly, pass back all properties.

import * as React from 'react';
import * as ReactDOM from 'react-dom';

import { MultiViewCalendar } from '@progress/kendo-react-dateinputs';
import { CustomHeaderTitle } from './customHeaderTitle.jsx';

class App extends React.Component {
    render() {
        return (
            <MultiViewCalendar headerTitle={CustomHeaderTitle} />
        );
    }
}

ReactDOM.render(
    <App />,
    document.querySelector('my-app')
);
import * as React from 'react';

import { CalendarHeaderTitle, CalendarViewEnum } from '@progress/kendo-react-dateinputs';

export class CustomHeaderTitle extends React.Component {
    render() {
        return (
            <CalendarHeaderTitle {...this.props}>
                {this.props.view === CalendarViewEnum.month
                    ? `${this.props.value.split(' ')[0]} - ${this.props.value.split(' ')[3]}`
                    : this.props.value}
                {this.props.view !== CalendarViewEnum.century
                    ? <code>↑</code>
                    : null}
            </CalendarHeaderTitle>
        );
    }
}

In this article