Skip to content

Commit fe0217d

Browse files
authored
Merge pull request #457 from ember-learn/update-pagination
Make pagination work with multiline links + add arrow
2 parents de3f855 + a40a690 commit fe0217d

File tree

5 files changed

+68
-49
lines changed

5 files changed

+68
-49
lines changed

addon/components/es-pagination.hbs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<div class="pagination-wrapper">
2-
{{#if (has-block "previous")}}
2+
{{#if (and (has-block "previous") @showPrevious)}}
33
<div class="previous-wrapper">
4-
{{yield to='previous'}}
4+
<img alt="left arrow" src="/images/icons/arrow-icon.svg" />
5+
<div>{{yield to='previous'}}</div>
56
</div>
67
{{/if}}
78

8-
{{#if (has-block "next")}}
9+
{{#if (and (has-block "next") @showNext)}}
910
<div class="next-wrapper">
10-
{{yield to='next'}}
11+
<div>{{yield to='next'}}</div>
12+
<img alt="right arrow" src="/images/icons/arrow-icon.svg" />
1113
</div>
1214
{{/if}}
1315
</div>

addon/styles/components/es-pagination.css

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,36 @@
66
gap: 0px 40px;
77
grid-template-areas:
88
"previous next";
9+
margin: var(--spacing-1) 0;
910
& > .previous-wrapper{
1011
grid-area: previous;
11-
&::before {
12-
content: "\2039";
12+
& > img {
13+
transform: rotate(90deg);
1314
}
14-
15-
&:hover::before {
16-
transform: translateX(-0.5em);
17-
color: var(--color-link-hover);
15+
&:hover > img {
16+
transform: rotate(90deg) translateY(0.5em);
1817
}
1918
}
2019

2120
& > .next-wrapper {
2221
grid-area: next;
22+
justify-content: end;
2323
text-align: right;
24-
&::after {
25-
content: "\203A";
24+
& > img {
25+
transform: rotate(270deg);
2626
}
2727

28-
&:hover::after {
29-
transform: translateX(0.5em);
30-
color: var(--color-link-hover);
28+
&:hover > img {
29+
transform: rotate(270deg) translateY(0.5em);
3130
}
3231
}
3332

3433
& > .previous-wrapper, & > .next-wrapper {
35-
&::before,
36-
&::after {
37-
color: var(--color-link);
38-
display: inline-block;
39-
font-weight: 700;
34+
display: flex;
35+
align-items: center;
36+
& > img {
4037
margin: 0 0.5em;
4138
transition: transform 0.3s;
4239
}
4340
}
4441
}
45-
46-
47-
48-
.previous {
49-
&::before {
50-
content: "\2039";
51-
}
52-
53-
&:hover::before {
54-
transform: translateX(-0.5em);
55-
}
56-
}
57-
58-
.next {
59-
&::after {
60-
content: "\203A";
61-
}
62-
63-
&:hover::after {
64-
transform: translateX(0.5em);
65-
}
66-
}

docs/components/pagination.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Pagination
22

3-
Adds back and forth pagination, using `named blocks`. You insert your previous link into a `<:previous></:previous>` block and the next link into a `<:next></:next>` block. This will add the underline styling to the link and an animated arrow to your link.
3+
Adds back and forth pagination, using `named blocks`. You insert your previous link into a `<:previous></:previous>` block and the next link into a `<:next></:next>` block. This will add the underline styling to the link and an animated arrow to your link. You will use the `showPrevious` and `showNext` prop to make sure the correct links are visible.
44

55
## Usage
66

77
Add the following code to the template
88

99
```handlebars
10-
<EsPagination>
10+
<EsPagination @showPrevious={{true}} @showNext={{true}}>
1111
<:previous>
1212
<LinkTo @route="page" @model={{this.previousId}}>
1313
Newer articles
@@ -21,21 +21,32 @@ Add the following code to the template
2121
</EsPagination>
2222
```
2323

24-
The example below show what happens if you only provide the `previous` block when it's the last page you are on.
24+
To only show the previous you've to pass `false` to the `showNext` prop.
2525

2626
```handlebars
27-
<EsPagination>
27+
<EsPagination @showPrevious={{true}} @showNext={{false}}>
2828
<:previous>
2929
<LinkTo @route="page" @model={{this.previousId}}>
3030
Newer articles
3131
</LinkTo>
3232
</:previous>
33+
<:next>
34+
<LinkTo @route="page" @model={{this.nextId}}>
35+
Older articles
36+
</LinkTo>
37+
</:next>
3338
</EsPagination>
3439
```
35-
The example below show what happens if you only provide the `next` block when it's the first page you are on.
40+
41+
To only show the previous you've to pass `false` to the `showPrevious` prop.
3642

3743
```handlebars
38-
<EsPagination>
44+
<EsPagination @showPrevious={{false}} @showNext={{true}}>
45+
<:previous>
46+
<LinkTo @route="page" @model={{this.previousId}}>
47+
Newer articles
48+
</LinkTo>
49+
</:previous>
3950
<:next>
4051
<LinkTo @route="page" @model={{this.nextId}}>
4152
Older articles

public/images/icons/arrow-icon.svg

Lines changed: 1 addition & 0 deletions
Loading

tests/integration/components/es-pagination-test.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module('Integration | Component | es-pagination', function (hooks) {
88

99
test('it renders', async function (assert) {
1010
await render(hbs`
11-
<EsPagination>
11+
<EsPagination @showPrevious={{true}} @showNext={{true}}>
1212
<:previous>
1313
Newer articles
1414
</:previous>
@@ -20,4 +20,34 @@ module('Integration | Component | es-pagination', function (hooks) {
2020

2121
assert.dom(this.element).hasText('Newer articles Older articles');
2222
});
23+
test('it renders only previous', async function (assert) {
24+
await render(hbs`
25+
<EsPagination @showPrevious={{true}} @showNext={{false}}>
26+
<:previous>
27+
Newer articles
28+
</:previous>
29+
<:next>
30+
Older articles
31+
</:next>
32+
</EsPagination>
33+
`);
34+
35+
assert.dom(this.element).hasText('Newer articles');
36+
assert.dom(this.element).doesNotIncludeText('Older articles');
37+
});
38+
test('it renders only next', async function (assert) {
39+
await render(hbs`
40+
<EsPagination @showPrevious={{false}} @showNext={{true}}>
41+
<:previous>
42+
Newer articles
43+
</:previous>
44+
<:next>
45+
Older articles
46+
</:next>
47+
</EsPagination>
48+
`);
49+
50+
assert.dom(this.element).hasText('Older articles');
51+
assert.dom(this.element).doesNotIncludeText('Newer articles');
52+
});
2353
});

0 commit comments

Comments
 (0)