Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of Info message, Information Box component and ENS Banner
- Loading branch information
1 parent
e39277b
commit 506c84c
Showing
10 changed files
with
270 additions
and
5 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
(ns quo2.components.info-message | ||
(:require [quo.theme :as theme] | ||
[quo.react-native :as rn] | ||
[quo2.components.text :as text] | ||
[quo2.foundations.colors :as colors] | ||
[quo2.components.icon :as quo2.icons])) | ||
|
||
(def themes | ||
{:light {:default colors/neutral-40 | ||
:success colors/success-50 | ||
:error colors/danger-50} | ||
:dark {:default colors/neutral-60 | ||
:success colors/success-60 | ||
:error colors/danger-60}}) | ||
|
||
(defn get-color [key] | ||
(get-in themes [(theme/get-theme) key])) | ||
|
||
(defn info-message | ||
"[info-message opts \"message\"] | ||
opts | ||
{:type :default/:success/:error | ||
:size :default/:tiny | ||
:icon :main-icons/info ;; info message icon | ||
:text-color colors/white ;; text color override | ||
:icon-color colors/white ;; icon color override" | ||
[{:keys [type size icon text-color icon-color]} message] | ||
(let [weight (if (= size :default) :regular :medium) | ||
size (if (= size :default) :paragraph-2 :label) | ||
text-color (or text-color (get-color type)) | ||
icon-color (or icon-color text-color)] | ||
[rn/view {:style {:flex-direction :row | ||
:flex 1}} | ||
[quo2.icons/icon icon {:color icon-color | ||
:size 12 | ||
:container-style {:margin-top 3}}] | ||
[text/text {:size size | ||
:weight weight | ||
:style {:color text-color | ||
:margin-horizontal 8}} message]])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
(ns quo2.components.information-box | ||
(:require [quo.theme :as theme] | ||
[quo.react-native :as rn] | ||
[reagent.core :as reagent] | ||
[clojure.string :as string] | ||
[quo2.foundations.colors :as colors] | ||
[quo2.components.icon :as quo2.icons] | ||
[quo2.components.button :as quo2.button] | ||
[status-im.utils.handlers :refer [<sub]] | ||
[quo2.components.info-message :as info-message] | ||
[status-im.async-storage.core :as async-storage])) | ||
|
||
(def themes | ||
{:light {:default {:bg colors/white | ||
:border colors/neutral-20 | ||
:icon colors/neutral-50 | ||
:text colors/black} | ||
:informative {:bg colors/primary-50-opa-5 | ||
:border colors/primary-50-opa-10 | ||
:icon colors/primary-50 | ||
:text colors/black} | ||
:error {:bg colors/danger-50-opa-5 | ||
:border colors/danger-50-opa-10 | ||
:icon colors/danger-50 | ||
:text colors/danger-50} | ||
:close-button colors/black} | ||
:dark {:default {:bg colors/neutral-90 | ||
:border colors/neutral-70 | ||
:icon colors/neutral-40 | ||
:text colors/white} | ||
:informative {:bg colors/primary-50-opa-5 | ||
:border colors/primary-50-opa-10 | ||
:icon colors/white | ||
:text colors/white} | ||
:error {:bg colors/danger-50-opa-5 | ||
:border colors/danger-50-opa-10 | ||
:icon colors/danger-50 | ||
:text colors/danger-50} | ||
:close-button colors/white}}) | ||
|
||
(defn get-color [key] | ||
(get-in themes [(theme/get-theme) key])) | ||
|
||
(defn get-color-by-type [type key] | ||
(get-in themes [(theme/get-theme) type key])) | ||
|
||
(defn id-hash [id public-key global?] | ||
(if global? | ||
(hash id) | ||
(hash (str public-key id)))) | ||
|
||
(defn close-information-box [id public-key global? closed? on-close] | ||
(reset! closed? true) | ||
(async-storage/set-item! (id-hash id public-key global?) true) | ||
(when on-close (on-close))) | ||
|
||
(defn information-box | ||
"[information-box opts \"message\"] | ||
opts | ||
{:type :default/:informative/:error | ||
:closable? true/false ;; allow information box to be closed? | ||
:id :information-box-id ;; unique id (required for closable? information box) | ||
:global? true/ false ;; close information box across all profiles | ||
:icon :main-icons/info ;; information box icon | ||
:style style | ||
:button-label \"PressMe\" ;; add action button with label | ||
:on-button-press action ;; (required for information box with button-label) | ||
:on-close on-close ;; (optional on-close call)" | ||
[{:keys [closable? id global?]} _] | ||
(let [closed? (reagent/atom true) | ||
public-key (when (and closable? (not global?)) (<sub [:multiaccount/public-key]))] | ||
(when closable? | ||
(async-storage/get-item (id-hash id public-key global?) #(reset! closed? %))) | ||
(fn [{:keys [type closable? id global? icon style button-label on-button-press on-close]} message] | ||
(when-not (and closable? @closed?) | ||
(let [background-color (get-color-by-type type :bg) | ||
border-color (get-color-by-type type :border) | ||
icon-color (get-color-by-type type :icon) | ||
text-color (get-color-by-type type :text) | ||
include-button? (not (string/blank? button-label))] | ||
[rn/view {:style (merge {:background-color background-color | ||
:border-color border-color | ||
:border-width 1 | ||
:border-radius 12 | ||
:padding-vertical (if include-button? 10 11) | ||
:padding-horizontal 16} style)} | ||
[rn/view {:style {:flex-direction :row | ||
:align-self :flex-start}} | ||
[info-message/info-message {:size :default | ||
:icon icon | ||
:text-color text-color | ||
:icon-color icon-color} message] | ||
(when closable? | ||
[rn/touchable-opacity | ||
{:on-press #(close-information-box id public-key global? closed? on-close)} | ||
[quo2.icons/icon :main-icons2/close {:size 12 | ||
:color (get-color :close-button) | ||
:container-style {:margin-top 3 | ||
:margin-left 8}}]])] | ||
(when include-button? | ||
[quo2.button/button {:type :primary | ||
:size 24 | ||
:on-press on-button-press | ||
:style {:margin-left 20 | ||
:margin-top 8 | ||
:align-self :flex-start}} button-label])]))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
(ns quo2.screens.info-message | ||
(:require [quo.react-native :as rn] | ||
[reagent.core :as reagent] | ||
[quo.previews.preview :as preview] | ||
[quo2.foundations.colors :as colors] | ||
[quo2.components.info-message :as quo2])) | ||
|
||
(def descriptor [{:label "Type:" | ||
:key :type | ||
:type :select | ||
:options [{:key :default | ||
:value "Default"} | ||
{:key :success | ||
:value "Success"} | ||
{:key :error | ||
:value "Error"}]} | ||
{:label "Size:" | ||
:key :size | ||
:type :select | ||
:options [{:key :default | ||
:value "Default"} | ||
{:key :tiny | ||
:value "Tiny"}]} | ||
{:label "Message" | ||
:key :message | ||
:type :text}]) | ||
|
||
(defn cool-preview [] | ||
(let [state (reagent/atom {:type :default | ||
:size :default | ||
:icon :main-icons2/placeholder | ||
:message "This is a message"})] | ||
(fn [] | ||
[rn/view {:margin-bottom 50 | ||
:padding 16} | ||
[preview/customizer state descriptor] | ||
[rn/view {:padding-vertical 60 | ||
:align-items :center} | ||
[quo2/info-message @state (:message @state)]]]))) | ||
|
||
(defn preview-info-message [] | ||
[rn/view {:background-color (colors/theme-colors colors/white colors/neutral-90) | ||
:flex 1} | ||
[rn/flat-list {:flex 1 | ||
:keyboardShouldPersistTaps :always | ||
:header [cool-preview] | ||
:key-fn str}]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
(ns quo2.screens.information-box | ||
(:require [quo.react-native :as rn] | ||
[reagent.core :as reagent] | ||
[quo.previews.preview :as preview] | ||
[quo2.foundations.colors :as colors] | ||
[quo2.components.information-box :as quo2])) | ||
|
||
(def descriptor [{:label "Type:" | ||
:key :type | ||
:type :select | ||
:options [{:key :default | ||
:value "Default"} | ||
{:key :informative | ||
:value "Informative"} | ||
{:key :error | ||
:value "Error"}]} | ||
{:label "Closable?:" | ||
:key :closable? | ||
:type :boolean} | ||
{:label "Message" | ||
:key :message | ||
:type :text} | ||
{:label "Button Label" | ||
:key :button-label | ||
:type :text}]) | ||
|
||
(defn cool-preview [] | ||
(let [state (reagent/atom {:type :default | ||
:closable? true | ||
:icon :main-icons2/placeholder | ||
:message "This is an information box This is an information" | ||
:button-label "Press Me" | ||
:style {:width 335} | ||
:id (keyword (str "id-" (rand-int 10000)))})] | ||
(fn [] | ||
[rn/view {:margin-bottom 50 | ||
:padding 16} | ||
[preview/customizer state descriptor] | ||
[rn/view {:padding-vertical 60 | ||
:align-items :center} | ||
[quo2/information-box @state (:message @state)]]]))) | ||
|
||
(defn preview-information-box [] | ||
[rn/view {:background-color (colors/theme-colors colors/white colors/neutral-90) | ||
:flex 1} | ||
[rn/flat-list {:flex 1 | ||
:keyboardShouldPersistTaps :always | ||
:header [cool-preview] | ||
:key-fn str}]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters