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-material-modifier

v1.0.4

Published

Ember Material Design integration

Downloads

6

Readme

ember-material-modifier

Node CI npm version

Lightweight Ember.js material design integration.

An Ember add-on for Material Component for web.

Compatibility

  • Ember.js v3.20 or above
  • Ember CLI v3.20 or above
  • Node.js v12 or above

Installation

ember install ember-material-modifier

Usage

ember-material-modifier is designed to be as minimal and unobtrusive as possible. It only downloads the JavaScript and CSS of google material design components that you use.

Button Example

For instance if you want to use @material/button install the package

npm install @material/button

Have a look at the material design docs for the component https://github.com/material-components/material-components-web/tree/master/packages/mdc-button. Then copy the example html to one of your templates.

<button class="mdc-button">
  <span class="mdc-button__ripple"></span>
  <span class="mdc-button__focus-ring"></span>
  <span class="mdc-button__label">Text Button</span>
</button>

Next you add the ember-material-modifier modifier {{material}}

<button class="mdc-button" {{material 'button'}}>
  <span class="mdc-button__ripple"></span>
  <span class="mdc-button__focus-ring"></span>
  <span class="mdc-button__label">Text Button</span>
</button>

Event listeners are added as usual

<button class="mdc-button" {{material 'button'}} {{on 'click' this.handleButtonClicked}}>
  <span class="mdc-button__ripple"></span>
  <span class="mdc-button__focus-ring"></span>
  <span class="mdc-button__label">Text Button</span>
</button>

If you find yourself duplicating this HTML you can extract it to a component that suits your application.

app/components/mdc-button.hbs

<button {{...attributes}} class="mdc-button" {{material 'button'}} >
  <span class="mdc-button__ripple"></span>
  <span class="mdc-button__focus-ring"></span>
  <span class="mdc-button__label">{{yield}}</span>
</button>

app/templates/application.hbs

<MdcButton {{on 'click' this.handleButtonClicked}}/>Text Button</MdcButton>

| :warning: WARNING | |:---------------------------| | Many of the material.io HTML examples use the Material Icons google font, you either need to install the font or edit the example HTML to use an alternative. |

Register component

The {{material}} modifier takes two positional arguments. The first is the name of the material design component. For instance you want to use the package @material/menu then the modifier is {{material 'menu'}}. You can also pass a second arguement to register the instance of material design component class with your application code.

<div
  class="mdc-menu mdc-menu-surface"
  {{material 'menu' this.registerMaterialMenu}}
>
@action
registerMaterialMenu(mdcMenu) {
  this.mdcMenu = mdcMenu;
}

You now have access to the MDCMenu properites and methods.

Custom Events

Many on the material design components emit custom events. You can add event listeners for these as you would any other event.

<ul
  class="mdc-list"
  {{material 'list'}}
  {{on 'MDCList:action' this.handleMdcListItemSelected}}
>
  <li class="mdc-list-item" tabindex="0">
    <span class="mdc-list-item__ripple"></span>
    <span class="mdc-list-item__text">Item 1 - Division 1</span>
  </li>
</ul>

Though in the case of a list item being selected you probably want to use a standard 'click' event listener on the specific list item.

<ul
  class="mdc-list"
  {{material 'list'}}
>
  <li
    class="mdc-list-item" tabindex="0"
    {{on 'click' this.handleMdcListItemSelected}}
  >
    <span class="mdc-list-item__ripple"></span>
    <span class="mdc-list-item__text">Item 1 - Division 1</span>
  </li>
</ul>

Theming

Google material design components can be themed using CSS variables.

You can find a list of CSS variables in the google style sheets. For instance if you install any of the @material/* packages they have a dependencies on @material/theme. You can open ./node_modules/@material/theme/dist/mdc.theme.css which gives a list of CSS variables.

For example to change the primary text color add the following to your app.css

app.css

:root {
  --mdc-theme-text-primary-on-background: purple;
};

You can use the color tool to preview material design themes.

CSS Loading

The CSS is lazy loaded when the material design components class is instantiated. It is loaded when the modifier is run after the HTML has been rendered. If it is the first time the material design component has been loaded there will be a noticeable delay until the CSS is applied, you will see the component unstyled.

To prevent this you can eager load the CSS for the material design components you use in the application router. For instance if you use {{material 'button'}} in one of your templates add importCss('button') to the beforeModel hook of your application route.

app/controller/application.js

import Route from '@ember/routing/route';

import importCss from 'ember-material-modifier/import-css';

export default class ApplicationRoute extends Route {
  beforeModel() {
    return importCss('button');
  }
}

It should be possible to remove this importCss and eager load the needed material design CSS without it. The need to call importCss will hopefully be removed.

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.