I'm trying to implement a 'switcher' or 'viewstack' component in Aurelia, this would be useful for wizards, paged content, and stepping through a list of tasks. This would show a single child component at a time from a number of possible children. I'd like the usage markup to resemble:
<my-switcher>
<one-component></one-component>
<two-component></two-component>
<three-component></three-component>
</my-switcher>
Now, the obvious alternatives here are:
<compose view-model.bind="currentStep">
and point the currentStep variable to each component at a time. (+ves: components are only instantiated when accessed, -ves: needing to know the path for each component, all children need to be valid view-models)- Add an
if.bind='active'
within the definition of each component in theslot
, and just set thisactive
member from themy-switcher
class. (+ves: easier to follow, -ves: components need to be specifically written for use here). - Retrieve the children via @children (if this now works reliably?) and add the Element as a child DOM element manually, then call
ViewCompiler.enhance
. (-ves: can't seem to get get @children to work, larger amount of custom code)
Each of these feels a bit contrived a solution. Does anyone have any idea about whether there a cleaner approach that could/should be used instead?