Skip to content

Commit 95a8fb6

Browse files
committed
feat(ui): daisyui login modal, wip
1 parent 5433b56 commit 95a8fb6

File tree

3 files changed

+84
-53
lines changed

3 files changed

+84
-53
lines changed

src/main/parts/frontend/components/login_modal.cljs

+49-39
Original file line numberDiff line numberDiff line change
@@ -32,49 +32,59 @@
3232

3333
($ modal
3434
{:show show
35-
:title "Log in"
3635
:on-close on-close}
3736

38-
($ :form {:on-submit handle-submit}
37+
($ :<>
3938
(when error
40-
($ :div {:class "error-message"}
41-
error))
39+
($ :div {:class "alert alert-error mb-4"}
40+
($ :span {:class "font-medium"} error)))
4241

43-
(when-let [csrf-token (utils/get-csrf-token)]
44-
($ :input
45-
{:type "hidden"
46-
:id "__anti-forgery-token"
47-
:name "__anti-forgery-token"
48-
:value csrf-token}))
42+
($ :form {:on-submit handle-submit}
4943

50-
($ :div {:class "form-group"}
51-
($ :label {:for "email"} "Email:")
52-
($ :input
53-
{:type "email"
54-
:id "email"
55-
:value email
56-
:disabled loading
57-
:on-change #(set-email (.. % -target -value))
58-
:required true}))
44+
(when-let [csrf-token (utils/get-csrf-token)]
45+
($ :input
46+
{:type "hidden"
47+
:id "__anti-forgery-token"
48+
:name "__anti-forgery-token"
49+
:value csrf-token}))
5950

60-
($ :div {:class "form-group"}
61-
($ :label {:for "password"} "Password:")
62-
($ :input
63-
{:type "password"
64-
:id "password"
65-
:value password
66-
:disabled loading
67-
:on-change #(set-password (.. % -target -value))
68-
:required true}))
51+
($ :fieldset
52+
{:class "fieldset w-full bg-base-200 border border-base-300 p-4 rounded-box"}
53+
($ :legend {:class "fieldset-legend"} "Login")
6954

70-
($ :div {:class "form-actions"}
71-
($ :button
72-
{:type "button"
73-
:disabled loading
74-
:on-click on-close}
75-
"Cancel")
76-
($ :button
77-
{:type "submit"
78-
:disabled loading
79-
:class "primary"}
80-
(if loading "Logging in..." "Log in")))))))
55+
($ :div {:class "form-control mb-3"}
56+
($ :label {:class "fieldset-label" :for "email"}
57+
"Email")
58+
($ :input
59+
{:type "email"
60+
:id "email"
61+
:placeholder "[email protected]"
62+
:class "input input-bordered w-full"
63+
:value email
64+
:disabled loading
65+
:on-change #(set-email (.. % -target -value))
66+
:required true}))
67+
68+
($ :div {:class "form-control"}
69+
($ :label {:class "fieldset-label" :for "password"}
70+
"Password")
71+
($ :input
72+
{:type "password"
73+
:id "password"
74+
:class "input input-bordered w-full"
75+
:value password
76+
:disabled loading
77+
:on-change #(set-password (.. % -target -value))
78+
:required true}))
79+
($ :div {:class "modal-action mt-6 space-x-2 flex"}
80+
($ :button
81+
{:type "button"
82+
:class "btn btn-outline flex-1"
83+
:disabled loading
84+
:on-click on-close}
85+
"Cancel")
86+
($ :button
87+
{:type "submit"
88+
:disabled loading
89+
:class (str "btn btn-primary flex-1" (when loading "loading"))}
90+
(if loading "Logging in..." "Log in")))))))))
+32-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
11
(ns parts.frontend.components.modal
22
(:require
3-
[uix.core :refer [defui $]]))
3+
[uix.core :refer [defui $ use-ref use-effect]]))
44

5-
(defui modal [{:keys [show title on-close children]}]
6-
(when show
7-
($ :div {:class "modal-overlay"}
8-
($ :div {:class "modal-container"}
9-
($ :div {:class "modal-header"}
10-
($ :h3 title)
11-
($ :button {:class "modal-close" :on-click on-close} "×"))
12-
($ :div {:class "modal-content"}
13-
children)))))
5+
(defui modal
6+
[{:keys [show title on-close children]}]
7+
(let [dialog-ref (use-ref nil)]
8+
9+
;; control modal visibility based on show prop
10+
(use-effect
11+
(fn []
12+
(when-let [dialog (.-current dialog-ref)]
13+
(if show
14+
(.showModal dialog)
15+
(.close dialog))))
16+
[show])
17+
18+
($ :dialog
19+
{:class "modal"
20+
:ref dialog-ref
21+
:on-click (fn [e]
22+
;; close when clicking backdrop
23+
(when (= (.-target e) (.-current dialog-ref))
24+
(on-close)))
25+
:on-cancel on-close} ;; handles ESC key
26+
($ :div
27+
{:class "modal-box"
28+
:on-click #(.stopPropagation %)}
29+
;; ;; ($ :button
30+
;; ;; {:class "btn btn-sm btn-circle btn-ghost absolute right-2 top-2"
31+
;; ;; :on-click on-close}
32+
;; "✕")
33+
(when title
34+
($ :h3 {:class "text-lg font-bold"} title))
35+
children))))

src/main/parts/frontend/components/system.cljs

+3-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@
5656
(let [[show-login-modal set-show-login-modal] (use-state false)
5757
{:keys [user loading logout]} (ctx/use-auth)]
5858
($ :div
59-
(when show-login-modal
60-
($ login-modal
61-
{:show true
62-
:on-close #(set-show-login-modal false)}))
59+
($ login-modal
60+
{:show show-login-modal
61+
:on-close #(set-show-login-modal false)})
6362
(when loading
6463
($ :span "(...) "))
6564
(if user

0 commit comments

Comments
 (0)