Refactor - Info/Info Message component (#20551)

This commit is contained in:
Ajay Sivan 2024-07-02 16:36:37 +05:30 committed by GitHub
parent 0581fc2f9d
commit b650591e58
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
29 changed files with 194 additions and 141 deletions

View File

@ -2,7 +2,7 @@
(:require (:require
[quo.components.buttons.button.view :as button] [quo.components.buttons.button.view :as button]
[quo.components.buttons.predictive-keyboard.style :as style] [quo.components.buttons.predictive-keyboard.style :as style]
[quo.components.info.info-message :as info-message] [quo.components.info.info-message.view :as info-message]
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[quo.theme] [quo.theme]
[react-native.core :as rn] [react-native.core :as rn]
@ -57,17 +57,17 @@
:key-fn str}] :key-fn str}]
:error :error
[info-message/info-message [info-message/view
{:icon :i/info {:icon :i/info
:size :default :size :default
:type :error} :status :error}
text] text]
:info :info
[info-message/info-message [info-message/view
(merge {:icon :i/info (merge {:icon :i/info
:size :default :size :default
:type (if (= type :error) :error :default)} :status (if (= type :error) :error :default)}
(when blur? (when blur?
{:text-color colors/white-opa-70 {:text-color colors/white-opa-70
:icon-color colors/white-opa-40})) :icon-color colors/white-opa-40}))

View File

@ -1,48 +0,0 @@
(ns quo.components.info.info-message
(:require
[quo.components.icon :as quo.icons]
[quo.components.markdown.text :as text]
[quo.foundations.colors :as colors]
[quo.theme :as quo.theme]
[react-native.core :as rn]))
(defn get-color
[k theme]
(case k
:success (colors/resolve-color :success theme)
:error (colors/resolve-color :danger theme)
:warning (colors/resolve-color :warning theme)
(colors/theme-colors colors/neutral-50 colors/neutral-40 theme)))
(defn info-message
"[info-message opts \"message\"]
opts
{:type :default/:success/:error
:size :default/:tiny
:icon :i/info ;; info message icon
:text-color colors/white ;; text color override
:icon-color colors/white ;; icon color override
:no-icon-color? false ;; disable tint color for icon"
[{:keys [type size icon text-color icon-color no-icon-color? style accessibility-label
container-style]} message]
(let [theme (quo.theme/use-theme)
weight (if (= size :default) :regular :medium)
icon-size (if (= size :default) 16 12)
size (if (= size :default) :paragraph-2 :label)
text-color (or text-color (get-color type theme))
icon-color (or icon-color text-color)]
[rn/view
{:style (merge {:flex-direction :row
:align-items :center}
style
container-style)}
[quo.icons/icon icon
{:color icon-color
:no-color no-icon-color?
:size icon-size}]
[text/text
{:accessibility-label accessibility-label
:size size
:weight weight
:style {:color text-color
:margin-horizontal 4}} message]]))

View File

@ -0,0 +1,32 @@
(ns quo.components.info.info-message.component-spec
(:require
[quo.components.info.info-message.view :as info-message]
[test-helpers.component :as h]))
(h/describe "Info: Info Message"
(h/test "basic render"
(h/render-with-theme-provider
[info-message/view
{:status :default
:size :default
:accessibility-label :info-message
:icon :i/placeholder} "Message"])
(h/is-truthy (h/get-by-label-text :info-message)))
(h/test "render with correct message"
(h/render-with-theme-provider
[info-message/view
{:status :default
:size :default
:accessibility-label :info-message
:icon :i/placeholder} "Message"])
(h/is-truthy (h/get-by-text "Message")))
(h/test "render icon"
(h/render-with-theme-provider
[info-message/view
{:status :default
:size :default
:accessibility-label :info-message
:icon :i/placeholder} "Message"])
(h/is-truthy (h/get-by-label-text :icon))))

View File

@ -0,0 +1,6 @@
(ns quo.components.info.info-message.style)
(def container
{:flex-direction :row
:gap 4
:align-items :center})

View File

@ -0,0 +1,53 @@
(ns quo.components.info.info-message.view
(:require [quo.components.icon :as icons]
[quo.components.info.info-message.style :as style]
[quo.components.markdown.text :as text]
[quo.foundations.colors :as colors]
[quo.theme :as quo.theme]
[react-native.core :as rn]
[schema.core :as schema]))
(def ?schema
[:=>
[:catn
[:props
[:map {:closed true}
[:status {:optional true} [:maybe [:enum :default :success :error :warning]]]
[:size {:optional true} [:maybe [:enum :default :tiny]]]
[:blur? {:optional true} [:maybe :boolean]]
[:icon :keyword]
[:color {:optional true} [:maybe :string]]
[:text-color {:optional true} [:maybe :string]]
[:icon-color {:optional true} [:maybe :string]]
[:no-icon-color? {:optional true} [:maybe :boolean]]
[:accessibility-label {:optional true} [:maybe :keyword]]
[:container-style {:optional true} [:maybe :map]]]]
[:message :string]]
:any])
(defn- get-color
[status theme blur?]
(case status
:success (if blur? colors/success-60 (colors/resolve-color :success theme))
:error (if blur? colors/danger-60 (colors/resolve-color :danger theme))
:warning (if blur? colors/warning-60 (colors/resolve-color :warning theme))
(if blur? colors/white-opa-40 (colors/theme-colors colors/neutral-50 colors/neutral-40 theme))))
(defn view-internal
[{:keys [status size blur? icon color icon-color text-color no-icon-color? container-style
accessibility-label]} message]
(let [theme (quo.theme/use-theme)
default-color (get-color status theme blur?)
text-color (or text-color color default-color)
icon-color (or icon-color color default-color)]
[rn/view {:style (merge style/container container-style)}
[icons/icon icon
{:size (if (= size :tiny) 12 16)
:color icon-color
:no-color? no-icon-color?}]
[text/text
{:size (if (= size :tiny) :label :paragraph-2)
:accessibility-label accessibility-label
:style {:color text-color}} message]]))
(def view (schema/instrument #'view-internal ?schema))

View File

@ -68,7 +68,7 @@
quo.components.graph.wallet-graph.view quo.components.graph.wallet-graph.view
quo.components.header quo.components.header
quo.components.icon quo.components.icon
quo.components.info.info-message quo.components.info.info-message.view
quo.components.info.information-box.view quo.components.info.information-box.view
quo.components.inputs.address-input.view quo.components.inputs.address-input.view
quo.components.inputs.input.view quo.components.inputs.input.view
@ -301,7 +301,7 @@
(def icon quo.components.icon/icon) (def icon quo.components.icon/icon)
;;;; Info ;;;; Info
(def info-message quo.components.info.info-message/info-message) (def info-message quo.components.info.info-message.view/view)
(def information-box quo.components.info.information-box.view/view) (def information-box quo.components.info.information-box.view/view)
;;;; Inputs ;;;; Inputs

View File

@ -41,6 +41,7 @@
quo.components.dropdowns.network-dropdown.component-spec quo.components.dropdowns.network-dropdown.component-spec
quo.components.gradient.gradient-cover.component-spec quo.components.gradient.gradient-cover.component-spec
quo.components.graph.wallet-graph.component-spec quo.components.graph.wallet-graph.component-spec
quo.components.info.info-message.component-spec
quo.components.inputs.address-input.component-spec quo.components.inputs.address-input.component-spec
quo.components.inputs.input.component-spec quo.components.inputs.input.component-spec
quo.components.inputs.locked-input.component-spec quo.components.inputs.locked-input.component-spec

View File

@ -31,10 +31,10 @@
:on-change-text #(reset! entered-password %)}] :on-change-text #(reset! entered-password %)}]
(when (not-empty error) (when (not-empty error)
[quo/info-message [quo/info-message
{:type :error {:status :error
:size :default :size :default
:icon :i/info :icon :i/info
:containstyle {:margin-top 8}} :container-style {:margin-top 8}}
(i18n/label :t/oops-wrong-password)]) (i18n/label :t/oops-wrong-password)])
[quo/button [quo/button
{:container-style {:margin-bottom 12 :margin-top 40} {:container-style {:margin-bottom 12 :margin-top 40}

View File

@ -34,9 +34,9 @@
[theme])] [theme])]
[rn/view {:style style/error-message} [rn/view {:style style/error-message}
[quo/info-message [quo/info-message
{:type :error {:status :error
:size :default :size :default
:icon :i/info} :icon :i/info}
error-message] error-message]
[rn/pressable [rn/pressable
{:hit-slop {:top 6 :bottom 20 :left 0 :right 0} {:hit-slop {:top 6 :bottom 20 :left 0 :right 0}

View File

@ -105,10 +105,10 @@
:max-length constants/max-group-chat-name-length}] :max-length constants/max-group-chat-name-length}]
(when error-message (when error-message
[quo/info-message [quo/info-message
{:type :error {:status :error
:icon :i/info :icon :i/info
:size :default :size :default
:style {:margin-top 8 :margin-left 20 :margin-bottom 16}} :container-style {:margin-top 8 :margin-left 20 :margin-bottom 16}}
error-message]) error-message])
[quo/divider-line] [quo/divider-line]
[rn/view [rn/view

View File

@ -38,14 +38,11 @@
[rn/view {:style style/info-message} [rn/view {:style style/info-message}
(when shown (when shown
[quo/info-message [quo/info-message
{:type status {:status status
:size :default :size :default
:icon (if (= status :success) :i/positive-state :i/info) :icon (if (= status :success) :i/positive-state :i/info)
:text-color (when (= status :default) :color (when (= status :default)
colors/white-70-blur) colors/white-70-blur)}
:icon-color (when (= status :default)
colors/white-70-blur)
:style {}}
text])]]) text])]])
(defn password-inputs (defn password-inputs

View File

@ -158,12 +158,11 @@
:on-change-text on-change-text}}]] :on-change-text on-change-text}}]]
[quo/info-message [quo/info-message
{:type info-type {:status info-type
:size :default :size :default
:icon (if valid-name? :i/positive-state :i/info) :icon (if valid-name? :i/positive-state :i/info)
:text-color (when (= :default info-type) colors/white-70-blur) :color (when (= :default info-type) colors/white-70-blur)
:icon-color (when (= :default info-type) colors/white-70-blur) :container-style style/info-message}
:style style/info-message}
info-message] info-message]
[quo/text [quo/text
{:size :paragraph-2 {:size :paragraph-2

View File

@ -1,28 +1,43 @@
(ns status-im.contexts.preview.quo.info.info-message (ns status-im.contexts.preview.quo.info.info-message
(:require (:require
[quo.core :as quo] [quo.core :as quo]
[reagent.core :as reagent] [react-native.core :as rn]
[status-im.contexts.preview.quo.preview :as preview])) [status-im.contexts.preview.quo.preview :as preview]))
(def descriptor (def descriptor
[{:key :type [{:key :status
:type :select :type :select
:options [{:key :default} :options [{:key :default}
{:key :success} {:key :success}
{:key :error}]} {:key :error}
{:key :warning}]}
{:key :size {:key :size
:type :select :type :select
:options [{:key :default} :options [{:key :default}
{:key :tiny}]} {:key :tiny}]}
{:key :blur?
:type :boolean}
{:key :icon
:type :select
:options [{:key :i/placeholder}
{:key :i/info}]}
{:key :message {:key :message
:type :text}]) :type :text}])
(defn view (defn view
[] []
(let [state (reagent/atom {:type :default (let [[state set-state] (rn/use-state
:size :default {:status :default
:icon :i/placeholder :size :default
:message "This is a message"})] :message "This is a message"
(fn [] :blur? false
[preview/preview-container {:state state :descriptor descriptor} :icon :i/placeholder})
[quo/info-message @state (:message @state)]]))) blur? (:blur? state)]
[preview/preview-container
{:state state
:descriptor descriptor
:blur-dark-only? true
:show-blur-background? blur?
:blur? blur?
:set-state set-state}
[quo/info-message (dissoc state :message) (:message state)]]))

View File

@ -65,9 +65,9 @@
:customization-color :blue} :customization-color :blue}
:header [rn/view :header [rn/view
[quo/info-message [quo/info-message
{:type :success {:status :success
:size :tiny :size :tiny
:icon :i/placeholder} :icon :i/placeholder}
"info-message as title"]] "info-message as title"]]
:body [quo/snippet {:language :clojure :max-lines 15 :syntax true} :body [quo/snippet {:language :clojure :max-lines 15 :syntax true}
snippet-preview/clojure-example] snippet-preview/clojure-example]

View File

@ -68,9 +68,9 @@
:on-change-text on-nickname-change :on-change-text on-nickname-change
:on-submit-editing on-nickname-submit}] :on-submit-editing on-nickname-submit}]
[quo/info-message [quo/info-message
{:icon :i/info {:icon :i/info
:size :default :size :default
:type (if-not (string/blank? error-msg) :error :default)} :status (if-not (string/blank? error-msg) :error :default)}
(if-not (string/blank? error-msg) (if-not (string/blank? error-msg)
error-msg error-msg
(i18n/label :t/nickname-visible-to-you))]] (i18n/label :t/nickname-visible-to-you))]]

View File

@ -58,9 +58,9 @@
:on-change-text on-change-text}] :on-change-text on-change-text}]
(when-not (string/blank? error-msg) (when-not (string/blank? error-msg)
[quo/info-message [quo/info-message
{:type :error {:status :error
:size :default :size :default
:icon :i/info} :icon :i/info}
error-msg])] error-msg])]
[rn/view {:style style/button-wrapper} [rn/view {:style style/button-wrapper}
[quo/button [quo/button

View File

@ -58,9 +58,9 @@
:on-change-text on-change-text}] :on-change-text on-change-text}]
(when-not (string/blank? @error-msg) (when-not (string/blank? @error-msg)
[quo/info-message [quo/info-message
{:type :error {:status :error
:size :default :size :default
:icon :i/info} :icon :i/info}
@error-msg])] @error-msg])]
[rn/view {:style style/button-wrapper} [rn/view {:style style/button-wrapper}
[quo/button [quo/button

View File

@ -24,12 +24,11 @@
[rn/view {:style style/info-message} [rn/view {:style style/info-message}
(when shown? (when shown?
[quo/info-message [quo/info-message
(cond-> {:type status (cond-> {:status status
:size :default} :size :default}
(not= :success status) (assoc :icon :i/info) (not= :success status) (assoc :icon :i/info)
(= :success status) (assoc :icon :i/positive-state) (= :success status) (assoc :icon :i/positive-state)
(= :default status) (assoc :text-color colors/white-70-blur (= :default status) (assoc :color colors/white-70-blur))
:icon-color colors/white-70-blur))
text])]]) text])]])
(defn- calc-password-strength (defn- calc-password-strength

View File

@ -43,9 +43,9 @@
{:style style/error-container} {:style style/error-container}
(when error (when error
[quo/info-message [quo/info-message
{:type :error {:status :error
:size :default :size :default
:icon :i/info} :icon :i/info}
(i18n/label :t/oops-wrong-password)])] (i18n/label :t/oops-wrong-password)])]
[quo/information-box [quo/information-box
{:type :error {:type :error

View File

@ -128,9 +128,9 @@
:default-value private-key}] :default-value private-key}]
(when flow-state (when flow-state
[quo/info-message [quo/info-message
{:type (if (= flow-state :correct-private-key) :success :error) {:status (if (= flow-state :correct-private-key) :success :error)
:size :default :size :default
:icon :i/info} :icon :i/info}
(case flow-state (case flow-state
:correct-private-key (i18n/label :t/correct-private-key) :correct-private-key (i18n/label :t/correct-private-key)
:invalid-private-key (i18n/label :t/invalid-private-key) :invalid-private-key (i18n/label :t/invalid-private-key)

View File

@ -94,9 +94,8 @@
:error? (not (string/blank? error-msg))}] :error? (not (string/blank? error-msg))}]
(when-not (string/blank? error-msg) (when-not (string/blank? error-msg)
[quo/info-message [quo/info-message
{:type :error {:status :error
:size :default :size :default
:icon :i/info :icon :i/info
:container-style style/error-container} :container-style style/error-container}
error-msg])]])) error-msg])]]))

View File

@ -85,8 +85,8 @@
{:accessibility-label :error-message {:accessibility-label :error-message
:size :default :size :default
:icon :i/alert :icon :i/alert
:type :error :status :error
:style style/info-message} :container-style style/info-message}
error-msg]))) error-msg])))
(defn- existing-saved-address (defn- existing-saved-address

View File

@ -103,8 +103,8 @@
(when activity-state (when activity-state
[quo/info-message [quo/info-message
(assoc props (assoc props
:style style/info-message :container-style style/info-message
:size :default) :size :default)
(i18n/label message)]))) (i18n/label message)])))
(defn view (defn view
@ -163,7 +163,7 @@
{:accessibility-label :error-message {:accessibility-label :error-message
:size :default :size :default
:icon :i/info :icon :i/info
:type :error :status :error
:style style/info-message} :container-style style/info-message}
@validation-msg] @validation-msg]
[activity-indicator activity-state])]])))) [activity-indicator])]]))))

View File

@ -117,12 +117,12 @@
{:weight :monospace} {:weight :monospace}
(:address derivation-path)]] (:address derivation-path)]]
[quo/info-message [quo/info-message
{:type (case state {:status (case state
:has-activity :success :has-activity :success
:no-activity :warning :no-activity :warning
:default) :default)
:icon (if (= state :scanning) :i/scanning :i/done) :icon (if (= state :scanning) :i/scanning :i/done)
:style style/info} :style style/info}
(i18n/label (case state (i18n/label (case state
:has-activity :t/address-activity :has-activity :t/address-activity
:no-activity :t/address-no-activity :no-activity :t/address-no-activity

View File

@ -91,7 +91,7 @@
:error error}] :error error}]
(when error (when error
[quo/info-message [quo/info-message
{:type :error {:status :error
:size :default :size :default
:icon :i/info :icon :i/info
:container-style style/error-container} :container-style style/error-container}

View File

@ -87,7 +87,7 @@
:container-style (style/title-input-container error)}] :container-style (style/title-input-container error)}]
(when error (when error
[quo/info-message [quo/info-message
{:type :error {:status :error
:size :default :size :default
:icon :i/info :icon :i/info
:container-style {:margin-left 20 :container-style {:margin-left 20

View File

@ -62,7 +62,7 @@
:container-style (style/title-input-container error)}] :container-style (style/title-input-container error)}]
(when error (when error
[quo/info-message [quo/info-message
{:type :error {:status :error
:size :default :size :default
:icon :i/info :icon :i/info
:container-style {:margin-left 20 :container-style {:margin-left 20

View File

@ -109,10 +109,10 @@
[] []
[rn/view {:style style/no-routes-found-container} [rn/view {:style style/no-routes-found-container}
[quo/info-message [quo/info-message
{:type :error {:status :error
:icon :i/alert :icon :i/alert
:size :default :size :default
:style {:margin-top 15}} :container-style {:margin-top 15}}
(i18n/label :t/no-routes-found)]]) (i18n/label :t/no-routes-found)]])
(defn- not-enough-asset (defn- not-enough-asset

View File

@ -200,9 +200,9 @@
(when (and (not valid-ens-or-address?) (> (count @input-value) 0)) (when (and (not valid-ens-or-address?) (> (count @input-value) 0))
[rn/view {:style {:padding 20}} [rn/view {:style {:padding 20}}
[quo/info-message [quo/info-message
{:type :error {:status :error
:icon :i/info :icon :i/info
:size :default} :size :default}
(i18n/label :t/invalid-address)]]) (i18n/label :t/invalid-address)]])
(if (or @input-focused? (> (count @input-value) 0)) (if (or @input-focused? (> (count @input-value) 0))
[rn/keyboard-avoiding-view [rn/keyboard-avoiding-view