You can customize how the header of calendar looks and how the components are arranged. Besides that you can also add custom functionality, like a segmented control that lets people switch between week and month view.
Use the header template for passing a custom header layout. There are predefined components - shorthands if you will - that can be used to assemble the header:
- Navigation component -
<MbscCalendarNav />. - Today button -
<MbscCalendarToday />. - Previous month button -
<MbscCalendarPrev />. - Next month button -
<MbscCalendarNext />.
Demo
The default header contains the two arrows on the far-right for previous and next months, while the current month indicator with the
MbscCalendarNav
component is placed to the far-left.
<template>
<MbscDatepicker
:controls="['calendar']"
:calendarSize="2"
calendarType="week"/>
</template>
You can reorder the controls and place the
MbscCalendarNav
in the middle with the two arrows -
MbscCalendarPrev and MbscCalendarNext
- to the sides.
<template>
<MbscDatepicker :controls="['calendar']">
<template #header>
<MbscCalendarPrev cssClass="custom-prev" />
<MbscCalendarNav cssClass="custom-nav" />
<MbscCalendarNext cssClass="custom-next" />
</template>
</MbscDatepicker>
</template>
You can also add a custom component, like a
MbscCalendarToday
button.
<template>
<MbscDatepicker :controls="['calendar']">
<template #header>
<MbscCalendarNav />
<div class="custom-buttons">
<MbscCalendarPrev />
<MbscCalendarToday />
<MbscCalendarNext />
</div>
</template>
</MbscDatepicker>
</template>
Use a segmented component for creating a view switcher.
<script setup>
const myCalendarType = ref('week')
</script>
<template>
<MbscDatepicker :controls="['calendar']" :calendarType="myCalendarType" :calendarSize="2">
<template #header>
<MbscCalendarNav cssClass="custom-view-nav" />
<div class="custom-view">
<MbscSegmentedGroup v-model="myCalendarType">
<MbscSegmented value="week" icon="material-date-range"></MbscSegmented>
<MbscSegmented value="month" icon="material-event-note"></MbscSegmented>
</MbscSegmentedGroup>
</div>
</template>
</MbscDatepicker>
</template>
Above all that you can give instructions or show the selected {value} in the header
<template>
<MbscDatepicker
:controls="['calendar']"
:calendarSize="2"
calendarType="week"
headerText="You selected {value}"
>
</template>
<script setup>
import {
MbscCalendarNav,
MbscCalendarNext,
MbscCalendarPrev,
MbscCalendarToday,
MbscDatepicker,
MbscSegmented,
MbscSegmentedGroup,
setOptions
} from '@mobiscroll/vue'
import { ref } from 'vue'
setOptions({
locale: ,
theme: ' ',
themeVariant: ' '
})
const myCalendarType = ref('week')
</script>
<template>
<MbscDatepicker :controls="['calendar']" :calendarSize="2" display="inline" calendarType="week" />
<MbscDatepicker :controls="['calendar']" display="inline">
<template #header>
<MbscCalendarPrev cssClass="custom-prev" />
<MbscCalendarNav cssClass="custom-nav" />
<MbscCalendarNext cssClass="custom-next" />
</template>
</MbscDatepicker>
<MbscDatepicker :controls="['calendar']" display="inline">
<template #header>
<MbscCalendarNav />
<div class="custom-buttons">
<MbscCalendarPrev />
<MbscCalendarToday />
<MbscCalendarNext />
</div>
</template>
</MbscDatepicker>
<MbscDatepicker
:controls="['calendar']"
:calendarSize="2"
:calendarType="myCalendarType"
display="inline"
>
<template #header>
<MbscCalendarNav cssClass="custom-view-nav" />
<div class="custom-view">
<MbscSegmentedGroup v-model="myCalendarType">
<MbscSegmented value="week" icon="material-date-range"></MbscSegmented>
<MbscSegmented value="month" icon="material-event-note"></MbscSegmented>
</MbscSegmentedGroup>
</div>
</template>
</MbscDatepicker>
<MbscDatepicker
:controls="['calendar']"
:calendarSize="2"
display="inline"
calendarType="week"
headerText="You selected {value}"
/>
</template>
<style>
.custom-buttons,
.custom-view,
.custom-nav {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: flex;
-webkit-flex: 1 0 auto;
-moz-box-flex: 1;
-ms-flex: 1 0 auto;
flex: 1 0 auto;
}
.custom-buttons {
-webkit-justify-content: flex-end;
-moz-box-pack: end;
-ms-flex-pack: end;
justify-content: flex-end;
}
.custom-view,
.custom-nav {
-webkit-justify-content: center;
-moz-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
}
.custom-view-nav .mbsc-calendar-title.mbsc-material {
font-size: 16px;
}
.custom-view .mbsc-segmented {
margin: 0;
}
.custom-view .mbsc-segmented.mbsc-material,
.custom-view .mbsc-segmented.mbsc-windows {
padding: 0 2px;
}
.custom-view .mbsc-segmented .mbsc-segmented-button {
padding: 0 1px;
}
.custom-view .mbsc-segmented .mbsc-icon {
font-size: 20px;
}
.custom-view .mbsc-segmented-button.mbsc-windows {
border: 0;
}
</style><script setup lang="ts">
import {
MbscCalendarNav,
MbscCalendarNext,
MbscCalendarPrev,
MbscCalendarToday,
MbscDatepicker,
MbscSegmented,
MbscSegmentedGroup,
setOptions
} from '@mobiscroll/vue'
import { ref } from 'vue'
setOptions({
locale: ,
theme: ' ',
themeVariant: ' '
})
const myCalendarType = ref<'month' | 'week'>('week')
</script>
<template>
<MbscDatepicker :controls="['calendar']" :calendarSize="2" display="inline" calendarType="week" />
<MbscDatepicker :controls="['calendar']" display="inline">
<template #header>
<MbscCalendarPrev cssClass="custom-prev" />
<MbscCalendarNav cssClass="custom-nav" />
<MbscCalendarNext cssClass="custom-next" />
</template>
</MbscDatepicker>
<MbscDatepicker :controls="['calendar']" display="inline">
<template #header>
<MbscCalendarNav />
<div class="custom-buttons">
<MbscCalendarPrev />
<MbscCalendarToday />
<MbscCalendarNext />
</div>
</template>
</MbscDatepicker>
<MbscDatepicker
:controls="['calendar']"
:calendarSize="2"
:calendarType="myCalendarType"
display="inline"
>
<template #header>
<MbscCalendarNav cssClass="custom-view-nav" />
<div class="custom-view">
<MbscSegmentedGroup v-model="myCalendarType">
<MbscSegmented value="week" icon="material-date-range"></MbscSegmented>
<MbscSegmented value="month" icon="material-event-note"></MbscSegmented>
</MbscSegmentedGroup>
</div>
</template>
</MbscDatepicker>
<MbscDatepicker
:controls="['calendar']"
:calendarSize="2"
display="inline"
calendarType="week"
headerText="You selected {value}"
/>
</template>
<style>
.custom-buttons,
.custom-view,
.custom-nav {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: flex;
-webkit-flex: 1 0 auto;
-moz-box-flex: 1;
-ms-flex: 1 0 auto;
flex: 1 0 auto;
}
.custom-buttons {
-webkit-justify-content: flex-end;
-moz-box-pack: end;
-ms-flex-pack: end;
justify-content: flex-end;
}
.custom-view,
.custom-nav {
-webkit-justify-content: center;
-moz-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
}
.custom-view-nav .mbsc-calendar-title.mbsc-material {
font-size: 16px;
}
.custom-view .mbsc-segmented {
margin: 0;
}
.custom-view .mbsc-segmented.mbsc-material,
.custom-view .mbsc-segmented.mbsc-windows {
padding: 0 2px;
}
.custom-view .mbsc-segmented .mbsc-segmented-button {
padding: 0 1px;
}
.custom-view .mbsc-segmented .mbsc-icon {
font-size: 20px;
}
.custom-view .mbsc-segmented-button.mbsc-windows {
border: 0;
}
</style>