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

ic-styled

v2.0.0

Published

automatically style components with css templates

Downloads

4,108

Readme

ic-styled

Build Status

Automatically style components with css templates.

Demo

http://instructure.github.io/ic-styled

Installation

bower install ic-styled

npm install ic-styled

... or download main.js and include it into your app however you want.

Module Support

ic-styled doesn't export anything, it just adds functionality to Ember.Component. If using a module system, require it somewhere in the root of your application somewhere (like application.js).

  • AMD

    define(['ic-styled'], function() {});

  • CJS

    require('ic-styled')

Usage

Given a component named x-foo, create an additional component template at components/x-foo-css, treat it like a css file. The css will be imported into your app automatically on the first instance of x-foo.

Sounds tricky but its not; here's a sample app:

<script type="text/x-handlebars">
  <h1>Application Template using x-foo</h1>
  {{x-foo}}
</script>

<script type="text/x-handlebars" id="components/x-foo">
  I am x-foo, the main component.
</script>

<script type="text/x-handlebars" id="components/x-foo-css">
  /* I am x-foo-css, the styles that go with x-foo */
  x-foo { color: red; font-weight: bold; }
</script>

<script>
  var App = Ember.Application.create();
  App.XFooComponent = Ember.Component.extend({
    tagName: 'x-foo'
  });
</script>

At the first render of {{x-foo}} the {{x-foo-css}} template is imported into the app to style x-foo elements.

Overriding Component Styles

Styled injects the css template to the top of the <head> element so its the first-ish css to be applied. This means that you can override the CSS of styled components the same as any native element since your app's CSS will be applied after.

Vim Config

If you use vim, add this to your vimrc to get css highlighting for these templates:

au BufNewFile,BufRead *-css.hbs set filetype=css

Use Tags to Style

I know, its been hammered into our brains not to use tagNames when writing CSS. But, when you build a component, you are creating a new custom element; you should mimick native elements as much as possible. Therefore, style it by tagName so everybody consuming your component can override styles the same way they override a <button>.

About the Implementation

A lot of questions come up, hopefully this answers them:

  • all styles are injected into a shared <style> tag to avoid the IE issue of only allowing 31 style/link tags
  • this style tag is at the top of the <head> so application CSS can override the same way they override native element css
  • styles for a component definition are only injected once, even if the component is used several times
  • a comment is inserted so you can see which component injected the css

Contributing

bower install
npm install
npm test

License and Copyright

MIT Style license

(c) 2013 Instructure, Inc.