Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(calendar): theme FullCalendar with Forma and a Trilium palette
Elian Dorande7e571d4537
diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsxindex fb67536384..cc08cbe9cd 100644--- a/apps/client/src/widgets/collections/calendar/index.tsx+++ b/apps/client/src/widgets/collections/calendar/index.tsx@@ -1,9 +1,11 @@// FullCalendar v7 ships no bundled CSS of its own — the skeleton and the chosen theme have to be-// pulled in by hand. Imported ahead of index.css so our own rules still come last.+// pulled in by hand. The theme's own palette is deliberately not among them: palette.css states+// the same variables in terms of Trilium's, which is the whole of the theming (see there).+// Imported ahead of index.css so our own rules still come last.import "fullcalendar/skeleton.css";-import "fullcalendar/themes/classic/theme.css";-import "fullcalendar/themes/classic/palette.css";+import "fullcalendar/themes/forma/theme.css";+import "./palette.css";import "./index.css";import { DISPLAYABLE_LOCALE_IDS } from "@triliumnext/commons";@@ -475,7 +477,7 @@ function usePlugins(isEditable: boolean, isCalendarRoot: boolean) {const plugins: PluginInput[] = [];// v7 pulled the theme out of core and made it a plugin; without one the calendar draws// with no styling at all.- plugins.push((await import("fullcalendar/themes/classic")).default);+ plugins.push((await import("fullcalendar/themes/forma")).default);plugins.push((await import("fullcalendar/daygrid")).default);plugins.push((await import("fullcalendar/timegrid")).default);plugins.push((await import("fullcalendar/list")).default);diff --git a/apps/client/src/widgets/collections/calendar/palette.css b/apps/client/src/widgets/collections/calendar/palette.cssnew file mode 100644index 0000000000..2c252e095c--- /dev/null+++ b/apps/client/src/widgets/collections/calendar/palette.css@@ -0,0 +1,62 @@+/*+ * Trilium's palette for FullCalendar's "Forma" theme.+ *+ * v7 splits a theme in two: structure — the theme plugin and its theme.css, both taken from npm+ * unchanged — and colour, which is nothing more than the variables below. So rather than importing+ * one of the stock palettes and fighting it, we define the same names in terms of Trilium's own.+ *+ * That is also why there is no dark-mode branch here. Trilium swaps its whole stylesheet between+ * light and dark (and between the legacy and Next families), so these read through to whatever is+ * loaded and follow it on their own.+ *+ * Declared on :root rather than scoped to the calendar because FullCalendar portals its day+ * popover out of the calendar's subtree, where a scoped variable would not reach it. The names are+ * namespaced, so saying it globally costs nothing.+ */+:root {+ /* Neutral surfaces and text. */+ --fc-forma-background: var(--main-background-color);+ --fc-forma-foreground: var(--main-text-color);+ --fc-forma-faint-foreground: var(--muted-text-color);+ --fc-forma-muted-foreground: var(--muted-text-color);++ /*+ * Forma's neutral ramp is a set of translucent overlays — black ones in its light palette,+ * white ones in its dark. Mixing the text colour into transparent gets both from one+ * declaration: that colour is already dark on a light theme and light on a dark one, so the+ * ramp inverts with the theme instead of us keeping two copies of it in step.+ */+ --fc-forma-faint: color-mix(in srgb, var(--main-text-color) 3%, transparent);+ --fc-forma-muted: color-mix(in srgb, var(--main-text-color) 7%, transparent);+ --fc-forma-strong: color-mix(in srgb, var(--main-text-color) 12%, transparent);+ --fc-forma-stronger: color-mix(in srgb, var(--main-text-color) 16%, transparent);+ --fc-forma-strongest: color-mix(in srgb, var(--main-text-color) 20%, transparent);++ /* Borders. The strong one is a grabbable edge (column resizers), so it is stated rather+ than left to the ordinary border colour. */+ --fc-forma-border: var(--main-border-color);+ --fc-forma-muted-border: var(--main-border-color);+ --fc-forma-strong-border: color-mix(in srgb, var(--main-text-color) 35%, transparent);++ /*+ * Primary: what Forma marks today with, and draws the now-indicator and pressed buttons in.+ * Its "over" and "down" steps darken on a light theme and lighten on a dark one — which is,+ * again, what mixing the text colour in gives for nothing.+ */+ --fc-forma-primary: var(--link-color);+ --fc-forma-primary-over: color-mix(in srgb, var(--link-color) 85%, var(--main-text-color));+ --fc-forma-primary-down: color-mix(in srgb, var(--link-color) 70%, var(--main-text-color));+ --fc-forma-primary-foreground: var(--active-item-text-color);++ /*+ * Events, read through the same calendar-specific variables the collection already honours so+ * that a theme customising those keeps its say. Only the Next themes define them, hence the+ * fallbacks for the legacy pair.+ */+ --fc-forma-event: var(--calendar-coll-event-background-color, var(--accented-background-color));+ --fc-forma-event-contrast: var(--calendar-coll-event-text-color, var(--main-text-color));+ --fc-forma-background-event: var(--link-color);++ /* The shading a range dragged out on the grid stands in. */+ --fc-forma-highlight: color-mix(in srgb, var(--link-color) 35%, transparent);+}