Refactor #3832 Refactor #3833 - For Calendar

pull/3853/head
Tuğçe Küçükoğlu 2023-04-06 11:19:46 +03:00
parent 679926be00
commit 448e5edc52
3 changed files with 116 additions and 24 deletions

View File

@ -44,9 +44,33 @@ const CalendarProps = [
{ {
name: 'icon', name: 'icon',
type: 'string', type: 'string',
default: 'pi pi-calendar', default: 'null',
description: 'Icon of the calendar button.' description: 'Icon of the calendar button.'
}, },
{
name: 'previousIcon',
type: 'string',
default: 'null',
description: 'Icon to show in the previous button.'
},
{
name: 'nextIcon',
type: 'string',
default: 'null',
description: 'Icon to show in the next button.'
},
{
name: 'incrementIcon',
type: 'string',
default: 'null',
description: 'Icon to show in each of the increment buttons.'
},
{
name: 'decrementIcon',
type: 'string',
default: 'null',
description: 'Icon to show in each of the decrement buttons.'
},
{ {
name: 'numberOfMonths', name: 'numberOfMonths',
type: 'number', type: 'number',
@ -436,6 +460,26 @@ const CalendarSlots = [
{ {
name: 'decade', name: 'decade',
description: 'Custom content for the calendar decade.' description: 'Custom content for the calendar decade.'
},
{
name: 'triggericon',
description: 'Custom trigger icon template.'
},
{
name: 'previcon',
description: 'Custom previous icon template.'
},
{
name: 'nexticon',
description: 'Custom next icon template.'
},
{
name: 'incrementicon',
description: 'Custom increment icon template.'
},
{
name: 'decrementicon',
description: 'Custom decrement icon template.'
} }
]; ];

View File

@ -109,27 +109,22 @@ export interface CalendarProps {
showIcon?: boolean | undefined; showIcon?: boolean | undefined;
/** /**
* Icon of the calendar button. * Icon of the calendar button.
* @defaultValue pi pi-calendar
*/ */
icon?: string | undefined; icon?: string | undefined;
/** /**
* Icon to show in the previous button. * Icon to show in the previous button.
* @defaultValue pi pi-chevron-left
*/ */
previousIcon?: string | undefined; previousIcon?: string | undefined;
/** /**
* Icon to show in the next button. * Icon to show in the next button.
* @defaultValue pi pi-chevron-right
*/ */
nextIcon?: string | undefined; nextIcon?: string | undefined;
/** /**
* Icon to show in each of the increment buttons. * Icon to show in each of the increment buttons.
* @defaultValue pi pi-chevron-up
*/ */
incrementIcon?: string | undefined; incrementIcon?: string | undefined;
/** /**
* Icon to show in each of the decrement buttons. * Icon to show in each of the decrement buttons.
* @defaultValue pi pi-chevron-down
*/ */
decrementIcon?: string | undefined; decrementIcon?: string | undefined;
/** /**
@ -368,6 +363,26 @@ export interface CalendarSlots {
*/ */
years: string[] | undefined; years: string[] | undefined;
}): VNode[]; }): VNode[];
/**
* Custom trigger icon template.
*/
triggericon(): VNode[];
/**
* Custom previous icon template.
*/
previcon(): VNode[];
/**
* Custom next icon template.
*/
nexticon(): VNode[];
/**
* Custom increment icon template.
*/
incrementicon(): VNode[];
/**
* Custom decrement icon template.
*/
decrementicon(): VNode[];
} }
/** /**

View File

@ -29,7 +29,6 @@
/> />
<CalendarButton <CalendarButton
v-if="showIcon" v-if="showIcon"
:icon="icon"
class="p-datepicker-trigger" class="p-datepicker-trigger"
:disabled="disabled" :disabled="disabled"
@click="onButtonClick" @click="onButtonClick"
@ -38,7 +37,11 @@
aria-haspopup="dialog" aria-haspopup="dialog"
:aria-expanded="overlayVisible" :aria-expanded="overlayVisible"
:aria-controls="panelId" :aria-controls="panelId"
/> >
<slot name="triggericon">
<component :is="icon ? 'span' : 'CalendarIcon'" :class="icon" />
</slot>
</CalendarButton>
<Portal :appendTo="appendTo" :disabled="inline"> <Portal :appendTo="appendTo" :disabled="inline">
<transition name="p-connected-overlay" @enter="onOverlayEnter($event)" @after-enter="onOverlayEnterComplete" @after-leave="onOverlayAfterLeave" @leave="onOverlayLeave"> <transition name="p-connected-overlay" @enter="onOverlayEnter($event)" @after-enter="onOverlayEnterComplete" @after-leave="onOverlayAfterLeave" @leave="onOverlayLeave">
<div <div
@ -70,7 +73,9 @@
:disabled="disabled" :disabled="disabled"
:aria-label="currentView === 'year' ? $primevue.config.locale.prevDecade : currentView === 'month' ? $primevue.config.locale.prevYear : $primevue.config.locale.prevMonth" :aria-label="currentView === 'year' ? $primevue.config.locale.prevDecade : currentView === 'month' ? $primevue.config.locale.prevYear : $primevue.config.locale.prevMonth"
> >
<span :class="['p-datepicker-prev-icon', previousIcon]" /> <slot name="previcon">
<component :is="previousIcon ? 'span' : 'ChevronLeftIcon'" :class="['p-datepicker-prev-icon', previousIcon]" />
</slot>
</button> </button>
<div class="p-datepicker-title"> <div class="p-datepicker-title">
<button <button
@ -109,7 +114,9 @@
:disabled="disabled" :disabled="disabled"
:aria-label="currentView === 'year' ? $primevue.config.locale.nextDecade : currentView === 'month' ? $primevue.config.locale.nextYear : $primevue.config.locale.nextMonth" :aria-label="currentView === 'year' ? $primevue.config.locale.nextDecade : currentView === 'month' ? $primevue.config.locale.nextYear : $primevue.config.locale.nextMonth"
> >
<span :class="['p-datepicker-next-icon', nextIcon]" /> <slot name="nexticon">
<component :is="nextIcon ? 'span' : 'ChevronRightIcon'" :class="['p-datepicker-next-icon', nextIcon]" />
</slot>
</button> </button>
</div> </div>
<div v-if="currentView === 'date'" class="p-datepicker-calendar-container"> <div v-if="currentView === 'date'" class="p-datepicker-calendar-container">
@ -202,7 +209,9 @@
@keyup.space="onTimePickerElementMouseUp($event)" @keyup.space="onTimePickerElementMouseUp($event)"
type="button" type="button"
> >
<span :class="incrementIcon" /> <slot name="incrementicon">
<component :is="incrementIcon ? 'span' : 'ChevronUpIcon'" :class="incrementIcon" />
</slot>
</button> </button>
<span>{{ formattedCurrentHour }}</span> <span>{{ formattedCurrentHour }}</span>
<button <button
@ -219,7 +228,9 @@
@keyup.space="onTimePickerElementMouseUp($event)" @keyup.space="onTimePickerElementMouseUp($event)"
type="button" type="button"
> >
<span :class="decrementIcon" /> <slot name="decrementicon">
<component :is="decrementIcon ? 'span' : 'ChevronDownIcon'" :class="decrementIcon" />
</slot>
</button> </button>
</div> </div>
<div class="p-separator"> <div class="p-separator">
@ -241,7 +252,9 @@
@keyup.space="onTimePickerElementMouseUp($event)" @keyup.space="onTimePickerElementMouseUp($event)"
type="button" type="button"
> >
<span :class="incrementIcon" /> <slot name="incrementicon">
<component :is="incrementIcon ? 'span' : 'ChevronUpIcon'" :class="incrementIcon" />
</slot>
</button> </button>
<span>{{ formattedCurrentMinute }}</span> <span>{{ formattedCurrentMinute }}</span>
<button <button
@ -259,7 +272,9 @@
@keyup.space="onTimePickerElementMouseUp($event)" @keyup.space="onTimePickerElementMouseUp($event)"
type="button" type="button"
> >
<span :class="decrementIcon" /> <slot name="decrementicon">
<component :is="decrementIcon ? 'span' : 'ChevronDownIcon'" :class="decrementIcon" />
</slot>
</button> </button>
</div> </div>
<div v-if="showSeconds" class="p-separator"> <div v-if="showSeconds" class="p-separator">
@ -281,7 +296,9 @@
@keyup.space="onTimePickerElementMouseUp($event)" @keyup.space="onTimePickerElementMouseUp($event)"
type="button" type="button"
> >
<span :class="incrementIcon" /> <slot name="incrementicon">
<component :is="incrementIcon ? 'span' : 'ChevronUpIcon'" :class="incrementIcon" />
</slot>
</button> </button>
<span>{{ formattedCurrentSecond }}</span> <span>{{ formattedCurrentSecond }}</span>
<button <button
@ -299,7 +316,9 @@
@keyup.space="onTimePickerElementMouseUp($event)" @keyup.space="onTimePickerElementMouseUp($event)"
type="button" type="button"
> >
<span :class="decrementIcon" /> <slot name="decrementicon">
<component :is="decrementIcon ? 'span' : 'ChevronDownIcon'" :class="decrementIcon" />
</slot>
</button> </button>
</div> </div>
<div v-if="hourFormat == '12'" class="p-separator"> <div v-if="hourFormat == '12'" class="p-separator">
@ -307,11 +326,15 @@
</div> </div>
<div v-if="hourFormat == '12'" class="p-ampm-picker"> <div v-if="hourFormat == '12'" class="p-ampm-picker">
<button v-ripple class="p-link" :aria-label="$primevue.config.locale.am" @click="toggleAMPM($event)" type="button" :disabled="disabled"> <button v-ripple class="p-link" :aria-label="$primevue.config.locale.am" @click="toggleAMPM($event)" type="button" :disabled="disabled">
<span :class="incrementIcon" /> <slot name="incrementicon">
<component :is="incrementIcon ? 'span' : 'ChevronUpIcon'" :class="incrementIcon" />
</slot>
</button> </button>
<span>{{ pm ? $primevue.config.locale.pm : $primevue.config.locale.am }}</span> <span>{{ pm ? $primevue.config.locale.pm : $primevue.config.locale.am }}</span>
<button v-ripple class="p-link" :aria-label="$primevue.config.locale.pm" @click="toggleAMPM($event)" type="button" :disabled="disabled"> <button v-ripple class="p-link" :aria-label="$primevue.config.locale.pm" @click="toggleAMPM($event)" type="button" :disabled="disabled">
<span :class="decrementIcon" /> <slot name="decrementicon">
<component :is="decrementIcon ? 'span' : 'ChevronDownIcon'" :class="decrementIcon" />
</slot>
</button> </button>
</div> </div>
</div> </div>
@ -328,6 +351,11 @@
<script> <script>
import Button from 'primevue/button'; import Button from 'primevue/button';
import CalendarIcon from 'primevue/icon/calendar';
import ChevronDownIcon from 'primevue/icon/chevrondown';
import ChevronLeftIcon from 'primevue/icon/chevronleft';
import ChevronRightIcon from 'primevue/icon/chevronright';
import ChevronUpIcon from 'primevue/icon/chevronup';
import OverlayEventBus from 'primevue/overlayeventbus'; import OverlayEventBus from 'primevue/overlayeventbus';
import Portal from 'primevue/portal'; import Portal from 'primevue/portal';
import Ripple from 'primevue/ripple'; import Ripple from 'primevue/ripple';
@ -364,23 +392,23 @@ export default {
}, },
icon: { icon: {
type: String, type: String,
default: 'pi pi-calendar' default: undefined
}, },
previousIcon: { previousIcon: {
type: String, type: String,
default: 'pi pi-chevron-left' default: undefined
}, },
nextIcon: { nextIcon: {
type: String, type: String,
default: 'pi pi-chevron-right' default: undefined
}, },
incrementIcon: { incrementIcon: {
type: String, type: String,
default: 'pi pi-chevron-up' default: undefined
}, },
decrementIcon: { decrementIcon: {
type: String, type: String,
default: 'pi pi-chevron-down' default: undefined
}, },
numberOfMonths: { numberOfMonths: {
type: Number, type: Number,
@ -2979,7 +3007,12 @@ export default {
}, },
components: { components: {
CalendarButton: Button, CalendarButton: Button,
Portal: Portal Portal: Portal,
CalendarIcon: CalendarIcon,
ChevronLeftIcon: ChevronLeftIcon,
ChevronRightIcon: ChevronRightIcon,
ChevronUpIcon: ChevronUpIcon,
ChevronDownIcon: ChevronDownIcon
}, },
directives: { directives: {
ripple: Ripple ripple: Ripple