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!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.9KB

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