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-modals

v1.0.0

Published

The default blueprint for ember-cli addons.

Downloads

32

Readme

Ember Modals

Adds API-like functionality for rendering and managing modals in your Ember application.

This addon tracks the context from where you showed a modal, allowing you to easily interact with your current route, component, or controller from within the modal.

Installation

ember install ember-modals

And add the {{ember-modals}} component in your application template:

{{outlet}}

{{ember-modals}}

Showing Modals

To show a modal using a HTMLBars action, call showModal and pass the name of any component to render as a modal.

You must specify target as modals. The target will reference the modals service, which is injected into routes, components, and controllers by default.

<button {{action 'showModal' 'welcome-dialog' target=modals}}>
  Show welcome
</button>

The showModal action accepts a second, optional parameter, context:

<button {{action 'showModal' 'welcome-dialog' this target=modals}}>
  Show welcome
</button>

When you pass a context, this will be set as the targetObject of the component you passed.

Passing Modal Options

Instead of passing a component and context to the showModal action, you can pass a single options object.

This object supports more options that name-and-context approach mentioned above:

/* Within some route, component, or controller... */

this.modals.send('showModal', {
  componentName: 'my-welcome-dialog',
  context: this,
  modalClassName: 'welcome-modal',
  overlayClassName: 'overlay-transparent',
  showCloseButton: true,
});

Accessing the Caller Context

Congratulations! You shiney new modal has been render in the DOM!

Because you rendered it from within some component or route, you might want to access properties or actions on that class. To do this, just access the targetObject property in your component or component's layout:

/* Some route, component, or controller... */

export default Ember.Component.extend({
  userName: 'Dave',

  actions: {
    checkWeCanDeleteThis() {
      this.modals.showModal('confirm-delete', this);
    },

    confirmDelete() {
      this.get('model').deleteRecord();
    }
  },
});
/* templates/components/confirm-delete.hbs */

Hey, {{targetObject.userName}}! Are you sure you want to delete this?

<button {{action 'confirmDelete' target=targetObject}}>
  Yes!
</button>

<button {{action 'closeModal'}}>
  No
</button>

Note two things:

  • You must have passed context to showModal() as described in passing modal options**
  • Set target=targetObject to call actions on the route or component you rendered the modal from

You can also access the modal property, giving you access to the original options to passed to showModal():

/* templates/components/confirm-delete.hbs */

I'm showing {{modal.componentName}}. {{!-- confirm-delete --}}

The context is {{modal.context}}, which is the same as {{targetObject}}.

The modal class name is {{modal.modalClassName}}.

Closing Modals

There are three ways modals can be closed:

  • Hitting esc
  • Clicking on the overlay
  • By sending the closeModal action from within the modal content:
/* templates/components/welcome-dialog.hbs */

Welcome to this app!

<button {{action 'closeModal'}}>
  Close modal
</button>