1.0.0 • Published 8 years ago

ember-modals v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
8 years ago

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

8 years ago

1.0.0-rc.2

8 years ago

1.0.0-rc.1

8 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.6

9 years ago

0.3.5

9 years ago

0.3.4

9 years ago

0.3.3

9 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.0

9 years ago