UNPKG

@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
# 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