Theme System
Theme management system providing theme context, CSS variables, and theme switching functionality.
Table of Contents
- Overview
- ThemeProvider
- ThemeContext
- Generated Resources
- CSS Variables System
- Theme Switching
- Style Customization
- API Reference
Overview
hikari-theme provides a complete theme management solution:
- ThemeProvider - Theme context provider component
- ThemeContext - Theme configuration and color definitions
- Generated - Auto-generated CSS variables and resources
- CSS Variables - Dynamic theme variable system
- Theme Switching - Runtime theme switching support
All theme components feature:
- Type Safe - Compile-time theme identifier checking
- Responsive - Automatically adapts to different themes
- Extensible - Supports custom themes
ThemeProvider
Provides theme context for the entire application.
Basic Usage
rust
1
2
3
4
5
6
7
8
use ThemeProvider;
rsx!
}
Theme Switching
rust
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
}
Props
| Property | Type | Default | Description |
|---|---|---|---|
| palette | String | "hikari" | Theme identifier |
| children | Element | - | Child elements |
Supported Themes
- hikari - Light theme
- tairitsu - Dark theme
ThemeContext
Data structure containing theme configuration and color definitions.
Structure Definition
rust
1
2
3
4
Field Descriptions
- palette - Theme identifier string
- colors - Theme palette configuration (from hikari-palette)
Default Values
rust
1
2
3
4
5
6
7
8
Generated Resources
Auto-generated static resources and CSS variables.
Tailwind CSS
rust
1
2
3
4
use tailwind;
// Access generated Tailwind CSS classes
let tailwind_classes = TAILWIND_CLASSES;
Generated Content
The generated/mod.rs module contains:
- tailwind - Tailwind CSS generated class names and variables
- components - Component style constants (generated by builder)
File Locations
mermaid
CSS Variables System
The theme system uses CSS variables for dynamic theme switching.
Root Variables
Defined under :root or [data-theme]:
css
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
}
}
Using CSS Variables
Use in component styles:
rust
1
2
3
4
5
6
rsx!
Or in SCSS:
scss
1
2
3
4
5
.my-component {
color: var(--hi-color-primary);
background-color: var(--hi-color-surface);
border: 1px solid var(--hi-color-border);
}
Complete Variable List
Color Variables
css
1
2
3
4
5
6
7
8
9
10
11
--/* Primary color */
--/* Secondary color */
--/* Accent color */
--/* Success color */
--/* Warning color */
--/* Danger color */
--/* Background color */
--/* Surface color */
--/* Border color */
--/* Primary text color */
--/* Secondary text color */
Typography Variables
css
1
2
3
4
5
6
7
8
9
--/* Sans-serif font */
--/* Monospace font */
--/* 12px */
--/* 14px */
--/* 16px */
--/* 18px */
--/* 20px */
--/* 24px */
--/* 30px */
Spacing Variables
css
1
2
3
4
5
6
--/* 4px */
--/* 8px */
--/* 16px */
--/* 24px */
--/* 32px */
--/* 48px */
Radius Variables
css
1
2
3
4
5
--/* 4px */
--/* 8px */
--/* 12px */
--/* 16px */
--/* 9999px */
Shadow Variables
css
1
2
3
4
--/* Small shadow */
--/* Medium shadow */
--/* Large shadow */
--/* Extra large shadow */
Transition Variables
css
1
2
3
--/* 150ms */
--/* 200ms */
--/* 300ms */
Theme Switching
Runtime Switching
rust
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
}
Persistent Theme
rust
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use LocalStorage;
}
System Theme Detection
rust
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use window;
}
Style Customization
Theme Variable Override
css
1
2
3
4
5
/* Override theme variables in global styles */
}
Component-level Theme
rust
1
2
3
4
5
6
7
8
rsx!
Custom Theme Variables
css
1
2
3
4
5
6
}
Best Practices
1. Theme Provider Placement
rust
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Good: Place ThemeProvider at application root
}
// Avoid: Nesting multiple ThemeProviders
}
}
2. Theme Switching Animation
css
1
2
3
4
5
6
/* Add smooth theme switching transition */
}
3. Conditional Styling
rust
1
2
3
4
5
6
7
8
9
10
rsx!
4. CSS Variable Fallback
css
1
2
3
4
5
/* Provide fallback for browsers that don't support CSS variables */
}
API Reference
ThemeProvider
rust
1
2
3
4
5
ThemeContext
rust
1
2
3
4
5
6
7
8
Integration with Other Systems
Integration with Palette
rust
1
2
3
4
use ;
let hikari_palette = palette;
println!;
Integration with Animation
rust
1
2
3
4
5
6
7
use AnimationBuilder;
use ThemeProvider;
// Theme variables can be used in animations
new
.add_style
.apply_with_transition;
Integration with Components
All components automatically inherit the theme provided by ThemeProvider:
rust
1
2
3
4
5
6
7
8
rsx!
}
Design Philosophy
Style
- Light theme (hikari):
- Primary: Pink (#FFB3A7)
- Background: White
- Text: Dark
- Dark theme (tairitsu):
- Primary: Duck Blue (#144A74)
- Background: Dark
- Text: Light
Elements
- Subtle glow effects
- Dynamic indicators (breathing lights)
- Fine borders
Responsive
- Mobile-first
- Adaptive layouts
- Breakpoint system
Related Systems
- Palette System - Color definitions and theme palettes
- Animation System - Animation and theme integration
- Components - Component library using themes