Styling
The Bryntum Calendar is rendered in the DOM using regular HTML and CSS, and can be completely styled using CSS. It ships with both pre-compiled CSS bundles, and the original CSS files. The CSS includes different themes and colors, which can be used to alter how the Calendar and its contents look.
You can also programmatically modify the appearance of cells, headers and events using renderers (depending on product).
Styling events using predefined colors
Bryntum Calendar ships with a palette predefined event colors. Color can be specified per resource or per event. Event settings overrides resource. The following snippet shows how to assign colors:
// Make all events assigned to a specific resource orange:
resource.eventColor = 'orange';
// Make a single event violet:
event.eventColor = 'violet';
This demo shows most of the predefined colors:
And the same colors in a month view:
Using a theme
Bryntum products have their "structural" CSS and themes separated. The structural CSS contains the basic layout and styling shared between all themes for the product. It defines a lot of CSS variables (CSS custom properties), that the themes then set to specific values to create the visual appearance.
The theme CSS files set CSS variables for all Bryntum products, so you can use the same theme file for all Bryntum products.
The Calendar ships with four themes, each available in light and dark variants:
- Stockholm (
stockholm-light.css&stockholm-dark.css) - Svalbard (
svalbard-light.css&svalbard-dark.css) - Visby (
visby-light.css&visby-dark.css) - Material3 (
material3-light.css&material3-dark.css) - Fluent2 (
fluent2-light.css&fluent2-dark.css)
The CSS is located in the /build folder of the Bryntum distribution. You can include it in your project by for example using link tags:
<!-- Structural CSS -->
<link rel="stylesheet" href="build/calendar.css">
<!-- Bryntum theme -->
<link rel="stylesheet" href="build/svalbard-light.css" data-bryntum-theme>
data-bryntum-theme attribute on the link tag is not strictly required, but it allows you to programmatically switch the theme at runtime using DomHelper.setTheme(). Comparison of themes
Svalbard
Our default theme, very light and minimalistic. It is designed to be easy on the eyes and to not distract from the data.
Stockholm
The Stockholm theme was our default theme prior to v7.0. It has been updated with a more modern look and feel.
Visby
The city of Visby is famous for its medieval city wall, and the Visby theme embraces that by using more borders than our other themes.
Material3
The Material3 theme is based on Google's Material Design. It is a modern and clean theme that is slightly more colorful than our Svalbard theme.
Fluent2
The Fluent2 theme is based on Microsoft's Fluent Design System. It features rounded corners, subtle depth, and a polished modern aesthetic with balanced use of color and spacing.
In most of the included examples you can switch theme on the fly by clicking on the gear icon found in the header and then picking a theme in the dropdown.
Combining products
The structural CSS described above include all the CSS you need to use Calendar and its helper widgets such as Popups, TextFields and so on. When combining multiple different Bryntum products on a single page using normal structural CSS, the shared styling will be included multiple times.
To avoid this, each product's structural CSS is available in a version that only contains the CSS specific for that product. These are called thin CSS bundles (e.g. calendar.thin.css).
When using them you will need to include one for each used level in the Bryntum product hierarchy (Calendar -> Core + Grid + Scheduler + Calendar).
For example to combine Calendar and TaskBoard using the Svalbard Light theme, you would include:
core.thin.cssgrid.thin.cssscheduler.thin.csscalendar.thin.csstaskboard.thin.csssvalbard-light.css
Which in your html file might look something like this:
<link rel="stylesheet" href="core.thin.css" >
<link rel="stylesheet" href="grid.thin.css">
<link rel="stylesheet" href="scheduler.thin.css">
<link rel="stylesheet" href="calendar.thin.css">
<link rel="stylesheet" href="taskboard.thin.css">
<link rel="stylesheet" href="svalbard-light.css" data-bryntum-theme>
Creating a custom theme
To create your own theme, get the distribution bundle or install the NPM package as usual and follow these steps:
- (Optional) Make a copy of an existing theme found under
build/(either in package under thenode_modulesfolder or in the extracted zip), for example thesvalbard-light.cssfile. If you pick the theme that is closest to what you want, you will have to change less. You can also start from scratch, but it will be more work. - Edit the variables in it to suit your needs, and add any additional variables you want to tweak. You can reference all the available variables in the API documentation for each widget, or by looking at the CSS files in the
libfolder. - Include your theme on page (and remove any default theme you where using).
Depending on the import order of your CSS files, you might need to make the theme's variables more specific than the structural CSS. If for example this does not alter the variables as you would expect:
:root {
--b-button-outlined-border-color : lightsalmon;
}
It might be because the structural CSS is included after your theme, and it sets the variable to a different value. In that case, you can either alter the inclusion order (if you have control over the build process), or make your variables more specific:
/* The :not rule can contain anything, its purpose is only to make this rule */
/* more specific */
:root:not(.b-nothing) {
--b-button-outlined-border-color : lightsalmon;
}
/* Another (less flexible) option is to scope it to a specific selector */
.b-button {
--b-button-outlined-border-color : lightsalmon;
}
Calendar also uses variables from grid-sass and scheduler-sass, found at node_modules/@bryntum/calendar/source/resources/[grid/scheduler]-sass/variables.scss
Please see the Custom theme example for a custom theme in action:
Overriding an existing theme
As an alternative to creating a full custom theme, you can also just override a few variables in an existing theme. To do so, include the structural CSS and the theme you want to use, and then add your own CSS file that overrides the variables you want to change.
<!-- Structural CSS -->
<link rel="stylesheet" href="build/calendar.css">
<!-- Bryntum theme -->
<link rel="stylesheet" href="build/svalbard-light.css" data-bryntum-theme>
<!-- Your customizations -->
<link rel="stylesheet" href="path/to/your/customizations.css">
In customizations.css, you can then override any variables you want to change:
:root {
/* Everything looks good in lightsalmon */
--b-button-outlined-border-color : lightsalmon;
}
Switching theme at runtime
You can also add a combo box (or other UI) that lets you change the theme at run-time, similar to the examples we have. To do so, ensure you have multiple themes in a folder (e.g. /themes).
.b-theme-info block in the CSS file to avoid collisions. Next, you need to add a combo box using tbar.
import { Calendar, DomHelper } from '@bryntum/calendar';
const calendar = new Calendar({
// ...calendar data
tbar : [
{
type : 'combo',
// list of themes shown in the drop down (combo box)
items : [
{ text : 'Svalbard Light', value : 'svalbard-light' },
{ text : 'Svalbard Dark', value : 'svalbard-dark' },
{ text : 'Visby-Light', value : 'visby-light' },
{ text : 'Visby-Dark', value : 'visby-dark' }
// More themes...
],
label : 'Theme',
// default theme
value : 'svalbard-light',
// change theme on selection
onAction(props) {
DomHelper.setTheme(props.value);
}
}
]
});
With that being set up, you can switch themes within your application.
Using renderers and CSS
Contents of events can be fully customized using 'renderers'. Renderers are functions with access to a data used output events (such as style and CSS classes). They can manipulate the data to alter appearances or return a value to have it displayed.
In the demo below, we use the following APIs:
- Event
clsfield - To provide event specific styling - Resource
clsfield - To provide resource specific styling - Event renderer - To affect text and style of the event
const calendar = new Calendar({
// Redacted for brevity
events : [
{ duration : 4, name : 'A' },
// Event with custom CSS class
{ duration : 4, name : 'B (event cls)', cls : 'important' },
{ duration : 2, name : 'C' },
// Events linked to a resource, which uses a custom CSS class
{ duration : 4, name : 'D (resource cls)', resourceId : 'resource' },
{ duration : 4, name : 'E (resource cls)', resourceId : 'resource' },
{ duration : 2, name : 'F' },
{ duration : 4, name : 'G' }
],
resources : [
// Resource with a custom CSS class
{ id : 'resource', cls : 'resource' }
],
// Function exectued for each event when rendering. Used here to change color and text of short events
eventRenderer({ eventRecord, renderData }) {
if (eventRecord.duration <= 2) {
renderData.eventColor = 'deep-orange';
return 'Short event (renderer)';
}
}
});
Troubleshooting
CSS mismatched version
If you've encountered a CSS error:
CSS version 7.0.0 doesn't match bundle version 7.3.0!
Make sure you have imported css from the appropriate product version.
That means you're using a wrong version of Bryntum theme file. Following are some of the ways to check and fix the issue:
Verify CSS version
Ensure that the CSS file being used matches the version of the Bryntum API. For example, if you're using version 7.3.0 of Calendar, you need to have the CSS files of version 7.3.0.
Clear Cache
Ensure the mismatched CSS file is not cached on your web server to prevent outdated files from being served. Clear the browser cache to ensure the latest CSS file is loaded.
Cache Busting
Cache busting is a technique used to force browsers to load the most recent versions of files. If the CSS file is imported in index.html, then it should have cache busting by specifying the version (calendar.css?v=7.3.0) or use timestamps (calendar.css?1704085200).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your Calendar App</title>
<link rel="stylesheet" href="path/to/stylesheet.css?v=1.2.3"> <!-- Cache busting by specifying version -->
</head>
<body>
<!-- Your content here -->
</body>
</html>
Modern frameworks apply this by default to the production code, but it needs to be manually implemented in vanilla JavaScript projects.