-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add PixNavigationButton and PixNavigationSeparator
- Loading branch information
Showing
10 changed files
with
220 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{{#if @route}} | ||
<LinkTo | ||
@route={{@route}} | ||
@models={{if @model (array @model) this.defaultModel}} | ||
@query={{if @query @query this.defaultParams}} | ||
class="pix-navigation-button" | ||
...attributes | ||
> | ||
{{#if @icon}} | ||
<PixIcon | ||
class="pix-navigation-button__icon" | ||
@ariaHidden={{true}} | ||
@name={{@icon}} | ||
@plainIcon={{@iconPlain}} | ||
/> | ||
{{/if}} | ||
{{yield}} | ||
</LinkTo> | ||
{{else}} | ||
{{! template-lint-disable link-href-attributes }} | ||
<a ...attributes class="pix-navigation-button" target={{if this.isLinkOpenInANewWindow "_blank"}}> | ||
{{#if @icon}} | ||
<PixIcon | ||
class="pix-navigation-button__icon" | ||
@ariaHidden={{true}} | ||
@name={{@icon}} | ||
@plainIcon={{@iconPlain}} | ||
/> | ||
{{/if}} | ||
{{yield}} | ||
{{#if this.isLinkOpenInANewWindow}} | ||
<PixIcon class="pix-navigation-button__external-icon" @ariaHidden={{true}} @name="openNew" /> | ||
{{/if}} | ||
</a> | ||
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Component from '@glimmer/component'; | ||
|
||
export default class PixNavigationButton extends Component { | ||
defaultParams = {}; | ||
defaultModel = []; | ||
|
||
get isLinkOpenInANewWindow() { | ||
return this.args?.target === '_blank'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<hr class="pix-navigation-separator" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
.pix-navigation-button { | ||
@extend %pix-body-s; | ||
|
||
--pix-navigation-button-bgcolor: var(--pix-neutral-100); | ||
|
||
position: relative; | ||
display: flex; | ||
gap: var(--pix-spacing-2x); | ||
align-items: center; | ||
width: max-content; | ||
width: 100%; | ||
padding: var(--pix-spacing-2x) var(--pix-spacing-3x); | ||
fill: var(--pix-navigation-button-bgcolor); | ||
|
||
&:focus::before, | ||
&:focus-visible::before, | ||
&.active::before, | ||
&:hover::before { | ||
position: absolute; | ||
top:0; | ||
left: 0; | ||
z-index: -1; | ||
width: 100%; | ||
height: 100%; | ||
background-color: currentcolor; | ||
border-radius: var(--pix-spacing-2x); | ||
content: ''; | ||
} | ||
|
||
&:hover::before { | ||
opacity: .3; | ||
} | ||
|
||
&:focus, &:focus-visible { | ||
border-radius: var(--pix-spacing-2x); | ||
outline: 1px solid currentcolor ; | ||
|
||
&::before{ | ||
opacity: .3; | ||
} | ||
} | ||
|
||
&:active::before { | ||
opacity: .5; | ||
} | ||
|
||
&.active::before { | ||
opacity: .2; | ||
} | ||
|
||
&.active { | ||
font-weight: var(--pix-font-bold); | ||
} | ||
|
||
} | ||
|
||
.pix-navigation-button__external-icon { | ||
width: 1rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.pix-navigation-separator { | ||
@extend %pix-body-l; | ||
|
||
margin: 0; | ||
height: 1.25rem; | ||
color: inherit; | ||
border: none; | ||
line-height: 1.25rem; | ||
&::after { | ||
content: '–'; | ||
font-weight: var(--pix-font-medium); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from '@1024pix/pix-ui/components/pix-navigation-button'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from '@1024pix/pix-ui/components/pix-navigation-separator'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
tests/integration/components/pix-navigation-button-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render, within } from '@1024pix/ember-testing-library'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
|
||
module('Integration | Component | pix-navigation-button', function (hooks) { | ||
setupRenderingTest(hooks); | ||
hooks.beforeEach(function () { | ||
this.owner.setupRouter(); | ||
}); | ||
test('it renders an HTML link', async function (assert) { | ||
// when | ||
const screen = await render( | ||
hbs`<PixNavigationButton @href='https://pix.fr'>content</PixNavigationButton>`, | ||
); | ||
|
||
// then | ||
const link = screen.getByRole('link', { name: 'content' }); | ||
assert.strictEqual(link.getAttribute('href'), 'https://pix.fr'); | ||
}); | ||
|
||
test('it renders an HTML link in a new window', async function (assert) { | ||
// when | ||
const screen = await render( | ||
hbs`<PixNavigationButton | ||
@href='https://pix.fr' | ||
@title='pix.fr' | ||
@target='_blank' | ||
@newWindowLabel='nouvelle fenêtre' | ||
>content</PixNavigationButton>`, | ||
); | ||
|
||
// then | ||
const link = screen.getByRole('link', { name: 'content' }); | ||
assert.strictEqual(link.getAttribute('title'), 'pix.fr - nouvelle fenêtre'); | ||
}); | ||
|
||
test('it renders an EmberJS link', async function (assert) { | ||
// when | ||
const screen = await render( | ||
hbs`<PixNavigationButton @route='hello'>content</PixNavigationButton>`, | ||
); | ||
|
||
// then | ||
const link = screen.getByRole('link', { name: 'content' }); | ||
assert.strictEqual(link.getAttribute('href'), '/hello-world'); | ||
}); | ||
|
||
test('it renders an EmberJS link with model', async function (assert) { | ||
// when | ||
const screen = await render( | ||
hbs`<PixNavigationButton @route='bye' @model='bye'>content</PixNavigationButton>`, | ||
); | ||
|
||
// then | ||
const link = screen.getByRole('link', { name: 'content' }); | ||
assert.strictEqual(link.getAttribute('href'), '/bye/bye'); | ||
}); | ||
|
||
test('it renders an EmberJS link with model and query params', async function (assert) { | ||
// when | ||
const screen = await render( | ||
hbs`<PixNavigationButton | ||
@route='bye' | ||
@model='bye' | ||
@query={{hash page=3 per_page=20}} | ||
>content</PixNavigationButton>`, | ||
); | ||
|
||
// then | ||
const link = screen.getByRole('link', { name: 'content' }); | ||
assert.strictEqual(link.getAttribute('href'), '/bye/bye?page=3&per_page=20'); | ||
}); | ||
|
||
test('it renders an icon', async function (assert) { | ||
// when | ||
const screen = await render( | ||
hbs`<PixNavigationButton @route='hello' @icon='coversionPath'>content</PixNavigationButton>`, | ||
); | ||
|
||
// then | ||
const link = screen.getByRole('link', { name: 'content' }); | ||
assert.ok(within(link).getByRole('img', { hidden: true })); | ||
}); | ||
}); |