Created
March 9, 2018 19:47
-
-
Save jmas/665964d48bd884d3c1961fa3cb39e601 to your computer and use it in GitHub Desktop.
PoC: hyperapp + twitter bootstrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { h } from 'hyperapp'; | |
import $ from 'jquery'; | |
import Button from './button'; | |
import { BUTTON_VARIANT_PRIMARY } from './button'; | |
export * from './button'; | |
/** | |
* @param {object} params | |
* @param {VNode} params.triggerContent | |
* @param {string} params.triggerVariant | |
* @param {boolean} params.right | |
* @param {array} children | |
*/ | |
export default function Dropdown({ | |
triggerContent=null, | |
triggerVariant=BUTTON_VARIANT_PRIMARY, | |
right=false, | |
}, children=null) { | |
const dropdownId = `dropdown_${ Math.ceil(Math.random()*1000) }`; | |
return ( | |
<div class="dropdown"> | |
<Button | |
class={ `btn btn-${ triggerVariant } dropdown-toggle` } | |
data-toggle="dropdown" | |
oncreate={ element => $(element).dropdown() } | |
ondestroy={ element => $(element).dropdown('dispose') } | |
>{ triggerContent }</Button> | |
<div | |
class={ `dropdown-menu ${ right ? 'dropdown-menu-right': null }` } | |
aria-labelledby={ dropdownId } | |
> | |
{ children } | |
</div> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment