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

ng2-styler

v0.1.2

Published

Angular2 Styler

Downloads

7

Readme

Angular2 Component Styler

This is an experimental new decorator created outside the Angular 2 ecosystem that is used to generate dynamic runtime styles out of plain objects.

Usage:

You can create parametrized, dynamic and LESS/SAAS styles directly in your component definition. As you can see in the example below the styles can be parametrized directly in your typescript file. For a more complex example checkout the runtime folder example from the repo github.

example:


var backgroundColor = "#FFFFFF",
    lightGray = "#EDEDED",
    padding = "10px";

@Style({
    ".card": {
        display: 'inline-block',
        width: '40%',
        margin: '30px',
        textTransform: 'uppercase',
        boxShadow: '0px 0px 2px rgba(0,0,0,0.6)',

        ".header": {
            display: 'block',
            backgroundColor: backgroundColor,
            padding: '10px',
            color: lightGray
        },

        ".content": {
            display: 'block',
            padding: padding
        },

        ".footer": {
            display: 'block',
            borderTop: '1px solid #808080'
        }
    }
})
@Component({
    selector: 'card',
    template: `
        <div class="card">
           <div class="header">
             Update
           </div>
           <div class="content">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenan convallis.
           </div>
           <span class="footer">
                <span class="action">view profile</span>
           </span>
        </div>`,

})
export class CardComponent extends Type {
    constructor() {
    }
}

How it works

Since @Style decorator is defined above @Component decorator and the metadata is stored from bottom to the top, the @Style decorator execution will override styles properties (if any) defined in the component. The styler is working simillar with LESS/SAAS preprocessors (where it was inspired from) thus, the definitions can be nested and the output will be fully CSS compatible.

".card": {
    display: 'inline-block',
    backgroundColor: '#FF0000',
    
    ".header": {
        display: 'block',
        "&:hover": {
            backgroundColor: '#808080'
        }
    }
}

//will output
.card { display: inline-block; background-color: #FF0000;}
.card .header { display: block; }
.card .header:hover { background-color: #808080; }

Advantages

  • No CSS preprocessor needed
  • No bunlder required
  • Take full advantage of Angular2 View Encapsulation
  • Can be parametrized at runtime
  • Styles are defined on location
  • Syntax similar to LESS/SAAS

Disadvantages

  • @Style is not an Angular native decorator
  • @Style decorator must ALWAYS be defined above @Component decorator

Give it a go

Command line

npm install --save-dev ng2-styler

If you are using angular-cli:

  • update angular-cli-build.js and add another line to vendorNpmFiles: 'ng2-styler/**/*.+(js|js.map)',

  • update src/system-config.ts with: 'ng2-styler': 'vendor/ng2-styler' in System.config map property and add 'ng2-styler', in the barrels

If you are in a hurry you can checkout this repo and run:

npm install
typings install
npm run all

In order to check the runtime theme selector you can open: http://localhost:3000 for first theme and http://localhost:3000/?compact for the compact theme.

Roadmap

  • add helper functions for color manipulations (darken, lighten etc.)
  • better fetching of Reflect object
  • ideas?