frayerjj-frontend 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +56 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frayerjj-frontend",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "My base frontend for various projects",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/index.js CHANGED
@@ -1,7 +1,59 @@
1
- import modal from "./modal.js";
2
- /*import { ajax, getIntVar, pageInit } from "./helpers.js";
1
+ import * as bootstrap from 'bootstrap';
2
+
3
+ const modal = {
4
+ build: vars => {
5
+ let html =
6
+ '<div id="' + vars.id + '" class="modal" tabindex="-1">' +
7
+ '<div class="modal-dialog ' + (vars.class ?? '') + '">' +
8
+ '<div class="modal-content">' +
9
+ '<div class="modal-header">' +
10
+ '<h5 class="modal-title">' + vars.title + '</h5>' +
11
+ '<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>' +
12
+ '</div>' +
13
+ '<div class="modal-body">' +
14
+ '<div class="col">' + (vars.body ?? '');
15
+ if (vars.inputs) Object.values(vars.inputs).forEach(i => {
16
+ if (i.type) html += modal.buildInputLine(i);
17
+ else html += modal.buildLine(i);
18
+ });
19
+ html +=
20
+ '</div>' +
21
+ '</div>' +
22
+ '<div class="modal-footer">';
23
+ if (vars.buttons) Object.values(vars.buttons).forEach(b => {
24
+ html += '<button type="button" class="btn btn-outline-secondary me-1 ' + (b.class ?? '') + '" data-bs-dismiss="modal">' + b.text + '</button>';
25
+ });
26
+ html +=
27
+ '</div>' +
28
+ '</div>' +
29
+ '</div>' +
30
+ '</div>';
31
+ return html;
32
+ },
33
+
34
+ alert: (msg, title = "Alert", button = "OK") => {
35
+ document.querySelector('body').insertAdjacentHTML('beforeend', modal.build({
36
+ id: 'alert-modal',
37
+ title: title,
38
+ body: '<p>' + msg + '</p>',
39
+ buttons: [ { text: button } ]
40
+ }));
41
+ let alertModal = document.getElementById('alert-modal');
42
+ alertModal.addEventListener('hidden.bs.modal', ev => {
43
+ ev.target.remove();
44
+ });
45
+ let bsAlertModal = new bootstrap.Modal(alertModal);
46
+ bsAlertModal.show();
47
+ }
48
+ };
49
+
50
+ export default { modal }; // Export only modal for now
51
+
52
+
53
+ /*import modal from "./modal.js";
54
+ import { ajax, getIntVar, pageInit } from "./helpers.js";
3
55
  import { loading } from "./loading.js";
4
56
  import { message } from "./message.js";
5
- import { validate } from "./validate.js";*/
57
+ import { validate } from "./validate.js";
6
58
 
7
- export default { modal/*, ajax, getIntVar, pageInit, loading, message, validate*/ };
59
+ export default { modal, ajax, getIntVar, pageInit, loading, message, validate };%/