Bulma Table with Modal
HTML
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.4.1/css/bulma.css">
<div id="app">
<h1>{{ title }}</h1>
<b-paginate-select v-model="perPage"></b-paginate-select>
<hr>
<b-paginate v-model="currentPage" :last="totalPages"></b-paginate>
<b-table :header="header" :table="table"></b-table>
<b-paginate v-model="currentPage" :last="totalPages"></b-paginate>
</div>
<!-- template for the modal component -->
<script type="text/x-template" id="modal-template">
<transition name="modal">
<div class="modal-mask">
<div class="modal-wrapper">
<div class="modal-container">
<div class="modal-header">
<slot name="header">
{{ header }}
</slot>
</div>
<div class="modal-body">
<slot name="body">
{{ body }}
</slot>
</div>
<div class="modal-footer">
<slot name="footer">
<button class="button is-primary modal-default-button" @click="$emit('close')">
OK
</button>
</slot>
</div>
</div>
</div>
</div>
</transition>
</script>
CSS
body {
padding: 10px
}
.pagination a {
max-width: 80px
}
th[scope="row"] {
cursor: pointer;
}
/* modal */
.modal-mask {
position: fixed;
z-index: 9998;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, .5);
display: table;
transition: opacity .3s ease;
}
.modal-wrapper {
display: table-cell;
vertical-align: middle;
}
.modal-container {
width: 300px;
margin: 0px auto;
padding: 20px 30px;
background-color: #fff;
border-radius: 2px;
box-shadow: 0 2px 8px rgba(0, 0, 0, .33);
transition: all .3s ease;
font-family: Helvetica, Arial, sans-serif;
}
.modal-header h3 {
margin-top: 0;
color: #42b983;
}
.modal-body {
margin: 20px 0;
}
.modal-footer {
padding: 0 0 30px 0;
}
.modal-default-button {
float: right;
}
/*
* The following styles are auto-applied to elements with
* transition="modal" when their visibility is toggled
* by Vue.js.
*
* You can easily play with the modal transition by editing
* these styles.
*/
.modal-enter {
opacity: 0;
}
.modal-leave-active {
opacity: 0;
}
.modal-enter .modal-container,
.modal-leave-active .modal-container {
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
JavaScript
Vue.component('b-paginate-select', Vue.extend({
props: ['value'],
data: () => ({ perPage: 0}),
mounted () {
this.perPage = this.value;
},
template: `<span class="select">
<select v-model="perPage" @change="$emit('input', perPage)">
<option :value="3">3</option>
<option :value="5">5</option>
<option :value="10">10</option>
</select>
</span>`
}));
Vue.component('b-paginate', Vue.extend({
props: ['value', 'last'],
template: `
<nav class="pagination is-centered">
<a class="pagination-previous" @click="$emit('input', 1)" :disabled="value === 1">First</a>
<a class="pagination-next" @click="$emit('input', last)" :disabled="value === last">Last</a>
<ul class="pagination-list">
<li v-for="__page in last" @click="$emit('input', __page)">
<a :class="['pagination-link', value === __page ? 'is-current' : '']">{{ __page }}</a>
</li>
</ul>
</nav>
`
}))
Vue.component('b-table', Vue.extend({
template:
`<div>
<table class="table">
<thead>
<tr>
<th>#</th>
<th v-for="_head in header">{{ _head.label }}</th>
</tr>
</thead>
<tbody>
<tr v-for="(_row, $index) in table">
<th scope="row" @click="open(_row)">{{ $index + 1 }}</th>
<td v-for="(_key, $id) in columns"> {{ _row[_key] }}</td>
</tr>
</tbody>
</table>
<v-modal v-if="modal.visible" @close="modal.visible = false" :header="modal.header" :body="modal.body">
<h3 slot="header">Custom Header</h3>
</v-modal>
</div>`,
props: {
header: {
required: true
},
table: {
required: true
}
},
data: () => ({
columns: [],
modal: {
visible: false,
header: '',
body: ''
}
}),
created () {
this.columns = this.header.map((_item) => {
return _item.column;
});
},
methods: {
open (data) {
this.modal.body = data.firstName;
this.modal.visible = true;
}
...