Skip to content

Commit f2861eb

Browse files
Merge pull request #75 from andreich1980/dev-pagination
Pagination #19
2 parents acc0a70 + 232083b commit f2861eb

File tree

8 files changed

+146
-0
lines changed

8 files changed

+146
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.idea
2+
/vendor

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ A Laravel front-end scaffolding preset for [Tailwind CSS](https://tailwindcss.co
2525

2626
The default `tailwind.config.js` configuration file included by this package simply uses the config from the Tailwind vendor files. Should you wish to make changes, you should remove the file and run `node_modules/.bin/tailwind init`, which will generate a fresh configuration file for you, which you are free to change to suit your needs.
2727

28+
Add a new i18n string in the `resources/lang/XX/pagination.php` file for each language that your app uses:
29+
```php
30+
'previous' => '« Previous',
31+
'next' => 'Next »',
32+
'goto_page' => 'Goto page #:page', // Add this line
33+
```
34+
This should help with accessibility
35+
```html
36+
<li>
37+
<a href="URL?page=2" class="..."
38+
aria-label="Goto page #2"
39+
>
40+
2
41+
</a>
42+
</li>
43+
```
44+
2845
### Screenshots
2946

3047
![Welcome](/screenshots/welcome.png)
@@ -38,3 +55,6 @@ The default `tailwind.config.js` configuration file included by this package sim
3855
![Dashboard](/screenshots/dashboard.png)
3956

4057
![Verify](/screenshots/verify.png)
58+
59+
![Pagination](/screenshots/pagination-links.png)
60+
![Simple Pagination](/screenshots/simple-pagination-links.png)

screenshots/pagination-links.png

1.27 KB
Loading
1.08 KB
Loading

src/TailwindCssPreset.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public static function install()
1515
static::updateStyles();
1616
static::updateBootstrapping();
1717
static::updateWelcomePage();
18+
static::updatePagination();
1819
static::removeNodeModules();
1920
}
2021

@@ -71,6 +72,13 @@ protected static function updateWelcomePage()
7172
copy(__DIR__.'/tailwindcss-stubs/resources/views/welcome.blade.php', resource_path('views/welcome.blade.php'));
7273
}
7374

75+
protected static function updatePagination()
76+
{
77+
(new Filesystem)->delete(resource_path('views/vendor/paginate'));
78+
79+
(new Filesystem)->copyDirectory(__DIR__.'/tailwindcss-stubs/resources/views/vendor/pagination', resource_path('views/vendor/pagination'));
80+
}
81+
7482
protected static function scaffoldAuth()
7583
{
7684
file_put_contents(app_path('Http/Controllers/HomeController.php'), static::compileControllerStub());

src/TailwindCssPresetServiceProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace LaravelFrontendPresets\TailwindCssPreset;
44

5+
use Illuminate\Pagination\Paginator;
56
use Illuminate\Support\ServiceProvider;
67
use Illuminate\Foundation\Console\PresetCommand;
78

@@ -22,5 +23,9 @@ public function boot()
2223
$command->info('Tailwind CSS scaffolding with auth views installed successfully.');
2324
$command->info('Please run "npm install && npm run dev" to compile your fresh scaffolding.');
2425
});
26+
27+
Paginator::defaultView('pagination::default');
28+
29+
Paginator::defaultSimpleView('pagination::simple-default');
2530
}
2631
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
@if ($paginator->hasPages())
2+
<nav role="navigation" aria-label="Pagination Navigation">
3+
<ul class="flex justify-center text-sm">
4+
{{-- Previous Page Link --}}
5+
@if ($paginator->onFirstPage())
6+
<li aria-label="@lang('pagination.previous')">
7+
<span class="px-4 py-3 text-gray-500 block border border-r-0 border-gray-300 rounded-l" aria-hidden="true">&larr;</span>
8+
</li>
9+
@else
10+
<li>
11+
<a href="{{ $paginator->previousPageUrl() }}"
12+
rel="prev"
13+
class="px-4 py-3 block text-blue-900 border border-r-0 border-gray-300 rounded-l hover:text-white hover:bg-blue-900 focus:outline-none focus:shadow-outline"
14+
aria-label="@lang('pagination.previous')"
15+
>
16+
&larr;
17+
</a>
18+
</li>
19+
@endif
20+
21+
{{-- Pagination Elements --}}
22+
@foreach ($elements as $element)
23+
{{-- "Three Dots" Separator --}}
24+
@if (is_string($element))
25+
<li aria-disabled="true">
26+
<span class="px-4 py-3 block text-gray-500 border border-r-0 border-gray-300">{{ $element }}</span>
27+
</li>
28+
@endif
29+
30+
{{-- Array Of Links --}}
31+
@if (is_array($element))
32+
@foreach ($element as $page => $url)
33+
@if ($page == $paginator->currentPage())
34+
<li aria-current="page">
35+
<span class="px-4 py-3 block text-white bg-blue-900 border border-r-0 border-gray-300">{{ $page }}</span>
36+
</li>
37+
@else
38+
<li>
39+
<a href="{{ $url }}"
40+
class="px-4 py-3 block text-blue-900 border border-r-0 border-gray-300 hover:text-white hover:bg-blue-900 focus:outline-none focus:shadow-outline"
41+
aria-label="@lang('pagination.goto_page', ['page' => $page])"
42+
>
43+
{{ $page }}
44+
</a>
45+
</li>
46+
@endif
47+
@endforeach
48+
@endif
49+
@endforeach
50+
51+
{{-- Next Page Link --}}
52+
@if ($paginator->hasMorePages())
53+
<li>
54+
<a href="{{ $paginator->nextPageUrl() }}"
55+
rel="next"
56+
class="px-4 py-3 block text-blue-900 border border-gray-300 rounded-r hover:text-white hover:bg-blue-900 focus:outline-none focus:shadow-outline"
57+
aria-label="@lang('pagination.next')"
58+
>
59+
&rarr;
60+
</a>
61+
</li>
62+
@else
63+
<li aria-disabled="true" aria-label="@lang('pagination.next')">
64+
<span class="px-4 py-3 block text-gray-500 border border-gray-300 rounded-r" aria-hidden="true">&rarr;</span>
65+
</li>
66+
@endif
67+
</ul>
68+
</nav>
69+
@endif
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@if ($paginator->hasPages())
2+
<nav role="navigation" aria-label="Pagination Navigation">
3+
<ul class="flex justify-center">
4+
{{-- Previous Page Link --}}
5+
@if ($paginator->onFirstPage())
6+
<li aria-disabled="true">
7+
<span class="px-4 py-3 block text-gray-500 border border-r-0 border-gray-300 rounded-l" aria-hidden="true">
8+
@lang('pagination.previous')
9+
</span>
10+
</li>
11+
@else
12+
<li>
13+
<a href="{{ $paginator->previousPageUrl() }}"
14+
rel="prev"
15+
class="px-4 py-3 block text-blue-900 border border-r-0 border-gray-300 rounded-l hover:text-white hover:bg-blue-900 focus:outline-none focus:shadow-outline"
16+
>
17+
@lang('pagination.previous')
18+
</a>
19+
</li>
20+
@endif
21+
22+
{{-- Next Page Link --}}
23+
@if ($paginator->hasMorePages())
24+
<li>
25+
<a href="{{ $paginator->nextPageUrl() }}"
26+
rel="next"
27+
class="px-4 py-3 block text-blue-900 border border-gray-300 rounded-r hover:text-white hover:bg-blue-900 focus:outline-none focus:shadow-outline"
28+
>
29+
@lang('pagination.next')
30+
</a>
31+
</li>
32+
@else
33+
<li aria-disabled="true">
34+
<span class="px-4 py-3 block text-gray-500 border border-gray-300 rounded-r">
35+
@lang('pagination.next')
36+
</span>
37+
</li>
38+
@endif
39+
</ul>
40+
</nav>
41+
@endif
42+

0 commit comments

Comments
 (0)