This repository was archived by the owner on Mar 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathivy-tab-panel.js
161 lines (142 loc) · 3.94 KB
/
ivy-tab-panel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import Ember from 'ember';
/**
* @module ivy-tabs
*/
/**
* @class IvyTabPanelComponent
* @namespace IvyTabs
* @extends Ember.Component
*/
export default Ember.Component.extend({
attributeBindings: ['aria-labelledby', 'role'],
classNames: ['ivy-tab-panel'],
classNameBindings: ['active'],
init() {
this._super(...arguments);
Ember.run.once(this, this._registerWithTabsContainer);
},
willDestroy() {
this._super(...arguments);
Ember.run.once(this, this._unregisterWithTabsContainer);
},
/**
* Tells screenreaders which tab labels this panel.
*
* See http://www.w3.org/TR/wai-aria/states_and_properties#aria-labelledby
*
* @property aria-labelledby
* @type String
* @readOnly
*/
'aria-labelledby': Ember.computed.alias('tab.elementId').readOnly(),
/**
* See http://www.w3.org/TR/wai-aria/roles#tabpanel
*
* @property role
* @type String
* @default 'tabpanel'
*/
role: 'tabpanel',
/**
* Accessed as a className binding to apply the panel's `activeClass` CSS
* class to the element when the panel's `isSelected` property is true.
*
* @property active
* @type String
* @readOnly
*/
active: Ember.computed(function() {
if (this.get('isSelected')) { return this.get('activeClass'); }
}).property('isSelected'),
/**
* The CSS class to apply to a panel's element when its `isSelected` property
* is `true`.
*
* @property activeClass
* @type String
* @default 'active'
*/
activeClass: 'active',
/**
* The index of this panel in the `ivy-tabs` component.
*
* @property index
* @type Number
*/
index: Ember.computed(function() {
return this.get('tabPanels').indexOf(this);
}).property('tabPanels.[]'),
/**
* Whether or not this panel's associated tab is selected.
*
* @property isSelected
* @type Boolean
* @readOnly
*/
isSelected: Ember.computed.alias('tab.isSelected').readOnly(),
/**
* If `false`, this panel will appear hidden in the DOM. This is an alias to
* `isSelected`.
*
* @property isVisible
* @type Boolean
* @readOnly
*/
isVisible: Ember.computed.alias('isSelected').readOnly(),
/**
* The `ivy-tab` associated with this panel.
*
* @property tab
* @type IvyTabs.IvyTabComponent
*/
tab: Ember.computed(function() {
const tabs = this.get('tabs');
if (tabs) { return tabs.objectAt(this.get('index')); }
}).property('tabs.[]', 'index'),
/**
* The `ivy-tab-list` component this panel belongs to.
*
* @property tabList
* @type IvyTabs.IvyTabListComponent
* @readOnly
*/
tabList: Ember.computed.alias('tabsContainer.tabList').readOnly(),
/**
* The array of all `ivy-tab-panel` instances within the `ivy-tabs`
* component.
*
* @property tabPanels
* @type Array | IvyTabs.IvyTabPanelComponent
* @readOnly
*/
tabPanels: Ember.computed.alias('tabsContainer.tabPanels').readOnly(),
/**
* The array of all `ivy-tab` instances within the `ivy-tab-list` component.
*
* @property tabs
* @type Array | IvyTabs.IvyTabComponent
* @readOnly
*/
tabs: Ember.computed.alias('tabList.tabs').readOnly(),
_deprecatedParentViewBasedTabsContainer: Ember.computed('parentView', function() {
Ember.deprecate('Inferring `tabsContainer` from `parentView` on `{{ivy-tab-panel}}` is deprecated. Please assign in an instance of `{{ivy-tabs}}` to the `tabsContainer` property.', false, {
id: 'ivy-tabs.ivy-tab-panel.tabs-container-missing',
until: '2.0.0'
});
return this.get('parentView');
}).readOnly(),
/**
* The `ivy-tabs` component.
*
* @property tabsContainer
* @type IvyTabs.IvyTabsComponent
* @readOnly
*/
tabsContainer: Ember.computed.oneWay('_deprecatedParentViewBasedTabsContainer'),
_registerWithTabsContainer() {
this.get('tabsContainer').registerTabPanel(this);
},
_unregisterWithTabsContainer() {
this.get('tabsContainer').unregisterTabPanel(this);
}
});