Skip to content

Commit 343c67f

Browse files
committed
Add support for Primer CSS framework
1 parent 45b07a7 commit 343c67f

File tree

6 files changed

+202
-0
lines changed

6 files changed

+202
-0
lines changed

.phpstorm.meta.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
'materialize-short',
3131
'materialize1',
3232
'materialize1-short',
33+
'primer',
34+
'primer-short',
35+
'primer20',
36+
'primer20-short',
3337
'semantic-ui',
3438
'semantic-ui-short',
3539
'semantic-ui2',

guide/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ The Aplus Framework Pagination Library works with the following front-end framew
163163
- `Bulma <https://bulma.io/>`_
164164
- `Foundation <https://get.foundation/>`_
165165
- `Materialize <https://materializecss.com/>`_
166+
- `Primer <https://primer.style/>`_
166167
- `Semantic UI <https://semantic-ui.com/>`_
167168
- `Tailwind <https://tailwindcss.com/>`_
168169

src/Pager.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ class Pager implements JsonSerializable
6363
'materialize-short' => __DIR__ . '/Views/materialize-short.php',
6464
'materialize1' => __DIR__ . '/Views/materialize.php',
6565
'materialize1-short' => __DIR__ . '/Views/materialize-short.php',
66+
// Primer 20
67+
'primer' => __DIR__ . '/Views/primer.php',
68+
'primer-short' => __DIR__ . '/Views/primer-short.php',
69+
'primer20' => __DIR__ . '/Views/primer.php',
70+
'primer20-short' => __DIR__ . '/Views/primer-short.php',
6671
// Semantic UI 2
6772
'semantic-ui' => __DIR__ . '/Views/semantic-ui.php',
6873
'semantic-ui-short' => __DIR__ . '/Views/semantic-ui-short.php',

src/Views/primer-short.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/*
3+
* This file is part of Aplus Framework Pagination Library.
4+
*
5+
* (c) Natan Felles <natanfelles@gmail.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
/**
11+
* @var Framework\Pagination\Pager $pager
12+
*/
13+
$language = $pager->getLanguage();
14+
?>
15+
<nav class="paginate-container" aria-label="Pagination">
16+
<div class="pagination">
17+
<?php if ($pager->getPreviousPage()) : ?>
18+
<a class="previous_page" rel="prev" href="<?= $pager->getPreviousPageUrl() ?>" aria-label="Previous Page">
19+
<?= $language->render('pagination', 'previous') ?>
20+
</a>
21+
<?php else: ?>
22+
<span class="previous_page" aria-disabled="true">
23+
<?= $language->render('pagination', 'previous') ?>
24+
</span>
25+
<?php endif ?>
26+
27+
<?php if ($pager->getNextPage()) : ?>
28+
<a class="next_page" rel="next" href="<?= $pager->getNextPageUrl() ?>" aria-label="Next Page">
29+
<?= $language->render('pagination', 'next') ?>
30+
</a>
31+
<?php else: ?>
32+
<span class="next_page" aria-disabled="true">
33+
<?= $language->render('pagination', 'next') ?>
34+
</span>
35+
<?php endif ?>
36+
</div>
37+
</nav>

src/Views/primer.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/*
3+
* This file is part of Aplus Framework Pagination Library.
4+
*
5+
* (c) Natan Felles <natanfelles@gmail.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
/**
11+
* @var Framework\Pagination\Pager $pager
12+
*/
13+
$language = $pager->getLanguage();
14+
?>
15+
<nav class="paginate-container" aria-label="Pagination">
16+
<div class="pagination">
17+
18+
<?php if ($pager->getPreviousPage()) : ?>
19+
<a class="previous_page" rel="prev" href="<?=
20+
$pager->getPreviousPageUrl() ?>" aria-label="<?=
21+
$language->render('pagination', 'previous') ?>"><?=
22+
$language->render('pagination', 'previous') ?></a>
23+
<?php else: ?>
24+
<span class="previous_page" aria-disabled="true"><?=
25+
$language->render('pagination', 'previous') ?></span>
26+
<?php endif ?>
27+
28+
<?php
29+
$page = array_key_first($pager->getPreviousPagesUrls());
30+
?>
31+
<?php if ($page > 1): ?>
32+
<a href="<?= $pager->getFirstPageUrl() ?>" aria-label="Page <?= $pager->getFirstPage() ?>" title="<?=
33+
$pager->getLanguage()->render('pagination', 'first') ?>">
34+
<?= $pager->getFirstPage() ?>
35+
</a>
36+
<?php if ($page > 2): ?>
37+
<a href="<?= $pager->getPageUrl(2) ?>" aria-label="Page 2">
38+
2
39+
</a>
40+
<?php if ($page > 3): ?>
41+
<span class="gap">…</span>
42+
<?php endif ?>
43+
<?php endif ?>
44+
<?php endif ?>
45+
46+
<?php foreach ($pager->getPreviousPagesUrls() as $p => $url) : ?>
47+
<a href="<?= $url ?>" aria-label="Page <?= $p ?>"><?= $p ?></a>
48+
<?php endforeach ?>
49+
50+
<em aria-current="page"><?= $pager->getCurrentPage() ?></em>
51+
52+
<?php foreach ($pager->getNextPagesUrls() as $p => $url) : ?>
53+
<a href="<?= $url ?>" aria-label="Page <?= $p ?>"><?= $p ?></a>
54+
<?php endforeach ?>
55+
56+
<?php
57+
$page = array_key_last($pager->getNextPagesUrls());
58+
$lastPage = $pager->getLastPage();
59+
?>
60+
<?php if ($page >= $pager->getCurrentPage()): ?>
61+
<?php if ($page < $lastPage - 2): ?>
62+
<span class="gap">…</span>
63+
<?php endif ?>
64+
<?php if ($page < $lastPage - 1): ?>
65+
<a href="<?= $pager->getPageUrl($lastPage - 1) ?>" aria-label="Page <?= $lastPage - 1 ?>">
66+
<?= $lastPage - 1 ?>
67+
</a>
68+
<?php endif ?>
69+
<?php if ($page < $lastPage): ?>
70+
<a href="<?= $pager->getLastPageUrl() ?>" aria-label="Page <?= $pager->getLastPage() ?>" title="<?=
71+
$pager->getLanguage()->render('pagination', 'last') ?>">
72+
<?= $pager->getLastPage() ?>
73+
</a>
74+
<?php endif ?>
75+
<?php endif ?>
76+
77+
<?php if ($pager->getNextPage() && $pager->getNextPage() < $pager->getLastPage() + 1) : ?>
78+
<a class="next_page" rel="next" href="<?=
79+
$pager->getNextPageUrl() ?>" aria-label="<?=
80+
$language->render('pagination', 'next') ?>"><?=
81+
$language->render('pagination', 'next') ?></a>
82+
<?php else: ?>
83+
<span class="next_page" aria-disabled="true"><?=
84+
$language->render('pagination', 'next') ?></span>
85+
<?php endif ?>
86+
87+
</div>
88+
</nav>

tests/PagerTest.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ public function testViews() : void
189189
'materialize-short' => \realpath(__DIR__ . '/../src/Views/materialize-short.php'),
190190
'materialize1' => \realpath(__DIR__ . '/../src/Views/materialize.php'),
191191
'materialize1-short' => \realpath(__DIR__ . '/../src/Views/materialize-short.php'),
192+
'primer' => \realpath(__DIR__ . '/../src/Views/primer.php'),
193+
'primer-short' => \realpath(__DIR__ . '/../src/Views/primer-short.php'),
194+
'primer20' => \realpath(__DIR__ . '/../src/Views/primer.php'),
195+
'primer20-short' => \realpath(__DIR__ . '/../src/Views/primer-short.php'),
192196
'semantic-ui' => \realpath(__DIR__ . '/../src/Views/semantic-ui.php'),
193197
'semantic-ui-short' => \realpath(__DIR__ . '/../src/Views/semantic-ui-short.php'),
194198
'semantic-ui2' => \realpath(__DIR__ . '/../src/Views/semantic-ui.php'),
@@ -297,6 +301,7 @@ public function viewsProvider() : array
297301
['bulma'],
298302
['foundation'],
299303
['materialize'],
304+
['primer'],
300305
['semantic-ui'],
301306
['tailwind'],
302307
];
@@ -317,6 +322,68 @@ public function testPaginationViews(string $view) : void
317322
self::assertStringContainsString('Last', $contents);
318323
}
319324

325+
/**
326+
* @return array<array<string>>
327+
*/
328+
public function previousDisabledProvider() : array
329+
{
330+
return [
331+
['primer', 'aria-disabled="true"'],
332+
['primer-short', 'aria-disabled="true"'],
333+
];
334+
}
335+
336+
/**
337+
* @dataProvider previousDisabledProvider
338+
*
339+
* @runInSeparateProcess
340+
*
341+
* @param string $view
342+
* @param string $needle
343+
*/
344+
public function testPreviousIsDisabled(string $view, string $needle) : void
345+
{
346+
$pager = new Pager(1, 10, 100);
347+
$contents = $pager->render($view);
348+
self::assertStringContainsString($needle, $contents);
349+
}
350+
351+
/**
352+
* @return array<array<string>>
353+
*/
354+
public function nextDisabledProvider() : array
355+
{
356+
return [
357+
['primer', 'aria-disabled="true"'],
358+
['primer-short', 'aria-disabled="true"'],
359+
];
360+
}
361+
362+
/**
363+
* @dataProvider nextDisabledProvider
364+
*
365+
* @runInSeparateProcess
366+
*
367+
* @param string $view
368+
* @param string $needle
369+
*/
370+
public function testNextIsDisabled(string $view, string $needle) : void
371+
{
372+
$pager = new Pager(10, 10, 100);
373+
$contents = $pager->render($view);
374+
self::assertStringContainsString($needle, $contents);
375+
}
376+
377+
/**
378+
* @runInSeparateProcess
379+
*/
380+
public function testPrimerGap() : void
381+
{
382+
$pager = new Pager(5, 10, 100);
383+
$contents = $pager->render('primer');
384+
self::assertStringContainsString('<span class="gap">…</span>', $contents);
385+
}
386+
320387
/**
321388
* @dataProvider viewsProvider
322389
*

0 commit comments

Comments
 (0)