Skip to content
This repository was archived by the owner on Mar 12, 2024. It is now read-only.

Commit 504297e

Browse files
committed
Merge pull request #3 from IvyApp/block-parameters
Use block parameters instead of `parentView`
2 parents aadc121 + e5c933b commit 504297e

26 files changed

+223
-197
lines changed

.npmignore

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
bower_components/
2-
tests/
3-
tmp/
4-
dist/
5-
1+
/bower_components
2+
/config/ember-try.js
3+
/dist
4+
/tests
5+
/tmp
6+
**/.gitkeep
67
.bowerrc
78
.editorconfig
89
.ember-cli
10+
.gitignore
11+
.jshintrc
12+
.watchmanconfig
913
.travis.yml
10-
.npmignore
11-
**/.gitkeep
1214
bower.json
13-
Brocfile.js
14-
testem.json
15+
ember-cli-build.js
16+
testem.js

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ cache:
1111

1212
env:
1313
- EMBER_TRY_SCENARIO=default
14+
- EMBER_TRY_SCENARIO=ember-1-13
1415
- EMBER_TRY_SCENARIO=ember-release
1516
- EMBER_TRY_SCENARIO=ember-beta
1617
- EMBER_TRY_SCENARIO=ember-canary

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 Envy Labs, LLC.
3+
Copyright (c) 2016 Envy Labs, LLC.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

README.md

+12-16
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,29 @@ Special thanks to [ic-tabs], which this addon is based on.
88

99
## Installation
1010

11-
### As an Ember CLI addon
12-
13-
Use this addon in your ember-cli application:
14-
1511
```sh
16-
npm install --save-dev IvyApp/ivy-tabs
12+
$ ember install ivy-tabs
1713
```
1814

1915
## Usage
2016

2117
```handlebars
22-
{{#ivy-tabs}}
23-
{{#ivy-tab-list}}
24-
{{#ivy-tab}}Foo{{/ivy-tab}}
25-
{{#ivy-tab}}Bar{{/ivy-tab}}
26-
{{#ivy-tab}}Baz{{/ivy-tab}}
18+
{{#ivy-tabs as |tabsContainer|}}
19+
{{#ivy-tab-list tabsContainer=tabsContainer as |tabList|}}
20+
{{#ivy-tab tabList=tabList}}Foo{{/ivy-tab}}
21+
{{#ivy-tab tabList=tabList}}Bar{{/ivy-tab}}
22+
{{#ivy-tab tabList=tabList}}Baz{{/ivy-tab}}
2723
{{/ivy-tab-list}}
2824
29-
{{#ivy-tab-panel}}
25+
{{#ivy-tab-panel tabsContainer=tabsContainer}}
3026
<h2>Foo</h2>
3127
{{/ivy-tab-panel}}
3228
33-
{{#ivy-tab-panel}}
29+
{{#ivy-tab-panel tabsContainer=tabsContainer}}
3430
<h2>Bar</h2>
3531
{{/ivy-tab-panel}}
3632
37-
{{#ivy-tab-panel}}
33+
{{#ivy-tab-panel tabsContainer=tabsContainer}}
3834
<h2>Baz</h2>
3935
{{/ivy-tab-panel}}
4036
{{/ivy-tabs}}
@@ -43,9 +39,9 @@ npm install --save-dev IvyApp/ivy-tabs
4339
Some things to note:
4440

4541
* Associations between tabs and tab-panes are inferred by order.
46-
* `ivy-tab-list` must be an immediate child of `ivy-tabs`.
47-
* `ivy-tab` must be an immediate child of `ivy-tab-list`.
48-
* `ivy-tab-panel` must be an immediate child of `ivy-tabs`.
42+
* Both `ivy-tabs` and `ivy-tab-list` yield themselves as a parameter, which
43+
should be passed down to their children as `tabsContainer` and `tabList`,
44+
respectively.
4945

5046
## Contributing
5147

addon/components/ivy-tab-list.js

+32-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Ember from 'ember';
2+
import layout from '../templates/components/ivy-tab-list';
23

34
/**
45
* @module ivy-tabs
@@ -10,17 +11,19 @@ import Ember from 'ember';
1011
* @extends Ember.Component
1112
*/
1213
export default Ember.Component.extend({
14+
layout: layout,
15+
1316
tagName: 'ul',
1417
attributeBindings: ['aria-multiselectable', 'role'],
1518
classNames: ['ivy-tab-list'],
1619

17-
init: function() {
18-
this._super();
20+
init() {
21+
this._super(...arguments);
1922
Ember.run.once(this, this._registerWithTabsContainer);
2023
},
2124

22-
willDestroy: function() {
23-
this._super();
25+
willDestroy() {
26+
this._super(...arguments);
2427
Ember.run.once(this, this._unregisterWithTabsContainer);
2528
},
2629

@@ -49,7 +52,7 @@ export default Ember.Component.extend({
4952
*
5053
* @method focusSelectedTab
5154
*/
52-
focusSelectedTab: function() {
55+
focusSelectedTab() {
5356
this.get('selectedTab').$().focus();
5457
},
5558

@@ -85,7 +88,7 @@ export default Ember.Component.extend({
8588
* @method registerTab
8689
* @param {IvyTabs.IvyTabComponent} tab
8790
*/
88-
registerTab: function(tab) {
91+
registerTab(tab) {
8992
this.get('tabs').pushObject(tab);
9093
},
9194

@@ -94,8 +97,8 @@ export default Ember.Component.extend({
9497
*
9598
* @method selectNextTab
9699
*/
97-
selectNextTab: function() {
98-
var index = this.get('selected-index') + 1;
100+
selectNextTab() {
101+
let index = this.get('selected-index') + 1;
99102
if (index === this.get('tabs.length')) { index = 0; }
100103
this.selectTabByIndex(index);
101104
},
@@ -105,8 +108,8 @@ export default Ember.Component.extend({
105108
*
106109
* @method selectPreviousTab
107110
*/
108-
selectPreviousTab: function() {
109-
var index = this.get('selected-index') - 1;
111+
selectPreviousTab() {
112+
let index = this.get('selected-index') - 1;
110113

111114
// Previous from the first tab should select the last tab.
112115
if (index < 0) { index = this.get('tabs.length') - 1; }
@@ -134,7 +137,7 @@ export default Ember.Component.extend({
134137
* @method selectTab
135138
* @param {IvyTabs.IvyTabComponent} tab
136139
*/
137-
selectTab: function(tab) {
140+
selectTab(tab) {
138141
this.selectTabByIndex(this.get('tabs').indexOf(tab));
139142
},
140143

@@ -144,27 +147,39 @@ export default Ember.Component.extend({
144147
* @method selectTabByIndex
145148
* @param {Number} index
146149
*/
147-
selectTabByIndex: function(index) {
150+
selectTabByIndex(index) {
148151
this.set('selected-index', index);
149152
},
150153

154+
tabs: Ember.computed(function() {
155+
return Ember.A();
156+
}).readOnly(),
157+
158+
_deprecatedParentViewBasedTabsContainer: Ember.computed('parentView', function() {
159+
Ember.deprecate('Inferring `tabsContainer` from `parentView` on `{{ivy-tab-list}}` is deprecated. Please assign in an instance of `{{ivy-tabs}}` to the `tabsContainer` property.', false, {
160+
id: 'ivy-tabs.ivy-tab-list.tabs-container-missing',
161+
until: '2.0.0'
162+
});
163+
return this.get('parentView');
164+
}).readOnly(),
165+
151166
/**
152167
* The `ivy-tabs` component.
153168
*
154169
* @property tabsContainer
155170
* @type IvyTabs.IvyTabsComponent
156171
* @readOnly
157172
*/
158-
tabsContainer: Ember.computed.alias('parentView').readOnly(),
173+
tabsContainer: Ember.computed.oneWay('_deprecatedParentViewBasedTabsContainer'),
159174

160175
/**
161176
* Removes a tab from the `tabs` array.
162177
*
163178
* @method unregisterTab
164179
* @param {IvyTabs.IvyTabComponent} tab
165180
*/
166-
unregisterTab: function(tab) {
167-
var index = tab.get('index');
181+
unregisterTab(tab) {
182+
const index = tab.get('index');
168183
this.get('tabs').removeObject(tab);
169184

170185
if (index < this.get('selected-index')) {
@@ -176,15 +191,11 @@ export default Ember.Component.extend({
176191
}
177192
},
178193

179-
_initTabs: Ember.on('init', function() {
180-
this.set('tabs', Ember.A());
181-
}),
182-
183-
_registerWithTabsContainer: function() {
194+
_registerWithTabsContainer() {
184195
this.get('tabsContainer').registerTabList(this);
185196
},
186197

187-
_unregisterWithTabsContainer: function() {
198+
_unregisterWithTabsContainer() {
188199
this.get('tabsContainer').unregisterTabList(this);
189200
}
190201
});

addon/components/ivy-tab-panel.js

+16-8
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ export default Ember.Component.extend({
1414
classNames: ['ivy-tab-panel'],
1515
classNameBindings: ['active'],
1616

17-
init: function() {
18-
this._super();
17+
init() {
18+
this._super(...arguments);
1919
Ember.run.once(this, this._registerWithTabsContainer);
2020
},
2121

22-
willDestroy: function() {
23-
this._super();
22+
willDestroy() {
23+
this._super(...arguments);
2424
Ember.run.once(this, this._unregisterWithTabsContainer);
2525
},
2626

@@ -102,7 +102,7 @@ export default Ember.Component.extend({
102102
* @type IvyTabs.IvyTabComponent
103103
*/
104104
tab: Ember.computed(function() {
105-
var tabs = this.get('tabs');
105+
const tabs = this.get('tabs');
106106
if (tabs) { return tabs.objectAt(this.get('index')); }
107107
}).property('tabs.[]', 'index'),
108108

@@ -134,20 +134,28 @@ export default Ember.Component.extend({
134134
*/
135135
tabs: Ember.computed.alias('tabList.tabs').readOnly(),
136136

137+
_deprecatedParentViewBasedTabsContainer: Ember.computed('parentView', function() {
138+
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, {
139+
id: 'ivy-tabs.ivy-tab-panel.tabs-container-missing',
140+
until: '2.0.0'
141+
});
142+
return this.get('parentView');
143+
}).readOnly(),
144+
137145
/**
138146
* The `ivy-tabs` component.
139147
*
140148
* @property tabsContainer
141149
* @type IvyTabs.IvyTabsComponent
142150
* @readOnly
143151
*/
144-
tabsContainer: Ember.computed.alias('parentView').readOnly(),
152+
tabsContainer: Ember.computed.oneWay('_deprecatedParentViewBasedTabsContainer'),
145153

146-
_registerWithTabsContainer: function() {
154+
_registerWithTabsContainer() {
147155
this.get('tabsContainer').registerTabPanel(this);
148156
},
149157

150-
_unregisterWithTabsContainer: function() {
158+
_unregisterWithTabsContainer() {
151159
this.get('tabsContainer').unregisterTabPanel(this);
152160
}
153161
});

addon/components/ivy-tab.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ export default Ember.Component.extend({
1515
classNames: ['ivy-tab'],
1616
classNameBindings: ['active'],
1717

18-
init: function() {
19-
this._super();
18+
init() {
19+
this._super(...arguments);
2020
Ember.run.once(this, this._registerWithTabList);
2121
},
2222

23-
willDestroy: function() {
24-
this._super();
23+
willDestroy() {
24+
this._super(...arguments);
2525
Ember.run.once(this, this._unregisterWithTabList);
2626
},
2727

@@ -144,14 +144,22 @@ export default Ember.Component.extend({
144144
this.get('tabList').selectTab(this);
145145
}),
146146

147+
_deprecatedParentViewBasedTabList: Ember.computed('parentView', function() {
148+
Ember.deprecate('Inferring `tabList` from `parentView` on `{{ivy-tab}}` is deprecated. Please assign in an instance of `{{ivy-tab-list}}` to the `tabList` property.', false, {
149+
id: 'ivy-tabs.ivy-tab.tab-list-missing',
150+
until: '2.0.0'
151+
});
152+
return this.get('parentView');
153+
}).readOnly(),
154+
147155
/**
148156
* The `ivy-tab-list` component this tab belongs to.
149157
*
150158
* @property tabList
151159
* @type IvyTabs.IvyTabListComponent
152160
* @readOnly
153161
*/
154-
tabList: Ember.computed.alias('parentView').readOnly(),
162+
tabList: Ember.computed.oneWay('_deprecatedParentViewBasedTabList'),
155163

156164
/**
157165
* The `ivy-tab-panel` associated with this tab.
@@ -191,11 +199,11 @@ export default Ember.Component.extend({
191199
*/
192200
tabsContainer: Ember.computed.alias('tabList.tabsContainer').readOnly(),
193201

194-
_registerWithTabList: function() {
202+
_registerWithTabList() {
195203
this.get('tabList').registerTab(this);
196204
},
197205

198-
_unregisterWithTabList: function() {
206+
_unregisterWithTabList() {
199207
this.get('tabList').unregisterTab(this);
200208
}
201209
});

0 commit comments

Comments
 (0)