From b60309284cb671686e0b58047365c65af29bffd7 Mon Sep 17 00:00:00 2001 From: Matthew Kilgore Date: Tue, 4 Aug 2020 20:06:00 -0400 Subject: [PATCH] update: common/components/Dropdown --- js/src/common/components/Dropdown.js | 64 ++++++++++++++-------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/js/src/common/components/Dropdown.js b/js/src/common/components/Dropdown.js index ecbb6d810..04f64fb9d 100644 --- a/js/src/common/components/Dropdown.js +++ b/js/src/common/components/Dropdown.js @@ -6,7 +6,7 @@ import listItems from '../helpers/listItems'; * The `Dropdown` component displays a button which, when clicked, shows a * dropdown menu beneath it. * - * ### Props + * ### Attrs * * - `buttonClassName` A class name to apply to the dropdown toggle button. * - `menuClassName` A class name to apply to the dropdown menu. @@ -19,33 +19,25 @@ import listItems from '../helpers/listItems'; * The children will be displayed as a list inside of the dropdown menu. */ export default class Dropdown extends Component { - static initProps(props) { - super.initProps(props); - - props.className = props.className || ''; - props.buttonClassName = props.buttonClassName || ''; - props.menuClassName = props.menuClassName || ''; - props.label = props.label || ''; - props.caretIcon = typeof props.caretIcon !== 'undefined' ? props.caretIcon : 'fas fa-caret-down'; - } - - init() { + oninit(vnode) { this.showing = false; } - view() { - const items = this.props.children ? listItems(this.props.children) : []; + view(vnode) { + const items = vnode.children ? listItems(vnode.children) : []; + + this.initAttrs(vnode.attrs); return ( -
- {this.getButton()} - {this.getMenu(items)} +
+ {this.getButton(vnode.attrs, vnode.children)} + {this.getMenu(vnode.attrs.menuClassName, items)}
); } - config(isInitialized) { - if (isInitialized) return; + oncreate(vnode) { + super.oncreate(vnode); // When opening the dropdown menu, work out if the menu goes beyond the // bottom of the viewport. If it does, we will apply class to make it show @@ -53,8 +45,8 @@ export default class Dropdown extends Component { this.$().on('shown.bs.dropdown', () => { this.showing = true; - if (this.props.onshow) { - this.props.onshow(); + if (vnode.attrs.onshow) { + vnode.attrs.onshow(); } m.redraw(); @@ -76,24 +68,32 @@ export default class Dropdown extends Component { this.$().on('hidden.bs.dropdown', () => { this.showing = false; - if (this.props.onhide) { - this.props.onhide(); + if (vnode.attrs.onhide) { + vnode.attrs.onhide(); } m.redraw(); }); } + initAttrs(attrs) { + attrs.className = attrs.className || ''; + attrs.buttonClassName = attrs.buttonClassName || ''; + attrs.menuClassName = attrs.menuClassName || ''; + attrs.label = attrs.label || ''; + attrs.caretIcon = typeof attrs.caretIcon !== 'undefined' ? attrs.caretIcon : 'fas fa-caret-down'; + } + /** * Get the template for the button. * * @return {*} * @protected */ - getButton() { + getButton(attrs, children) { return ( - ); } @@ -104,15 +104,15 @@ export default class Dropdown extends Component { * @return {*} * @protected */ - getButtonContent() { + getButtonContent(attrs, children) { return [ - this.props.icon ? icon(this.props.icon, { className: 'Button-icon' }) : '', - {this.props.label}, - this.props.caretIcon ? icon(this.props.caretIcon, { className: 'Button-caret' }) : '', + attrs.icon ? icon(attrs.icon, { className: 'Button-icon' }) : '', + {attrs.label}, + attrs.caretIcon ? icon(attrs.caretIcon, { className: 'Button-caret' }) : '', ]; } - getMenu(items) { - return ; + getMenu(menuClassName, items) { + return ; } }