Skip to content

Commit 3ad3c3c

Browse files
committed
fix: improve support for gregory calendar
1 parent d852aa5 commit 3ad3c3c

File tree

9 files changed

+113
-61
lines changed

9 files changed

+113
-61
lines changed

demo/assets/styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.vuec-theme-indra {
1+
.vuec-theme-orange {
22
.vuec-day {
33
color: #979797;
44
&.disabled {

demo/layouts/default.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<main>
3-
<nuxt/>
3+
<Nuxt />
44
</main>
55
</template>
66

@@ -12,7 +12,6 @@ export default {
1212

1313
<style>
1414
main {
15-
direction: rtl;
1615
margin: 50px;
1716
}
1817
</style>

demo/pages/index.vue

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
<template>
22
<div>
33
<div>
4-
<h3>Range Input</h3>
5-
<vuec-range-input
6-
:min-date="now"
7-
:max-date="maxDate"
8-
:mobile="false"
9-
theme="indra" />
4+
<h2>Gregory</h2>
5+
<div>
6+
<h3>Range Input</h3>
7+
<VuecRangeInput
8+
:min-date="now"
9+
:max-date="maxDate"
10+
:mobile="false"
11+
theme="orange"
12+
/>
13+
</div>
14+
<div>
15+
<h3>Single Input</h3>
16+
<VuecSingleInput />
17+
</div>
1018
</div>
11-
<div>
12-
<h3>Single Input</h3>
13-
<vuec-single-input/>
19+
<div class="jalali">
20+
<h2>Jalali</h2>
21+
<div>
22+
<h3>Range Input</h3>
23+
<VuecRangeInput
24+
:date="todayInJalali"
25+
:min-date="now"
26+
:max-date="maxDate"
27+
:mobile="false"
28+
theme="orange"
29+
/>
30+
</div>
1431
</div>
1532
</div>
1633
</template>
@@ -27,8 +44,18 @@ export default {
2744
data() {
2845
return {
2946
now: dayjs(),
47+
todayInJalali: dayjs().calendar('jalali').locale('fa'),
3048
maxDate: dayjs().add(26, 'day'),
3149
};
3250
},
51+
mounted() {
52+
window.dayjs = dayjs;
53+
},
3354
};
3455
</script>
56+
57+
<style lang="scss">
58+
.jalali {
59+
direction: rtl;
60+
}
61+
</style>

src/components/core/calendar.vue

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
<template>
22
<div
3-
:class="['vuec-theme-' + theme]"
4-
class="vuec-calendar">
3+
:class="['vuec-theme-' + theme, date.$C]"
4+
class="vuec-calendar"
5+
>
56
<div
67
v-if="showNavigation"
78
class="vuec-nav"
8-
align-v="center">
9+
align-v="center"
10+
>
911
<span
1012
class="vuec-btn-prev"
11-
@click="previousPage">
13+
@click="previousPage"
14+
>
1215
<slot name="prev-page">
13-
<icon-arrow-right />
16+
<IconArrowRight />
1417
</slot>
1518
</span>
1619
<span
1720
class="vuec-btn-next"
18-
@click="nextPage">
21+
@click="nextPage"
22+
>
1923
<slot name="next-page">
20-
<icon-arrow-left />
24+
<IconArrowLeft />
2125
</slot>
2226
</span>
2327
</div>
2428
<div class="vuec-month-wrapper">
25-
<vuec-month
26-
v-for="(month, index) in months"
27-
:key="index"
29+
<VuecMonth
30+
v-for="(month, monthIndex) in months"
31+
:key="monthIndex"
2832
:adapter="getDayData"
2933
:title="month.title"
3034
:date="month.date"
@@ -39,29 +43,29 @@
3943
>
4044
<template
4145
slot="day-of-week"
42-
slot-scope="{ name, index, locale }">
46+
slot-scope="{ name, index, locale }"
47+
>
4348
<slot
4449
v-bind="{ name, index, locale }"
45-
name="day-of-week">
50+
name="day-of-week"
51+
>
4652
{{ name }}
4753
</slot>
48-
4954
</template>
5055
<template
5156
slot="day"
52-
slot-scope="props">
53-
57+
slot-scope="props"
58+
>
5459
<slot
5560
v-bind="props"
56-
name="day">
61+
name="day"
62+
>
5763
<div class="vuec-default-day">
5864
{{ props.date.format('D') }}
5965
</div>
6066
</slot>
61-
6267
</template>
63-
64-
</vuec-month>
68+
</VuecMonth>
6569
</div>
6670
</div>
6771
</template>

src/components/core/day.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
<slot
1111
:data="data"
1212
:date="date"
13-
name="day">
13+
name="day"
14+
>
1415
<div class="vuec-default-day">
1516
{{ date.format('D') }}
1617
</div>
1718
</slot>
1819
</div>
19-
<div class="vuec-square-placeholder"/>
20+
<div class="vuec-square-placeholder" />
2021
</div>
2122
</template>
2223

src/components/core/month.vue

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,30 @@
22
<div class="vuec-month">
33
<div
44
:show="showTitle"
5-
class="vuec-month-name">
5+
class="vuec-month-name"
6+
>
67
<h2>{{ title || date.format('MMMM') }}</h2>
78
</div>
89
<div class="vuec-week-nav vuec-7col">
910
<div
1011
v-for="(name, index) in weekDays"
1112
:key="index"
12-
class="vuec-col">
13+
class="vuec-col"
14+
>
1315
<div class="vuec-week-content">
1416
<slot
1517
v-bind="{ name, index, locale }"
16-
name="day-of-week">
18+
name="day-of-week"
19+
>
1720
{{ name }}
1821
</slot>
1922
</div>
20-
<div class="vuec-week-placeholder"/>
23+
<div class="vuec-week-placeholder" />
2124
</div>
2225
</div>
2326
<div class="vuec-month-content">
2427
<div class="vuec-month-days vuec-7col">
25-
<day-view
28+
<DayView
2629
v-for="(day, i) in days"
2730
:key="day.dayKey"
2831
:index="i"
@@ -40,24 +43,23 @@
4043
>
4144
<template
4245
slot="day"
43-
slot-scope="props">
44-
46+
slot-scope="props"
47+
>
4548
<slot
4649
v-bind="props"
47-
name="day"/>
48-
50+
name="day"
51+
/>
4952
</template>
50-
51-
</day-view>
53+
</DayView>
5254
</div>
53-
<div class="vuec-month-placeholder"/>
55+
<div class="vuec-month-placeholder" />
5456
</div>
5557
</div>
5658
</template>
5759

5860
<script>
5961
import dayjs from '../../date';
60-
62+
import { rotate } from '../../utils';
6163
import DayView from './day.vue';
6264
6365
export default {
@@ -99,9 +101,10 @@ export default {
99101
},
100102
},
101103
data() {
104+
const startOfWeek = this.date.startOf('week').day();
102105
return {
103106
locale: this.date.$locale().name,
104-
weekDays: this.date.$locale().weekdays,
107+
weekDays: rotate(this.date.$locale().weekdays, startOfWeek),
105108
};
106109
},
107110
computed: {

src/components/range-input.vue

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
class="vuec-date-inputs"
55
@click="showPicker"
66
>
7-
<div class="input">{{ formattedDates[0] }}</div>
8-
<div class="input">{{ formattedDates[1] }}</div>
7+
<div class="input">
8+
{{ formattedDates[0] }}
9+
</div>
10+
<div class="input">
11+
{{ formattedDates[1] }}
12+
</div>
913
</div>
10-
<transition name="popup-animation">
14+
<Transition name="popup-animation">
1115
<div
1216
v-if="visible"
1317
:class="{ mobile: mobile }"
@@ -16,26 +20,29 @@
1620
>
1721
<div
1822
v-if="mobile"
19-
class="vuec-popup-header">
23+
class="vuec-popup-header"
24+
>
2025
<slot name="title">
2126
تاریخ ورود و خروج
2227
</slot>
2328
<div
2429
class="vuec-popup-close"
25-
@click="showPicker(false)">
26-
<icon-close/>
30+
@click="showPicker(false)"
31+
>
32+
<IconClose />
2733
</div>
2834
</div>
29-
<vuec-select-range
35+
<VuecSelectRange
3036
:theme="theme"
3137
:value="dates"
38+
:date="date"
3239
:min-date="minDate"
3340
:max-date="maxDate"
3441
:visible-months="2"
3542
:selectable="true"
3643
/>
3744
</div>
38-
</transition>
45+
</Transition>
3946
</div>
4047
</template>
4148

@@ -66,6 +73,10 @@ export default {
6673
type: String,
6774
default: 'single',
6875
},
76+
date: {
77+
type: Object,
78+
default: () => dayjs(),
79+
},
6980
data: {
7081
type: Object,
7182
default: () => ({}),
@@ -96,7 +107,7 @@ export default {
96107
},
97108
},
98109
data() {
99-
const [fromDate = dayjs(), toDate = dayjs()] = this.value;
110+
const [fromDate = this.date, toDate = this.date] = this.value;
100111
return {
101112
visible: this.open,
102113
temporaryDisableClickListen: false,
@@ -163,12 +174,10 @@ export default {
163174
box-shadow: 0 15px 12px rgba(0,0,0,0.22), 0 0 38px rgba(0,0,0,0.30);
164175
border-radius: 4PX;
165176
padding: 16px;
166-
direction: rtl;
167177
position: relative;
168178
z-index: 10;
169179
position: absolute;
170180
top: 100%;
171-
right: 0;
172181
}
173182
.vuec-popup-header {
174183
padding: 10px 20px;
@@ -199,6 +208,7 @@ export default {
199208
width: 300px;
200209
.input {
201210
flex: 1;
211+
padding: 16px;
202212
}
203213
}
204214
.mobile {

src/components/single-input.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44
class="vuec-date-inputs"
55
@click="showPicker"
66
>
7-
<div class="input">{{ formattedDates[0] }}</div>
8-
<div class="input">{{ formattedDates[1] }}</div>
7+
<div class="input">
8+
{{ formattedDates[0] }}
9+
</div>
10+
<div class="input">
11+
{{ formattedDates[1] }}
12+
</div>
913
</div>
1014
<div
1115
v-show="visible"
1216
class="vuec-popup"
1317
@click="onClickDelegate"
1418
>
15-
<vuec-single-select
19+
<VuecSingleSelect
1620
:theme="theme"
1721
:value="dates"
1822
:visible-months="1"

src/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ export function toEnglishDigits(value) {
4141
.replace(/[۰-۹]/g, w => w.charCodeAt(0) - PERSIAN_ZERO_CHAR_CODE)
4242
.replace(/[٠-٩]/g, w => w.charCodeAt(0) - ARABIC_ZERO_CHAR_CODE);
4343
}
44+
45+
export function rotate(arr, n) {
46+
return arr.slice(n, arr.length).concat(arr.slice(0, n));
47+
}

0 commit comments

Comments
 (0)