2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
const {Component} = Ember;
|
|
|
|
|
2014-09-15 04:40:24 +04:00
|
|
|
/**
|
|
|
|
Heavily inspired by ic-tabs (https://github.com/instructure/ic-tabs)
|
|
|
|
|
|
|
|
Three components work together for smooth tabbing.
|
|
|
|
1. tabs-manager (gh-tabs)
|
|
|
|
2. tab (gh-tab)
|
|
|
|
3. tab-pane (gh-tab-pane)
|
|
|
|
|
|
|
|
## Usage:
|
|
|
|
The tabs-manager must wrap all tab and tab-pane components,
|
|
|
|
but they can be nested at any level.
|
|
|
|
|
|
|
|
A tab and its pane are tied together via their order.
|
|
|
|
So, the second tab within a tab manager will activate
|
|
|
|
the second pane within that manager.
|
|
|
|
|
|
|
|
```hbs
|
|
|
|
{{#gh-tabs-manager}}
|
|
|
|
{{#gh-tab}}
|
|
|
|
First tab
|
|
|
|
{{/gh-tab}}
|
|
|
|
{{#gh-tab}}
|
|
|
|
Second tab
|
|
|
|
{{/gh-tab}}
|
|
|
|
|
|
|
|
....
|
|
|
|
{{#gh-tab-pane}}
|
|
|
|
First pane
|
|
|
|
{{/gh-tab-pane}}
|
|
|
|
{{#gh-tab-pane}}
|
|
|
|
Second pane
|
|
|
|
{{/gh-tab-pane}}
|
|
|
|
{{/gh-tabs-manager}}
|
|
|
|
```
|
|
|
|
## Options:
|
|
|
|
|
|
|
|
the tabs-manager will send a "selected" action whenever one of its
|
|
|
|
tabs is clicked.
|
|
|
|
```hbs
|
|
|
|
{{#gh-tabs-manager selected="myAction"}}
|
|
|
|
....
|
|
|
|
{{/gh-tabs-manager}}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Styling:
|
|
|
|
Both tab and tab-pane elements have an "active"
|
|
|
|
class applied when they are active.
|
|
|
|
|
|
|
|
*/
|
2015-10-28 14:36:45 +03:00
|
|
|
export default Component.extend({
|
2014-09-15 04:40:24 +04:00
|
|
|
activeTab: null,
|
|
|
|
tabs: [],
|
|
|
|
tabPanes: [],
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
// Used by children to find this tabsManager
|
|
|
|
isTabsManager: true,
|
|
|
|
|
2014-09-15 04:40:24 +04:00
|
|
|
// Called when a gh-tab is clicked.
|
2015-10-28 14:36:45 +03:00
|
|
|
select(tab) {
|
2014-09-15 04:40:24 +04:00
|
|
|
this.set('activeTab', tab);
|
|
|
|
this.sendAction('selected');
|
|
|
|
},
|
|
|
|
|
|
|
|
// Register tabs and their panes to allow for
|
|
|
|
// interaction between components.
|
2015-10-28 14:36:45 +03:00
|
|
|
registerTab(tab) {
|
2014-09-15 04:40:24 +04:00
|
|
|
this.get('tabs').addObject(tab);
|
|
|
|
},
|
2014-10-25 01:09:50 +04:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
unregisterTab(tab) {
|
2014-09-15 04:40:24 +04:00
|
|
|
this.get('tabs').removeObject(tab);
|
|
|
|
},
|
2014-10-25 01:09:50 +04:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
registerTabPane(tabPane) {
|
2014-09-15 04:40:24 +04:00
|
|
|
this.get('tabPanes').addObject(tabPane);
|
|
|
|
},
|
2014-10-25 01:09:50 +04:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
unregisterTabPane(tabPane) {
|
2014-09-15 04:40:24 +04:00
|
|
|
this.get('tabPanes').removeObject(tabPane);
|
|
|
|
}
|
|
|
|
});
|