Skip to content

Commit

Permalink
feat(nav): add nav components
Browse files Browse the repository at this point in the history
  • Loading branch information
velrest committed Jun 30, 2020
1 parent 490ead0 commit 066f867
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 0 deletions.
5 changes: 5 additions & 0 deletions addon/components/nav.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ul
class="uk-subnav uk-subnav-divider uk-subnav-pill uk-width-1 uk-child-width-1-4 uk-text-center uk-padding-small uk-padding-remove-horizontal"
>
{{yield}}
</ul>
5 changes: 5 additions & 0 deletions addon/components/nav/item.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<li class="uk-child-width-1-1 {{if this.isActive 'uk-active'}}" ...attributes>
<LinkTo @route={{@route}}>
{{yield}}
</LinkTo>
</li>
10 changes: 10 additions & 0 deletions addon/components/nav/item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { inject as service } from "@ember/service";
import Component from "@glimmer/component";

export default class NavItemComponent extends Component {
@service router;

get isActive() {
return this.router.currentRoute.name.includes(this.args.route);
}
}
1 change: 1 addition & 0 deletions app/components/nav.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "ember-emeis/components/nav";
1 change: 1 addition & 0 deletions app/components/nav/item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "ember-emeis/components/nav/item";
19 changes: 19 additions & 0 deletions tests/integration/components/nav-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars";
import { setupRenderingTest } from "ember-qunit";
import { module, test } from "qunit";

module("Integration | Component | nav", function (hooks) {
setupRenderingTest(hooks);

test("it renders", async function (assert) {
await render(hbs`
<Nav>
<li>Nav 1</li>
<li>Nav 2</li>
</Nav>
`);

assert.dom("ul li").exists({ count: 2 });
});
});
28 changes: 28 additions & 0 deletions tests/integration/components/nav/item-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars";
import { setupRenderingTest } from "ember-qunit";
import { module, test } from "qunit";

module("Integration | Component | nav/item", function (hooks) {
setupRenderingTest(hooks);

test("it renders", async function (assert) {
this.set("route", "test");

this.set("router", this.owner.lookup("router:main"));
this.set("router.currentRoute", { name: "someotherroute" });

await render(hbs`
<Nav::Item @route={{this.route}}>
Test
</Nav::Item>
`);

assert.dom("li").doesNotHaveClass("uk-active");
assert.dom("li a").hasText("Test");

this.set("router.currentRoute", { name: "some.test" });

assert.dom("li").hasClass("uk-active");
});
});

0 comments on commit 066f867

Please sign in to comment.