primevue-mirror/components/lib/timeline/Timeline.vue

166 lines
3.9 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
2023-05-10 07:28:34 +00:00
<div :class="containerClass" v-bind="ptm('root')">
<div v-for="(item, index) of value" :key="getKey(item, index)" class="p-timeline-event" v-bind="ptm('event')">
<div class="p-timeline-event-opposite" v-bind="ptm('opposite')">
2022-09-06 12:03:37 +00:00
<slot name="opposite" :item="item" :index="index"></slot>
</div>
2023-05-10 07:28:34 +00:00
<div class="p-timeline-event-separator" v-bind="ptm('separator')">
2022-09-06 12:03:37 +00:00
<slot name="marker" :item="item" :index="index">
2023-05-10 07:28:34 +00:00
<div class="p-timeline-event-marker" v-bind="ptm('marker')"></div>
2022-09-06 12:03:37 +00:00
</slot>
2022-09-14 11:26:01 +00:00
<slot v-if="index !== value.length - 1" name="connector" :item="item" :index="index">
2023-05-10 07:28:34 +00:00
<div class="p-timeline-event-connector" v-bind="ptm('connector')"></div>
2022-09-06 12:03:37 +00:00
</slot>
</div>
2023-05-10 07:28:34 +00:00
<div class="p-timeline-event-content" v-bind="ptm('content')">
2022-09-06 12:03:37 +00:00
<slot name="content" :item="item" :index="index"></slot>
</div>
</div>
</div>
</template>
<script>
2023-05-10 07:28:34 +00:00
import BaseComponent from 'primevue/basecomponent';
2022-09-14 11:26:01 +00:00
import { ObjectUtils } from 'primevue/utils';
2022-09-06 12:03:37 +00:00
export default {
name: 'Timeline',
2023-05-10 07:28:34 +00:00
extends: BaseComponent,
2022-09-06 12:03:37 +00:00
props: {
value: null,
align: {
mode: String,
default: 'left'
},
layout: {
mode: String,
default: 'vertical'
},
dataKey: null
},
methods: {
getKey(item, index) {
return this.dataKey ? ObjectUtils.resolveFieldData(item, this.dataKey) : index;
}
},
computed: {
containerClass() {
2022-09-14 11:26:01 +00:00
return ['p-timeline p-component', 'p-timeline-' + this.align, 'p-timeline-' + this.layout];
2022-09-06 12:03:37 +00:00
}
}
2022-09-14 11:26:01 +00:00
};
2022-09-06 12:03:37 +00:00
</script>
<style>
.p-timeline {
display: flex;
flex-grow: 1;
flex-direction: column;
}
.p-timeline-left .p-timeline-event-opposite {
text-align: right;
}
.p-timeline-left .p-timeline-event-content {
text-align: left;
}
.p-timeline-right .p-timeline-event {
flex-direction: row-reverse;
}
.p-timeline-right .p-timeline-event-opposite {
text-align: left;
}
.p-timeline-right .p-timeline-event-content {
text-align: right;
}
.p-timeline-vertical.p-timeline-alternate .p-timeline-event:nth-child(even) {
flex-direction: row-reverse;
}
.p-timeline-vertical.p-timeline-alternate .p-timeline-event:nth-child(odd) .p-timeline-event-opposite {
text-align: right;
}
.p-timeline-vertical.p-timeline-alternate .p-timeline-event:nth-child(odd) .p-timeline-event-content {
text-align: left;
}
.p-timeline-vertical.p-timeline-alternate .p-timeline-event:nth-child(even) .p-timeline-event-opposite {
text-align: left;
}
.p-timeline-vertical.p-timeline-alternate .p-timeline-event:nth-child(even) .p-timeline-event-content {
text-align: right;
}
.p-timeline-event {
display: flex;
position: relative;
min-height: 70px;
}
.p-timeline-event:last-child {
min-height: 0;
}
.p-timeline-event-opposite {
flex: 1;
padding: 0 1rem;
}
.p-timeline-event-content {
flex: 1;
padding: 0 1rem;
}
.p-timeline-event-separator {
flex: 0;
display: flex;
align-items: center;
flex-direction: column;
}
.p-timeline-event-marker {
display: flex;
align-self: baseline;
}
.p-timeline-event-connector {
flex-grow: 1;
}
.p-timeline-horizontal {
flex-direction: row;
}
.p-timeline-horizontal .p-timeline-event {
flex-direction: column;
flex: 1;
}
.p-timeline-horizontal .p-timeline-event:last-child {
flex: 0;
}
.p-timeline-horizontal .p-timeline-event-separator {
flex-direction: row;
}
2022-09-14 11:26:01 +00:00
.p-timeline-horizontal .p-timeline-event-connector {
2022-09-06 12:03:37 +00:00
width: 100%;
}
.p-timeline-bottom .p-timeline-event {
flex-direction: column-reverse;
}
.p-timeline-horizontal.p-timeline-alternate .p-timeline-event:nth-child(even) {
flex-direction: column-reverse;
}
</style>