Skip to content

Commit

Permalink
Merge pull request #41 from emulsify-ds/feat-pager
Browse files Browse the repository at this point in the history
feat: Pager component: adding first and last and adding addAttributes
  • Loading branch information
mcortes19 authored Mar 14, 2023
2 parents aa21af8 + 0de459b commit 5899f8e
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 106 deletions.
65 changes: 20 additions & 45 deletions components/02-molecules/pager/_pager.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,66 +10,41 @@

.pager__item {
display: inline-block;
margin: 0 0.7em;
margin: 0 0.2em;

@include large {
margin: 0 1em;
margin: 0 0.5em;
}
}

.pager__link,
.pager__link:link,
.pager__link:visited {
.pager__link {
padding: 0.5em;
color: clr(text);
font-weight: 600;
text-decoration: none;

&.is-active,
&:hover {
color: clr(accent);
&:hover,
&:focus {
background-color: clr(text);
color: clr(text-inverse);
}
}

@mixin pager-link {
display: block;

span {
display: none;
}

&::before {
border: 8px solid clr(text);
border-bottom: 6px solid transparent;
border-right: 7px solid transparent;
border-top: 6px solid transparent;
content: '';
display: block;
position: relative;
top: 1px;
}

&:hover {
&::before {
border-left-color: clr(accent);
}
&.is-active:hover,
&.is-active:focus {
background-color: clr(accent);
}
}

.pager__link--next,
.pager__link--prev {
@include pager-link;
}

.pager__link--prev {
&::before {
border-left-color: transparent;
border-right-color: clr(text);
}
.pager__link--prev,
.pager__link--first,
.pager__link--last {
display: block;
padding: 0;

&:hover {
&::before {
border-left-color: transparent;
border-right-color: clr(accent);
}
&:hover,
&:focus {
background-color: transparent;
color: clr(accent);
}
}
24 changes: 11 additions & 13 deletions components/02-molecules/pager/pager-both-ellipses.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
pager__uid: 1
current: 5
ellipses:
previous: true
next: true
items:
previous:
href: '#'
attributes: ''
next:
href: '#'
attributes: ''
pages:
- href: '#'
attributes: ''
- href: '#'
attributes: ''
- href: '#'
attributes: ''
- href: '#'
attributes: ''
- href: '#'
attributes: ''
3:
href: '#'
4:
href: '#'
5:
href: '#'
6:
href: '#'
7:
href: '#'
19 changes: 0 additions & 19 deletions components/02-molecules/pager/pager-ellipses.yml

This file was deleted.

24 changes: 24 additions & 0 deletions components/02-molecules/pager/pager-first-last.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
current: 10
ellipses:
previous: true
next: true
items:
first:
href: '#'
last:
href: '#'
previous:
href: '#'
next:
href: '#'
pages:
9:
href: '#'
10:
href: '#'
11:
href: '#'
12:
href: '#'
13:
href: '#'
17 changes: 17 additions & 0 deletions components/02-molecules/pager/pager-next-ellipses.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
current: 5
ellipses:
next: true
items:
next:
href: '#'
pages:
1:
href: '#'
2:
href: '#'
3:
href: '#'
4:
href: '#'
5:
href: '#'
23 changes: 11 additions & 12 deletions components/02-molecules/pager/pager-prev-ellipses.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
pager__uid: 3
current: 8
ellipses:
previous: true
items:
previous:
href: '#'
attributes: ''
pages:
- href: '#'
attributes: ''
- href: '#'
attributes: ''
- href: '#'
attributes: ''
- href: '#'
attributes: ''
- href: '#'
attributes: ''
5:
href: '#'
6:
href: '#'
7:
href: '#'
8:
href: '#'
9:
href: '#'
8 changes: 6 additions & 2 deletions components/02-molecules/pager/pager.stories.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import pager from './pager.twig';

import pagerData from './pager.yml';
import pagerEllipsesData from './pager-ellipses.yml';
import pagerNextEllipsesData from './pager-next-ellipses.yml';
import pagerPrevEllipsesData from './pager-prev-ellipses.yml';
import pagerBothEllipsesData from './pager-both-ellipses.yml';
import pagerFirstLastData from './pager-first-last.yml';

/**
* Storybook Definition.
Expand All @@ -12,9 +13,12 @@ export default { title: 'Molecules/Menus/Pager' };

export const basic = () => pager(pagerData);

export const withNext = () => pager({ ...pagerData, ...pagerEllipsesData });
export const withNext = () => pager({ ...pagerData, ...pagerNextEllipsesData });

export const withBoth = () => pager({ ...pagerData, ...pagerBothEllipsesData });

export const withPrevious = () =>
pager({ ...pagerData, ...pagerPrevEllipsesData });

export const withFirstAndLast = () =>
pager({ ...pagerData, ...pagerFirstLastData });
31 changes: 28 additions & 3 deletions components/02-molecules/pager/pager.twig
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,24 @@
#}
{% set pager__base_class = 'pager' %}

{% set pager__attributes = pager__attributes|default({
'class': bem(pager__base_class, pager__modifiers, pager__blockname),
'aria-label': pagination_id|default('Pagination'|t),
'role': 'navigation'
}) %}

{% if items %}
<nav {{ bem(pager__base_class) }} aria-label="{{ pagination_id|default('Pagination'|t) }}">
<nav {{ add_attributes(pager__attributes) }}>
<ul {{ bem('items', [], pager__base_class, ['js-pager__items']) }}>
{# Print first item. #}
{% if items.first %}
<li {{ bem('item', ['first'], pager__base_class) }}>
<a {{ bem('link', ['first'], pager__base_class) }} href="{{ items.first.href }}" title="{{ 'Go to first page'|t }}" {{ items.first.attributes|without('href', 'title', 'rel') }}>
<span {{ bem('visually-hidden') }}>{{ 'First page'|t }}</span>
<span aria-hidden="true">{{ items.first.text|default('« First'|t) }}</span>
</a>
</li>
{% endif %}
{# Print previous item if we are not on the first page. #}
{% if items.previous %}
<li {{ bem('item', ['prev'], pager__base_class) }}>
Expand All @@ -49,10 +64,11 @@
{% endif %}
{# Now generate the actual pager piece. #}
{% for key, item in items.pages %}
{% set current_class = current == key ? ' is-active' : '' %}
{% set current_class = current == key ? 'is-active' : '' %}
{% set aria_current = current == key ? 'aria-current="page"' : '' %}
<li {{ bem('item', [], pager__base_class, [current_class]) }}>
{% set title = current == key ? 'Current page'|t : 'Go to page @key'|t({'@key': key}) %}
<a {{ bem('link', [], pager__base_class, [current_class]) }} href="{{ item.href }}" title="{{ title }}"{{ item.attributes|without('href', 'title') }}>
<a {{ bem('link', [], pager__base_class, [current_class]) }} href="{{ item.href }}" title="{{ title }}"{{ item.attributes|without('href', 'title') }} {{ aria_current }}>
<span {{ bem('visually-hidden') }}>
{{ current == key ? 'Current page'|t : 'Page '|t }}
</span>
Expand All @@ -73,6 +89,15 @@
</a>
</li>
{% endif %}
{# Print last item. #}
{% if items.last %}
<li {{ bem('item', ['last'], pager__base_class) }}>
<a {{ bem('link', ['last'], pager__base_class) }} href="{{ items.last.href }}" title="{{ 'Go to last page'|t }}" {{ items.last.attributes|without('href', 'title', 'rel') }}>
<span {{ bem('visually-hidden') }}>{{ 'Last page'|t }}</span>
<span aria-hidden="true">{{ items.last.text|default('Last »'|t) }}</span>
</a>
</li>
{% endif %}
</ul>
</nav>
{% endif %}
26 changes: 14 additions & 12 deletions components/02-molecules/pager/pager.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
pager__uid: 0
current: 1
current: 3
ellipses:
next: false
prev: false
items:
pages:
- href: '#'
attributes: ''
- href: '#'
attributes: ''
- href: '#'
attributes: ''
- href: '#'
attributes: ''
- href: '#'
attributes: ''
1:
href: '#'
2:
href: '#'
3:
href: '#'
4:
href: '#'
5:
href: '#'

0 comments on commit 5899f8e

Please sign in to comment.