2019-08-31 20:51:14 -07:00
|
|
|
import Component from '@ember/component';
|
2020-08-28 16:19:46 -07:00
|
|
|
import { tagName, layout } from '@ember-decorators/component';
|
2019-08-31 20:51:14 -07:00
|
|
|
import { set } from '@ember/object';
|
2020-08-28 16:19:46 -07:00
|
|
|
// @ts-ignore: Ignore import of compiled template
|
|
|
|
import template from '../../templates/components/nacho/nacho-tab-cacher';
|
2019-08-31 20:51:14 -07:00
|
|
|
/**
|
|
|
|
* This component will lazy load when demanded its content. Lazy load means that it will not yield
|
|
|
|
* until currentTab === id. Once that happens, content won't be deleted or rerendered
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* lazyLoad: boolean ()
|
|
|
|
* currentTab: string (actual string value of the selected current tab's id)
|
|
|
|
* id: string (this tab id)
|
|
|
|
*
|
|
|
|
*/
|
2020-08-28 16:19:46 -07:00
|
|
|
@layout(template)
|
2019-08-31 20:51:14 -07:00
|
|
|
@tagName('')
|
|
|
|
export default class NachoTabPager extends Component {
|
|
|
|
/**
|
|
|
|
* if you want lazy load behavior
|
|
|
|
*/
|
2020-08-28 16:19:46 -07:00
|
|
|
lazyLoad?: boolean;
|
2019-08-31 20:51:14 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* actual string value of the selected current tab's id
|
|
|
|
*/
|
2020-08-28 16:19:46 -07:00
|
|
|
currentTab?: string;
|
2019-08-31 20:51:14 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* this tab id
|
|
|
|
*/
|
2020-08-28 16:19:46 -07:00
|
|
|
id?: string;
|
2019-08-31 20:51:14 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* internal flag to say whether this tab has been already rendered
|
|
|
|
*/
|
2020-08-28 16:19:46 -07:00
|
|
|
cached?: boolean;
|
2019-08-31 20:51:14 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook to check current tab and cache accondingly
|
|
|
|
*/
|
2020-08-28 16:19:46 -07:00
|
|
|
didReceiveAttrs(): void {
|
2019-08-31 20:51:14 -07:00
|
|
|
const { id, currentTab } = this;
|
|
|
|
if (id === currentTab) {
|
|
|
|
set(this, 'cached', true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|