Themes Implementation in Vanilla-Gantt
The Gantt follows the grid's base/theme split
(Themes § 1):
vanilla-gantt.css holds the timeline's structure only, and each theme file
holds its paint only. Two themes ship, default and default-dark, with the
look of the grid's two default themes.
1. One attribute, both panes
theme="default-dark" loads themes/vn-gantt-default-dark.css for the
timeline and sets theme="default-dark" on the embedded grid. Each Gantt theme
is therefore also a grid theme; tests/node/gantt-theme-set.test.js checks it
for the built-in ones, and that SUPPORTED_THEMES matches the theme files.
VanillaGanttElement.registerTheme(name, cssPath)registers the timeline's stylesheet for a name;getSupportedThemes()lists the built-in names and the registered ones. The task grid uses the grid theme of the same name, built in or registered withVanillaGridElement.registerTheme(). When the grid knows no such theme it keepsdefault, with one warning.theme-css-pathoverrides the timeline's stylesheet only; the grid keeps the themethemenames.- An unknown name loads the timeline's
defaulttheme, as the grid does. - A
<vn-gantt-toolbar>linked to the task grid follows the grid's theme by itself, so it switches with the Gantt's.
Row height and header height are not Gantt tokens: the lanes take the grid's measured row height, and the header is sized to end where the grid's rows begin (Timeline § 4).
2. Tokens
Each theme defines these on .vn-gantt; the base stylesheet reads them.
tests/node/gantt-theme-set.test.js checks that every --vn-gantt-* property
the base stylesheet reads is defined by every theme.
| Property | Use | Default | Default Dark |
|---|---|---|---|
--vn-gantt-bg, --vn-gantt-fg |
Timeline surface and text | #ffffff, #333333 |
#1a1b2e, #e5e7f5 |
--vn-gantt-border-color |
The line under each lane (the grid's cell divider colour in both themes) | #e0e0e0 |
#2e3150 |
--vn-gantt-row-alt-bg |
Odd lanes (vn-gantt-lane-alt) |
transparent |
transparent |
--vn-gantt-row-hover-bg |
A hovered lane, and the lane of a task whose grid row is hovered (vn-gantt-lane-hover), see-through over the tick lines; over the selection tint too, as in the grid, where the selected task's row keeps the grid theme's selection marker (--vn-grid-selection-marker-color) |
rgba(0, 0, 0, 0.04) |
rgba(163, 177, 255, 0.08) |
--vn-gantt-row-selected-bg |
The selected task's lane (vn-gantt-lane-selected), over the stripes; the grid theme's --vn-grid-frozen-bg-selected, so both panes show one tint |
rgba(102, 126, 234, 0.12) |
rgba(163, 177, 255, 0.12) |
--vn-gantt-header-bg, --vn-gantt-header-fg |
Header | #667eea, white |
#4f5bd5, white |
--vn-gantt-tick-line-color |
Lines at the lower tier's boundaries | #eeeeee |
#23253d |
--vn-gantt-bar-bg |
Bars (they hold no text) | #667eea |
#a3b1ff |
--vn-gantt-bar-radius, --vn-gantt-bar-height |
Bar shape | 3px, 14px |
3px, 14px |
--vn-gantt-summary-bg, --vn-gantt-milestone-bg |
Summary brackets, milestone diamonds | #3f4a9e |
#c7d2fe |
--vn-gantt-bar-dragging-bg |
The moved bar (and its subtree) while a move is previewed | #4553c4 |
#c7d2fe |
--vn-gantt-bar-pushed-bg |
Every other bar the previewed move changes | #e39a2d |
#f2b866 |
--vn-gantt-bar-focus-ring |
The ring around the selected task's bar (vn-gantt-lane-selected, however it was selected; bars are never focused), and the timeline's inset outline while it has keyboard focus (:focus-visible, not after a bar press) |
#312e81 |
#ffffff |
--vn-gantt-link-color, --vn-gantt-link-violated-color |
Dependency links and their arrowheads; violated links | #6e7591, #d93838 |
#8589b0, #ff6b6b |
--vn-gantt-link-width |
Link stroke | 1.25px |
1.25px |
--vn-gantt-link-redirected-dash |
A link redirected to a collapsed ancestor (stroke-dasharray) |
4 3 |
4 3 |
--vn-gantt-scrollbar-thumb-color, -color-hover, --vn-gantt-scrollbar-thumb-shadow |
The horizontal scrollbar | The grid's scrollbar fallbacks | The same |
--vn-gantt-splitter-color |
The line between the task list and the timeline (the splitter) | #e0e0e0, the border colour |
#2e3150 |
--vn-gantt-splitter-active-color |
That line while hovered, dragged or focused | #667eea, the header and bar colour |
#a3b1ff, the accent of the selected tint |
The grid's own scrollbar tokens are not reused by name, since they style
.vn-grid-* classes; the Gantt themes give --vn-gantt-scrollbar-* the same
values. The selected-row tint is copied the same way: the grid declares
--vn-grid-frozen-bg-selected on .vn-grid-table-container, which the
timeline is not inside. A registered timeline theme without
--vn-gantt-row-selected-bg leaves the selected lane untinted; its grid row
keeps its own tint. The other way, a task row marked hovered from its lane
(vn-grid-row-hover) is painted by the grid's base stylesheet with the grid
theme's --vn-grid-frozen-bg-hover, the colour its :hover paints
(Timeline § 2). Each theme also styles a few classes directly, as the grid's themes
do: the timeline's border and radius (.vn-gantt-timeline, matching the
grid container's), and the header's tier and tick separators.
One frame. The two panes read as one framed component. The base
stylesheet, not the themes, removes the inner edges: the task grid's
container loses its right border and right corners
(.vn-gantt-grid-pane .vn-grid-table-container), the timeline its left ones
(.vn-gantt-layout > .vn-gantt-timeline). Both selectors have two classes, so
they win over a theme's one-class border and radius whatever order the sheets
load in; the outer corners keep each theme's radius. The splitter draws the
one line between them, the full height, so the two headers read as one band
cut by it (Web Component § 8). A
registered timeline theme whose border colour differs from its grid theme's
shows two colours on one frame; the line takes the timeline theme's
--vn-gantt-splitter-color.
Grid internals the base stylesheet overrides. To put the task grid's
vertical scrollbar at the timeline's right edge
(Timeline § 6.2) the
base stylesheet styles grid classes inside .vn-gantt-grid-pane: the vertical
track and the row-range label (position: fixed), and, with !important
over the grid's inline writes, the horizontal track's right and the
corner's display. It also gives the last column the cells' normal 8px right
padding in place of the grid's 10px, which cleared the scrollbar's old place.
A grid change to those class names or the inline writes must be checked
against these rules.
Each task row reaches the splitter, as its lane reaches the timeline's edge,
with no rule of the Gantt's: past its last column every grid row is a filler
cell from the grid's base stylesheet
(Row Virtualization § 1.2).
The space is part of the row: its background, zebra, selected and hover
tints, its :hover and its click. The filler draws the row's divider in the
grid theme's --vn-grid-row-border-color, the colour of its cells' own line,
whatever theme pair is registered.
3. Loading
The base stylesheet and the theme link are injected by the element, with the
grid's link machinery copied (refcounted links keyed by URL, per-instance load
waiters, the ?v= token): see
Web Component § 7. ready() waits for
both sheets, and for the task grid's (its stylesheetsReady()), and the pane
geometry is re-measured once the Gantt's have loaded.
4. Forced colors
Forced colors (Windows High Contrast) reset backgrounds to the system
background, which would leave a bar Canvas on Canvas, and recolour SVG
strokes. The base stylesheet's @media (forced-colors: active) block opts the
bars, the scrollbar thumb, the link layer and the splitter out (forced-color-adjust: none)
and paints them in system colours itself:
| Part | Colour |
|---|---|
| A bar | Canvas, outlined 1px solid CanvasText, its label CanvasText |
| A summary bracket, a milestone diamond | filled with CanvasText |
| The moved and pushed bars of a previewed move | Highlight, labels HighlightText |
| The selected task's bar's ring, and the timeline's outline while it has keyboard focus | 2px solid Highlight; a bar that isn't selected has none |
| The selected task's grid row past its last column (the filler) | Highlight, from the grid's stylesheet, as it paints the row's cells |
| The selected task's lane | An inset outline, 2px solid Highlight at outline-offset: -2px; not a fill, since a previewed bar is Highlight and would vanish on it |
| Links and arrowheads | CanvasText; violated links Mark |
| Tick lines | GrayText |
| The horizontal scrollbar's thumb | CanvasText |
| The splitter | A CanvasText line; Highlight while hovered, dragged or focused, its focus outline Highlight |
The header, the lanes and their borders take the system colours the forced
palette gives them. The task grid's selected row shows in the grid's
selected-item colours, Highlight cells with HighlightText, from the
grid's base stylesheet (Themes § 4.2).
A hovered task shows in neither pane: the hover marks are backgrounds, which
the forced palette resets, as it does a :hover. tests/playwright/gantt-forced-colors.spec.js checks each
part under forcedColors: 'active'.
5. Page-global themes
Gantt themes style plain .vn-gantt-* classes and set their tokens on
.vn-gantt, like the grid's themes. Two Gantts with different themes on one
page therefore share the grid's known defect: both take the last-loaded theme.
Per-instance scoping would fix the timeline only, since the grid pane stays
page-global.