Skip to content

Commit bfb934c

Browse files
author
Bedram Tamang
committed
refactor: refactor
1 parent 9684363 commit bfb934c

File tree

5 files changed

+98
-82
lines changed

5 files changed

+98
-82
lines changed

__tests__/Calendar.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('CalendarPanel', () => {
9999
[true, false].forEach((holidayClickable) => {
100100
it('props: holidayClickable', () => {
101101
const holidayDate = (date: Date) => {
102-
return date === new Date(2019, 9, 1);
102+
return date < new Date(2019, 9, 1) || date > new Date(2019, 9, 20);
103103
};
104104
const mockFn = jest.fn();
105105
wrapper = mount(Calendar, {

lib/Picker.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export interface PickerBaseProps {
2525
confirmText?: string;
2626
shortcuts?: Array<{ text: string; onClick: () => Date | Date[] }>;
2727
disabledDate?: (v: Date) => boolean;
28+
holidayDate?: (v: Date) => boolean;
29+
holidayClickable?: boolean;
2830
disabledTime?: (v: Date) => boolean;
2931
onClose?: () => void;
3032
onOpen?: () => void;
@@ -49,6 +51,8 @@ function Picker(originalProps: PickerProps, { slots }: SetupContext) {
4951
format: 'YYYY-MM-DD',
5052
type: 'date' as PickerType,
5153
disabledDate: () => false,
54+
holidayDate: () => false,
55+
holidayClickable: false,
5256
disabledTime: () => false,
5357
confirmText: 'OK',
5458
});

lib/PickerInput.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export interface PickerInputProps extends PickerInputBaseProps {
2626
formatDate: (v: Date) => string;
2727
parseDate: (v: string) => Date;
2828
disabledDate: (v: Date) => boolean;
29+
holidayDate: (v: Date) => boolean;
30+
holidayClickable?: boolean;
2931
onChange: (v: Date | Date[] | null | null[]) => void;
3032
onFocus: () => void;
3133
onBlur: () => void;

lib/calendar/Calendar.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function Calendar(originalProps: CalendarProps) {
4242
defaultValue: startOfDay(new Date()),
4343
type: 'date' as PickerType,
4444
disabledDate: () => false,
45-
holidayClickable: () => false,
45+
holidayClickable: false,
4646
holidayDate: () => false,
4747
getClasses: () => [],
4848
titleFormat: 'YYYY-MM-DD',
@@ -97,10 +97,7 @@ function Calendar(originalProps: CalendarProps) {
9797
if (isDisabled(date)) {
9898
return false;
9999
}
100-
if (!props.holidayClickable && isHoliday(date)) {
101-
return false;
102-
}
103-
return true;
100+
return !(!props.holidayClickable && isHoliday(date));
104101
};
105102

106103
const emitDate = (date: Date, type: string) => {

src/App.vue

Lines changed: 89 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,101 @@
11
<script lang="ts">
2-
import { defineComponent } from 'vue';
3-
import DatePicker from 'vue-datepicker-next';
4-
import { format, parse } from 'date-format-parse';
2+
import { format, parse } from "date-format-parse"
3+
import { defineComponent } from "vue"
4+
import DatePicker from "vue-datepicker-next"
55
6-
export default defineComponent({
7-
components: {
8-
DatePicker,
9-
},
10-
data() {
11-
return {
12-
inputProps: {
13-
clearable: false,
14-
editable: false,
15-
placeholder: 'test placeholder',
16-
inputAttr: {
17-
name: 'test',
18-
id: 'test',
6+
export default defineComponent({
7+
components: {
8+
DatePicker,
199
},
20-
},
21-
shortcuts: [
22-
{
23-
text: 'range',
24-
onClick() {
25-
return [new Date(), new Date()];
26-
},
10+
data() {
11+
return {
12+
inputProps: {
13+
clearable: false,
14+
editable: false,
15+
placeholder: "test placeholder",
16+
inputAttr: {
17+
name: "test",
18+
id: "test",
19+
},
20+
},
21+
shortcuts: [
22+
{
23+
text: "range",
24+
onClick() {
25+
return [new Date(), new Date()]
26+
},
27+
},
28+
],
29+
value: new Date(),
30+
append: false,
31+
rangeValue: [new Date(2019, 9, 4, 8, 30, 0), new Date(2019, 9, 4, 18, 30, 0)],
32+
formatter: {
33+
stringify(date: Date) {
34+
return format(date, "DD/MMM/YYYY")
35+
},
36+
parse(value: string) {
37+
return parse(value, "DD/MMM/YYYY")
38+
},
39+
getWeek(date: Date) {
40+
return date.getDate()
41+
},
42+
},
43+
}
2744
},
28-
],
29-
value: new Date(),
30-
append: false,
31-
rangeValue: [new Date(2019, 9, 4, 8, 30, 0), new Date(2019, 9, 4, 18, 30, 0)],
32-
formatter: {
33-
stringify(date: Date) {
34-
return format(date, 'DD/MMM/YYYY');
45+
methods: {
46+
handleChange() {
47+
console.log("change")
48+
},
49+
handleUpdate(val: Date) {
50+
this.value = val
51+
},
3552
},
36-
parse(value: string) {
37-
return parse(value, 'DD/MMM/YYYY');
38-
},
39-
getWeek(date: Date) {
40-
return date.getDate();
41-
},
42-
},
43-
};
44-
},
45-
methods: {
46-
handleChange() {
47-
console.log('change');
48-
},
49-
handleUpdate(val: Date) {
50-
this.value = val;
51-
},
52-
},
53-
});
53+
})
5454
</script>
5555

5656
<template>
57-
<div>
58-
<button @click="append = !append">ass</button>
59-
<DatePicker
60-
v-model:value="value"
61-
v-bind="inputProps"
62-
:clearable="false"
63-
:append-to-body="append"
64-
type="datetime"
65-
:time-picker-options="{ start: '00:00', end: '09:00', step: '00:30' }"
66-
:disabled-date="(date) => date < new Date(2021, 10, 9)"
67-
:open="true"
68-
></DatePicker>
69-
<DatePicker
70-
v-model:value="rangeValue"
71-
:append-to-body="false"
72-
range
73-
:shortcuts="shortcuts"
74-
:editable="false"
75-
></DatePicker>
76-
</div>
57+
<div>
58+
<button @click="append = !append">ass</button>
59+
<DatePicker
60+
v-model:value="value"
61+
v-bind="inputProps"
62+
:clearable="false"
63+
:append-to-body="append"
64+
type="datetime"
65+
:time-picker-options="{ start: '00:00', end: '09:00', step: '00:30' }"
66+
:disabled-date="(date) => date < new Date(2021, 10, 9)"
67+
:holiday-clickable="false"
68+
:holiday-date="(date)=>date > new Date()"
69+
:open="true"
70+
></DatePicker>
71+
<DatePicker
72+
v-model:value="rangeValue"
73+
:append-to-body="false"
74+
range
75+
:shortcuts="shortcuts"
76+
:disabled-date="(date) => date < new Date(2021, 10, 9)"
77+
:editable="false"
78+
:holiday-clickable="false"
79+
:holiday-date="(date)=>date > new Date()"
80+
></DatePicker>
81+
<DatePicker v-model:value="value"
82+
:holiday-clickable="true"
83+
:holiday-date="(date)=>date > new Date()">
84+
</DatePicker>
85+
</div>
7786
</template>
7887

7988
<style>
80-
#app {
81-
font-family: Avenir, Helvetica, Arial, sans-serif;
82-
-webkit-font-smoothing: antialiased;
83-
-moz-osx-font-smoothing: grayscale;
84-
/* color: #2c3e50; */
85-
margin-top: 60px;
86-
margin-left: 60px;
87-
}
89+
#app {
90+
font-family: Avenir, Helvetica, Arial, sans-serif;
91+
-webkit-font-smoothing: antialiased;
92+
-moz-osx-font-smoothing: grayscale;
93+
/* color: #2c3e50; */
94+
margin-top: 60px;
95+
margin-left: 60px;
96+
}
97+
98+
.holiday {
99+
color: #ff0000;
100+
}
88101
</style>

0 commit comments

Comments
 (0)