I am struggling to create a seemingly easy component in Vue.js - just a bootstrap panel with optional heading, content and optional footer using JS render function. The idea is for it to go something like this:
<panel>
<panel-header> Header </panel-header>
[ The panel content goes here ]
<panel-footer> Footer </panel-footer>
</panel>
My question is: How can I "include" children components (panel-header & panel-footer) with their particular classes (i.e. "panel-header" class) in the render function, keep them both optional and yet allow for full freedom in composing the panel body's, with its own classes (i.e. "panel-body" class and props.title)?
To put it differently: How can I control the children, but separate components and yet have [children] to populate the middle of the panel?
My rendering sctipt looks something like this:
import classNames from 'classnames';
export const props = {
tag: {
type: String,
default: "div"
},
className: {
type: String
},
align: {
type: String,
default: 'left'
},
title: {
type: String,
},
header: {
type: String,
}
};
export default {
functional: true,
props,
render(h, { props, data, children }) {
const dataObj = {
class: classNames(
'card',
props.align ? 'text-' + props.align : '',
props.className ? props.className : ''
),
};
const title = [
h('h4', {
class: 'card-title'
}, props.title)
];
const content = [
h('div', {
class: 'card-body'
})
];
return h(props.tag, dataObj, [title, children] );
}
};
With Best Regards, Paco Pacici
EDIT: I know that once I do it as above, I'll get the desired effect - having the header, content and footer in the panel, in correct order. But what If I wanted to add some properties to the panels' content alone, not including the footer and header? As such, they'd be considered children as well and therefore submit to my manipulation. I'd like to treat them as separately, but inside the very same function.