Last active
February 23, 2018 21:18
-
-
Save tabula-rasa/aa57dec6fe07698578148c850afbec91 to your computer and use it in GitHub Desktop.
Mithril JS Bootstrap 4 modal dialog component
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
//usage | |
import modal from './modal(es6)' | |
var state = { | |
showDialog: false, | |
onOk() { | |
console.log('OK pressed') | |
}, | |
onCancel() { | |
console.log('Cancel pressed') | |
} | |
} | |
var app = { | |
view: (vnode) => { | |
return m('.container', [ | |
m('button.btn.btn-primary[type=button]', {onclick: () => { state.showDialog = true }}, "Show dialog"), | |
state.showDialog ? | |
m(modal, { | |
title: "Modal demo", | |
body: "Now you see", | |
buttons: [ | |
m('button.btn.btn-primary[type=button]', {onclick: state.onOk}, "Ok"), | |
m('button.btn.btn-secondary[type=button]', {onclick: state.onCancel}, "Close"), | |
] | |
}) : null | |
]) | |
} | |
} |
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
modal { | |
position: fixed; | |
left: 0; | |
width: 100%; | |
top: 0; | |
height: 100%; | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
background: rgba(0,0,0,0.3); | |
} |
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 m from 'mithril' | |
const Modal = { | |
view: (vnode) => { | |
var ui = vnode.state; | |
return m('modal[tabindex=-1][role=dialog]', [ | |
m('.modal-dialog[role=document]', [ | |
m('.modal-content', [ | |
m('.modal-header', [ | |
m('h5.modal-title', vnode.attrs.title || "Are you sure?"), | |
]), | |
m('.modal-body', [ | |
m('div', vnode.attrs.body || '') | |
]), | |
m('.modal-footer', vnode.attrs.buttons) | |
]) | |
]) | |
]) | |
} | |
} | |
export default Modal; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment