• Stars
    star
    184
  • Rank 209,187 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Render elsewhere in the DOM, with nice composition, animation, etc. Based on 100% public API.

ember-elsewhere

NPM Ember Observer Score Ember Version

This addon makes it easy to manage sidebars, toolbars, popups, modals, or any piece of DOM that you want to lift outside your normal route hiearchy.

It is similar to ember-wormhole, but is a better choice when your target is within your own Ember app (as opposed to arbitrary, potentially foreign DOM). It is also easier to compose with animations and it's based on 100% public API.

The best documentation is the sample application in tests/dummy, which is also running at http://ef4.github.io/ember-elsewhere/.

Install

ember install ember-elsewhere

Components

Create a target named "my-right-sidebar":

<FromElsewhere @name="my-right-sidebar" />

Anywhere else in your app, declare which component should render in the target -- complete with bound inputs and actions:

<ToElsewhere
  @named="my-right-sidebar"
  @send={{component "cool-thing"
    model=this.model
    launch=this.launchIt
  }}
/>

For fancier behaviors, you can use the block form of <FromElsewhere>, which gives you an opportunity to extend the target's behavior in arbitrary ways. For example, this lets your target animate as its content changes:

<FromElsewhere @name="modal" as |modal|>
  {{#liquid-bind modal as |currentModal|}}
    <div class="modal-background"></div>
    <div class="modal-container">
      {{component modal}}
    </div>
  {{/liquid-bind}}
</FromElsewhere>

Rendering multiple components into a single target

There might be use cases where you would like to render multiple component into a single target, for example a <FromElsewhere> "actions" might receive multiple action buttons via <ToElsewhere>. Instead of <FromElsewhere/> just use the complementary <MultipleFromElsewhere> component.

<MultipleFromElsewhere @name="actions"/>
<!-- ... -->
<ToElsewhere @named="actions" @send={{component "test-button" text="Button1"}} />
<ToElsewhere @named="actions" @send={{component "test-button" text="Button2"}} />
<ToElsewhere @named="actions" @send={{component "test-button" text="Button3"}} />

Passing additional state through to the target

When you're using the block form of <FromElsewhere>, it's entirely up to you what information you pass to the target. It can be more than just a component. Here is a complete example of an animatable modal that supports an onOutsideClick action while providing shared layout for the background and container:

<ToElsewhere @named="modal"
             @send={{component "warning-message"}}
             @outsideParams={{hash onOutsideClick=this.close 
                                   title="modal title"}} />
<FromElsewhere @name="modal" as |modal outsideParams|>
  {{#liquid-bind modal as |currentModal|}}
    <div class="modal-container">
      <div class="modal-background" {{on "click" outsideParams.onOutsideClick}}></div>
      <div class="modal-dialog" >
        <div class="modal-title">{{outsideParams.title}}</div>
        <currentModal />
      </div>
    </div>
  {{/liquid-bind}}
</FromElsewhere>

If you plan to send a component, you can use Ember's component helper. The component helper accepts the component name and other properties, such as {{component "my-component-name" someValue="something"}}, which will cover most use cases. However, if you need to provide additional content to use outside of the component scope, that is when you can use the outsideParams attribute.

Crossing Engines

Engines deliberately are deliberately isolated from each other, so a <ToElsewhere> in one engine cannot target a <FromElsewhere> in another. But you can optionally share the ember-elsewhere service between them to make it work, see #26 (comment)

Ember's native in-element

Since Ember 3.21 there is also a native in-element helper. This helper offer less functionality than this addon, but may be enough for some use-cases. More details

Linting

Running tests

  • npm test (Runs ember try:testall to test your addon against multiple Ember versions)
  • ember test
  • ember test --server

Running the dummy application

For more information on using ember-cli, visit http://www.ember-cli.com/.

More Repositories

1

prember

Prerender Ember apps with Fastboot at build time.
JavaScript
193
star
2

ember-browserify

ember-cli addon for easily loading CommonJS packages from npm via browserify.
JavaScript
172
star
3

ember-animation-demo

A presentation at EmberConf 2014
CSS
129
star
4

ember-code-snippet

An Ember component for rendering pretty code snippets.
JavaScript
84
star
5

mho

Experimental service-worker based build system
TypeScript
76
star
6

memory-scroll

An Ember component that remembers its scroll position
JavaScript
57
star
7

ember-sidebars

A sidebar manager for Ember apps.
JavaScript
45
star
8

ember-handoff

Ember Engine for mounting and enhancing server-rendered web pages.
JavaScript
44
star
9

cardstack-editor

CSS
42
star
10

living-animation

Interactive EmberConf 2018 Slides
JavaScript
42
star
11

ember-set-body-class

Fastboot-compatible, template-driven helper for setting classes on the body
JavaScript
38
star
12

ember-giftwrap

A tool for packaging Ember addons
JavaScript
34
star
13

ember-cli-deploy-git

ember-cli-deploy plugin for uploading your built app to Git.
JavaScript
30
star
14

physical-design-demo

A demo app showing motion design in an Ember app. EmberConf 2015.
CSS
29
star
15

tracked-params

TypeScript
22
star
16

ember-cli-deploy-appshell

applicationCache-based shell for loading Ember apps
JavaScript
22
star
17

relativity

Interval tree clocks for Javascript
JavaScript
19
star
18

ember-resource-metadata

Per-resource metadata for ember-data
JavaScript
15
star
19

fast-sourcemap-concat

Fast sourcemap generation & concatenation.
JavaScript
13
star
20

ember-sass-bootstrap

Use the parts of bootstrap-sass that you want, and none that you don't.
JavaScript
13
star
21

ember-overlays

Annotated overlays for Ember apps.
JavaScript
12
star
22

ember-ignore-children-helper

Helps you ignore events that didn't directly target your own element.
JavaScript
11
star
23

ember-root-url

A template helper to keep your URLs relative to the app's rootURL.
JavaScript
10
star
24

ember-react-example

Example of invoking React components from an Ember app.
JavaScript
10
star
25

ember-data-relationship-tracker

JavaScript
9
star
26

pdfkit-www

In-browser PDF generation
Ruby
9
star
27

better-mocha-html-reporter

JavaScript
7
star
28

broccoli-sourcemap-concat

Fast, caching broccoli filter that generates & propagates source maps.
JavaScript
7
star
29

drupal-ember-dev

Drupal module that supports Ember development
PHP
7
star
30

xrouter

Home for Ember Polaris Routing experimentation.
JavaScript
6
star
31

emberconf-2017-demo

JavaScript
6
star
32

ember-head

Fastboot-compatible component for rendering content into <head>
JavaScript
6
star
33

are-my-node-modules-messed-up

It's a question worth asking.
JavaScript
6
star
34

ember-computed-cleanup

Ember computed properties with cleanup.
JavaScript
5
star
35

lazy-load-highcharts-demo

Code that accompanies a screencast.
JavaScript
4
star
36

prember-crawler

A web crawler for discovering URLs you want to pre-render with prember
JavaScript
4
star
37

ember-strict-warnings

Make warnings into errors during dev and test.
JavaScript
4
star
38

linkedin-demo

A demo I gave at LinkedIn.
HTML
4
star
39

initial-render-perf

A test scenario for Ember initial rendering performance
JavaScript
4
star
40

babel-import-util

Utility for manipulating imports within babel plugins
TypeScript
3
star
41

demonstrate-pdfjs

How to use pdfjs in an Ember app
JavaScript
3
star
42

ember-css-url

A helper for safely embedding URLs in style properties
JavaScript
3
star
43

ember-cli-proxy

JavaScript
3
star
44

build-if.macro

TypeScript
3
star
45

debugify

Exposes all browserify modules for console debugging (like requireify but different).
CoffeeScript
2
star
46

learning-demo

Demo to accompany a talk at EmberNYC, March 2018
JavaScript
2
star
47

flip-demo

Animation demos to accompany a presentation.
JavaScript
2
star
48

jan2020-meetup-example

Example code for a presentation at Boston Ember, January 2020.
JavaScript
2
star
49

optimist

An alternative model layer for Sproutcore.
1
star
50

distributed-ember-presentation

A presentation at WickedGoodEmber 2014.
CSS
1
star
51

tailwind-demo

How to integrate TailwindCSS into an Ember App
JavaScript
1
star
52

embroider-resolver-demo

Quick demo of how the Embroider resolver API works
JavaScript
1
star
53

koa-better-route

Like koa-route, except it works with koa-compose
JavaScript
1
star