goodteditor-ui 1.0.12 → 1.0.13
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.
- package/.eslintrc.js +7 -7
- package/.prettierrc +14 -14
- package/README.md +35 -35
- package/babel.config.js +5 -5
- package/dist/js.png +0 -0
- package/index.js +51 -51
- package/jsconfig.json +13 -13
- package/package.json +57 -57
- package/src/App.vue +36 -36
- package/src/components/ui/Avatar.md +68 -68
- package/src/components/ui/Avatar.vue +177 -177
- package/src/components/ui/Badge.md +20 -20
- package/src/components/ui/Badge.vue +75 -75
- package/src/components/ui/Collapse.md +90 -90
- package/src/components/ui/Collapse.vue +86 -86
- package/src/components/ui/ColorPicker/Alpha.vue +114 -114
- package/src/components/ui/ColorPicker/Colors.vue +117 -117
- package/src/components/ui/ColorPicker/Hue.vue +113 -113
- package/src/components/ui/ColorPicker/Preview.vue +55 -55
- package/src/components/ui/ColorPicker/Saturation.vue +123 -123
- package/src/components/ui/ColorPicker/mixin.js +105 -105
- package/src/components/ui/ColorPicker.md +17 -17
- package/src/components/ui/ColorPicker.vue +314 -314
- package/src/components/ui/Datalist.md +41 -41
- package/src/components/ui/Datalist.vue +157 -157
- package/src/components/ui/DatePicker.md +168 -168
- package/src/components/ui/DatePicker.vue +527 -527
- package/src/components/ui/FileSelector.md +105 -105
- package/src/components/ui/FileSelector.vue +82 -82
- package/src/components/ui/Grid.md +130 -130
- package/src/components/ui/Grid.vue +92 -92
- package/src/components/ui/Image.md +59 -59
- package/src/components/ui/Image.vue +57 -57
- package/src/components/ui/InputAutocomplete.md +115 -115
- package/src/components/ui/InputAutocomplete.vue +341 -341
- package/src/components/ui/InputColorPicker.md +51 -51
- package/src/components/ui/InputColorPicker.vue +151 -151
- package/src/components/ui/InputDatePicker.md +121 -121
- package/src/components/ui/InputDatePicker.vue +310 -310
- package/src/components/ui/InputTags.md +51 -51
- package/src/components/ui/InputTags.vue +184 -184
- package/src/components/ui/InputTimePicker.md +25 -25
- package/src/components/ui/InputTimePicker.vue +253 -253
- package/src/components/ui/InputUnits.md +20 -20
- package/src/components/ui/InputUnits.vue +257 -257
- package/src/components/ui/Lazy.md +37 -37
- package/src/components/ui/Lazy.vue +92 -92
- package/src/components/ui/Pagination.md +74 -74
- package/src/components/ui/Pagination.vue +138 -138
- package/src/components/ui/Paginator.md +34 -34
- package/src/components/ui/Paginator.vue +83 -83
- package/src/components/ui/Popover.md +34 -34
- package/src/components/ui/Popover.vue +258 -209
- package/src/components/ui/Popup.md +59 -59
- package/src/components/ui/Popup.vue +150 -150
- package/src/components/ui/ResponsiveContainer.md +58 -58
- package/src/components/ui/ResponsiveContainer.vue +99 -99
- package/src/components/ui/Select.md +187 -187
- package/src/components/ui/Select.vue +420 -420
- package/src/components/ui/TimePicker.md +50 -50
- package/src/components/ui/TimePicker.vue +252 -252
- package/src/components/ui/Tooltip.md +114 -52
- package/src/components/ui/Tooltip.vue +113 -113
- package/src/components/ui/utils/FormComponent.js +107 -107
- package/src/components/ui/utils/Helpers.js +84 -61
- package/src/components/ui/utils/WithPopover.js +99 -81
- package/src/main.js +8 -8
- package/styleguide.config.js +37 -37
- package/vue.config.js +8 -8
- package/.idea/codeStyles/Project.xml +0 -51
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/goodt-ui.iml +0 -12
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { useIntersectionObserver } from './utils/Helpers';
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
props: {
|
|
6
|
-
/** which tag name to use when wrapping slot */
|
|
7
|
-
tag: { type: String, default: 'div' },
|
|
8
|
-
/** viewport element selector/reference or null for 'viewport' */
|
|
9
|
-
root: { type: [String, Element], default: null },
|
|
10
|
-
/** viewport margins */
|
|
11
|
-
rootMargin: { type: String, default: '300px' },
|
|
12
|
-
/** target's visibility ratios */
|
|
13
|
-
threshold: { type: [Number, Array], default: 0 },
|
|
14
|
-
/** defered rendering delay (ms) */
|
|
15
|
-
renderDelay: { type: Number, default: 100 },
|
|
16
|
-
/** defered rendering delay (ms) */
|
|
17
|
-
unrenderDelay: { type: Number, default: 500 },
|
|
18
|
-
/** default initial min-height of the lazy content */
|
|
19
|
-
minHeight: { type: String, default: '' },
|
|
20
|
-
},
|
|
21
|
-
data: () => ({ shouldRender: false, minHeightCalc: 0 }),
|
|
22
|
-
created() {
|
|
23
|
-
/** @type {Function} */
|
|
24
|
-
this.stopObserver = null;
|
|
25
|
-
/** @type {number} */
|
|
26
|
-
this.renderTimeout = null;
|
|
27
|
-
},
|
|
28
|
-
computed: {
|
|
29
|
-
/** @return {object} */
|
|
30
|
-
cssStyle() {
|
|
31
|
-
const { minHeight, minHeightCalc } = this;
|
|
32
|
-
const mh = minHeightCalc ? `${minHeightCalc}px` : minHeight;
|
|
33
|
-
return { minHeight: mh };
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
mounted() {
|
|
37
|
-
const { root: rootSelector, rootMargin, threshold } = this;
|
|
38
|
-
const root =
|
|
39
|
-
rootSelector instanceof Element ? rootSelector : document.querySelector(rootSelector);
|
|
40
|
-
const { stop } = useIntersectionObserver(
|
|
41
|
-
this.$el,
|
|
42
|
-
([{ isIntersecting }]) => this.handleIntersection(isIntersecting),
|
|
43
|
-
{ root, rootMargin, threshold }
|
|
44
|
-
);
|
|
45
|
-
this.stopObserver = stop;
|
|
46
|
-
this.calcMinHeight();
|
|
47
|
-
},
|
|
48
|
-
beforeDestroy() {
|
|
49
|
-
if (this.stopObserver) {
|
|
50
|
-
this.stopObserver();
|
|
51
|
-
}
|
|
52
|
-
this.calcMinHeight();
|
|
53
|
-
},
|
|
54
|
-
methods: {
|
|
55
|
-
/**
|
|
56
|
-
* @param {boolean} shouldRender
|
|
57
|
-
* @effect shouldRender, renderTimeout
|
|
58
|
-
*/
|
|
59
|
-
handleIntersection(shouldRender) {
|
|
60
|
-
const { renderTimeout, renderDelay, unrenderDelay } = this;
|
|
61
|
-
// clear prev render/unrender if any
|
|
62
|
-
if (renderTimeout) {
|
|
63
|
-
clearTimeout(renderTimeout);
|
|
64
|
-
}
|
|
65
|
-
const delay = shouldRender ? renderDelay : unrenderDelay;
|
|
66
|
-
this.renderTimeout = setTimeout(() => {
|
|
67
|
-
this.$nextTick(() => {
|
|
68
|
-
this.shouldRender = shouldRender;
|
|
69
|
-
if (shouldRender) {
|
|
70
|
-
this.calcMinHeight();
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}, delay);
|
|
74
|
-
},
|
|
75
|
-
/**
|
|
76
|
-
* Recalcs min-height
|
|
77
|
-
* @effect minHeightCalc
|
|
78
|
-
*/
|
|
79
|
-
calcMinHeight() {
|
|
80
|
-
this.$nextTick(() => {
|
|
81
|
-
this.minHeightCalc = this.$el.clientHeight;
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
render(h) {
|
|
86
|
-
const { tag, shouldRender, cssStyle: style } = this;
|
|
87
|
-
const { default: defaultSlot } = this.$scopedSlots;
|
|
88
|
-
const children = shouldRender && defaultSlot ? defaultSlot() : [];
|
|
89
|
-
return h(tag, { style }, children);
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
</script>
|
|
1
|
+
<script>
|
|
2
|
+
import { useIntersectionObserver } from './utils/Helpers';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
props: {
|
|
6
|
+
/** which tag name to use when wrapping slot */
|
|
7
|
+
tag: { type: String, default: 'div' },
|
|
8
|
+
/** viewport element selector/reference or null for 'viewport' */
|
|
9
|
+
root: { type: [String, Element], default: null },
|
|
10
|
+
/** viewport margins */
|
|
11
|
+
rootMargin: { type: String, default: '300px' },
|
|
12
|
+
/** target's visibility ratios */
|
|
13
|
+
threshold: { type: [Number, Array], default: 0 },
|
|
14
|
+
/** defered rendering delay (ms) */
|
|
15
|
+
renderDelay: { type: Number, default: 100 },
|
|
16
|
+
/** defered rendering delay (ms) */
|
|
17
|
+
unrenderDelay: { type: Number, default: 500 },
|
|
18
|
+
/** default initial min-height of the lazy content */
|
|
19
|
+
minHeight: { type: String, default: '' },
|
|
20
|
+
},
|
|
21
|
+
data: () => ({ shouldRender: false, minHeightCalc: 0 }),
|
|
22
|
+
created() {
|
|
23
|
+
/** @type {Function} */
|
|
24
|
+
this.stopObserver = null;
|
|
25
|
+
/** @type {number} */
|
|
26
|
+
this.renderTimeout = null;
|
|
27
|
+
},
|
|
28
|
+
computed: {
|
|
29
|
+
/** @return {object} */
|
|
30
|
+
cssStyle() {
|
|
31
|
+
const { minHeight, minHeightCalc } = this;
|
|
32
|
+
const mh = minHeightCalc ? `${minHeightCalc}px` : minHeight;
|
|
33
|
+
return { minHeight: mh };
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
mounted() {
|
|
37
|
+
const { root: rootSelector, rootMargin, threshold } = this;
|
|
38
|
+
const root =
|
|
39
|
+
rootSelector instanceof Element ? rootSelector : document.querySelector(rootSelector);
|
|
40
|
+
const { stop } = useIntersectionObserver(
|
|
41
|
+
this.$el,
|
|
42
|
+
([{ isIntersecting }]) => this.handleIntersection(isIntersecting),
|
|
43
|
+
{ root, rootMargin, threshold }
|
|
44
|
+
);
|
|
45
|
+
this.stopObserver = stop;
|
|
46
|
+
this.calcMinHeight();
|
|
47
|
+
},
|
|
48
|
+
beforeDestroy() {
|
|
49
|
+
if (this.stopObserver) {
|
|
50
|
+
this.stopObserver();
|
|
51
|
+
}
|
|
52
|
+
this.calcMinHeight();
|
|
53
|
+
},
|
|
54
|
+
methods: {
|
|
55
|
+
/**
|
|
56
|
+
* @param {boolean} shouldRender
|
|
57
|
+
* @effect shouldRender, renderTimeout
|
|
58
|
+
*/
|
|
59
|
+
handleIntersection(shouldRender) {
|
|
60
|
+
const { renderTimeout, renderDelay, unrenderDelay } = this;
|
|
61
|
+
// clear prev render/unrender if any
|
|
62
|
+
if (renderTimeout) {
|
|
63
|
+
clearTimeout(renderTimeout);
|
|
64
|
+
}
|
|
65
|
+
const delay = shouldRender ? renderDelay : unrenderDelay;
|
|
66
|
+
this.renderTimeout = setTimeout(() => {
|
|
67
|
+
this.$nextTick(() => {
|
|
68
|
+
this.shouldRender = shouldRender;
|
|
69
|
+
if (shouldRender) {
|
|
70
|
+
this.calcMinHeight();
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}, delay);
|
|
74
|
+
},
|
|
75
|
+
/**
|
|
76
|
+
* Recalcs min-height
|
|
77
|
+
* @effect minHeightCalc
|
|
78
|
+
*/
|
|
79
|
+
calcMinHeight() {
|
|
80
|
+
this.$nextTick(() => {
|
|
81
|
+
this.minHeightCalc = this.$el.clientHeight;
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
render(h) {
|
|
86
|
+
const { tag, shouldRender, cssStyle: style } = this;
|
|
87
|
+
const { default: defaultSlot } = this.$scopedSlots;
|
|
88
|
+
const children = shouldRender && defaultSlot ? defaultSlot() : [];
|
|
89
|
+
return h(tag, { style }, children);
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
</script>
|
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
Simple example
|
|
2
|
-
|
|
3
|
-
```vue
|
|
4
|
-
<template>
|
|
5
|
-
<div class="pad-l5">
|
|
6
|
-
<ui-pagination v-bind="props" @select="n => (props.page = n)"></ui-pagination>
|
|
7
|
-
</div>
|
|
8
|
-
</template>
|
|
9
|
-
<script>
|
|
10
|
-
import UiPagination from './Pagination.vue';
|
|
11
|
-
|
|
12
|
-
export default {
|
|
13
|
-
components: { UiPagination },
|
|
14
|
-
data() {
|
|
15
|
-
return {
|
|
16
|
-
props: {
|
|
17
|
-
page: 1,
|
|
18
|
-
pages: 25,
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
</script>
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
Advance example. Slots, sync
|
|
27
|
-
|
|
28
|
-
```vue
|
|
29
|
-
<template>
|
|
30
|
-
<div class="pad-l5">
|
|
31
|
-
<ui-pagination :page.sync="props.page" :pages="props.pages">
|
|
32
|
-
<template #before="{ page, prev }">
|
|
33
|
-
<div class="btn btn-inline" :class="{ disabled: page <= 1 }" @click="prev">
|
|
34
|
-
prev
|
|
35
|
-
</div>
|
|
36
|
-
</template>
|
|
37
|
-
<template #default="{ page, currentPage, index, selectPage }">
|
|
38
|
-
<div
|
|
39
|
-
class="pad-2 text-center cursor-pointer"
|
|
40
|
-
@click="selectPage(page)"
|
|
41
|
-
style="width:3em"
|
|
42
|
-
>
|
|
43
|
-
<template v-if="page">
|
|
44
|
-
<div class="d-block" :class="[page == currentPage ? 'mark' : 'code']">
|
|
45
|
-
{{ page }}
|
|
46
|
-
</div>
|
|
47
|
-
</template>
|
|
48
|
-
<template v-else>...</template>
|
|
49
|
-
</div>
|
|
50
|
-
</template>
|
|
51
|
-
<template #after="{ page, pages, next }">
|
|
52
|
-
<div class="btn btn-inline" :class="{ disabled: page >= pages }" @click="next">
|
|
53
|
-
next
|
|
54
|
-
</div>
|
|
55
|
-
</template>
|
|
56
|
-
</ui-pagination>
|
|
57
|
-
</div>
|
|
58
|
-
</template>
|
|
59
|
-
<script>
|
|
60
|
-
import UiPagination from './Pagination.vue';
|
|
61
|
-
|
|
62
|
-
export default {
|
|
63
|
-
components: { UiPagination },
|
|
64
|
-
data() {
|
|
65
|
-
return {
|
|
66
|
-
props: {
|
|
67
|
-
page: 1,
|
|
68
|
-
pages: 25,
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
</script>
|
|
74
|
-
```
|
|
1
|
+
Simple example
|
|
2
|
+
|
|
3
|
+
```vue
|
|
4
|
+
<template>
|
|
5
|
+
<div class="pad-l5">
|
|
6
|
+
<ui-pagination v-bind="props" @select="n => (props.page = n)"></ui-pagination>
|
|
7
|
+
</div>
|
|
8
|
+
</template>
|
|
9
|
+
<script>
|
|
10
|
+
import UiPagination from './Pagination.vue';
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
components: { UiPagination },
|
|
14
|
+
data() {
|
|
15
|
+
return {
|
|
16
|
+
props: {
|
|
17
|
+
page: 1,
|
|
18
|
+
pages: 25,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
</script>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Advance example. Slots, sync
|
|
27
|
+
|
|
28
|
+
```vue
|
|
29
|
+
<template>
|
|
30
|
+
<div class="pad-l5">
|
|
31
|
+
<ui-pagination :page.sync="props.page" :pages="props.pages">
|
|
32
|
+
<template #before="{ page, prev }">
|
|
33
|
+
<div class="btn btn-inline" :class="{ disabled: page <= 1 }" @click="prev">
|
|
34
|
+
prev
|
|
35
|
+
</div>
|
|
36
|
+
</template>
|
|
37
|
+
<template #default="{ page, currentPage, index, selectPage }">
|
|
38
|
+
<div
|
|
39
|
+
class="pad-2 text-center cursor-pointer"
|
|
40
|
+
@click="selectPage(page)"
|
|
41
|
+
style="width:3em"
|
|
42
|
+
>
|
|
43
|
+
<template v-if="page">
|
|
44
|
+
<div class="d-block" :class="[page == currentPage ? 'mark' : 'code']">
|
|
45
|
+
{{ page }}
|
|
46
|
+
</div>
|
|
47
|
+
</template>
|
|
48
|
+
<template v-else>...</template>
|
|
49
|
+
</div>
|
|
50
|
+
</template>
|
|
51
|
+
<template #after="{ page, pages, next }">
|
|
52
|
+
<div class="btn btn-inline" :class="{ disabled: page >= pages }" @click="next">
|
|
53
|
+
next
|
|
54
|
+
</div>
|
|
55
|
+
</template>
|
|
56
|
+
</ui-pagination>
|
|
57
|
+
</div>
|
|
58
|
+
</template>
|
|
59
|
+
<script>
|
|
60
|
+
import UiPagination from './Pagination.vue';
|
|
61
|
+
|
|
62
|
+
export default {
|
|
63
|
+
components: { UiPagination },
|
|
64
|
+
data() {
|
|
65
|
+
return {
|
|
66
|
+
props: {
|
|
67
|
+
page: 1,
|
|
68
|
+
pages: 25,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
</script>
|
|
74
|
+
```
|
|
@@ -1,138 +1,138 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="ui-pagination">
|
|
3
|
-
<!--
|
|
4
|
-
@slot Custom before slot
|
|
5
|
-
@binding {Number} page page
|
|
6
|
-
@binding {Number} pages pages
|
|
7
|
-
@binding {Function} prev selects prev page
|
|
8
|
-
@binding {Function} next selects next page
|
|
9
|
-
-->
|
|
10
|
-
<slot name="before" v-bind="{ page, pages, prev, next }"></slot>
|
|
11
|
-
<!--
|
|
12
|
-
@slot Page item slot
|
|
13
|
-
@binding {Number} page page
|
|
14
|
-
@binding {Number} index index
|
|
15
|
-
@binding {Function} selectPage function that selects the page
|
|
16
|
-
-->
|
|
17
|
-
<slot
|
|
18
|
-
v-for="(i, index) in pagesComputed"
|
|
19
|
-
v-bind="{ page: i, index, currentPage: page, selectPage }"
|
|
20
|
-
>
|
|
21
|
-
<div :key="index">
|
|
22
|
-
<div v-if="i == null">...</div>
|
|
23
|
-
<div
|
|
24
|
-
class="btn btn-small"
|
|
25
|
-
:class="[i == page ? 'btn-primary' : 'btn-ghost']"
|
|
26
|
-
@click="selectPage(i)"
|
|
27
|
-
v-else
|
|
28
|
-
>
|
|
29
|
-
{{ i.toLocaleString() }}
|
|
30
|
-
</div>
|
|
31
|
-
</div>
|
|
32
|
-
</slot>
|
|
33
|
-
<!--
|
|
34
|
-
@slot Custom after slot
|
|
35
|
-
@binding {Number} page page
|
|
36
|
-
@binding {Number} pages pages
|
|
37
|
-
@binding {Function} prev selects prev page
|
|
38
|
-
@binding {Function} next selects next page
|
|
39
|
-
-->
|
|
40
|
-
<slot name="after" v-bind="{ page, pages, prev, next }"></slot>
|
|
41
|
-
</div>
|
|
42
|
-
</template>
|
|
43
|
-
<style lang="less" scoped>
|
|
44
|
-
.ui-pagination {
|
|
45
|
-
display: flex;
|
|
46
|
-
align-items: center;
|
|
47
|
-
}
|
|
48
|
-
</style>
|
|
49
|
-
<script>
|
|
50
|
-
export default {
|
|
51
|
-
props: {
|
|
52
|
-
/**
|
|
53
|
-
* Current page
|
|
54
|
-
*/
|
|
55
|
-
page: {
|
|
56
|
-
type: Number,
|
|
57
|
-
default: 1,
|
|
58
|
-
},
|
|
59
|
-
/**
|
|
60
|
-
* Total pages
|
|
61
|
-
*/
|
|
62
|
-
pages: {
|
|
63
|
-
type: Number,
|
|
64
|
-
default: 1,
|
|
65
|
-
},
|
|
66
|
-
/**
|
|
67
|
-
* Number of pages to display
|
|
68
|
-
*/
|
|
69
|
-
numItems: {
|
|
70
|
-
type: Number,
|
|
71
|
-
default: 7,
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
computed: {
|
|
75
|
-
pagesComputed() {
|
|
76
|
-
let arr = [];
|
|
77
|
-
let i = Math.min(
|
|
78
|
-
this.pages + 1 - this.numItems,
|
|
79
|
-
Math.max(1, this.page - ((this.numItems / 2) | 0))
|
|
80
|
-
);
|
|
81
|
-
i = i < 1 ? 1 : i;
|
|
82
|
-
let end = i + this.numItems;
|
|
83
|
-
end = end > this.pages ? this.pages : end;
|
|
84
|
-
while (i < end) {
|
|
85
|
-
arr.push(i++);
|
|
86
|
-
}
|
|
87
|
-
if (arr[0] > 1) {
|
|
88
|
-
if (arr[0] > 2) {
|
|
89
|
-
arr.unshift(null);
|
|
90
|
-
}
|
|
91
|
-
arr.unshift(1);
|
|
92
|
-
}
|
|
93
|
-
if (arr[arr.length - 1] < this.pages) {
|
|
94
|
-
if (arr[arr.length - 1] < this.pages - 1) {
|
|
95
|
-
arr.push(null);
|
|
96
|
-
}
|
|
97
|
-
arr.push(this.pages);
|
|
98
|
-
}
|
|
99
|
-
return arr;
|
|
100
|
-
},
|
|
101
|
-
pageFirst() {
|
|
102
|
-
return this.pagesComputed[0];
|
|
103
|
-
},
|
|
104
|
-
pageLast() {
|
|
105
|
-
return this.pagesComputed[this.pagesComputed.length - 1];
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
methods: {
|
|
109
|
-
selectPage(page) {
|
|
110
|
-
/**
|
|
111
|
-
* Select page event
|
|
112
|
-
* @property {Number} page
|
|
113
|
-
*/
|
|
114
|
-
this.$emit('select', page);
|
|
115
|
-
/**
|
|
116
|
-
* Change page event
|
|
117
|
-
* @property {Number} page
|
|
118
|
-
*/
|
|
119
|
-
this.$emit('change', page);
|
|
120
|
-
/**
|
|
121
|
-
* Update page event (for .sync usage)
|
|
122
|
-
* @property {Number} page
|
|
123
|
-
*/
|
|
124
|
-
this.$emit('update:page', page);
|
|
125
|
-
},
|
|
126
|
-
prev() {
|
|
127
|
-
if (this.page > 1) {
|
|
128
|
-
this.selectPage(this.page - 1);
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
next() {
|
|
132
|
-
if (this.page < this.pages) {
|
|
133
|
-
this.selectPage(this.page + 1);
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
};
|
|
138
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<div class="ui-pagination">
|
|
3
|
+
<!--
|
|
4
|
+
@slot Custom before slot
|
|
5
|
+
@binding {Number} page page
|
|
6
|
+
@binding {Number} pages pages
|
|
7
|
+
@binding {Function} prev selects prev page
|
|
8
|
+
@binding {Function} next selects next page
|
|
9
|
+
-->
|
|
10
|
+
<slot name="before" v-bind="{ page, pages, prev, next }"></slot>
|
|
11
|
+
<!--
|
|
12
|
+
@slot Page item slot
|
|
13
|
+
@binding {Number} page page
|
|
14
|
+
@binding {Number} index index
|
|
15
|
+
@binding {Function} selectPage function that selects the page
|
|
16
|
+
-->
|
|
17
|
+
<slot
|
|
18
|
+
v-for="(i, index) in pagesComputed"
|
|
19
|
+
v-bind="{ page: i, index, currentPage: page, selectPage }"
|
|
20
|
+
>
|
|
21
|
+
<div :key="index">
|
|
22
|
+
<div v-if="i == null">...</div>
|
|
23
|
+
<div
|
|
24
|
+
class="btn btn-small"
|
|
25
|
+
:class="[i == page ? 'btn-primary' : 'btn-ghost']"
|
|
26
|
+
@click="selectPage(i)"
|
|
27
|
+
v-else
|
|
28
|
+
>
|
|
29
|
+
{{ i.toLocaleString() }}
|
|
30
|
+
</div>
|
|
31
|
+
</div>
|
|
32
|
+
</slot>
|
|
33
|
+
<!--
|
|
34
|
+
@slot Custom after slot
|
|
35
|
+
@binding {Number} page page
|
|
36
|
+
@binding {Number} pages pages
|
|
37
|
+
@binding {Function} prev selects prev page
|
|
38
|
+
@binding {Function} next selects next page
|
|
39
|
+
-->
|
|
40
|
+
<slot name="after" v-bind="{ page, pages, prev, next }"></slot>
|
|
41
|
+
</div>
|
|
42
|
+
</template>
|
|
43
|
+
<style lang="less" scoped>
|
|
44
|
+
.ui-pagination {
|
|
45
|
+
display: flex;
|
|
46
|
+
align-items: center;
|
|
47
|
+
}
|
|
48
|
+
</style>
|
|
49
|
+
<script>
|
|
50
|
+
export default {
|
|
51
|
+
props: {
|
|
52
|
+
/**
|
|
53
|
+
* Current page
|
|
54
|
+
*/
|
|
55
|
+
page: {
|
|
56
|
+
type: Number,
|
|
57
|
+
default: 1,
|
|
58
|
+
},
|
|
59
|
+
/**
|
|
60
|
+
* Total pages
|
|
61
|
+
*/
|
|
62
|
+
pages: {
|
|
63
|
+
type: Number,
|
|
64
|
+
default: 1,
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Number of pages to display
|
|
68
|
+
*/
|
|
69
|
+
numItems: {
|
|
70
|
+
type: Number,
|
|
71
|
+
default: 7,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
computed: {
|
|
75
|
+
pagesComputed() {
|
|
76
|
+
let arr = [];
|
|
77
|
+
let i = Math.min(
|
|
78
|
+
this.pages + 1 - this.numItems,
|
|
79
|
+
Math.max(1, this.page - ((this.numItems / 2) | 0))
|
|
80
|
+
);
|
|
81
|
+
i = i < 1 ? 1 : i;
|
|
82
|
+
let end = i + this.numItems;
|
|
83
|
+
end = end > this.pages ? this.pages : end;
|
|
84
|
+
while (i < end) {
|
|
85
|
+
arr.push(i++);
|
|
86
|
+
}
|
|
87
|
+
if (arr[0] > 1) {
|
|
88
|
+
if (arr[0] > 2) {
|
|
89
|
+
arr.unshift(null);
|
|
90
|
+
}
|
|
91
|
+
arr.unshift(1);
|
|
92
|
+
}
|
|
93
|
+
if (arr[arr.length - 1] < this.pages) {
|
|
94
|
+
if (arr[arr.length - 1] < this.pages - 1) {
|
|
95
|
+
arr.push(null);
|
|
96
|
+
}
|
|
97
|
+
arr.push(this.pages);
|
|
98
|
+
}
|
|
99
|
+
return arr;
|
|
100
|
+
},
|
|
101
|
+
pageFirst() {
|
|
102
|
+
return this.pagesComputed[0];
|
|
103
|
+
},
|
|
104
|
+
pageLast() {
|
|
105
|
+
return this.pagesComputed[this.pagesComputed.length - 1];
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
methods: {
|
|
109
|
+
selectPage(page) {
|
|
110
|
+
/**
|
|
111
|
+
* Select page event
|
|
112
|
+
* @property {Number} page
|
|
113
|
+
*/
|
|
114
|
+
this.$emit('select', page);
|
|
115
|
+
/**
|
|
116
|
+
* Change page event
|
|
117
|
+
* @property {Number} page
|
|
118
|
+
*/
|
|
119
|
+
this.$emit('change', page);
|
|
120
|
+
/**
|
|
121
|
+
* Update page event (for .sync usage)
|
|
122
|
+
* @property {Number} page
|
|
123
|
+
*/
|
|
124
|
+
this.$emit('update:page', page);
|
|
125
|
+
},
|
|
126
|
+
prev() {
|
|
127
|
+
if (this.page > 1) {
|
|
128
|
+
this.selectPage(this.page - 1);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
next() {
|
|
132
|
+
if (this.page < this.pages) {
|
|
133
|
+
this.selectPage(this.page + 1);
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
</script>
|