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 🙏

© 2024 – Pkg Stats / Ryan Hefner

jss-theme-angular

v0.1.10

Published

JSS theming solution utils for Angular

Downloads

22

Readme

JSS Theme Angular

npm version GitHub license Size Downloads

Angular bindings for jss-theme package.

Deprecated

This package is deprecated for Angular version starting from 9. with Ivy enabled. Please refer to this section for new usage.

Demo & docs

Demo and docs could be found here.

Example in sandbox could be found here.

Notes

Include necessary typescript typings.

Update

As stated below both @NgStyled decorator and NgStyledComponent works bad w/ Ivy and aot mode.

To overcome this since version v1.1.1 it is intoduced ThemeProvide, UseStyles and createJssStyledComponent section.

Steps to easily migrate old projects:

// NgStyledComponent.ts
import { createJssStyledComponent, ThemeProvide } from 'jss-theme'
import { theme } from './path/to/your/app/theme';

const themeProvider = new ThemeProvide(theme);

const NgStyledComponent = createJssStyledComponent(themeProvider);

Then in your app just replace old NgStyledComponent with new:

// import { NgStyledComponent } from 'jss-theme-angular';
import { NgStyledComponent } from './path/to/your/app/NgStyledComponent';

@Component({ ... })
class SomeComponent extends NgStyledComponent {
  constructor() { super(styles); }
}

!!! NOTE is is also necessary to change invocations of updateTheme() from jss-theme package with themeProvider.updateTheme() in order for themeProvider track theme changes.

Another way is to use UseStyles decorator.

Important

This bindings correctly works w/ Angular 8 and 9 without Ivy.

In Ivy there were introduced breaking changes so that it is impossible to use as earlier custom decorators / extend classes. Here is an Issue.

Still it is possible to use this JSS Theming solution w/ Angular with Ivy, just doing manually that work, which is done under @NgStyled and NgStyledComponent.

Usage

@NgStyled(styles, options?, theme?)

Decorator for usage with Angular components. Internally creates property 'classes' and puts classNames for compiled styles into it and watches for theme updates.

NOTE! Because of --aot Angular compiler, it is necessary to at least implement those methods, which are used in custom decorator in Component. So for styles w/ theme ( aka: makeStyles((theme) => ({ ... })) ) in is necessary implement both ngOnInit and ngDoCheck. For styles which do not depend on theme -> only ngOnInit.

If one of necessary methods won't be provided -> it will throw an Error to prevent bugs in future.

OR! use NgStyledComponent.

Second optional argument provides default options for creating new stylesheets.

Third optional argument could be used to call this method on specific Theme instance:

import { Component, OnInit, DoCheck } from '@angular/core';
import { makeStyles, NgStyled, Theme, Classes } from 'jss-theme';

const SomeTheme = new Theme({ spacing: 1 });

const styles = makeStyles({
	className1: {
		display: 'flex',
		marginTop: 10,
	},
});

@Component({
	template: `<div [class]="classes.className1">Jss styled div</div>`,
	...
})
// @NgStyled(styles, null, Theme) // Specific Theme
@NgStyled(styles) // Default Theme
export class SomeComponent implements OnInit, DoCheck {
  public classes: Classes = { };

  public ngOnInit(): void {}

  public ngDoCheck(): void {}
}

NgStyledComponent

Class for usage with Angular components. Internally creates property 'classes' and puts classNames for compiled styles into it and watches for theme updates.

NOTE! Please be sure to set target: 'es2015' in your tsconfig.json in order to use NgStyledComponent because of Angular CLI changes.

Second optional argument provides default options for creating new stylesheets.

Third optional argument could be used to call this method on specific Theme instance:

import { Component } from '@angular/core';
import { makeStyles, NgStyledComponent, Theme } from 'jss-theme';

const SomeTheme = new Theme({ spacing: 1 });

const styles = makeStyles({
	className1: {
		display: 'flex',
		marginTop: 10,
	},
});

@Component({
	template: `<div [class]="classes.className1">Jss styled div</div>`,
	...
})
export class SomeComponent extends NgStyledComponent {
  public classes: Classes = { };

  constructor() {
    // super(styles, { ... }, Theme); // Specific Theme
    super(styles); // Default Theme
  }
}