mirror of
https://github.com/penpot/penpot.git
synced 2025-01-25 07:58:49 -05:00
✨ Improve specs usage on messages.
This commit is contained in:
parent
81e909b961
commit
be24e1fb71
2 changed files with 30 additions and 26 deletions
|
@ -9,32 +9,46 @@
|
|||
|
||||
(ns app.main.data.messages
|
||||
(:require
|
||||
[beicon.core :as rx]
|
||||
[cljs.spec.alpha :as s]
|
||||
[potok.core :as ptk]
|
||||
[app.common.data :as d]
|
||||
[app.common.exceptions :as ex]
|
||||
[app.common.pages :as cp]
|
||||
[app.common.spec :as us]
|
||||
[app.config :as cfg]))
|
||||
[app.config :as cfg]
|
||||
[beicon.core :as rx]
|
||||
[cljs.spec.alpha :as s]
|
||||
[potok.core :as ptk]))
|
||||
|
||||
(declare hide)
|
||||
(declare show)
|
||||
|
||||
(def +animation-timeout+ 600)
|
||||
|
||||
(s/def ::message-type #{:success :error :info :warning})
|
||||
(s/def ::message-position #{:fixed :floating :inline})
|
||||
(s/def ::message-status #{:visible :hide})
|
||||
(s/def ::message-controls #{:none :close :inline-actions :bottom-actions})
|
||||
(s/def ::message-tag string?)
|
||||
(s/def ::label string?)
|
||||
(s/def ::type #{:success :error :info :warning})
|
||||
(s/def ::position #{:fixed :floating :inline})
|
||||
(s/def ::status #{:visible :hide})
|
||||
(s/def ::controls #{:none :close :inline-actions :bottom-actions})
|
||||
|
||||
(s/def ::tag ::us/string)
|
||||
(s/def ::label ::us/string)
|
||||
(s/def ::callback fn?)
|
||||
(s/def ::message-action (s/keys :req-un [::label ::callback]))
|
||||
(s/def ::message-actions (s/nilable (s/coll-of ::message-action :kind vector?)))
|
||||
(s/def ::action (s/keys :req-un [::label ::callback]))
|
||||
(s/def ::actions (s/every ::message-action :kind vector?))
|
||||
(s/def ::timeout ::us/integer)
|
||||
(s/def ::content ::us/string)
|
||||
|
||||
(s/def ::message
|
||||
(s/keys :req-un [::type]
|
||||
:opt-un [::status
|
||||
::position
|
||||
::controls
|
||||
::tag
|
||||
::timeout
|
||||
::actions
|
||||
::status]))
|
||||
|
||||
(defn show
|
||||
[data]
|
||||
(us/verify ::message data)
|
||||
(ptk/reify ::show
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
|
|
|
@ -9,27 +9,17 @@
|
|||
|
||||
(ns app.main.ui.messages
|
||||
(:require
|
||||
[rumext.alpha :as mf]
|
||||
[clojure.spec.alpha :as s]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.common.spec :as us]
|
||||
[app.main.ui.icons :as i]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.messages :as dm]
|
||||
[app.main.refs :as refs]
|
||||
[app.main.store :as st]
|
||||
[app.util.data :refer [classnames]]
|
||||
[app.main.ui.icons :as i]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.i18n :as i18n :refer [t]]
|
||||
[app.util.timers :as ts]))
|
||||
[rumext.alpha :as mf]))
|
||||
|
||||
(mf/defc banner
|
||||
[{:keys [type position status controls content actions on-close] :as props}]
|
||||
(us/assert ::dm/message-type type)
|
||||
(us/assert ::dm/message-position position)
|
||||
(us/assert ::dm/message-status status)
|
||||
(us/assert ::dm/message-controls controls)
|
||||
(us/assert ::dm/message-actions actions)
|
||||
(us/assert (s/nilable ::us/fn) on-close)
|
||||
[:div.banner {:class (dom/classnames
|
||||
:warning (= type :warning)
|
||||
:error (= type :error)
|
||||
|
@ -62,7 +52,7 @@
|
|||
(mf/defc notifications
|
||||
[]
|
||||
(let [message (mf/deref refs/message)
|
||||
on-close #(st/emit! dm/hide)]
|
||||
on-close (st/emitf dm/hide)]
|
||||
(when message
|
||||
[:& banner (assoc message
|
||||
:position (or (:position message) :fixed)
|
||||
|
|
Loading…
Add table
Reference in a new issue