Coder Social home page Coder Social logo

ember-routable-modal's Introduction

Ember Routable Modal Build Status

The ember-routable-modal addon allows you to quickly and easily implement URL-first modals, similar to those found on sites such as Facebook, Twitter, and Dribbble. You can navigate to modals elsewhere in the route tree without losing your place on the current page, making it ideal for lightboxes and photo viewers.

Usage

Installation

ember install ember-routable-modal

Ember.js 2.12+ is required.

You must add {{routable-modal-outlet}} to the bottom of your application template in order for modals to render.

Stylesheets

The addon comes with a lightweight default Sass stylesheet. To use it, you must first install ember-cli-sass, then import the files at the top of your styles/app.scss file as so;

@import "ember-routable-modal/core";
@import "ember-routable-modal/dialog";

Generating Modal Routes

You can use the modal-route generator to quickly scaffold modal routes, sharing the syntax of the built-in route generator. Try running the following command;

ember generate modal-route example

If you are using the pod structure, make sure you pass the -p parameter.

You will now see that a route has been generated with the provided mixin, as well as a template with a sample dialog element.

// app/routes/example.js
import Ember from 'ember';
import ModalRouteMixin from 'ember-routable-modal/mixins/route';

export default Ember.Route.extend(ModalRouteMixin, {
});
// app/templates/example.hbs
<div class="routable-modal--dialog">
    <div class="routable-modal--content">
        <div class="routable-modal--header">
            {{routable-modal-close-button class="routable-modal--close"}}
            <h4 class="routable-modal--title">Modal title</h4>
        </div>
        <div class="routable-modal--body">
            Content
        </div>
    </div>
</div>

Now whenever you navigate to /example, through the usual {{link-to}} helper or by calling this.transitionTo() within a route, the example modal will render on top of your currently active route. If you load the page from the /example URL directly, the closest parent route will be rendered underneath the modal.

You are free to delete the provided template and build your own dialog component if you wish, the addon is flexible.

Loading Substates

Modal routes also work with the loading substate when an asynchronous object is passed to the route's model hook. Just create a template with the filename in the format {route}-loading, and it will be rendered on top of the modal backdrop while your model hook waits to resolve.

Closing Modals

You can close modals in one of two ways;

Programmatically

The addon comes with a service called current-routed-modal. Simply inject it wherever you would like to be able to control the modal, for instance in a component;

import Ember from 'ember';

export default Ember.Component.extend({
    modal: Ember.inject.service('current-routed-modal'),
    tagName: 'button',
    click() {
        this.get('modal').close();
    }
});

Helper Component

You can also use the {{routable-modal-close-button}} component, which has the same implementation as the code sample above. You can see an example of it used in the auto-generated modal route template. It can also be used in block form, such as {{#routable-modal-close-button}}Close{{/routable-modal-close-button}}

Configuration

Customize Element Classes

You can override the default modal element classes by setting the ENV['ember-routable-modal'] option in config/environment.js like so;

ENV['ember-routable-modal'] = {
    modalClassNames: ['modal'],
    backdropClassNames: ['modal-backdrop'],
    modalOpenBodyClassName: 'modal-open'
};
Property Default
modalClassNames ['routable-modal']
backdropClassNames ['routable-modal--backdrop']
modalOpenBodyClassName routable-modal--open

Running tests

  • ember test – Runs the test suite on the current Ember version
  • ember test --server – Runs the test suite in "watch mode"
  • npm test – Runs ember try:each to test your addon against multiple Ember versions

ember-routable-modal's People

Contributors

benkingcode avatar dwayneh avatar ember-tomster avatar kemenaran avatar kltdwrds avatar

Stargazers

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

Watchers

 avatar  avatar

ember-routable-modal's Issues

Option to disable routing

This might sound like a weird suggestion, but it would be nice to have an option to make a modal non-routable (basically being able to disable the primary feature of this addon.

Here is why:

  1. in the case of the security modal, i.e. "Please confirm you really want to delete your account", we should not be able to access that route directly: example.com/user/settings/delete-confirmation
  2. for styling and to avoid code duplication, to fix 1. we don't want to move to another, second ember modal addon such as https://github.com/yapplabs/ember-modal-dialog

So yes, I currently have to use both ember-routable-modal and ember-modal-dialog, but would like to use only one of them (yours!).

What do you think?

Using outlet within routable modal doesn't render

I've tried adding an outlet within my modal so that I can create steps for creating an order, eg. order/create/details, order/create/items

The outlet doesn't seem to render when navigating via link-to, however, it does render when I navigate to the nested route by entering the url directly.

Override Modal Close Functionality

Hey! I love this addon and it has been easy to work with, but I've got a question.

I'm currently using a modal that handles a user creation form for an app and was curious if there was a way to override the behavior when a user clicks out of a modal to close it. I've currently set a cancel button and the typical 'X' in the corner to close the modal to rollback my model on close, but when looking through the documentation I haven't found a way to mimic that behavior when a user clicks away.

I don't mind working on adding a feature like this if it doesn't currently exist if you'd like, but I wanted to double check before I go down that path =).

Thanks!

Loading State

Hi,
we´ve got an weired behaviour opening a routed modal with a model hook.
There are 2 routed modals. One without a model hook (MR1) and one with a model hook (MR2). For both there is no loading state defined.

  1. Opening MR1 --> MR1 is displayed as expected
  2. Closing MR1 --> MR1 is closed as expected
  3. Opening MR2 --> MR1 is shown as loading state, while model is resolving, then MR2 is shown NOT EXPECTED

Opening just MR2 works as expected.
Defining an loading template for MR2 fixes the problem of case 3.

Doesn't work with Ember FastBoot

The checks in the current-routed-modal service fail in FastBoot mode. This seems to be because the checks are merely looking whether $ or window are undefined, but it seems to be possible for both to be defined in FastBoot mode, because that's what's happening to me.

I'm not sure what the most reliable check is. Ensuring document is undefined seems to work. Injecting the fastboot service and checking its isFastBoot property seems to work, too.

Model not found when visiting modal route directly

When moving from blog.com/articles/5/ to blog.com/articles/5/edit, the modal opens and the model for article with id 5 is found without problem.

When visiting blog.com/articles/5/edit directly, the model is not found unless I look for it myself:

import Ember from 'ember';

import ModalRouteMixin from 'ember-routable-modal/mixins/route';

const { Route } = Ember;

export default Route.extend(ModalRouteMixin, {
  model() {
    return this.store.peekRecord('article', this.router.targetState.routerJsState.params['articles.show'].id);
  }
});

Is this something that could be avoided? Thanks

Can't write any integration test

integration test, I mean Ember integration test.

TypeError: Cannot read property 'get' of undefined

When launching the basic, generated integration test of Ember

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.