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

with-style-mixin

v0.1.3

Published

An Ember mixin to allow you to bind style properties on your view/controller/whatever properties. Very simple live demo available [here](http://huafu.github.io/with-style-mixin/)

Downloads

17

Readme

with-style-mixin Build Status

An Ember mixin to allow you to bind style properties on your view/controller/whatever properties. Very simple live demo available here

Installation

  • npm install --save-dev with-style-mixin

Using

To use in your app with any view, import and use the mixin:

import Ember from 'ember';
import WithStyleMixin from 'with-style-mixin/mixins/with-style';

export default Ember.View.extend(WithStyleMixin, {
  styleBindings: [
    'width[px]', 'color', 'fontSize:font-size[em]', 'margin[px]',
    'show:display?block:none', 'visible:visibility?:hidden'
  ],
  width: 10,        // => 'width: 10px;'
  color: 'red',     // => 'color: red;'
  fontSize: '3pt',  // => 'font-size: 3pt;'
  margin: 0,        // => 'margin: 0;'
  show: true        // => 'display: block;' (if true => 'display: block;')
  visible: false    // => visibility: hidden; (if true => '')
});

You'll then get that in the generated HTML:

<div style="width: 10px; color: red; font-size: 3pt; margin: 0; display: block; visibility: hidden;"></div>

...well, ok it doesn't make sense as a style but it is to show the different features.


You can also use the {{bind-style ...}} helper if you need to bind styles on any other element than the main element of a view. It's working exactly the same thinking that you give as arguments each entry you'd put in the view's styleBindings property:

<div {{bind-style 'width[px]' 'color' 'fontSize:font-size[em]' 'margin[px]'
    'show:display?block:none' 'visible:visibility?:hidden'}}>
  <p>hello!<p>
</div>

You can also combine all in one string, separating each of them with a space:

<div {{bind-style 'width[px] color fontSize:font-size[em] margin[px]'
    'show:display?block:none visible:visibility?:hidden'}}>
  <p>hello!<p>
</div>

API

  • All style properties have to be defined on styleBindings as an array
  • Each property can be:
    • The name of the css property:
      • width (the width Ember property will then be used as source for width css property)
    • The name of your Ember property + : + the name of the css property:
      • myWidth:width (the myWidth Ember property will then be used as source for width css property)
    • One of the 2 above + a unit between [ and ]:
      • width[px] (the width Ember property will then be used as source for width css property, append px at the end of the value)
      • myWidth:width[px] (the myWidth Ember property will then be used as source for width css property, append px at the end of the value)
    • One of the 3 above (well 4 exactly) + ? + the value to use if truthy + : + the value to use if falsy:
      • display?block:none (block will be used if display is truthy, else none)
      • isVisible:display?:none (nothing used if isVisible is truthy, none is used if isVisible is falsy)
      • isLarge:line-height[px]?30:20 (line-height will be 30px if isLarge is truthy, else 20px)
  • If the property value is undefined, null or '' (empty string), it'll not be included in the style
  • When a unit is specified, it'll be appended to the value unless the value is 0 or not numeric, which allow you to do:
    • width[px]:
      • width is 0: width: 0;
      • width is 10 or '10': width: 10px; (works also with float values)
      • width is '10%': width: 10%;

Authors