Files
puter/src/UI/Components/StepView.js
T
KernelDeimos e050506a05 Add class registry (second pass)
ExportService gets removed and instead a global class registry is added.
The `init.js` file is split into `init_sync.js` and `init_async.js`
so that synchronous code that isn't dependent on imports is guarenteed
to run before initgui.js. The globalThis scope and service-script API
now expose `def`, a function for registering class definitions, and
`use`, a function for obtaining registered classes.
2024-05-28 19:06:00 -04:00

68 lines
1.7 KiB
JavaScript

const Component = use('util.Component');
export default def(class StepView extends Component {
static ID = 'ui.component.StepView';
static PROPERTIES = {
children: {},
done: { value: false },
position: { value: 0 },
}
static CSS = `
#wrapper { display: none }
* { -webkit-font-smoothing: antialiased;}
`;
create_template ({ template }) {
$(template).html(`
<div id="wrapper">
<slot name="inside"></slot>
</div>
`);
}
on_focus () {
this.children[this.get('position')].focus();
}
on_ready ({ listen }) {
for ( const child of this.get('children') ) {
child.setAttribute('slot', 'inside');
child.attach(this);
$(child).hide();
}
// show the first child
$(this.children[0]).show();
// listen for changes to the current step
listen('position', position => {
// hide all children
for ( const child of this.children ) {
$(child).hide();
}
// show the child at the current position
$(this.children[position]).show();
this.children[position].focus();
});
// now that we're ready, show the wrapper
$(this.dom_).find('#wrapper').show();
}
back () {
if ( this.get('position') === 0 ) return;
this.set('position', this.get('position') - 1);
}
next () {
if ( this.get('position') === this.children.length - 1 ) {
this.set('done', true);
return;
}
this.set('position', this.get('position') + 1);
}
});