@casoon/dragonfly
Version:
Modular, lightweight CSS framework and design system for modern web projects. Optimized for Astro JS, LightningCSS and Container Queries with @layer-based architecture and comprehensive accessibility.
220 lines (180 loc) ⢠6.99 kB
Markdown
# Themes System
Modern, performant theme system for the Dragonfly UI library.
## šļø **Architecture**
### **Layer Structure**
```css
@layer tokens, themes.aliases, themes.mode, themes.transitions, themes.variants;
```
1. **`tokens`** - Base design tokens (@property definitions)
2. **`themes.aliases`** - Semantic component aliases
3. **`themes.mode`** - Light/dark mode definitions
4. **`themes.transitions`** - Theme transitions
5. **`themes.variants`** - Opt-in theme variants
### **Directory Structure**
```
themes/
āāā index.css # Main entry point
āāā aliases.css # Semantic aliases
āāā theme-transitions.css # Theme transitions
āāā light-mode.css # Light mode
āāā dark-mode.css # Dark mode
āāā theme-helper.js # JavaScript theme loader
āāā theme-switcher.html # Test/demo interface
āāā variants/ # Theme variants (opt-in)
āāā autumn.css # Autumn theme
āāā brand.css # Corporate brand
āāā day.css # Bright day
āāā forest.css # Forest theme
āāā monochrome.css # Black & white
āāā neon.css # Neon colors
āāā night.css # Dark night
āāā ocean.css # Ocean theme
āāā pastel.css # Pastel tones
āāā retro.css # Retro style
āāā spring.css # Spring theme
āāā summer.css # Summer theme
āāā sunset.css # Sunset colors
āāā winter.css # Winter theme
```
## šØ **Theme Activation**
### **Data-Theme System**
All themes use the unified `data-theme` attribute:
```html
<!-- Light/Dark Modes -->
<html data-theme="light">
<html data-theme="dark">
<html data-theme="auto">
<!-- Theme Variants -->
<html data-theme="autumn">
<html data-theme="ocean">
<html data-theme="forest">
<html data-theme="day">
<html data-theme="night">
```
### **JavaScript API**
```javascript
// Load theme variant
ThemeHelper.loadThemeVariant('autumn');
// Switch mode
document.documentElement.dataset.theme = 'dark';
// Auto-detection
ThemeHelper.loadThemeVariant('auto');
```
## š¦ **Integration**
### **Base System (always loaded)**
```css
@import url("path/to/themes/index.css");
```
Includes: Design tokens, aliases, light/dark modes, transitions
### **Theme Variants (opt-in)**
```css
/* Static */
@import url("path/to/themes/variants/autumn.css");
/* Dynamic */
<script>
ThemeHelper.loadThemeVariant('autumn');
</script>
```
### **CDN Compatible**
```html
<link rel="stylesheet" href="https://cdn.example.com/dragonfly/themes/index.css">
<script>
// Dynamic loading of variants
ThemeHelper.loadThemeVariant('ocean');
</script>
```
## š§ **Development**
### **Creating New Theme Variants**
All theme variants follow the unified structure based on `tokens/colors.css`:
```css
/**
* Custom Theme Variant
*
* Standalone theme variant that can be loaded independently.
* Uses [data-theme="custom"] scope for activation.
* CDN-compatible and opt-in via import or JS.
*
* @layer themes.variants
*/
@layer themes.variants {
[data-theme="custom"] {
/* Primary Colors */
--color-primary: #your-primary;
--color-secondary: #your-secondary;
/* Status Colors */
--color-success: #10b981;
--color-warning: #f59e0b;
--color-error: #ef4444;
--color-info: #06b6d4;
/* Text Colors */
--color-text: #your-text;
--color-text-muted: #4b5563;
--color-text-inverse: #ffffff;
/* Surface Colors */
--color-background: #your-background;
--color-surface: #your-surface;
--color-surface-elevated: #ffffff;
/* Border Colors */
--color-border: #your-border;
--color-border-strong: #your-border-strong;
/* Transition Colors for smooth animations */
--color-transition-primary: #your-primary;
--color-transition-surface: #your-background;
--color-transition-text: #your-text;
}
}
```
### **Using Semantic Aliases**
```css
.my-component {
background: var(--surface-bg); /* ā
Semantic */
color: var(--text-primary); /* ā
Semantic */
border: 1px solid var(--border); /* ā
Semantic */
/* Instead of direct token references */
background: var(--color-gray-50); /* ā Direct */
}
```
## š **Performance**
- **Base System**: ~25KB (compressed) - contains all essential features
- **Theme Variants**: ~1-2KB per variant (opt-in, unified structure)
- **CSS Layers**: Optimal specificity without !important
- **@property**: Better browser performance and tooling
- **Unified**: All 14 variants follow the same structure
## šÆ **Features**
- ā
**Framework-agnostic** - Works with any CSS framework
- ā
**CDN-compatible** - Can be loaded from CDN
- ā
**Opt-in variants** - Only load what you need
- ā
**Unified structure** - All variants based on `tokens/colors.css`
- ā
**TypeScript support** - @property definitions for better DX
- ā
**Dark mode** - Automatic and manual
- ā
**Transitions** - Smooth theme transitions
- ā
**localStorage** - Persistent theme selection
- ā
**SSR-compatible** - Server-side rendering support
## š **Available Themes**
All theme variants use the unified `data-theme` system:
| Theme | Description | Primary Colors | Use Case |
|-------|-------------|----------------|----------|
| `light` | Standard Light Mode | Neutral grays | Default light mode |
| `dark` | Standard Dark Mode | Dark grays | Default dark mode |
| `auto` | System Preference | Automatic | Follows OS setting |
| `brand` | Corporate Brand | Indigo (#4f46e5) | Company branding |
| `day` | Bright Day | Bright Blue (#2563eb) | Very bright day view |
| `night` | Dark Night | Purple/Indigo (#6366f1) | Very dark night view |
| `autumn` | Autumn Tones | Amber (#d97706) | Warm autumn colors |
| `winter` | Winter Tones | Cyan (#0891b2) | Cool winter colors |
| `spring` | Spring Tones | Green (#16a34a) | Fresh spring colors |
| `summer` | Summer Tones | Yellow (#ca8a04) | Bright summer colors |
| `ocean` | Ocean Tones | Teal (#0891b2) | Ocean colors |
| `forest` | Forest Tones | Green (#059669) | Forest colors |
| `sunset` | Sunset Colors | Orange (#ea580c) | Sunset colors |
| `retro` | Retro Style | Brown (#a16207) | Vintage tones |
| `monochrome` | Black & White | Gray (#374151) | Grayscale only |
| `pastel` | Pastel Tones | Purple (#8b5cf6) | Soft pastel colors |
| `neon` | Neon Colors | Bright Purple (#a855f7) | Bright neon colors |
## š **Testing**
Open `theme-switcher.html` in your browser for interactive testing of all themes and features.
## š **Recent Updates**
- **Unification**: All 14 theme variants now use the same structure
- **Flat hierarchy**: `mode/` and `base/` directories resolved
- **Consistent activation**: All themes use `data-theme` attribute
- **Based on tokens/colors.css**: Full compatibility with design token system