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

ember-emotion

v5.0.0

Published

Work with emotion.js in Ember

Downloads

40

Readme

ember-emotion

Use emotion in Ember.js

Build Status Ember Observer Score npm version

This addon

  • 👩‍🎤 Exposes emotion as a module that can be imported in Ember
  • 📦 Adds the ability to define styles scoped to a pod
  • 🚀 Supports FastBoot out-of-the-box
  • ⚡️ Allows for dynamically defining CSS values

Installation

ember install ember-emotion

Make sure that the changes to your resolver.js file were applied; your resolver must include the provided mixin

Usage

To start using ember-emotion, add a style.js file within a Component or Controller pod. Each named export can be accessed through the emotion-class helper in the pod's template. The default export, for Component pods, is merged into the classNames property automatically

// components/foo-bar/style.js
import { css } from 'emotion';

export default css`
  background: grey;
`;

export const paragraph = css`
  color: blue;
`;
{{! components/foo-bar/template.hbs }}
The component background will be grey.
<p class={{emotion-class 'paragraph'}}>
  Just this text will be blue.
</p>

Advanced Usage

Often times you want to define style based on the state of your component. ember-emotion provides tools for pulling in that state and using it to define your CSS dynamically.

As a quick example, image you have an input component that should have black text normally, but should turn red when there's an error. Here's what the CSS definition for that component might look like:

import { computed } from 'ember-emotion';

export default text = computed('hasError')`
  color: ${ctx => ctx.get('hasError') ? 'red' : 'black'}
`;

By using the computed function to define your CSS block, two features are unlocked. Arguments passed to computed (like hasError above) are dependent keys just like in an Ember computed property definition. Functions embedded in the CSS definition are passed the context of the component as the first argument, so you can base your CSS off of the state. In the example above, any time hasError changes, the function will be called again and red or black will be set as the text color accordingly. This provides an alternative to the "normal" approach of doing this logic in the template to define different classes manually based on the state. Instead, you can allow Ember and Emotion to do that logic for you.

If the state you care about is present initially and will never change, you can also just use the computed function as a template tag directly and define no dependent keys, like so:

import { computed } from 'ember-emotion';

export default computed`
  padding: ${ctx => ctx.get('paddingAmount')}
`;

Note that this will not be re-computed should paddingAmount be changed.

To make this easier, this addon provides a global-styles blueprint that can be used to generate the appropriate instance initializer. You can run:

ember generate global-styles __name__of__initializer__

where __name__of__initializer__ would be replaced by whatever you want to call this file, and you'll get an initializer pre-configured to execute at the right time. You can simply add to the injectGlobals usage provided there and everything else will be taken care of.

Configuration Options

Configuration options can be provided in the ember-cli-build.js file.

Example:

/* ember-cli-build.js */
const app = new EmberApp(defaults, {
  emotion: {
    injectMixin: true, // Enabled by default
    babel: {
      // See `babel-plugin-emotion` for options
    }
  }
});

Defaults to true

See the documentation for that package for details more.

Caveats

  • You must have a component.js or controller.js file in your pod for the emotion styles to work, even if it just re-exports the default implementation
  • Even if it's empty, you must leave your app.css file in place (for now). The build will break without it.