I'm pretty new on Vue Cal VueJS 3. I need help on this.
I have these events data which have boolean condition. if true, display green color otherwise red color.
I refer to Vue Cal documentation, and right now I don't have idea how can I set different background color to date cell on month view calendar.
In inspect element, I can see that I need to adjust the class of .vuecal__cell--selected
to achieve my goal . But I'm not sure how to add it inside <vue-cal><vue-cal>
component.
This is what I achieve so far.
Component.vue
<template>
<vue-cal
class="vuecal--blue-theme"
selected-date="2022-08-25"
xsmall
:disable-views="['years', 'year', 'week', 'day']"
active-view="month"
:events-on-month-views="true"
:events="calendarEvents"
hide-view-selector
:time="false"
style="width: 300px; height: 262px"
>
<template #events-count="{ events }">
<span :style="{ backgroundColor: '#00FF00' }" v-if="eventWorkingDay(events) === true"
>1
<span :style="{ backgroundColor: '#00FF00' }" v-if="eventIsAvailable(events) === true">1</span>
<span :style="{ backgroundColor: '#FF0000' }" v-else>1</span>
</span>
<span :style="{ backgroundColor: '#FF0000' }" v-else>1</span>
</template>
</vue-cal>
</template>
<script>
import vuecal from 'vue-cal';
import 'vue-cal/dist/vuecal.css';
import { defineComponent, ref } from 'vue';
export default defineComponent({
name: 'Calendar',
components: {
'vue-cal': vuecal,
},
setup() {
const calendarEvents = ref([
{
id: '01',
start: '2022-08-01',
end: '2022-08-01',
name: 'Event Name 01',
isWorkingDay: false,
isAvailable: false,
},
{
id: '02',
start: '2022-08-02',
end: '2022-08-02',
name: 'Event Name 02',
isWorkingDay: false,
isAvailable: false,
},
{
id: '03',
start: '2022-08-03',
end: '2022-08-03',
name: 'Event Name 03',
isWorkingDay: false,
isAvailable: false,
}
]);
const eventCount = (calendarEvents) => {
for (let i = 0; i < calendarEvents.length; i++) {
let cond = calendarEvents[i].isWorkingDay;
if (cond === true) {
return 0;
} else {
return 1;
}
}
};
const eventWorkingDay = (calendarEvents) => {
for (let i = 0; i < calendarEvents.length; i++) {
let cond = calendarEvents[i].isWorkingDay;
if (cond === true) {
return true;
} else {
return false;
}
}
};
const eventIsAvailable = (calendarEvents) => {
for (let i = 0; i < calendarEvents.length; i++) {
let cond = calendarEvents[i].isAvailable;
if (cond === true) {
return true;
} else {
return false;
}
}
};
return {
inputs,
eventCount,
eventWorkingDay,
eventIsAvailable,
calendarEvents,
};
},
});
</script>
<style scoped>
.vuecal__cell-events-count {
background: transparent;
}
</style>
Current Output :
Expected Output : I want to fill date cell to background-color like this.
Appreciate if someone can help me on this. Thanks.