Skip to content

Commit

Permalink
examples.layout.card.MainContainer: next & prev button logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiu committed Apr 20, 2024
1 parent edc44fd commit 8a91178
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions examples/layout/card/MainContainer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MainContainer extends ConfigurationViewport {

createConfigurationComponents() {
let me = this,
{layout} = me.exampleComponent;
{layout} = me.exampleComponent.getItem('card-container');

return [{
module : Radio,
Expand Down Expand Up @@ -81,22 +81,31 @@ class MainContainer extends ConfigurationViewport {
width : 400,

items: [{
module: Container,
layout: {ntype: 'card', slideDirection: 'horizontal'},
items : [{
module : Container,
layout : {ntype: 'card', slideDirection: 'horizontal'},
reference: 'card-container',

items: [{
style: {backgroundColor: 'red'}
}, {
style: {backgroundColor: 'blue'}
}, {
style: {backgroundColor: 'green'}
}]
}, {
module: Toolbar,
flex : 'none',
items : [{
handler: 'onNextButtonClick',
text : 'Prev'
style : {marginTop: '1em'},

items: [{
disabled: true,
handler : 'up.onPrevButtonClick',
reference: 'prev-button',
text : 'Prev'
}, '->', {
handler: 'onPrevButtonClick',
text : 'Next'
handler : 'up.onNextButtonClick',
reference: 'next-button',
text : 'Next'
}]
}]
})
Expand All @@ -106,7 +115,12 @@ class MainContainer extends ConfigurationViewport {
* @param {Object} data
*/
onNextButtonClick(data) {
this.exampleComponent.layout.activeIndex++;
let cardContainer = this.getItem('card-container'),
{layout} = cardContainer;

layout.activeIndex++;
data.component.disabled = layout.activeIndex === cardContainer.items.length - 1;
this.getItem('prev-button').disabled = false;
}

/**
Expand All @@ -124,7 +138,12 @@ class MainContainer extends ConfigurationViewport {
* @param {Object} data
*/
onPrevButtonClick(data) {
this.exampleComponent.layout.activeIndex--;
let cardContainer = this.getItem('card-container'),
{layout} = cardContainer;

layout.activeIndex--;
data.component.disabled = layout.activeIndex === 0;
this.getItem('next-button').disabled = false;
}
}

Expand Down

0 comments on commit 8a91178

Please sign in to comment.