|
4 | 4 | [](https://www.npmjs.com/package/@angularui/theme)
|
5 | 5 | [](https://opensource.org/licenses/MIT)
|
6 | 6 |
|
7 |
| -> **Modern Theme Management for Angular** - A lightweight, feature-rich theme library with automatic dark mode detection, SSR support, and zero configuration required. |
| 7 | +Modern Theme Management for Angular - A lightweight, feature-rich theme library with automatic dark mode detection, SSR support, and zero configuration required. |
8 | 8 |
|
9 | 9 | **🌐 [Live Demo](https://angularcafe.github.io/angularui-theme/)**
|
10 | 10 |
|
@@ -97,27 +97,24 @@ body {
|
97 | 97 | }
|
98 | 98 | ```
|
99 | 99 |
|
100 |
| -## 🎯 Why @angularui/theme? |
101 |
| - |
102 |
| -### For Angular Developers |
103 |
| - |
104 |
| -- **Native Angular Integration** - Built specifically for Angular with signals, dependency injection, and modern patterns |
105 |
| -- **TypeScript First** - Full type safety with comprehensive TypeScript support |
106 |
| -- **Angular 20+ Ready** - Uses latest Angular features like signals and standalone components |
107 |
| -- **Modern DI Pattern** - Uses Angular's inject() function for better performance and tree-shaking |
108 |
| -- **Future-Proof** - Built with Angular's latest patterns and best practices |
109 |
| -- **Enterprise Ready** - Designed for large-scale applications with proper error handling |
110 |
| -- **Clean Architecture** - Uses app initializer for testable, flexible initialization |
| 100 | +### How to Prevent Theme Flash (FOUC) with an Inline Script |
| 101 | +Add this **inline** script to your `index.html` `<head>`: |
| 102 | +```html |
| 103 | +<script> |
| 104 | +(function(){'use strict';try{var t=localStorage.getItem('theme')||'system',e=t==='system'?window.matchMedia('(prefers-color-scheme: dark)').matches?'dark':'light':t==='light'||t==='dark'?t:'light',n=document.documentElement;if(n){n.classList.remove('light','dark'),e==='dark'?(n.classList.add('dark'),n.setAttribute('data-theme','dark')):(n.classList.remove('dark'),n.removeAttribute('data-theme')),n.style.colorScheme=e}}catch(e){try{var n=document.documentElement;n&&(n.classList.remove('light','dark'),n.removeAttribute('data-theme'),n.style.colorScheme='light')}catch(e){}}})(); |
| 105 | +</script> |
| 106 | +``` |
| 107 | +**Why inline?** Angular does not provide a way to inject scripts into the HTML `<head>` at build time. For true FOUC prevention, the script must run immediately as the HTML is parsed—before any content is rendered. External scripts or Angular providers/services run too late to prevent a flash. This is why the script must be copied directly into your `index.html` head. |
111 | 108 |
|
112 |
| -### Benefits for Angular Ecosystem |
| 109 | +## Why @angularui/theme? |
113 | 110 |
|
114 |
| -- **Consistent Theming** - Standardized approach across Angular applications |
115 |
| -- **Developer Experience** - Excellent IDE support with full autocomplete |
116 |
| -- **Performance** - Leverages Angular's signal system for optimal reactivity |
117 |
| -- **Maintainability** - Clean, well-documented API following Angular conventions |
118 |
| -- **Community** - Contributes to Angular's rich ecosystem of tools |
119 |
| -- **Reduced Bundle Size** - Tree-shakeable and optimized for production |
120 |
| -- **Better Testing** - App initializer pattern enables easier unit testing |
| 111 | +- Native Angular integration: signals, DI, and standalone components |
| 112 | +- TypeScript-first and future-proof (Angular 20+ ready) |
| 113 | +- Clean, testable architecture (app initializer pattern) |
| 114 | +- Consistent, standardized theming across apps |
| 115 | +- Excellent developer experience (autocomplete, IDE support) |
| 116 | +- Performance optimized and tree-shakeable |
| 117 | +- Well-documented, maintainable, and enterprise-ready |
121 | 118 |
|
122 | 119 | ## 🏗️ Modern Architecture
|
123 | 120 |
|
@@ -167,33 +164,28 @@ interface ThemeConfig {
|
167 | 164 | #### Tailwind CSS Integration
|
168 | 165 | ```typescript
|
169 | 166 | provideUiTheme({
|
170 |
| - strategy: 'class', |
171 |
| - defaultTheme: 'system', |
172 |
| - enableColorScheme: true |
| 167 | + strategy: 'class' |
173 | 168 | })
|
174 | 169 | ```
|
175 | 170 |
|
176 | 171 | #### Custom Storage Key
|
177 | 172 | ```typescript
|
178 | 173 | provideUiTheme({
|
179 |
| - storageKey: 'my-app-theme', |
180 |
| - defaultTheme: 'dark' |
| 174 | + storageKey: 'my-app-theme' |
181 | 175 | })
|
182 | 176 | ```
|
183 | 177 |
|
184 | 178 | #### Disable System Detection
|
185 | 179 | ```typescript
|
186 | 180 | provideUiTheme({
|
187 |
| - enableSystem: false, |
188 |
| - defaultTheme: 'light' |
| 181 | + enableSystem: false |
189 | 182 | })
|
190 | 183 | ```
|
191 | 184 |
|
192 | 185 | #### Forced Theme (for demos)
|
193 | 186 | ```typescript
|
194 | 187 | provideUiTheme({
|
195 |
| - forcedTheme: 'dark', |
196 |
| - enableAutoInit: true |
| 188 | + forcedTheme: 'dark' |
197 | 189 | })
|
198 | 190 | ```
|
199 | 191 |
|
@@ -405,23 +397,14 @@ effect(() => {
|
405 | 397 |
|
406 | 398 | ## 🤝 Contributing
|
407 | 399 |
|
408 |
| -We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details. |
| 400 | +Contributions are welcome! To contribute: |
409 | 401 |
|
410 |
| -### Development |
| 402 | +1. **Fork** this repository. |
| 403 | +2. **Create a new branch** for your feature or fix. |
| 404 | +3. **Make your changes** and ensure all tests pass. |
| 405 | +4. **Open a Pull Request** with a clear description of your changes. |
411 | 406 |
|
412 |
| -```bash |
413 |
| -# Clone the repository |
414 |
| -git clone https://github.com/angularcafe/angularui-theme.git |
415 |
| - |
416 |
| -# Install dependencies |
417 |
| -npm install |
418 |
| - |
419 |
| -# Run tests |
420 |
| -npm test |
421 |
| - |
422 |
| -# Build the package |
423 |
| -npm run build |
424 |
| -``` |
| 407 | +Please review our [Contributing Guide](CONTRIBUTING.md) before submitting your PR. |
425 | 408 |
|
426 | 409 | ## 📄 License
|
427 | 410 |
|
|
0 commit comments