Browse Source

feat(nc-gui): week picker

pull/7611/head
DarkPhoenix2704 9 months ago
parent
commit
92627f9163
  1. 50
      packages/nc-gui/components/nc/DatePicker.vue
  2. 2
      packages/nc-gui/lang/en.json

50
packages/nc-gui/components/nc/DatePicker.vue

@ -6,20 +6,29 @@ interface Props {
pageDate?: Date; pageDate?: Date;
activeDates?: Date[]; activeDates?: Date[];
isMondayFirst?: boolean; isMondayFirst?: boolean;
weekPicker?: boolean;
startDate?: Date | null;
endDate?: Date | null;
} }
const emit = defineEmits(['change', 'update:selectedDate', 'update:pageDate']); const emit = defineEmits(['change', 'update:selected-date', 'update:page-date', 'update:start-date', 'update:end-date']);
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
selectedDate: null, selectedDate: null,
isDisabled: false, isDisabled: false,
isMondayFirst: false, isMondayFirst: false,
pageDate: new Date(), pageDate: new Date(),
weekPicker: false,
activeDates: [], activeDates: [],
startDate: null,
endDate: null,
}); });
const pageDate = useVModel(props, 'pageDate', emit); const pageDate = useVModel(props, 'pageDate', emit);
const selectedDate = useVModel(props, 'selectedDate', emit); const selectedDate = useVModel(props, 'selectedDate', emit);
const activeDates = useVModel(props, 'activeDates', emit); const activeDates = useVModel(props, 'activeDates', emit);
const startDate = useVModel(props, 'startDate', emit);
const endDate = useVModel(props, 'endDate', emit);
const days = computed(() => { const days = computed(() => {
if (props.isMondayFirst) { if (props.isMondayFirst) {
@ -82,6 +91,7 @@ const blankDaysAtEnd = computed((): any => {
}); });
function isSelectedDate(dObj: Date): boolean { function isSelectedDate(dObj: Date): boolean {
if(!selectedDate.value) return false;
const propDate = new Date(selectedDate.value); const propDate = new Date(selectedDate.value);
return props.selectedDate ? compareDates(propDate, dObj) : false; return props.selectedDate ? compareDates(propDate, dObj) : false;
} }
@ -109,6 +119,7 @@ interface DateObj {
isSelected: boolean; isSelected: boolean;
timestamp: number; timestamp: number;
hasEvent: boolean; hasEvent: boolean;
inSelectedWeek: boolean;
} }
const monthDays = computed((): DateObj[] => { const monthDays = computed((): DateObj[] => {
@ -123,6 +134,7 @@ const monthDays = computed((): DateObj[] => {
date: dObj.getDate(), date: dObj.getDate(),
isSelected: isSelectedDate(dObj), isSelected: isSelectedDate(dObj),
hasEvent: isActiveDate(dObj), hasEvent: isActiveDate(dObj),
inSelectedWeek: false,
}); });
setDate(dObj, (dObj.getDate() + 1)); setDate(dObj, (dObj.getDate() + 1));
} }
@ -137,14 +149,32 @@ const paginateMonth = (direction: 'next' | 'prev') => {
newDate.setMonth(newDate.getMonth() - 1); newDate.setMonth(newDate.getMonth() - 1);
} }
pageDate.value = newDate; pageDate.value = newDate;
emit('update:pageDate', newDate); emit('update:page-date', newDate);
}; };
const selectDate = (day: number) => { const selectDate = (day: number) => {
const date = new Date(pageDate.value); if(props.weekPicker) {
date.setDate(day); const date = new Date(pageDate.value.getFullYear(), pageDate.value.getMonth(), day)
selectedDate.value = date; if(!startDate.value) {
emit('update:selectedDate', date); console.log('setting start date')
startDate.value = date;
console.log(startDate.value)
emit('update:start-date', date);
} else if(!endDate.value) {
endDate.value = date;
emit('update:end-date', date);
} else {
startDate.value = date;
endDate.value = null;
emit('update:start-date', date);
emit('update:end-date', null);
}
} else {
const date = new Date(pageDate.value);
date.setDate(day);
selectedDate.value = date;
emit('update:selected-date', date);
}
}; };
</script> </script>
@ -166,9 +196,11 @@ const selectDate = (day: number) => {
<div class="flex flex-row flex-wrap gap-2 p-2"> <div class="flex flex-row flex-wrap gap-2 p-2">
<span v-for="day in blankDaysAtStart" class="h-9 w-9 px-1 py-2 text-gray-400 flex items-center justify-center">{{day.day}}</span> <span v-for="day in blankDaysAtStart" class="h-9 w-9 px-1 py-2 text-gray-400 flex items-center justify-center">{{day.day}}</span>
<span v-for="day in monthDays" :key="day.timestamp" :class="{ <span v-for="day in monthDays" :key="day.timestamp" :class="{
'bg-brand-50 border-2 !border-brand-500' : day.isSelected, 'rounded-lg' : !weekPicker,
'hover:(border-1 border-gray-200 bg-gray-100)' : !day.isSelected 'bg-brand-50 border-2 !border-brand-500' : day.isSelected && !weekPicker,
}" class="h-9 w-9 px-1 py-2 relative font-medium rounded-lg flex items-center cursor-pointer justify-center" 'hover:(border-1 border-gray-200 bg-gray-100)' : !day.isSelected && !weekPicker,
'border-y-2 border-brand-50 !border-brand-500': day.inSelectedWeek && weekPicker,
}" class="h-9 w-9 px-1 py-2 relative font-medium flex items-center cursor-pointer justify-center"
@click="selectDate(day.date)" @click="selectDate(day.date)"
> >
<span v-if="day.hasEvent" class="absolute h-1.5 w-1.5 rounded-full bg-brand-500 top-1 right-1"></span> <span v-if="day.hasEvent" class="absolute h-1.5 w-1.5 rounded-full bg-brand-500 top-1 right-1"></span>

2
packages/nc-gui/lang/en.json

@ -208,7 +208,7 @@
"page": "Page", "page": "Page",
"pages": "Pages", "pages": "Pages",
"record": "record", "record": "record",
"records": "records", "records": "Records",
"webhook": "Webhook", "webhook": "Webhook",
"webhooks": "Webhooks", "webhooks": "Webhooks",
"view": "View", "view": "View",

Loading…
Cancel
Save