Kaynağa Gözat

enhance(ux): support enter key shortcut for the shui button

charlie 1 yıl önce
ebeveyn
işleme
c74f1749c8
1 değiştirilmiş dosya ile 22 ekleme ve 0 silme
  1. 22 0
      deps/shui/src/logseq/shui/base/core.cljs

+ 22 - 0
deps/shui/src/logseq/shui/base/core.cljs

@@ -0,0 +1,22 @@
+(ns logseq.shui.base.core
+  (:require [logseq.shui.util :as util]
+            [rum.core :as rum]))
+
+(def button-base (util/lsui-wrap "Button" {:static? false}))
+(def link (util/lsui-wrap "Link"))
+
+;; Note: don't define component with rum/defc
+;; to be compatible for the radix as-child option
+(defn button
+  [& props-and-children]
+  (let [props (first props-and-children)
+        children (rest props-and-children)
+        on-key-up' (:on-key-up props)
+        children (if (map? props) children (cons props children))
+        props (assoc (if (map? props) props {})
+                :on-key-up (fn [^js e]
+                             ;; TODO: return value
+                             (when (fn? on-key-up') (on-key-up' e))
+                             (when (= "Enter" (.-key e))
+                               (some-> (.-target e) (.click)))))]
+    (apply button-base props children)))