IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

63 Zeilen
1.7KB

  1. import { h, Component, createRef } from 'preact';
  2. class WBDialog extends Component {
  3. constructor(...args) {
  4. super(...args);
  5. this.modalRef = createRef();
  6. }
  7. show() {
  8. $(this.modalRef.current).modal();
  9. }
  10. hide() {
  11. $(this.modalRef.current).modal('hide');
  12. }
  13. componentWillUnmount() {
  14. $(this.modalRef.current).modal('hide');
  15. }
  16. render({ title, children, canAccept, accept, reject }) {
  17. return (
  18. <form class="m-0">
  19. <div class="modal" tabindex="-1" role="dialog" ref={ this.modalRef }>
  20. <div class="modal-dialog modal-lg" role="document">
  21. <div class="modal-content">
  22. <div class="modal-header">
  23. <h5 class="modal-title">{ title }</h5>
  24. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  25. <span aria-hidden="true">&times;</span>
  26. </button>
  27. </div>
  28. <div class="modal-body">
  29. { children[0] }
  30. </div>
  31. <div class="modal-footer">
  32. { children[1] ? children[1] : [
  33. <input type="submit" class="btn btn-primary" value="Accept"
  34. onclick={ e => { e.preventDefault(); if (!canAccept()) return; this.hide(); accept(); } } />,
  35. <button type="button" class="btn btn-secondary"
  36. onclick={ () => { this.hide(); reject(); } }>Cancel</button>
  37. ] }
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. </form>
  43. );
  44. }
  45. }
  46. WBDialog.defaultProps = {
  47. title: 'Dialog',
  48. accept: () => {},
  49. reject: () => {},
  50. canAccept: () => true
  51. };
  52. export default WBDialog;