Another update on a recent version (0.10.1).
Today I introduced a solution to a generic item child component, that can be used either by dropdown or by lists etc.
Consider the following code:
{{#dropdown label="Dropdown button"}}
{{> item href="#some" label="Action"}}
{{> item href="#where" label="Another action"}}
{{> item href="#else" label="Something else here"}}
{{/dropdown}}
Much easier to reason about than using complex html constructs, isn’t it? But how does the item know, if it should have the classname dropdown-item or list-group-item? I approached this with two options:
A - Explicitly declare the type using a parameter
This is the faster way (no parent tree traversal required) but also requires an additional type parameter:
{{> item type="dropdown" href="#some" label="Action"}}
B - Auto traverse the parent tree
Leaving out the type parameter leads to a traversal of the parentView and originalParentView properties of the Template’s view until a Template is found (which is then considered as outer parent).
This why
{{> item type="dropdown" href="#some" label="Action"}}
inside a {{#dropdown}} will find the Template.dropdown parent and the internal mapping of item will thus internally assign dropdown-item as classname to the element.
Focus more on the important stuff
Having abstracted away the meaning of the item we have also more space to focus on custom html content:
{{#dropdown label="Dropdown button"}}
{{#item href="#some"}}<strong>Action</strong>{{/item}}
{{#item href="#where"}}<u>Another action</u>{{/item}}
{{#item href="#else"}}<i>Something else here</i>{{/item}}
{{/dropdown}}
I hope this pays out in the long run. Compatibility for various list-group modes is still in development but will be completed next.
If you are interested in this project please support and contribute by trying the DEMO, leaving an issue or open a PR.