<div class="pop-over">
<span class="pop-over-anchor">
Pick Something
</span>
<div class="pop-over-body">
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</div>
</div>
components/pop-over.js
PopOverComponent = Ember.Component.extend({
classNames: ["pop-over"],
anchorText: "Anchor",
isOpen: false,
selected: null,
options: null,
actions: {
toggle: function(){
this.toggleProperty("isOpen")
},
select: function(option) {
this.set("selected", option)
}
}
})
templates/components/pop-over.handlebars
application.handlebars
Things that we can't do easily:
- change the option template content
- change the anchor HTML / class etc...
- change the layout of the popover body
This assumes HTMLBars as there's stuff here that plain handlebars couldn't do.
Here we specify that the anchor has a content name of "anchor" and default content of {{anchorText}}
templates/components/pop-over.handlebars
We can set the content for that with content for=xxx
:
application.handlebars
We could even set attributes of the insertion point:
application.handlebars
To override the option, we need to be able to use its value, so the content
helper can pass values by listing them:
templates/components/pop-over.handlebars
Here we can use option
when overriding item
with ruby-style block syntax and choose an appropriate name etc:
application.handlebars
The context of the block is the parent, not the component, as it is now:
application.handlebars
The component would yield itself to the block so that you can address it from inside in a similar manner to content overrides:
application.handlebars
For block components which yield, anything not marked as content would be the template.
Eg, if our popover was instead built as follows:
templates/components/pop-over.handlebars
Then we could override the anchor and set the body like so:
application.handlebars
This would output:
<div class="pop-over">
<span class="pop-over-anchor">
Select (Tom)
</span>
<div class="pop-over-body">
<ul>
<li>Tom</li>
<li>Dick</li>
<li>Jane</li>
</ul>
</div>
</div>