Skip to content

Commit

Permalink
Add support for W3.CSS framework
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed Nov 1, 2022
1 parent 343c67f commit 8362e6d
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
'tailwind-short',
'tailwind3',
'tailwind3-short',
'w3',
'w3-short',
'w34',
'w34-short',
);
expectedArguments(
\Framework\Pagination\Pager::getView(),
Expand Down
1 change: 1 addition & 0 deletions guide/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ The Aplus Framework Pagination Library works with the following front-end framew
- `Primer <https://primer.style/>`_
- `Semantic UI <https://semantic-ui.com/>`_
- `Tailwind <https://tailwindcss.com/>`_
- `W3.CSS <https://www.w3schools.com/w3css/default.asp/>`_

Note that it is necessary to load links from CSS files.

Expand Down
5 changes: 5 additions & 0 deletions src/Pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ class Pager implements JsonSerializable
'tailwind-short' => __DIR__ . '/Views/tailwind-short.php',
'tailwind3' => __DIR__ . '/Views/tailwind.php',
'tailwind3-short' => __DIR__ . '/Views/tailwind-short.php',
// W3.CSS 4
'w3' => __DIR__ . '/Views/w3.php',
'w3-short' => __DIR__ . '/Views/w3-short.php',
'w34' => __DIR__ . '/Views/w3.php',
'w34-short' => __DIR__ . '/Views/w3-short.php',
];
protected string $defaultView = 'pagination';
protected URL $url;
Expand Down
29 changes: 29 additions & 0 deletions src/Views/w3-short.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/*
* This file is part of Aplus Framework Pagination Library.
*
* (c) Natan Felles <natanfelles@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* @var Framework\Pagination\Pager $pager
*/
$language = $pager->getLanguage();
?>
<div class="w3-center">
<div class="w3-bar">
<?php if ($pager->getPreviousPage()) : ?>
<a rel="prev" href="<?= $pager->getPreviousPageUrl() ?>" class="w3-button">
<?= $language->render('pagination', 'previous') ?>
</a>
<?php endif ?>

<?php if ($pager->getNextPage()) : ?>
<a rel="next" href="<?= $pager->getNextPageUrl() ?>" class="w3-button">
<?= $language->render('pagination', 'next') ?>
</a>
<?php endif ?>
</div>
</div>
51 changes: 51 additions & 0 deletions src/Views/w3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/*
* This file is part of Aplus Framework Pagination Library.
*
* (c) Natan Felles <natanfelles@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* @var Framework\Pagination\Pager $pager
*/
$language = $pager->getLanguage();
?>
<div class="w3-center">
<div class="w3-bar">
<?php if ($pager->getCurrentPage() - $pager->getSurround() > 1) : ?>
<a class="w3-button" href="<?= $pager->getFirstPageUrl() ?>"><?= $pager->getLanguage()
->render('pagination', 'first') ?></a>
<?php endif ?>

<?php if ($pager->getPreviousPage()) : ?>
<a class="w3-button" rel="prev" href="<?= $pager->getPreviousPageUrl() ?>" title="<?=
$language->render('pagination', 'previous') ?>">&laquo;</a>
<?php endif ?>

<?php foreach ($pager->getPreviousPagesUrls() as $p => $url) : ?>
<a href="<?= $url ?>" class="w3-button"><?= $p ?></a>
<?php endforeach ?>

<a href="<?= $pager->getCurrentPageUrl() ?>" rel="canonical" class="w3-button w3-blue w3-hover-blue">
<?= $pager->getCurrentPage() ?>
</a>

<?php foreach ($pager->getNextPagesUrls() as $p => $url) : ?>
<a href="<?= $url ?>" class="w3-button"><?= $p ?></a>
<?php endforeach ?>

<?php if ($pager->getNextPage() && $pager->getNextPage() < $pager->getLastPage() + 1) : ?>
<a class="w3-button" rel="next" href="<?= $pager->getNextPageUrl() ?>" title="<?=
$language->render('pagination', 'next') ?>">&raquo;</a>
<?php endif ?>

<?php if ($pager->getLastPage()
&& $pager->getCurrentPage() + $pager->getSurround() < $pager->getLastPage()
) : ?>
<a class="w3-button" href="<?= $pager->getLastPageUrl() ?>"><?= $pager->getLanguage()
->render('pagination', 'last') ?></a>
<?php endif ?>
</div>
</div>
5 changes: 5 additions & 0 deletions tests/PagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ public function testViews() : void
'tailwind-short' => \realpath(__DIR__ . '/../src/Views/tailwind-short.php'),
'tailwind3' => \realpath(__DIR__ . '/../src/Views/tailwind.php'),
'tailwind3-short' => \realpath(__DIR__ . '/../src/Views/tailwind-short.php'),
'w3' => \realpath(__DIR__ . '/../src/Views/w3.php'),
'w3-short' => \realpath(__DIR__ . '/../src/Views/w3-short.php'),
'w34' => \realpath(__DIR__ . '/../src/Views/w3.php'),
'w34-short' => \realpath(__DIR__ . '/../src/Views/w3-short.php'),
];
self::assertSame($views, $this->pager->getViews());
$this->pager->setView('foo', __FILE__);
Expand Down Expand Up @@ -304,6 +308,7 @@ public function viewsProvider() : array
['primer'],
['semantic-ui'],
['tailwind'],
['w3'],
];
}

Expand Down

0 comments on commit 8362e6d

Please sign in to comment.