Skip to content

Commit 80f16e9

Browse files
committed
feat: introduce limitView - navigate limatation
1 parent 7a7a942 commit 80f16e9

File tree

6 files changed

+77
-41
lines changed

6 files changed

+77
-41
lines changed

bili.config.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module.exports = {
2-
// js: 'buble',
3-
plugins: [
4-
'vue',
5-
],
6-
formats: [
7-
'cjs-min',
8-
'umd-min',
9-
'es',
10-
],
2+
// js: 'buble',
3+
plugins: [
4+
'vue',
5+
],
6+
formats: [
7+
'cjs-min',
8+
'umd-min',
9+
'es',
10+
],
1111
};

demo/layouts/default.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
2-
<main>
3-
<Nuxt />
4-
</main>
2+
<main>
3+
<Nuxt />
4+
</main>
55
</template>
66

77
<script>

demo/nuxt.config.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import path from 'path';
22

33
export default {
4-
head: {
5-
meta: [
6-
{ charset: 'utf-8' },
7-
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
4+
head: {
5+
meta: [
6+
{ charset: 'utf-8' },
7+
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
8+
],
9+
},
10+
css: [
11+
'~/assets/styles.scss',
812
],
9-
},
10-
css: [
11-
'~/assets/styles.scss',
12-
],
1313

14-
srcDir: path.resolve(__dirname),
15-
rootDir: path.resolve(__dirname, '..'),
14+
srcDir: path.resolve(__dirname),
15+
rootDir: path.resolve(__dirname, '..'),
1616
};

src/components/core/calendar.vue

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
>
1111
<span
1212
class="vuec-btn-prev"
13+
:class="{ disabled: disablePreviousButton }"
1314
@click="previousPage"
1415
>
1516
<slot name="prev-page">
@@ -18,6 +19,7 @@
1819
</span>
1920
<span
2021
class="vuec-btn-next"
22+
:class="{ disabled: disableNextButton }"
2123
@click="nextPage"
2224
>
2325
<slot name="next-page">
@@ -67,8 +69,12 @@
6769
</template>
6870
<template
6971
slot="month-title"
70-
slot-scope="scope">
71-
<slot name="month-title" v-bind="scope">
72+
slot-scope="scope"
73+
>
74+
<slot
75+
name="month-title"
76+
v-bind="scope"
77+
>
7278
<h2>{{ scope.date.format('MMMM') }}</h2>
7379
</slot>
7480
</template>
@@ -131,6 +137,10 @@ export default {
131137
type: Array,
132138
default: () => [],
133139
},
140+
limitView: {
141+
type: Boolean,
142+
default: false,
143+
},
134144
},
135145
data() {
136146
return {
@@ -177,6 +187,16 @@ export default {
177187
178188
return months;
179189
},
190+
disablePreviousButton() {
191+
return this.limitView
192+
&& this.minDate
193+
&& !this.localDate.isAfter(this.minDate, 'month');
194+
},
195+
disableNextButton() {
196+
return this.limitView
197+
&& this.maxDate
198+
&& !this.localDate.isBefore(this.maxDate, 'month');
199+
},
180200
},
181201
watch: {
182202
date(newDate) {
@@ -201,11 +221,21 @@ export default {
201221
this.$emit('click-day', $event);
202222
},
203223
previousPage() {
224+
if (this.disablePreviousButton) {
225+
return;
226+
}
227+
204228
this.localDate = this.localDate.subtract(this.visibleMonths, 'Month').startOf('Month');
229+
205230
this.$emit('previous-page', this.localDate);
206231
},
207232
nextPage() {
233+
if (this.disableNextButton) {
234+
return;
235+
}
236+
208237
this.localDate = this.localDate.add(this.visibleMonths, 'Month').startOf('Month');
238+
209239
this.$emit('next-page', this.localDate);
210240
},
211241
},
@@ -235,6 +265,9 @@ export default {
235265
flex: 1;
236266
text-align: center;
237267
}
268+
.disabled {
269+
opacity: 0.3;
270+
}
238271
}
239272
}
240273
</style>

src/components/core/month.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
:show="showTitle"
55
class="vuec-month-name"
66
>
7-
<slot name="month-title" :date="date" />
7+
<slot
8+
name="month-title"
9+
:date="date"
10+
/>
811
</div>
912
<div class="vuec-week-nav vuec-7col">
1013
<div

src/utils.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
* Persian numeric characters
33
*/
44
export const PERSIAN_DIGITS = [
5-
'۰',
6-
'۱',
7-
'۲',
8-
'۳',
9-
'۴',
10-
'۵',
11-
'۶',
12-
'۷',
13-
'۸',
14-
'۹',
5+
'۰',
6+
'۱',
7+
'۲',
8+
'۳',
9+
'۴',
10+
'۵',
11+
'۶',
12+
'۷',
13+
'۸',
14+
'۹',
1515
];
1616

1717
/**
@@ -29,19 +29,19 @@ export const PERSIAN_ZERO_CHAR_CODE = PERSIAN_DIGITS[0].charCodeAt(0);
2929
export const ARABIC_ZERO_CHAR_CODE = ARABIC_DIGITS[0].charCodeAt(0);
3030

3131
export function toNumeric(value) {
32-
return String(value).replace(/[^-\d]/g, '');
32+
return String(value).replace(/[^-\d]/g, '');
3333
}
3434

3535
export function toPersianDigits(value) {
36-
return String(value).replace(/[0-9]/g, w => PERSIAN_DIGITS[parseInt(w)]);
36+
return String(value).replace(/[0-9]/g, w => PERSIAN_DIGITS[parseInt(w)]);
3737
}
3838

3939
export function toEnglishDigits(value) {
40-
return String(value)
41-
.replace(/[۰-۹]/g, w => w.charCodeAt(0) - PERSIAN_ZERO_CHAR_CODE)
42-
.replace(/[٠-٩]/g, w => w.charCodeAt(0) - ARABIC_ZERO_CHAR_CODE);
40+
return String(value)
41+
.replace(/[۰-۹]/g, w => w.charCodeAt(0) - PERSIAN_ZERO_CHAR_CODE)
42+
.replace(/[٠-٩]/g, w => w.charCodeAt(0) - ARABIC_ZERO_CHAR_CODE);
4343
}
4444

4545
export function rotate(arr, n) {
46-
return arr.slice(n, arr.length).concat(arr.slice(0, n));
46+
return arr.slice(n, arr.length).concat(arr.slice(0, n));
4747
}

0 commit comments

Comments
 (0)