mirror of
https://github.com/penpot/penpot.git
synced 2025-02-03 21:09:00 -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
|
(ns app.main.data.messages
|
||||||
(:require
|
(:require
|
||||||
[beicon.core :as rx]
|
|
||||||
[cljs.spec.alpha :as s]
|
|
||||||
[potok.core :as ptk]
|
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
[app.common.pages :as cp]
|
[app.common.pages :as cp]
|
||||||
[app.common.spec :as us]
|
[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 hide)
|
||||||
(declare show)
|
(declare show)
|
||||||
|
|
||||||
(def +animation-timeout+ 600)
|
(def +animation-timeout+ 600)
|
||||||
|
|
||||||
(s/def ::message-type #{:success :error :info :warning})
|
(s/def ::type #{:success :error :info :warning})
|
||||||
(s/def ::message-position #{:fixed :floating :inline})
|
(s/def ::position #{:fixed :floating :inline})
|
||||||
(s/def ::message-status #{:visible :hide})
|
(s/def ::status #{:visible :hide})
|
||||||
(s/def ::message-controls #{:none :close :inline-actions :bottom-actions})
|
(s/def ::controls #{:none :close :inline-actions :bottom-actions})
|
||||||
(s/def ::message-tag string?)
|
|
||||||
(s/def ::label string?)
|
(s/def ::tag ::us/string)
|
||||||
|
(s/def ::label ::us/string)
|
||||||
(s/def ::callback fn?)
|
(s/def ::callback fn?)
|
||||||
(s/def ::message-action (s/keys :req-un [::label ::callback]))
|
(s/def ::action (s/keys :req-un [::label ::callback]))
|
||||||
(s/def ::message-actions (s/nilable (s/coll-of ::message-action :kind vector?)))
|
(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
|
(defn show
|
||||||
[data]
|
[data]
|
||||||
|
(us/verify ::message data)
|
||||||
(ptk/reify ::show
|
(ptk/reify ::show
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
|
|
@ -9,27 +9,17 @@
|
||||||
|
|
||||||
(ns app.main.ui.messages
|
(ns app.main.ui.messages
|
||||||
(:require
|
(:require
|
||||||
[rumext.alpha :as mf]
|
|
||||||
[clojure.spec.alpha :as s]
|
|
||||||
[app.common.uuid :as uuid]
|
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.main.ui.icons :as i]
|
[app.common.uuid :as uuid]
|
||||||
[app.main.data.messages :as dm]
|
[app.main.data.messages :as dm]
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.util.data :refer [classnames]]
|
[app.main.ui.icons :as i]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[app.util.i18n :as i18n :refer [t]]
|
[rumext.alpha :as mf]))
|
||||||
[app.util.timers :as ts]))
|
|
||||||
|
|
||||||
(mf/defc banner
|
(mf/defc banner
|
||||||
[{:keys [type position status controls content actions on-close] :as props}]
|
[{: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
|
[:div.banner {:class (dom/classnames
|
||||||
:warning (= type :warning)
|
:warning (= type :warning)
|
||||||
:error (= type :error)
|
:error (= type :error)
|
||||||
|
@ -62,7 +52,7 @@
|
||||||
(mf/defc notifications
|
(mf/defc notifications
|
||||||
[]
|
[]
|
||||||
(let [message (mf/deref refs/message)
|
(let [message (mf/deref refs/message)
|
||||||
on-close #(st/emit! dm/hide)]
|
on-close (st/emitf dm/hide)]
|
||||||
(when message
|
(when message
|
||||||
[:& banner (assoc message
|
[:& banner (assoc message
|
||||||
:position (or (:position message) :fixed)
|
:position (or (:position message) :fixed)
|
||||||
|
|
Loading…
Add table
Reference in a new issue