Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let the component more common #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions dev/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@
</div>
</template>
</vue-event-calendar>
<!-- add by Yupi Li -->
<h2 class="t-center">Without Events Wrapper</h2>
<vue-event-calendar :events="demoEvents" :showEventsWrapper="false"></vue-event-calendar>
<h2 class="t-center">Without Events Title</h2>
<vue-event-calendar :events="demoEvents" :showTitle="false">
<template scope="props">
<div v-for="(event, index) in props.showEvents" class="event-item">
<!-- In here do whatever you want, make you owner event template -->
{{event}}
</div>
</template>
</vue-event-calendar>
</div>
<!-- add by Yupi Li -->
</template>

<script>
Expand Down
77 changes: 77 additions & 0 deletions src/components/cal-events-wrapper.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!-- add by Yupi Li -->
<template>
<div class="events-wrapper" :style="bgColor">
<h2 class="date" v-if="showTitle">
{{dayEventsTitle}}
</h2>
<slot>
<div class="cal-events">
<div v-for="(event, index) in events" class="event-item" :key="index">
<cal-event-item :event="event" :index="index" :locale="locale"></cal-event-item>
</div>
</div>
</slot>
</div>
</template>

<script>
import i18n from '../i18n.js'
import { dateTimeFormatter } from '../tools.js'
import calEventItem from './cal-event-item.vue'
export default {
name: 'cal-events',
data () {
return {
i18n
}
},
components: {
'cal-event-item': calEventItem
},
props: {
title: String,
showTitle: {
type: Boolean,
default: true
},
dayEvents: {
type: Object,
required: true
},
locale: {
type: String,
required: true
},
color: {
type: String,
required: true
}
},
computed: {
dayEventsTitle () {
if (this.title) return this.title
if (this.dayEvents.date !== 'all') {
let tempDate
if (this.dayEvents.events.length !== 0) {
tempDate = Date.parse(new Date(this.dayEvents.events[0].date))
return dateTimeFormatter(tempDate, i18n[this.locale].fullFormat)
} else {
tempDate = dateTimeFormatter(Date.parse(new Date(this.dayEvents.date)), i18n[this.locale].fullFormat)
return `${tempDate} ${i18n[this.locale].notHaveEvents}`
}
} else {
return i18n[this.locale].dayEventsTitle
}
},
events () {
return this.dayEvents.events
},
bgColor () {
return {backgroundColor: this.color}
}
},
methods: {
dateTimeFormatter
}
}
</script>
9 changes: 4 additions & 5 deletions src/components/cal-events.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
<template>
<div class="events-wrapper" :style="bgColor">
<h2 class="date">
{{dayEventsTitle}}
</h2>
<div class="cal-events">
<slot>
<div v-for="(event, index) in events" class="event-item" :key="index">
<cal-event-item :event="event" :index="index" :locale="locale"></cal-event-item>
</div>
</slot>
</div>
</div>
</template>

<script>
Expand All @@ -29,6 +24,10 @@ export default {
},
props: {
title: String,
showTitle: {
type: Boolean,
default: true
},
dayEvents: {
type: Object,
required: true
Expand Down
31 changes: 26 additions & 5 deletions src/vue-event-calendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,30 @@
@cur-day-changed="handleChangeCurDay"
@month-changed="handleMonthChanged">
</cal-panel>
<!-- add by Yupi Li -->
<cal-events-wrapper :title="title"
:dayEvents="selectedDayEvents"
:locale="calendarOptions.options.locale"
:color="calendarOptions.options.color"
:showTitle="showTitle"
v-if="showEventsWrapper">
</cal-events-wrapper>
<!-- add by Yupi Li -->
<cal-events
:title="title"
:dayEvents="selectedDayEvents"
:locale="calendarOptions.options.locale"
:color="calendarOptions.options.color">
:title="title"
:dayEvents="selectedDayEvents"
:locale="calendarOptions.options.locale"
:color="calendarOptions.options.color"
:showTitle="showTitle"
v-if="!showEventsWrapper">
<slot :showEvents="selectedDayEvents.events"></slot>
</cal-events>
</div>
</template>
<script>
import { isEqualDateStr} from './tools.js'

import calEventsWrapper from './components/cal-events-wrapper.vue'
import calEvents from './components/cal-events.vue'
import calPanel from './components/cal-panel.vue'

Expand All @@ -27,7 +39,8 @@ export default {
name: 'vue-event-calendar',
components: {
'cal-events': calEvents,
'cal-panel': calPanel
'cal-panel': calPanel,
'cal-events-wrapper': calEventsWrapper
},
data () {
return {
Expand All @@ -39,6 +52,14 @@ export default {
},
props: {
title: String,
showTitle: {
type: Boolean,
default: true
},
showEventsWrapper: {
type: Boolean,
default: true
},
events: {
type: Array,
required: true,
Expand Down