Git Product home page Git Product logo

ember-modals's Introduction

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>

ember-modals's People

Contributors

ember-tomster avatar juliogarciag avatar solirvine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ember-modals's Issues

Clicking overlay on iPhone

Clicking the overlay does not always close the modal on iOS. Expected behaviour is the overlay closes when tapped but not pinched, etc.

Question about ember-modals on IE8 / plans for supporting Ember 1.13

Hi,

I've just tried out your demo on IE8 and ran into some problems. The modal opens but isn't shown correctly. The tests are failing on IE8 but I didn't look at the errors closely yet.

I'm curious to know if supporting IE8 is something that you are interested in doing. It seems like it could be possible because the modal does show (at least somewhat) on IE8. Obviously this would only be for a version that's compatible with Ember 1.13 as IE8 will go away in Ember 2.0. For me it's ok if the solution is that I need to add a polyfill for some functionality that's missing in IE8. If this is the way to go, could you point me in the right direction for which polyfills I'd need to use?

This leads me to my next question: Are you planning to release a version that works with the Ember 1.13 libraries (ember, ember-data, ember-cli, etc)? I haven't tried your library yet in my app that uses Ember 1.13 so it might even work now. I'm asking because I saw that the demo used Ember 1.10.

Thanks, Ben

Firefox doesn't transition box shadow

Low priority - stylesheets considered complementary, not core. For example, use any included animation in a current Firefox browser and watch the box shadow around the modal content.

Modal closing is not animated

I figured out today that this happened after updating from 0.2.1 to 0.3.4. After some debug i found that the problem happened here: https://github.com/sir-dunxalot/ember-modals/blob/master/addon/views/modal.js#L81. The problem is that outletBeingClosed is "modal" and this.get('outlet') is undefined. After going back to 0.2.1, i found that everything worked because both outletBeingClosed and the outlet property were both undefined.

I followed the steps of creating a template, setting the mixin in the application route and calling showModal from the controller. I wanted to keep diving in the code to figure out what happened but i don't know too much about ember internals to know why the call here returns undefined.

PD: My Ember version is 1.10.0 and my Ember-CLI version is 0.2.0.

no action handler for: closeModal

Hi,
I've just started with this ember addon, but I still can't solve my problem. Component can't find closeModal action. And close button from option "showCloseButton" works.

welcome-dialog.hbs:

<h2>Welcome!</h2>
<button {{action 'closeModal'}}>Close</button>

welcome-dialog.js:

import Ember from 'ember';

export default Ember.Component.extend({
});

route template:

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

application.hbs

{{outlet}}

{{ember-modals}}

Error: Uncaught Error: <test-app@component:welcome-dialog::ember716> had no action handler for: closeModal

Cannot open from inside component

You get this.showModal is not a function. It's redundant to have to send an action outside of the component when the component is the thing responsible for this modal.

Application route mixin not found

Ember 2.4.3
Ember-CLI 2.4.3

import ApplicationRouteMixin from 'ember-modals/mixins/routes/application';

Migrating from ember 1.X to 2.X I started getting this error.

Close modal being used in place of hide

In the wiki for usage, closing a modal was incorrectly using

this.get('modal').close()

instead of

this.get('modal').hide()

edited the wiki to fix the problem

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.