forceCalendar
Interface Package

Theming

CSS custom property theming system with full variable reference.

Overview

forceCalendar uses CSS custom properties (CSS variables) for theming. All variables use the --fc- prefix. Because components use Shadow DOM, theme variables must be set on the host element or inherited from a parent.

forcecal-main {
  --fc-primary: #1a73e8;
  --fc-bg: #ffffff;
  --fc-text: #202124;
  --fc-font-family: 'Inter', sans-serif;
}

StyleUtils

The StyleUtils class provides programmatic access to the theming system.

import { StyleUtils } from '@forcecalendar/interface';

setCSSVariables(element, variables)

Set multiple CSS variables on an element.

StyleUtils.setCSSVariables(calendarEl, {
  '--fc-primary': '#1a73e8',
  '--fc-bg': '#1e1e1e',
  '--fc-text': '#e0e0e0',
});

getCSSVariable(element, name)

Read a CSS variable value.

const primary = StyleUtils.getCSSVariable(calendarEl, '--fc-primary');

Color Utilities

StyleUtils.darken('#4285f4', 0.2);     // Darken by 20%
StyleUtils.lighten('#4285f4', 0.2);    // Lighten by 20%
StyleUtils.getContrastColor('#4285f4'); // Returns '#ffffff' or '#000000'
StyleUtils.hexToRgba('#4285f4', 0.5);  // 'rgba(66, 133, 244, 0.5)'

sanitizeColor(value)

Validates and sanitizes a CSS color value to prevent CSS injection. Strips anything that could be used for injection (e.g., url(), expression()).

StyleUtils.sanitizeColor('#4285f4');                    // '#4285f4'
StyleUtils.sanitizeColor('url(evil)');                  // '' (rejected)
StyleUtils.sanitizeColor('red; background: url(evil)'); // '' (rejected)

CSS Variable Reference

Colors

VariableDefaultDescription
--fc-primary#4285f4Primary accent color
--fc-primary-hover#3367d6Primary hover state
--fc-primary-light#e8f0feLight primary for backgrounds
--fc-bg#ffffffMain background
--fc-bg-secondary#f8f9faSecondary background
--fc-bg-hover#f1f3f4Hover background
--fc-bg-selected#e8f0feSelected item background
--fc-text#202124Primary text color
--fc-text-secondary#5f6368Secondary text
--fc-text-disabled#80868bDisabled text
--fc-text-on-primary#ffffffText on primary color
--fc-border#dadce0Border color
--fc-border-light#e8eaedLight border
--fc-today-bg#e8f0feToday highlight background
--fc-today-text#1a73e8Today text color
--fc-weekend-bg#f8f9faWeekend column background
--fc-event-default-bg#4285f4Default event background
--fc-event-default-text#ffffffDefault event text
--fc-event-default-border#3367d6Default event border

Typography

VariableDefaultDescription
--fc-font-familysystem-ui, sans-serifFont family
--fc-font-size-sm0.75remSmall text
--fc-font-size-base0.875remBase text
--fc-font-size-lg1remLarge text
--fc-font-size-xl1.25remExtra large
--fc-font-weight-normal400Normal weight
--fc-font-weight-medium500Medium weight
--fc-font-weight-bold600Bold weight
--fc-line-height1.5Line height

Spacing

VariableDefaultDescription
--fc-spacing-xs0.25remExtra small
--fc-spacing-sm0.5remSmall
--fc-spacing-md0.75remMedium
--fc-spacing-lg1remLarge
--fc-spacing-xl1.5remExtra large

Borders

VariableDefaultDescription
--fc-border-radius4pxStandard radius
--fc-border-radius-lg8pxLarge radius
--fc-border-width1pxBorder width

Shadows

VariableDefaultDescription
--fc-shadow-sm0 1px 2px rgba(0,0,0,0.1)Small shadow
--fc-shadow-md0 2px 4px rgba(0,0,0,0.12)Medium shadow
--fc-shadow-lg0 4px 8px rgba(0,0,0,0.15)Large shadow

Transitions

VariableDefaultDescription
--fc-transition-fast0.1s easeFast transition
--fc-transition-normal0.2s easeNormal transition
--fc-transition-slow0.3s easeSlow transition

Z-Index

VariableDefaultDescription
--fc-z-base1Base layer
--fc-z-dropdown100Dropdowns
--fc-z-modal200Modals
--fc-z-tooltip300Tooltips

Dark Mode Example

forcecal-main.dark {
  --fc-bg: #1e1e1e;
  --fc-bg-secondary: #2d2d2d;
  --fc-bg-hover: #3d3d3d;
  --fc-bg-selected: #1a3a5c;
  --fc-text: #e0e0e0;
  --fc-text-secondary: #a0a0a0;
  --fc-text-disabled: #666666;
  --fc-border: #404040;
  --fc-border-light: #333333;
  --fc-today-bg: #1a3a5c;
  --fc-today-text: #64b5f6;
  --fc-weekend-bg: #252525;
  --fc-shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --fc-shadow-md: 0 2px 4px rgba(0,0,0,0.4);
}

Responsive Design

@media (max-width: 768px) {
  forcecal-main {
    --fc-font-size-base: 0.75rem;
    --fc-spacing-md: 0.5rem;
    --fc-spacing-lg: 0.75rem;
  }
}

Style Functions

StyleUtils also provides functions for generating base styles used by components:

FunctionDescription
getBaseStyles()Core layout and typography styles
getButtonStyles()Button component styles
getGridStyles()Month/week/day grid styles
getAnimations()Keyframe animation definitions
mediaQuery(breakpoint)Generate responsive media queries