import { gMainApp, gEventBus } from "./MainApp.js" ;
// --------------------------------------------------------------------
gMainApp.component( "accordian", {
props: [ "accordianId" ],
data() { return {
panes: [],
} ; },
template: `
`,
mounted() {
// expand the specified pane
gEventBus.on( "expand-pane", (accordianId, paneKey, isClick) => {
if ( this.accordianId != accordianId )
return ;
// update the state for each child pane
this.panes.forEach( (pane) => {
let newIsExpanded = (paneKey != null && pane.paneKey == paneKey) ;
if ( pane.isExpanded && ! newIsExpanded )
pane.$emit( "pane-collapsed", pane.paneKey, isClick ) ;
else if ( ! pane.isExpanded && newIsExpanded )
pane.$emit( "pane-expanded", pane.paneKey, isClick ) ;
pane.isExpanded = newIsExpanded ;
} ) ;
} ) ;
},
} ) ;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
gMainApp.component( "accordian-pane", {
props: [ "paneKey", "title", "entries", "getEntryKey", "iconUrl", "backgroundUrl", "borderClass" ],
data() { return {
isExpanded: false,
cssBackground: this.backgroundUrl ? "url(" + this.backgroundUrl + ")": null,
} ; },
template: `
![]()
{{title}}
`,
created() {
// notify the parent
this.$parent.panes.push( this ) ;
},
methods: {
onClickEntry( entry ) {
// notify the parent that an entry was clicked
this.$emit( "entry-clicked", this.paneKey, entry ) ;
},
onToggleExpand() {
// notify the parent
gEventBus.emit( "expand-pane", this.$parent.accordianId,
this.isExpanded ? null : this.paneKey,
true
) ;
},
},
} ) ;