Skip to content

Commit

Permalink
Support adding additional classes to PaginateLinks component
Browse files Browse the repository at this point in the history
  • Loading branch information
TahaSh committed Dec 12, 2016
1 parent dfc50e4 commit a7bcb92
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 7 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,29 @@ Right arrow –> `ul.paginate-links > li.right-arrow > a`

Ellipses –> `ul.paginate-links > li.ellipses > a`

#### Adding additional classes

In some cases, especially when you're using a CSS framework, you'll need to add additional classes to your links elements. You can do so simply by using the `classes` prop on your `PaginateLinks` component. This prop takes an object that contains the element's selector as the key, and the class you want to add as the value.

Here's an example:

``` html
<paginate-links
for="languages"
:simple="{
prev: 'Back',
next: 'Next'
}"
:classes="{
'ul': 'simple-links-container',
'.next > a': 'next-link',
'.prev > a': 'prev-link'
}"
></paginate-links>
```

Note that this feature works on all link types – full links, simple links, and limited links.

## License

[MIT](http://opensource.org/licenses/MIT)
Expand Down
30 changes: 28 additions & 2 deletions dist/vue-paginate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* vue-paginate v3.1.0
* vue-paginate v3.2.0
* (c) 2016 Taha Shashtari
* @license MIT
*/
Expand Down Expand Up @@ -5492,6 +5492,10 @@
validator: function validator (obj) {
return obj.next && obj.prev
}
},
classes: {
type: Object,
default: null
}
},
data: function data () {
Expand Down Expand Up @@ -5550,15 +5554,25 @@
}
},
render: function render (h) {
var this$1 = this;

var links = this.simple
? getSimpleLinks(this, h)
: this.limit > 0
? getLimitedLinks(this, h)
: getFullLinks(this, h)

return h('ul', {
var el = h('ul', {
class: ['paginate-links', this.for]
}, links)

if (this.classes) {
vue_common.nextTick(function () {
addAdditionalClasses(el.elm, this$1.classes)
})
}

return el
}
}

Expand Down Expand Up @@ -5669,6 +5683,18 @@
return link
}

function addAdditionalClasses (linksContainer, classes) {
Object.keys(classes).forEach(function (selector) {
if (selector === 'ul') {
linksContainer.classList.add(classes['ul'])
}
linksContainer.querySelectorAll(selector).forEach(function (node) {
console.log(node)
node.classList.add(classes[selector])
})
})
}

function paginateDataGenerator (listNames) {
if ( listNames === void 0 ) listNames = [];

Expand Down
6 changes: 3 additions & 3 deletions dist/vue-paginate.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-paginate",
"version": "3.1.0",
"version": "3.2.0",
"description": "A simple vue.js plugin to paginate data",
"main": "dist/vue-paginate.js",
"scripts": {
Expand Down
26 changes: 25 additions & 1 deletion src/components/PaginateLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export default {
validator (obj) {
return obj.next && obj.prev
}
},
classes: {
type: Object,
default: null
}
},
data () {
Expand Down Expand Up @@ -82,9 +86,17 @@ export default {
? getLimitedLinks(this, h)
: getFullLinks(this, h)

return h('ul', {
const el = h('ul', {
class: ['paginate-links', this.for]
}, links)

if (this.classes) {
Vue.nextTick(() => {
addAdditionalClasses(el.elm, this.classes)
})
}

return el
}
}

Expand Down Expand Up @@ -194,3 +206,15 @@ function getTargetPageForLink (link, limit, currentPage) {
// which is number
return link
}

function addAdditionalClasses (linksContainer, classes) {
Object.keys(classes).forEach(selector => {
if (selector === 'ul') {
linksContainer.classList.add(classes['ul'])
}
linksContainer.querySelectorAll(selector).forEach(node => {
console.log(node)
node.classList.add(classes[selector])
})
})
}

0 comments on commit a7bcb92

Please sign in to comment.