npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

dynamic-theme-lib

v0.0.7

Published

A flexible and powerful theme management library for Angular applications that allows dynamic color management and theme switching.

Readme

Dynamic Theme Library for Angular

A flexible and powerful theme management library for Angular applications that allows dynamic color management and theme switching.

Features

  • Dynamic color management
  • Theme persistence using session storage
  • Fallback to default colors if configuration fails
  • Real-time theme updates
  • Support for background and text colors
  • Easy integration with Angular applications

Installation

npm install dynamic-theme-lib

Quick Start

  1. Import the module in your app.module.ts:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';
import { DynamicThemeLibModule } from 'dynamic-theme-lib';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    DynamicThemeLibModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
  1. Create a color configuration file at src/assets/colors/color-config.json:
{
  "primary-color": "#007bff",
  "secondary-color": "#6c757d",
  "background-color": "#ffffff",
  "text-color": "#212529"
}
  1. Set up your component to load the color configuration:
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ColourService } from 'dynamic-theme-lib';

interface ColorConfig {
  'primary-color': string;
  'secondary-color': string;
  'background-color': string;
  'text-color': string;
}

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
  title = 'dynamic-theme-app';
  colorConfig: ColorConfig = {} as ColorConfig;
  
  constructor(
    private http: HttpClient,
    private colourService: ColourService
  ) {}

  ngOnInit() {
    // Load colors from configuration file
    this.http.get<ColorConfig>('assets/colors/color-config.json').subscribe({
      next: (data) => {
        this.colorConfig = data;
        sessionStorage.setItem('colorConfig', JSON.stringify(data));
      },
      error: (error) => {
        console.error('Error loading color configuration:', error);
      }
    });
  }
}
  1. Use the directives in your template:
<div class="container">
  <h1 libTextColour="primary-color">{{ title }}</h1>
  
  <div class="theme-controls">
    <h2 libTextColour="secondary-color">Theme Demo</h2>
    <div libBackgroundColour="background-color" class="demo-section">
      <h3 libTextColour="text-color">Background Color Demo</h3>
      <p libTextColour="text-color">This section demonstrates the background and text color directives.</p>
    </div>
  </div>

  <div class="content">
    <div class="card" libBackgroundColour="background-color">
      <h3 libTextColour="primary-color">Sample Card</h3>
      <p libTextColour="text-color">This card uses the theme colors from the configuration.</p>
    </div>
  </div>
</div>
  1. Add some basic styles:
.container {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
}

.theme-controls {
  margin: 20px 0;
  padding: 20px;
  border: 1px solid #eee;
  border-radius: 4px;
}

.demo-section {
  margin-top: 20px;
  padding: 20px;
  border-radius: 4px;
  border: 1px solid #eee;
}

.card {
  padding: 20px;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  margin-top: 20px;
  border: 1px solid #eee;
}

API

Directives

  • [libBackgroundColour]: Apply background color to an element
  • [libTextColour]: Apply text color to an element

Service Methods

  • setColor(variableName: string, colorValue: string): Update a color value
  • getColor(variableName: string): Get a color value
  • getAllColors(): Get all color configurations
  • reloadColors(): Reload colors from configuration

Requirements

  • Angular 12 or higher (supports Angular 12.x, 13.x, 14.x, 15.x, 16.x, 17.x, 18.x, and 19.x)
  • @angular/common/http

Best Practices

  1. Color Configuration:

    • Store your color configuration in assets/colors/color-config.json
    • Use meaningful color variable names
    • Include fallback colors in your configuration
  2. Directive Usage:

    • Apply libBackgroundColour to container elements
    • Use libTextColour for text elements
    • Combine both directives for better visual hierarchy
  3. Error Handling:

    • Always handle potential errors when loading the color configuration
    • Provide fallback colors in case of loading failures
    • Use session storage for persistence during the session

License

MIT