Base CSS Variables for Web Components
Pure Admin exports --base-* CSS custom properties that enable automatic theming for web components
like web-daterangepicker, web-multiselect, and others.
Purpose: Web components consume these variables via fallback chains, automatically inheriting
the current Pure Admin theme colors without any manual configuration.
How It Works
Architecture
- Pure Admin defines SCSS variables -
$base-*variables in_variables.scss - Themes override as needed - Each theme can customize these base variables
- Mixin outputs CSS properties -
_base-css-variables.scssconverts SCSS to CSS - Web components consume - Components use
var(--base-*, fallback)
Data Flow
_variables.scss themes/express.scss Output CSS
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโ
$base-accent-color: $base-accent-color: :root {
#3b82f6 !default; โ #dc2626; โ --base-accent-color: #dc2626;
@include output-base-vars; ...
}
Web Component Consumption
/* In web component CSS */
:host {
--ms-accent-color: var(--base-accent-color, #3b82f6);
--ms-text-color: var(--base-text-color-1, #333);
--ms-input-bg: var(--base-input-background, #fff);
}
Variable Reference
| Category | Count | Variables |
|---|---|---|
| Colors | 11 |
--base-accent-color,
--base-accent-color-hover,
--base-accent-color-active,
--base-primary-bg,
--base-primary-bg-hover,
--base-text-color-1 to --base-text-color-4,
--base-text-on-accent,
--base-border-color
|
| Input Fields | 7 |
--base-input-background,
--base-input-color,
--base-input-border,
--base-input-border-hover,
--base-input-border-focus,
--base-input-placeholder-color,
--base-input-background-disabled
|
| Input Sizes | 5 |
--base-input-size-xs-height (3.1),
--base-input-size-sm-height (3.3),
--base-input-size-md-height (3.5),
--base-input-size-lg-height (3.8),
--base-input-size-xl-height (4.1)
Unitless multipliers for 10px base |
| Dropdown | 3 |
--base-dropdown-background,
--base-dropdown-border,
--base-dropdown-box-shadow
|
| Tooltip | 2 |
--base-tooltip-background,
--base-tooltip-text-color
|
| Typography | 14 |
--base-font-family,
--base-font-size-2xs to --base-font-size-2xl (unitless),
--base-font-weight-normal,
--base-font-weight-medium,
--base-font-weight-semibold,
--base-line-height-tight,
--base-line-height-normal,
--base-line-height-relaxed
|
| Border Radius | 3 |
--base-border-radius-sm (0.4),
--base-border-radius-md (0.6),
--base-border-radius-lg (0.8)
Unitless multipliers for 10px base |
| Total | 45 |
Current Theme Values
These are the --base-* CSS variable values from the currently selected theme:
Colors
--base-accent-color
--base-accent-color-hover
--base-primary-bg
--base-border-color
Text Colors
--base-text-color-1
--base-text-color-2
--base-text-color-3
--base-text-color-4
Input Fields
--base-input-background
--base-dropdown-background
--base-tooltip-background
Typography
--base-font-size-2xs (1.0)
--base-font-size-xs (1.2)
--base-font-size-sm (1.4)
--base-font-size-base (1.6)
--base-font-size-lg (1.8)
Theme Implementation Pattern
Each theme follows this pattern to output base CSS variables:
// themes/express.scss
@import '../variables';
// Override accent color for theme
$accent-color: $express-red;
// Sync base variables with theme colors
$base-accent-color: $accent-color;
$base-accent-color-hover: $express-red-hover;
$base-accent-color-active: lighten($express-red, 15%);
// ... other theme overrides ...
@import '../core';
@import '../utilities';
@import '../base-css-variables';
// Output CSS variables in :root block
:root {
--page-loader-bg: rgba(0, 0, 0, 0.95);
--page-loader-spinner-border: #333;
--page-loader-spinner-accent: #FFCC00;
// Base CSS variables for web components
@include output-base-css-variables;
}
Files Reference
| File | Purpose |
|---|---|
src/scss/_variables.scss |
Contains 45 $base-* SCSS variables with !default flags |
src/scss/_base-css-variables.scss |
Mixin output-base-css-variables that outputs all CSS custom properties |
src/scss/themes/*.scss |
Each theme imports the mixin and includes it in :root |
docs/BASE_VARIABLES_INTEGRATION_PLAN.md |
Complete implementation plan and architecture documentation |
Benefits
Automatic Theming
Web components inherit Pure Admin theme colors without configuration
Web components inherit Pure Admin theme colors without configuration
Single Source of Truth
Pure Admin defines the theme, components follow
Pure Admin defines the theme, components follow
No Manual Sync
Theme changes propagate automatically to all components
Theme changes propagate automatically to all components
9 Themes Supported
All themes export consistent
All themes export consistent
--base-* variables