]> BookStack Code Mirror - bookstack/commitdiff
Added new confirm-dialog component, both view and logic
authorDan Brown <redacted>
Wed, 20 Apr 2022 13:58:37 +0000 (14:58 +0100)
committerDan Brown <redacted>
Wed, 20 Apr 2022 13:58:37 +0000 (14:58 +0100)
resources/js/components/confirm-dialog.js [new file with mode: 0644]
resources/js/components/index.js
resources/js/components/popup.js
resources/sass/_components.scss
resources/views/common/confirm-dialog.blade.php [new file with mode: 0644]

diff --git a/resources/js/components/confirm-dialog.js b/resources/js/components/confirm-dialog.js
new file mode 100644 (file)
index 0000000..c6c5d10
--- /dev/null
@@ -0,0 +1,53 @@
+import {onSelect} from "../services/dom";
+
+/**
+ * Custom equivalent of window.confirm() using our popup component.
+ * Is promise based so can be used like so:
+ * `const result = await dialog.show()`
+ * @extends {Component}
+ */
+class ConfirmDialog {
+
+    setup() {
+        this.container = this.$el;
+        this.confirmButton = this.$refs.confirm;
+
+        this.res = null;
+
+        onSelect(this.confirmButton, () => {
+            this.sendResult(true);
+            this.getPopup().hide();
+        });
+    }
+
+    show() {
+        this.getPopup().show(null, () => {
+            this.sendResult(false);
+        });
+
+        return new Promise((res, rej) => {
+           this.res = res;
+        });
+    }
+
+    /**
+     * @returns {Popup}
+     */
+    getPopup() {
+        return this.container.components.popup;
+    }
+
+    /**
+     * @param {Boolean} result
+     */
+    sendResult(result) {
+        if (this.res) {
+            console.log('sending result', result);
+            this.res(result)
+            this.res = null;
+        }
+    }
+
+}
+
+export default ConfirmDialog;
\ No newline at end of file
index fe348aba758a157562e2d48724f6066c22301d0e..6a4a8c2b08fc9096380fc225f361e28196883150 100644 (file)
@@ -10,6 +10,7 @@ import chapterToggle from "./chapter-toggle.js"
 import codeEditor from "./code-editor.js"
 import codeHighlighter from "./code-highlighter.js"
 import collapsible from "./collapsible.js"
+import confirmDialog from "./confirm-dialog"
 import customCheckbox from "./custom-checkbox.js"
 import detailsHighlighter from "./details-highlighter.js"
 import dropdown from "./dropdown.js"
@@ -26,7 +27,6 @@ import headerMobileToggle from "./header-mobile-toggle.js"
 import homepageControl from "./homepage-control.js"
 import imageManager from "./image-manager.js"
 import imagePicker from "./image-picker.js"
-import index from "./index.js"
 import listSortControl from "./list-sort-control.js"
 import markdownEditor from "./markdown-editor.js"
 import newUserPassword from "./new-user-password.js"
@@ -66,6 +66,7 @@ const componentMapping = {
     "code-editor": codeEditor,
     "code-highlighter": codeHighlighter,
     "collapsible": collapsible,
+    "confirm-dialog": confirmDialog,
     "custom-checkbox": customCheckbox,
     "details-highlighter": detailsHighlighter,
     "dropdown": dropdown,
@@ -82,7 +83,6 @@ const componentMapping = {
     "homepage-control": homepageControl,
     "image-manager": imageManager,
     "image-picker": imagePicker,
-    "index": index,
     "list-sort-control": listSortControl,
     "markdown-editor": markdownEditor,
     "new-user-password": newUserPassword,
index 13cf69d2192c37b21b39edf8733fa7329ae22bf2..ec111963f51e65358c51d5d3333bd5d47fb8e55d 100644 (file)
@@ -34,7 +34,7 @@ class Popup {
     }
 
     hide(onComplete = null) {
-        fadeOut(this.container, 240, onComplete);
+        fadeOut(this.container, 120, onComplete);
         if (this.onkeyup) {
             window.removeEventListener('keyup', this.onkeyup);
             this.onkeyup = null;
@@ -45,7 +45,7 @@ class Popup {
     }
 
     show(onComplete = null, onHide = null) {
-        fadeIn(this.container, 240, onComplete);
+        fadeIn(this.container, 120, onComplete);
 
         this.onkeyup = (event) => {
             if (event.key === 'Escape') {
index 95ba81520bc431eaac45a9b7dba22931126505a4..bce456cf2ce1e1b82147ae45e8f368ac83a91e83 100644 (file)
     width: 800px;
     max-width: 90%;
   }
+  &.very-small {
+    margin: 2% auto;
+    width: 600px;
+    max-width: 90%;
+  }
   &:before {
     display: flex;
     align-self: flex-start;
diff --git a/resources/views/common/confirm-dialog.blade.php b/resources/views/common/confirm-dialog.blade.php
new file mode 100644 (file)
index 0000000..107d04a
--- /dev/null
@@ -0,0 +1,21 @@
+<div components="popup confirm-dialog"
+     refs="confirm-dialog@popup"
+     class="popup-background">
+    <div class="popup-body very-small" tabindex="-1">
+
+        <div class="popup-header primary-background">
+            <div class="popup-title">{{ $title }}</div>
+            <button refs="popup@hide" type="button" class="popup-header-close">x</button>
+        </div>
+
+        <div class="px-m py-m">
+            {{ $slot }}
+
+            <div class="text-right">
+                <button type="button" class="button outline" refs="popup@hide">{{ trans('common.cancel') }}</button>
+                <button type="button" class="button" refs="confirm-dialog@confirm">{{ trans('common.continue') }}</button>
+            </div>
+        </div>
+
+    </div>
+</div>
\ No newline at end of file
Morty Proxy This is a proxified and sanitized view of the page, visit original site.