mirror of
https://github.com/status-im/consul.git
synced 2025-01-09 21:35:52 +00:00
Move javascript tab class to tab-nav
This commit is contained in:
parent
a8b44eb6e2
commit
3559549db7
@ -1,31 +1,7 @@
|
|||||||
import Component from '@glimmer/component';
|
import Component from '@glimmer/component';
|
||||||
import { tracked } from '@glimmer/tracking';
|
|
||||||
import { hrefTo } from 'consul-ui/helpers/href-to';
|
|
||||||
import { inject as service } from '@ember/service';
|
import { inject as service } from '@ember/service';
|
||||||
import { getOwner } from '@ember/application';
|
import { getOwner } from '@ember/application';
|
||||||
|
import { Tab } from 'consul-ui/components/tab-nav';
|
||||||
class PeerTab {
|
|
||||||
@tracked route;
|
|
||||||
@tracked label;
|
|
||||||
@tracked currentRouteName;
|
|
||||||
|
|
||||||
constructor(opts) {
|
|
||||||
const { currentRouteName, route, label, owner } = opts;
|
|
||||||
|
|
||||||
this.currentRouteName = currentRouteName;
|
|
||||||
this.owner = owner;
|
|
||||||
this.route = route;
|
|
||||||
this.label = label;
|
|
||||||
}
|
|
||||||
|
|
||||||
get selected() {
|
|
||||||
return this.currentRouteName === this.route;
|
|
||||||
}
|
|
||||||
|
|
||||||
get href() {
|
|
||||||
return hrefTo(this.owner, [this.route]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class PeeringsProvider extends Component {
|
export default class PeeringsProvider extends Component {
|
||||||
@service router;
|
@service router;
|
||||||
@ -56,8 +32,6 @@ export default class PeeringsProvider extends Component {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return tabs.map(
|
return tabs.map((tab) => new Tab({ ...tab, currentRouteName: router.currentRouteName, owner }));
|
||||||
(tab) => new PeerTab({ ...tab, currentRouteName: router.currentRouteName, owner })
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,74 @@
|
|||||||
import Component from '@glimmer/component';
|
import Component from '@glimmer/component';
|
||||||
|
import { tracked } from '@glimmer/tracking';
|
||||||
|
import { hrefTo } from 'consul-ui/helpers/href-to';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class that encapsulates the data abstraction that we expect the TabNav to
|
||||||
|
* be passed as `@items`.
|
||||||
|
*
|
||||||
|
* You can use this class when you want to create tab-nav from javascript.
|
||||||
|
*
|
||||||
|
* Instead of doing this in the template layer:
|
||||||
|
*
|
||||||
|
* ```handlebars
|
||||||
|
* <TabNav @items={{array
|
||||||
|
* (hash
|
||||||
|
* label="First Tab"
|
||||||
|
* href=(href-to "some.route")
|
||||||
|
* selected=(is-href "some.route")
|
||||||
|
* )
|
||||||
|
* (hash
|
||||||
|
* label="Second Tab"
|
||||||
|
* href=(href-to "some.route")
|
||||||
|
* selected=(is-href "some.route")
|
||||||
|
* )
|
||||||
|
* }}
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* You can do the following in a js-file:
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* export default class WootComponent extends Component {
|
||||||
|
* // ...
|
||||||
|
* get tabs() {
|
||||||
|
* const { router } = this;
|
||||||
|
* const owner = getOwner(this);
|
||||||
|
* return [
|
||||||
|
* new Tab({
|
||||||
|
* label: 'First Tab',
|
||||||
|
* route: 'some.route',
|
||||||
|
* currentRouteName: router.currentRouteName,
|
||||||
|
* owner
|
||||||
|
* }),
|
||||||
|
* // ...
|
||||||
|
* ];
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export class Tab {
|
||||||
|
@tracked route;
|
||||||
|
@tracked label;
|
||||||
|
@tracked currentRouteName;
|
||||||
|
|
||||||
|
constructor(opts) {
|
||||||
|
const { currentRouteName, route, label, owner } = opts;
|
||||||
|
|
||||||
|
this.currentRouteName = currentRouteName;
|
||||||
|
this.owner = owner;
|
||||||
|
this.route = route;
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
get selected() {
|
||||||
|
return this.currentRouteName === this.route;
|
||||||
|
}
|
||||||
|
|
||||||
|
get href() {
|
||||||
|
return hrefTo(this.owner, [this.route]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function noop() {}
|
function noop() {}
|
||||||
export default class TabNav extends Component {
|
export default class TabNav extends Component {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user