vue-slim-tables 0.1.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,151 +0,0 @@
1
- <template>
2
- <table class="vst">
3
- <thead v-if="columns.length">
4
- <tr>
5
- <th
6
- v-for="column in columns"
7
- :key="column.key"
8
- :class="['vst-th', { 'vst-orderable': column.orderable }]"
9
- @click.prevent="column.orderable ? onOrderClick(column.key) : null">
10
- <slot
11
- :name="`head:${column.key}`"
12
- :column="column">
13
- {{ column.title }}
14
- </slot>
15
- <a
16
- v-if="column.orderable"
17
- href="#"
18
- :class="`vst-orderable-toggle ${orders[column.key] || ''}`" />
19
- </th>
20
- </tr>
21
- </thead>
22
- <tbody>
23
- <slot
24
- v-for="(row, i) in rows"
25
- name="row"
26
- :row="row"
27
- :index="i"
28
- :columns="columns">
29
- <tr :key="row.id || i">
30
- <td
31
- v-for="column in columns"
32
- :key="column.key">
33
- <slot
34
- :name="`cell:${column.key}`"
35
- :row="row"
36
- :value="row[column.key]"
37
- :column="column"
38
- :index="i">
39
- {{ row[column.key] }}
40
- </slot>
41
- </td>
42
- </tr>
43
- </slot>
44
-
45
- <slot v-if="syncState === 'fetched' && rows.length === 0" name="row:empty">
46
- <tr>
47
- <td :colspan="columns.length">
48
- No records found
49
- </td>
50
- </tr>
51
- </slot>
52
-
53
- <slot v-if="syncState === 'syncing'" name="row:loading">
54
- <LoadingRow
55
- v-for="(row, i) in perPage"
56
- :key="`loadingRow${i}`"
57
- :columns-length="columns.length" />
58
- </slot>
59
- </tbody>
60
- <tfoot>
61
- <tr>
62
- <td :colspan="columns.length">
63
- <slot name="pagination" :page="page" :rows="rows">
64
- <ul v-if="page > 1 || rows.length === perPage" class="vst-pagination mt-3">
65
- <li :class="['vst-page-item', { disabled: page === 1 }]">
66
- <a class="vst-page-link" @click.prevent="page -= 1">←</a>
67
- </li>
68
-
69
- <li :class="['vst-page-item', { disabled: rows.length < perPage }]">
70
- <a class="vst-page-link" @click.prevent="page += 1">→</a>
71
- </li>
72
- </ul>
73
- </slot>
74
- </td>
75
- </tr>
76
- </tfoot>
77
- </table>
78
- </template>
79
-
80
- <script>
81
- import qs from 'qs'
82
- import LoadingRow from './loading_row.vue'
83
-
84
- export default {
85
- components: { LoadingRow },
86
- props: {
87
- columns: { type: Array, required: true },
88
- source: { type: [String, Function], required: true },
89
- perPage: { type: Number, default: 25 },
90
- },
91
- data() {
92
- return {
93
- page: 1,
94
- rows: [],
95
- syncState: 'initial',
96
- orders: {},
97
- }
98
- },
99
- watch: {
100
- page: 'fetchData',
101
- orders: 'refetch',
102
- perPage: 'refetch',
103
- },
104
- created() {
105
- this.fetchData()
106
- },
107
- methods: {
108
- reload() {
109
- this.fetchData(this.page)
110
- },
111
- async fetchData(page = 1) {
112
- const params = { per_page: this.perPage, page }
113
-
114
- const orderKeys = Object.keys(this.orders)
115
- if (orderKeys.length) {
116
- params.order = orderKeys.map((key) => ({ field: key, direction: this.orders[key] }))
117
- }
118
-
119
- this.syncState = 'syncing'
120
- this.rows = []
121
-
122
- let data
123
- if (typeof this.source === 'string') {
124
- const response = await fetch(`${this.source}?${qs.stringify(params, { arrayFormat: 'brackets' })}`)
125
- data = await response.json()
126
- } else {
127
- data = await this.source(params)
128
- }
129
-
130
- this.rows = data
131
- this.syncState = 'fetched'
132
- },
133
- onOrderClick(key) {
134
- if (this.orders[key] === 'asc') {
135
- this.orders = { [key]: 'desc' }
136
- } else if (this.orders[key] === 'desc') {
137
- this.orders = {}
138
- } else {
139
- this.orders = { [key]: 'asc' }
140
- }
141
- },
142
- refetch() {
143
- if (this.page === 1) {
144
- this.fetchData(1)
145
- } else {
146
- this.page = 1
147
- }
148
- },
149
- },
150
- }
151
- </script>
package/src/js/index.js DELETED
@@ -1,5 +0,0 @@
1
- import '../stylesheets/index.scss'
2
-
3
- import VueSlimTable from './components/table.vue'
4
-
5
- export default VueSlimTable
@@ -1,97 +0,0 @@
1
- @keyframes moving-gradient {
2
- 0% { background-position: -250px 0; }
3
- 100% { background-position: 250px 0; }
4
- }
5
-
6
- .vst {
7
- &-th {
8
- line-height: 20px;
9
- }
10
-
11
- &-orderable:hover {
12
- cursor: pointer;
13
-
14
- .vst-orderable-toggle {
15
- color: #555 !important;
16
- }
17
- }
18
-
19
- &-orderable-toggle {
20
- font-size: 20px;
21
- float: right;
22
- color: #ccc !important;
23
-
24
- &:after {
25
- content: " \2194";
26
- display: inline-block;
27
- transform: rotate(-90deg);
28
- }
29
-
30
- &.desc:after {
31
- content: " \2191";
32
- transform: rotate(0);
33
- }
34
-
35
- &.asc:after {
36
- content: " \2193";
37
- transform: rotate(0);
38
- }
39
- }
40
-
41
- &-loading-row div {
42
- height: 20px;
43
- background: linear-gradient(to right, #eee 20%, #ddd 50%, #eee 80%);
44
- background-size: 500px 20px;
45
- animation-name: moving-gradient;
46
- animation-duration: 1s;
47
- animation-iteration-count: infinite;
48
- animation-timing-function: linear;
49
- animation-fill-mode: forwards;
50
- }
51
-
52
- tr td.vst-loading-row {
53
- @for $i from 1 through 10 {
54
- &-#{$i} div {
55
- animation-delay: #{($i - 11)*100}ms;
56
- }
57
- }
58
- }
59
-
60
- &-pagination {
61
- display: flex;
62
- padding-left: 0;
63
- list-style: none;
64
- border-radius: 0.25rem;
65
-
66
- a {
67
- position: relative;
68
- display: block;
69
- padding: 8px 12px;
70
- padding: 0.5rem 0.75rem;
71
- margin-left: -1px;
72
- line-height: 1.25;
73
- color: #007bff;
74
- background-color: #fff;
75
- border: 1px solid #dee2e6;
76
-
77
- &:hover {
78
- z-index: 2;
79
- color: #0056b3;
80
- text-decoration: none;
81
- background-color: #e9ecef;
82
- border-color: #dee2e6;
83
- }
84
- }
85
- }
86
-
87
- &-page-item.disabled .vst-page-link {
88
- pointer-events: none;
89
- color: #6c757d;
90
- cursor: auto;
91
- background-color: #fff;
92
- }
93
-
94
- &-page-item .vst-page-link {
95
- cursor: pointer;
96
- }
97
- }
package/webpack.config.js DELETED
@@ -1,48 +0,0 @@
1
- const path = require('path');
2
- const { VueLoaderPlugin } = require('vue-loader');
3
- const TerserPlugin = require('terser-webpack-plugin');
4
- const MiniCssExtractPlugin = require('mini-css-extract-plugin');
5
-
6
- module.exports = {
7
- mode: 'production',
8
- entry: {
9
- bundle: './src/js/index.js'
10
- },
11
- output: {
12
- filename: '[name].js',
13
- library: 'VueSlimTable',
14
- libraryTarget: 'umd'
15
- },
16
- module: {
17
- rules: [
18
- {
19
- test: /\.vue$/,
20
- loader: 'vue-loader'
21
- },
22
- {
23
- test: /\.js$/,
24
- loader: 'babel-loader',
25
- include: __dirname,
26
- exclude: /node_modules/
27
- },
28
- {
29
- test: /\.scss$/,
30
- use: [
31
- process.env.NODE_ENV === 'production' ? MiniCssExtractPlugin.loader : 'style-loader',
32
- 'css-loader',
33
- 'sass-loader'
34
- ],
35
- }
36
- ]
37
- },
38
- plugins: [
39
- new VueLoaderPlugin(),
40
- new MiniCssExtractPlugin({
41
- filename: '[name].css'
42
- })
43
- ],
44
- optimization: {
45
- minimize: true,
46
- minimizer: [new TerserPlugin()]
47
- }
48
- };