feat: make active class work
This commit is contained in:
parent
8115563d67
commit
3d1c1e41c7
2 changed files with 44 additions and 19 deletions
|
@ -1,17 +1,24 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="datepicker-with-range">
|
<div class="datepicker-with-range">
|
||||||
<div class="selections">
|
<div class="selections">
|
||||||
<a @click="setDatesToToday">Today</a>
|
<button @click="setDateRange(datesToday)" :class="{'is-active': dateRange === datesToday}">
|
||||||
<a @click="setDatesToNextWeek">Next Week</a>
|
{{ $t('task.show.today') }}
|
||||||
<a @click="setDatesToNextMonth">Next Month</a>
|
</button>
|
||||||
<a>Custom</a>
|
<button @click="setDateRange(datesNextWeek)" :class="{'is-active': dateRange === datesNextWeek}">
|
||||||
|
{{ $t('task.show.nextWeek') }}
|
||||||
|
</button>
|
||||||
|
<button @click="setDateRange(datesNextMonth)" :class="{'is-active': dateRange === datesNextMonth}">
|
||||||
|
{{ $t('task.show.nextMonth') }}
|
||||||
|
</button>
|
||||||
|
<button :class="{'is-active': customRangeActive}">
|
||||||
|
{{ $t('misc.custom') }}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="flatpickr-container">
|
<div class="flatpickr-container">
|
||||||
<flat-pickr
|
<flat-pickr
|
||||||
:config="flatPickerConfig"
|
:config="flatPickerConfig"
|
||||||
v-model="dateRange"
|
v-model="dateRange"
|
||||||
/>
|
/>
|
||||||
{{ dateRange }}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -48,6 +55,10 @@ const dateRange = ref('')
|
||||||
watch(
|
watch(
|
||||||
() => dateRange.value,
|
() => dateRange.value,
|
||||||
newVal => {
|
newVal => {
|
||||||
|
if (newVal === null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const [fromDate, toDate] = newVal.split(' to ')
|
const [fromDate, toDate] = newVal.split(' to ')
|
||||||
|
|
||||||
if (typeof fromDate === 'undefined' || typeof toDate === 'undefined') {
|
if (typeof fromDate === 'undefined' || typeof toDate === 'undefined') {
|
||||||
|
@ -65,23 +76,33 @@ function formatDate(date) {
|
||||||
return format(date, 'yyyy-MM-dd HH:mm')
|
return format(date, 'yyyy-MM-dd HH:mm')
|
||||||
}
|
}
|
||||||
|
|
||||||
function setDatesToToday() {
|
const datesToday = computed(() => {
|
||||||
const startDate = new Date()
|
const startDate = new Date()
|
||||||
const endDate = new Date((new Date()).setDate((new Date()).getDate() + 1))
|
const endDate = new Date((new Date()).setDate((new Date()).getDate() + 1))
|
||||||
dateRange.value = `${formatDate(startDate)} to ${formatDate(endDate)}`
|
return `${formatDate(startDate)} to ${formatDate(endDate)}`
|
||||||
}
|
})
|
||||||
|
|
||||||
function setDatesToNextWeek() {
|
const datesNextWeek = computed(() => {
|
||||||
const startDate = new Date()
|
const startDate = new Date()
|
||||||
const endDate = new Date((new Date()).getTime() + 7 * 24 * 60 * 60 * 1000)
|
const endDate = new Date((new Date()).getTime() + 7 * 24 * 60 * 60 * 1000)
|
||||||
dateRange.value = `${formatDate(startDate)} to ${formatDate(endDate)}`
|
return `${formatDate(startDate)} to ${formatDate(endDate)}`
|
||||||
}
|
})
|
||||||
|
|
||||||
function setDatesToNextMonth() {
|
const datesNextMonth = computed(() => {
|
||||||
const startDate = new Date()
|
const startDate = new Date()
|
||||||
const endDate = new Date((new Date()).setMonth((new Date()).getMonth() + 1))
|
const endDate = new Date((new Date()).setMonth((new Date()).getMonth() + 1))
|
||||||
dateRange.value = `${formatDate(startDate)} to ${formatDate(endDate)}`
|
return `${formatDate(startDate)} to ${formatDate(endDate)}`
|
||||||
|
})
|
||||||
|
|
||||||
|
function setDateRange(range) {
|
||||||
|
dateRange.value = range
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const customRangeActive = computed(() => {
|
||||||
|
return dateRange.value !== datesToday.value &&
|
||||||
|
dateRange.value !== datesNextWeek.value &&
|
||||||
|
dateRange.value !== datesNextMonth.value
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
@ -113,7 +134,7 @@ function setDatesToNextMonth() {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
||||||
a {
|
button {
|
||||||
display: block;
|
display: block;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
|
@ -121,12 +142,15 @@ function setDatesToNextMonth() {
|
||||||
transition: $transition;
|
transition: $transition;
|
||||||
font-size: .9rem;
|
font-size: .9rem;
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
|
background: transparent;
|
||||||
|
border: 0;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
&.active {
|
&.is-active {
|
||||||
color: var(--primary);
|
color: var(--primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
&:hover, &.active {
|
&:hover, &.is-active {
|
||||||
background-color: var(--grey-100);
|
background-color: var(--grey-100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -476,7 +476,8 @@
|
||||||
"showMenu": "Show the menu",
|
"showMenu": "Show the menu",
|
||||||
"hideMenu": "Hide the menu",
|
"hideMenu": "Hide the menu",
|
||||||
"forExample": "For example:",
|
"forExample": "For example:",
|
||||||
"welcomeBack": "Welcome Back!"
|
"welcomeBack": "Welcome Back!",
|
||||||
|
"custom": "Custom"
|
||||||
},
|
},
|
||||||
"input": {
|
"input": {
|
||||||
"resetColor": "Reset Color",
|
"resetColor": "Reset Color",
|
||||||
|
|
Loading…
Reference in a new issue