spatie / vue-data-component

A renderless Vue component to build data-driven interfaces
https://spatie.be/open-source
MIT License
72 stars 4 forks source link

Add Pagination component #3

Closed sebastiandedeyne closed 6 years ago

sebastiandedeyne commented 6 years ago

https://github.com/spatie/vue-data-component/blob/eefd8371192bfa5a685d0ad5b5d91f5b513916cc/src/components/DataComponent.js#L184

<data-paginator :page="page" :page-count="pageCount">
    <ul slot-scope="{ pages }">
        <li v-for="page in pages" :class="{ 'is-active': page.active }">
            {{ page.number }}
        </li>
    </ul>
</data-paginator>
<data-paginator :page="page" :page-count="pageCount" :links-on-each-side="2">
    <ul slot-scope="{ pages, firstPage, lastPage }">
        <li :class="{ 'is-active': firstPage.active }">
            {{ firstPage.number }}
        </li>
        <li>...</li>
        <li v-for="page in pages" :class="{ 'is-active': page.active }">
            {{ page.number }}
        </li>
        <li>...</li>
        <li :class="{ 'is-active': lastPage.active }">
            {{ lastPage.number }}
        </li>
    </ul>
</data-paginator>

The last example is going to be a bit harder to implement. Some example (edge) cases:

<data-paginator :page="4" :page-count="10" :links-on-each-side="2">
1 ... 2 3 [4] 5 6 ... 10

<data-paginator :page="9" :page-count="10" :links-on-each-side="2">
1 ... 7 8 [9] 10

<data-paginator :page="2" :page-count="3" :links-on-each-side="2">
1 [2] 3
AdrianMrn commented 6 years ago

notes to self: -To start developing, run yarn and yarn dev in both the root and in the /docs folder

-data-paginator should have a default scoped slot that, by default, returns the code in the 2nd last code block of Seb's comment, but allows the user to implement their own styling

laravel implementation: /Users/adriaanmarain/sites/smartassist/vendor/laravel/framework/src/Illuminate/Pagination/UrlWindow.php

use https://gist.github.com/kottenator/9d936eb3e4e3c3e02598#gistcomment-1748957 ?