Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task #227 - Pagination component #831

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions blocks/init/src/Blocks/components/pagination/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://raw.githubusercontent.com/infinum/eightshift-frontend-libs/develop/schemas/component.json",
"componentName": "pagination",
"title": "Pagination",
"componentClass": "pagination",
"components": {
"icon": "icon"
}
}
54 changes: 54 additions & 0 deletions blocks/init/src/Blocks/components/pagination/pagination-style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
.pagination {
--pagination-scoped-radius-size: calc(var(--base-font-size) * 2.7rem);
--pagination-scoped-color: var(--global-colors-black);
--pagination-scoped-background-color: transparent;

display: flex;
align-items: center;
justify-content: space-between;

@include media(tablet up) {
justify-content: center;
}

> * {
margin: 0 calc(var(--base-font-size) * 0.5rem);
font-size: calc(var(--base-font-size) * 1.7rem);
line-height: 1.5;
color: var(--pagination-scoped-color);
transition: color 0.3s ease-out;

span {
width: var(--pagination-scoped-radius-size);
height: var(--pagination-scoped-radius-size);
border-radius: calc(var(--base-font-size) * 0.4rem);
display: flex;
align-items: center;
justify-content: center;
background-color: var(--pagination-scoped-background-color);
}
}

&__prev {
.icon{
transform: rotate(180deg);
}
}

&__link{
text-decoration: none;

&:hover {
color: var(--global-colors-primary700);
}
}

.current {
color: var(--global-colors-white);

span {
--pagination-scoped-background-color: var(--global-colors-primary500);
--pagination-scoped-color: var(--global-colors-white);
}
}
}
53 changes: 53 additions & 0 deletions blocks/init/src/Blocks/components/pagination/pagination.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/**
* Template for the Pagination Component.
*
* @package %g_namespace%
*/

use %g_namespace_vendor_prefix%\EightshiftLibs\Helpers\Helpers;

$manifest = Helpers::getManifestByDir(__DIR__);

$componentClass = $manifest['componentClass'] ?? '';
$additionalClass = $attributes['additionalClass'] ?? '';
$blockClass = $attributes['blockClass'] ?? '';
$selectorClass = $attributes['selectorClass'] ?? $componentClass;

$paginationClass = Helpers::classnames([
$componentClass,
Helpers::selector($blockClass, $blockClass, $selectorClass),
$additionalClass
]);

$paginationPrevClass = Helpers::selector($componentClass, $componentClass, 'prev');
$paginationNextClass = Helpers::selector($componentClass, $componentClass, 'next');
$paginationLinkClass = Helpers::selector($componentClass, $componentClass, 'link');

$icon = Helpers::render(
'icon',
Helpers::props('icon', $attributes, [
'blockClass' => $componentClass,
'selectorClass' => 'icon',
])
);
?>

<div class="<?php echo esc_attr($paginationClass); ?>">
<?php
$pagination_links = paginate_links(
[
'before_page_number' => '<span>',
'after_page_number' => '</span>',
'prev_text' => '<span class="' . $paginationPrevClass . '" aria-label = ' . __('Previous', '%g_textdomain%') . '>' . $icon . '</span>',
'next_text' => '<span class="' . $paginationNextClass . '"aria-label = ' . __('Next', '%g_textdomain%') . '>' . $icon . '</span>',
]
);

// Add custom css classes.
$pagination_links = str_replace('<a', '<a class="' . $paginationLinkClass . '"', $pagination_links);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a no no, as this could possibly break something. If you need to add custom selectors you can use type='array' and create your own layout but this is an overkill so adding a CSS selector to a I fine in this application

https://developer.wordpress.org/reference/functions/paginate_links/


echo $pagination_links;
?>
</div>
Loading