Skip to content

Commit ffd4ca9

Browse files
committed
soft popup
1 parent 5be2cec commit ffd4ca9

File tree

2 files changed

+58
-11
lines changed

2 files changed

+58
-11
lines changed

public/css/style.css

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ input, textarea {
7474
}
7575

7676

77-
#mosaic_libman button, #mosaic_libman .buttongroup {
77+
#mosaic_libman button,
78+
#mosaic_libman input[type=submit],
79+
#mosaic_libman .buttongroup {
7880
background: #f8f8f8 0% 0% no-repeat padding-box;
7981
box-shadow: 0px 1px 4px #00000033;
8082
border-radius: 7px;
@@ -86,6 +88,7 @@ input, textarea {
8688
box-shadow: 0px 0px 4px hsla(0, 0%, 0%, 0.2);
8789
}
8890
#mosaic_libman button.primary,
91+
#mosaic_libman input[type=submit],
8992
#mosaic_libman .buttongroup.primary {
9093
background-color: #0E1A32;
9194
color: white;
@@ -246,6 +249,29 @@ input, textarea {
246249
grid-template-columns: 1fr 2fr 2fr;
247250
}
248251

252+
#mosaic_libman .modal {
253+
position: absolute;
254+
top: 50%;
255+
left: 50%;
256+
transform: translate(-50%, -50%);
257+
background: white;
258+
box-shadow: 0px 0px 10px #00000033;
259+
border-radius: 7px;
260+
border: 1px solid lightgray;
261+
padding: 20px 20px;
262+
263+
}
264+
#mosaic_libman .modal.hidden {
265+
display: none;
266+
}
267+
#mosaic_libman .modal input[type=text] {
268+
display: block;
269+
margin: 1em 0;
270+
}
271+
#mosaic_libman .modal input[type=submit] {
272+
margin-left:1em;
273+
}
274+
249275
/* editor */
250276
#mosaic_editor * {
251277
margin: 0;

src/main/nyancad/mosaic/libman.cljs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@
2323

2424
(def schdbmeta {:name "schematics" :url cm/default-sync})
2525

26+
(defonce modal-content (r/atom nil))
27+
28+
(defn modal []
29+
[:div.modal
30+
{:class (if @modal-content "visible" "hidden")}
31+
@modal-content])
32+
33+
(defn prompt [text cb]
34+
(reset! modal-content
35+
[:form {:on-submit (fn [^js e]
36+
(js/console.log e)
37+
(.preventDefault e)
38+
(let [name (.. e -target -elements -valuefield -value)]
39+
(when (seq name)
40+
(cb name)))
41+
(reset! modal-content nil))}
42+
[:div text]
43+
[:input {:name "valuefield" :type "text"}]
44+
[:button {:on-click #(reset! modal-content nil)} "Cancel"]
45+
[:input {:type "submit" :value "Ok"}]]))
46+
2647
(defn get-dbatom [dbid]
2748
(if-let [pa (get @dbcache dbid)]
2849
pa
@@ -173,12 +194,12 @@
173194

174195
(defn cell-view []
175196
(let [db (get-dbatom (or @seldb :schematics))
176-
add-cell #(when-let [name (and @seldb (js/prompt "Enter the name of the new cell"))]
177-
(swap! db assoc (str "models" sep name) {:name name}))
178-
add-schem #(when-let [name (and @seldb @selcell (js/prompt "Enter the name of the new schematic"))]
179-
(swap! db assoc-in [@selcell :models (keyword name)] {:name name, :type "schematic"}))
180-
add-spice #(when-let [name (and @seldb @selcell (js/prompt "Enter the name of the new SPICE model"))]
181-
(swap! db assoc-in [@selcell :models (keyword name)] {:name name :type "spice"}))]
197+
add-cell #(prompt "Enter the name of the new cell"
198+
(fn [name] (swap! db assoc (str "models" sep name) {:name name})))
199+
add-schem #(prompt "Enter the name of the new schematic"
200+
(fn [name] (swap! db assoc-in [@selcell :models (keyword name)] {:name name, :type "schematic"})))
201+
add-spice #(prompt "Enter the name of the new SPICE model"
202+
(fn [name] (swap! db assoc-in [@selcell :models (keyword name)] {:name name :type "spice"})))]
182203
[:<>
183204
[:div.schsel
184205
[:div.addbuttons
@@ -206,13 +227,13 @@
206227
[:div.libhead
207228
[:h1 "Library"]
208229
[:button.plus {:on-click
209-
#(let [name (js/prompt "Enter the name of the new database")]
210-
(when (seq name)
211-
(swap! databases assoc (str "databases" sep name) {:name name})))}
230+
#(prompt "Enter the name of the new database"
231+
(fn [name] (swap! databases assoc (str "databases" sep name) {:name name})))}
212232
"+"]]
213233
[database-selector]
214234
[db-properties]]
215-
[cell-view]])
235+
[cell-view]
236+
[modal]])
216237

217238
(def shortcuts {})
218239

0 commit comments

Comments
 (0)