Skip to content

Commit ece3920

Browse files
committed
Create recovery-phrase input
Add simple test asd
1 parent 9ddea48 commit ece3920

File tree

5 files changed

+111
-1
lines changed

5 files changed

+111
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(ns quo2.components.inputs.recovery-phrase.component-spec
2+
(:require [quo2.components.inputs.recovery-phrase.view :as recovery-phrase]
3+
[test-helpers.component :as h]))
4+
5+
(h/describe "Recovery phrase input"
6+
(h/test "Default render"
7+
(h/render [recovery-phrase/recovery-phrase-input {}])
8+
(h/is-truthy (h/get-by-label-text :recovery-phrase-input))))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
(ns quo2.components.inputs.recovery-phrase.style
2+
(:require [quo2.components.markdown.text :as markdown.text]
3+
[quo2.foundations.colors :as colors]))
4+
5+
(def container
6+
{:min-height 40
7+
:flex 1
8+
:padding-vertical 4
9+
:padding-horizontal 20})
10+
11+
(defn input
12+
[]
13+
(assoc (markdown.text/text-style {})
14+
:height 32
15+
:flex-grow 1
16+
:padding-vertical 5
17+
:text-align-vertical :top))
18+
19+
(defn placeholder-color
20+
[input-state override-theme blur?]
21+
(cond
22+
(and (= input-state :focused) blur?)
23+
(colors/theme-colors colors/neutral-80-opa-20 colors/white-opa-20 override-theme)
24+
25+
(= input-state :focused) ; Not blur
26+
(colors/theme-colors colors/neutral-30 colors/neutral-60 override-theme)
27+
28+
blur? ; :default & blur
29+
(colors/theme-colors colors/neutral-80-opa-40 colors/white-opa-30 override-theme)
30+
31+
:else ; :default & not blur
32+
(colors/theme-colors colors/neutral-40 colors/neutral-50 override-theme)))
33+
34+
(defn cursor-color
35+
[customization-color override-theme]
36+
(colors/theme-colors (colors/custom-color customization-color 50)
37+
(colors/custom-color customization-color 60)
38+
override-theme))
39+
40+
(defn error-word
41+
[]
42+
{:height 22
43+
:padding-horizontal 20
44+
:background-color colors/danger-50-opa-10
45+
:color (colors/theme-colors colors/danger-50 colors/danger-60)})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
(ns quo2.components.inputs.recovery-phrase.view
2+
(:require [clojure.string :as string]
3+
[quo2.components.inputs.recovery-phrase.style :as style]
4+
[react-native.core :as rn]
5+
[reagent.core :as reagent]))
6+
7+
(def ^:private custom-props
8+
[:customization-color :override-theme :blur? :cursor-color :multiline :on-focus :on-blur
9+
:placeholder-text-color :mark-errors? :error-pred :word-limit])
10+
11+
(defn- error-word
12+
[text]
13+
[rn/text {:style (style/error-word)}
14+
text])
15+
16+
(defn- mark-error-words
17+
[pred text word-limit]
18+
(let [word-limit (or word-limit ##Inf)]
19+
(into [:<>]
20+
(comp (map-indexed (fn [idx word]
21+
(if (or (pred word) (>= idx word-limit))
22+
[error-word word]
23+
word)))
24+
(interpose " "))
25+
(string/split text #" "))))
26+
27+
(defn recovery-phrase-input
28+
[_ _]
29+
(let [state (reagent/atom :default)
30+
set-focused #(reset! state :focused)
31+
set-default #(reset! state :default)]
32+
(fn [{:keys [customization-color override-theme blur? on-focus on-blur mark-errors?
33+
error-pred word-limit]
34+
:or {customization-color :blue}
35+
:as props}
36+
text]
37+
(let [extra-props (apply dissoc props custom-props)]
38+
[rn/view {:style style/container}
39+
[rn/text-input
40+
(merge {:accessibility-label :recovery-phrase-input
41+
:style (style/input)
42+
:placeholder-text-color (style/placeholder-color @state override-theme blur?)
43+
:cursor-color (style/cursor-color customization-color override-theme)
44+
:multiline true
45+
:on-focus (fn []
46+
(set-focused)
47+
(when on-focus (on-focus)))
48+
:on-blur (fn []
49+
(set-default)
50+
(when on-blur (on-blur)))}
51+
extra-props)
52+
(if mark-errors?
53+
(mark-error-words error-pred text word-limit)
54+
text)]]))))

src/quo2/core.cljs

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
quo2.components.info.information-box
3434
quo2.components.inputs.input.view
3535
quo2.components.inputs.profile-input.view
36+
quo2.components.inputs.recovery-phrase.view
3637
quo2.components.inputs.search-input.view
3738
quo2.components.inputs.title-input.view
3839
quo2.components.links.url-preview-list.view
@@ -154,8 +155,9 @@
154155

155156
;;;; INPUTS
156157
(def input quo2.components.inputs.input.view/input)
157-
(def search-input quo2.components.inputs.search-input.view/search-input)
158158
(def profile-input quo2.components.inputs.profile-input.view/profile-input)
159+
(def recovery-phrase-input quo2.components.inputs.recovery-phrase.view/recovery-phrase-input)
160+
(def search-input quo2.components.inputs.search-input.view/search-input)
159161
(def title-input quo2.components.inputs.title-input.view/title-input)
160162

161163
;;;; LIST ITEMS

src/quo2/core_spec.cljs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
[quo2.components.drawers.permission-context.component-spec]
1414
[quo2.components.inputs.input.component-spec]
1515
[quo2.components.inputs.profile-input.component-spec]
16+
[quo2.components.inputs.recovery-phrase.component-spec]
1617
[quo2.components.inputs.title-input.component-spec]
1718
[quo2.components.links.url-preview-list.component-spec]
1819
[quo2.components.links.url-preview.component-spec]

0 commit comments

Comments
 (0)