Skip to content
This repository has been archived by the owner on May 25, 2018. It is now read-only.

Add the collapse option to Panel component. Closes issue #21 #391

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
6 changes: 6 additions & 0 deletions docs/example/accordionDocs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
<p><code>null</code></p>
<p>Define the type of color for the tab (single).</p>
</div>
<div>
<p>collapse</p>
<p><code>Boolean</code></p>
<p><code>null</code></p>
<p>Define whether this panel can be collapsed. This will default to true if in an accordion.</p>
</div>
</doc-table>
<p>If you want to personalice your header with some html you can use the slot instead of header attribute (panel&nbsp;#1 in the example).</p>
</doc-section>
Expand Down
17 changes: 13 additions & 4 deletions src/Panel.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="panel {{panelType}}">
<div :class="['panel-heading',{'accordion-toggle':inAccordion}]" @click.prevent="inAccordion&&toggle()">
<div :class="['panel-heading',{'toggle-collapse':collapse}]" @click.prevent="collapse&&toggle()">
<slot name="header">
<h4 class="panel-title">{{ header }}</h4>
</slot>
Expand Down Expand Up @@ -32,12 +32,17 @@ export default {
},
type: {
type: String,
default : null
default: null
},
collapse: {
type: Boolean,
coerce: coerce.boolean,
default: null
}
},
computed: {
inAccordion () {
return this.$parent && this.$parent._isAccordion
return this.$parent != null && this.$parent._isAccordion === true
},
panelType () {
return 'panel-' + (this.type || (this.$parent && this.$parent.type) || 'default')
Expand All @@ -64,6 +69,10 @@ export default {
}
},
created () {
// Set as collapsible if in accordion by default
if (this.collapse === null) {
this.collapse = this.inAccordion
}
if (this.isOpen === null) {
this.isOpen = !this.inAccordion
}
Expand All @@ -72,7 +81,7 @@ export default {
</script>

<style>
.accordion-toggle {
.toggle-collapse {
cursor: pointer;
}
.collapse-transition {
Expand Down