Skip to content

Commit

Permalink
Redo TabView using render function with JSX to be able to project slo…
Browse files Browse the repository at this point in the history
…ts of TabPanels
  • Loading branch information
cagataycivici committed Dec 11, 2018
1 parent 295f781 commit b3036ec
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 22 deletions.
45 changes: 28 additions & 17 deletions src/components/tabview/TabView.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
<template>
<div class="p-tabview p-component p-tabview-top">
<ul class="p-tabview-nav p-resest" role="tablist">
<li role="presentation" v-for="(tab,i) of tabs" :key="tab.header"
:class="{'p-highlight': (d_activeTabIndex === i), 'p-disabled': tab.disabled}">
<a role="tab" @click="onTabClick($event, tab, i)" @keydown.enter="onTabClick($event, tab, i)">
<span class="p-tabview-title">{{tab.header}}</span>
</a>
</li>
</ul>
<div class="p-tabview-panels">
<slot></slot>
</div>
</div>
</template>

<script>
export default {
props: {
Expand Down Expand Up @@ -43,7 +27,7 @@ export default {
},
methods: {
onTabClick(event, tab, index) {
if (!tab.disabled) {
if (!tab.disabled && index !== this.d_activeTabIndex) {
this.activateTab(index);
this.$emit('tabchange', {
Expand All @@ -57,7 +41,34 @@ export default {
for (let i = 0; i < this.tabs.length; i++) {
this.tabs[i].active = (i === index);
}
},
onTabKeydown(event, index) {
if (event.which === 13) {
this.onTabClick(index);
}
}
},
render() {
return (
<div class="p-tabview p-component p-tabview-top">
<ul class="p-tabview-nav p-resest" role="tablist">
{
this.tabs.map((tab, i) => {
return (
<li role="presentation" key={tab.header} class={{'p-highlight': (this.d_activeTabIndex === i), 'p-disabled': tab.disabled}}>
<a role="tab" on-click={event => this.onTabClick(event, tab, i)} on-keydown={event => this.onTabKeydown(event, i)} tabindex={tab.disabled ? null : '0'}>
{tab.$slots.header || tab.header}
</a>
</li>
);
})
}
</ul>
<div class="p-tabview-panels">
{this.$slots.default}
</div>
</div>
);
}
}
</script>
32 changes: 27 additions & 5 deletions src/views/tabview/TabViewDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,31 @@
</p-tabView>

<h3>Custom Content</h3>
<p-tabView>
<p-tabView class="tabview-custom">
<p-tabPanel>
<template slot="header">XXX Godfather I</template>
<template slot="header">
<i class="pi pi-calendar"></i>
<span>Godfather I</span>
</template>
The story begins as Don Vito Corleone, the head of a New York Mafia family, overseeshis daughter's wedding. His beloved son ichael has just come home from the war,
but does not intend to become part of his father's business. Through Michael's life the nature of the family business becomes clear. The business of the family is
just like the head of the family, kind and benevolent to those who give respect, but given to ruthless violence whenever anything stands against the good of the family.
</p-tabPanel>
<p-tabPanel>
<template slot="header">XXX Godfather II</template>
<template slot="header">
<span>Godfather II</span>
<i class="pi pi-user"></i>
</template>
Francis Ford Coppola's legendary continuation and sequel to his landmark 1972 film, TheGodfather parallels the young Vito Corleone's rise with his son Michael's spiritual fall,
deepening The Godfather's depiction of the dark side of the American dream. In the early 1900s, the child Vito flees his Sicilian village for America after the local Mafia kills
his family. Vito struggles to make a living, legally or illegally, for his wife and growing brood in Little Italy.
</p-tabPanel>
<p-tabPanel>
<template slot="header">XXX Godfather III</template>
<template slot="header">
<i class="pi pi-search"></i>
<span>Godfather II</span>
<i class="pi pi-times"></i>
</template>
The Godfather Part III is set in 1979 and 1980. Michael has moved back to New York and taken great strides to remove the family from crime. He turns over his New York criminal
interests to longtime enforcer Joey Zasa. He uses his wealth in an attempt to rehabilitate his reputation through numerous philanthropic acts, administered by a foundation named after his father.
A decade earlier, he gave custody of his two children to Kay, who has since remarried.
Expand All @@ -110,4 +120,16 @@ export default {
}
}
}
</script>
</script>

<style lang="scss" scoped>
.tabview-custom {
i, span {
vertical-align: middle;
}
span {
margin: 0 .5em;
}
}
</style>

0 comments on commit b3036ec

Please sign in to comment.