UNPKG

@rxap/ngx-theme

Version:

This package provides an Angular theme service that allows you to manage and customize the look and feel of your application. It includes features such as dark mode support, theme density control, typography settings, and color palette management. The ser

93 lines (79 loc) 14.7 kB
<!DOCTYPE html><html class="default" lang="en" data-base="."><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>@rxap/ngx-theme - v19.1.1</title><meta name="description" content="Documentation for @rxap/ngx-theme"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script defer src="assets/main.js"></script><script async src="assets/icons.js" id="tsd-icons-script"></script><script async src="assets/search.js" id="tsd-search-script"></script><script async src="assets/navigation.js" id="tsd-nav-script"></script><script async src="assets/hierarchy.js" id="tsd-hierarchy-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search"><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">@rxap/ngx-theme - v19.1.1</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><h1>@rxap/ngx-theme - v19.1.1</h1></div><div class="tsd-panel tsd-typography"><p>This package provides an Angular theme service that allows you to manage and customize the look and feel of your application. It includes features such as dark mode support, theme density control, typography settings, and color palette management. The service also provides utilities for computing color palettes and observing theme density changes.</p> <p><a href="https://www.npmjs.com/package/@rxap/ngx-theme"><img src="https://img.shields.io/npm/v/@rxap/ngx-theme?style=flat-square" alt="npm version"></a> <a href="https://commitizen.github.io/cz-cli/"><img src="https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square" alt="commitizen friendly"></a> <a href="https://github.com/prettier/prettier"><img src="https://img.shields.io/badge/styled_with-prettier-ff69b4.svg?style=flat-square" alt="styled with prettier"></a> <img src="https://img.shields.io/librariesio/release/npm/@rxap/ngx-theme" alt="Libraries.io dependency status for latest release, scoped npm package"> <img src="https://img.shields.io/npm/dm/@rxap/ngx-theme" alt="npm"> <img src="https://img.shields.io/npm/l/@rxap/ngx-theme" alt="NPM"></p> <ul> <li><a href="#installation">Installation</a></li> <li><a href="#guides">Guides</a></li> <li><a href="#generators">Generators</a> <ul> <li><a href="#init">init</a></li> </ul> </li> </ul> <a id="installation" class="tsd-anchor"></a><h1 class="tsd-anchor-link">Installation<a href="#installation" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1><p><strong>Add the package to your workspace:</strong></p> <pre><code class="bash"><span class="hl-0">yarn</span><span class="hl-1"> </span><span class="hl-2">add</span><span class="hl-1"> </span><span class="hl-2">@rxap/ngx-theme</span> </code><button type="button">Copy</button></pre> <p><strong>Install peer dependencies:</strong></p> <pre><code class="bash"><span class="hl-0">yarn</span><span class="hl-1"> </span><span class="hl-2">add</span><span class="hl-1"> </span><span class="hl-2">@angular/cdk</span><span class="hl-1"> </span><span class="hl-2">@angular/core</span><span class="hl-1"> </span><span class="hl-2">@rxap/config</span><span class="hl-1"> </span><span class="hl-2">@rxap/ngx-pub-sub</span><span class="hl-1"> </span><span class="hl-2">@rxap/rxjs</span><span class="hl-1"> </span><span class="hl-2">@rxap/utilities</span><span class="hl-1"> </span><span class="hl-2">rxjs</span><span class="hl-1"> </span> </code><button type="button">Copy</button></pre> <p><strong>Execute the init generator:</strong></p> <pre><code class="bash"><span class="hl-0">yarn</span><span class="hl-1"> </span><span class="hl-2">nx</span><span class="hl-1"> </span><span class="hl-2">g</span><span class="hl-1"> </span><span class="hl-2">@rxap/ngx-theme:init</span> </code><button type="button">Copy</button></pre> <a id="guides" class="tsd-anchor"></a><h1 class="tsd-anchor-link">Guides<a href="#guides" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1><a id="dark-and-light-mode-with-tailwind-and-angular-material-3" class="tsd-anchor"></a><h1 class="tsd-anchor-link">Dark and Light mode with tailwind and angular material 3<a href="#dark-and-light-mode-with-tailwind-and-angular-material-3" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1><p>This guide provides the setup steps for configuring Tailwind CSS and Angular Material for the light/dark/system theme switching mechanism, using the approaches we discussed previously.</p> <a id="1-configure-tailwind-with-the-variant-strategy" class="tsd-anchor"></a><h2 class="tsd-anchor-link">1. Configure Tailwind with the Variant Strategy<a href="#1-configure-tailwind-with-the-variant-strategy" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>Update your tailwind.config.js to use the variant strategy. This allows Tailwind to react to both the system preference (prefers-color-scheme) and specific classes (.light, .dark) for manual overrides.</p> <pre><code class="js"><span class="hl-3">// tailwind.config.js</span><br/><span class="hl-3">/** </span><span class="hl-4">@type</span><span class="hl-3"> </span><span class="hl-5">{import(&#39;tailwindcss&#39;).Config}</span><span class="hl-3"> */</span><br/><span class="hl-5">module</span><span class="hl-1">.</span><span class="hl-5">exports</span><span class="hl-1"> = {</span><br/><span class="hl-1"> </span><span class="hl-3">// ... other configurations</span><br/><span class="hl-1"> </span><span class="hl-6">darkMode:</span><span class="hl-1"> </span><span class="hl-2">&#39;selector&#39;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-6">theme:</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-6">extend:</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">// ... your theme extensions</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> </span><span class="hl-6">plugins:</span><span class="hl-1"> [],</span><br/><span class="hl-1"> </span><span class="hl-3">// ...</span><br/><span class="hl-1">};</span> </code><button type="button">Copy</button></pre> <p>This configuration tells Tailwind to apply dark: variants if EITHER the system preference is dark (and not overridden by .light) OR if the .dark class is explicitly set on an ancestor element.</p> <a id="2-integrate-with-angular-material-modern-mdc-approach" class="tsd-anchor"></a><h2 class="tsd-anchor-link">2. Integrate with Angular Material (Modern MDC Approach)<a href="#2-integrate-with-angular-material-modern-mdc-approach" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>Use the modern Angular Material Sass API (mat.theme) to define your theme once and emit CSS variables. Then, use CSS to control the color-scheme property based on the .light and .dark classes applied by the ThemeService. Material components will react automatically to the computed color-scheme.</p> <pre><code class="scss">@use '@angular/material' as mat; html { @include mat.theme(( color: mat.$violet-palette, typography: Roboto, density: 0 )); } // --- Tailwind Integration --- @tailwind base; @tailwind components; @tailwind utilities; // --- Color Scheme Control & Base Styles --- html { // Setting on html or :root is fine // Default: Let the browser choose light/dark based on system preference. // Material components & Tailwind's media query variant will react to this. color-scheme: light dark; // Apply base background/text colors (Tailwind handles dark via variants). // Add transitions for smoother switching. @apply bg-white text-gray-800 transition-colors duration-200 ease-in-out; } // Force light mode when .light class is present on an ancestor (e.g., body) // Use :where to keep specificity low, preventing conflicts. :where(html.light, body.light, .light) { color-scheme: light; // Ensure light background/text if overriding system dark mode @apply bg-white text-gray-800; } // Force dark mode when .dark class is present on an ancestor (e.g., body) // Use :where to keep specificity low. :where(html.dark, body.dark, .dark) { color-scheme: dark; // Apply dark background/text (complements Tailwind's dark: variants) @apply bg-gray-900 text-gray-200; } // Other global styles can go here body { // Ensure body takes full height if needed, etc. @apply min-h-screen m-0; // Added margin reset } </code><button type="button">Copy</button></pre> <p>This setup provides the configuration for Tailwind and the recommended SCSS structure for Angular Material theming that integrates with the ThemeService managing the .light and .dark classes.</p> <a id="generators" class="tsd-anchor"></a><h1 class="tsd-anchor-link">Generators<a href="#generators" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1><a id="init" class="tsd-anchor"></a><h2 class="tsd-anchor-link">init<a href="#init" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><blockquote> <p>Initialize the package in the workspace</p> </blockquote> <pre><code class="bash"><span class="hl-0">nx</span><span class="hl-1"> </span><span class="hl-2">g</span><span class="hl-1"> </span><span class="hl-2">@rxap/ngx-theme:init</span> </code><button type="button">Copy</button></pre> </div></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#installation"><span>Installation</span></a><a href="#guides"><span>Guides</span></a><a href="#dark-and-light-mode-with-tailwind-and-angular-material-3"><span>Dark and <wbr/>Light mode with tailwind and angular material 3</span></a><ul><li><a href="#1-configure-tailwind-with-the-variant-strategy"><span>1. <wbr/>Configure <wbr/>Tailwind with the <wbr/>Variant <wbr/>Strategy</span></a></li><li><a href="#2-integrate-with-angular-material-modern-mdc-approach"><span>2. <wbr/>Integrate with <wbr/>Angular <wbr/>Material (<wbr/>Modern MDC <wbr/>Approach)</span></a></li></ul><a href="#generators"><span>Generators</span></a><ul><li><a href="#init"><span>init</span></a></li></ul></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="modules.html">@rxap/ngx-theme - v19.1.1</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>