-
Notifications
You must be signed in to change notification settings - Fork 984
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7db401
commit 165758a
Showing
11 changed files
with
169 additions
and
11 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/quo2/components/buttons/predictive_keyboard/component_spec.cljs
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,20 @@ | ||
(ns quo2.components.buttons.predictive-keyboard.component-spec | ||
(:require [quo2.components.buttons.predictive-keyboard.view :as predictive-keyboard] | ||
[test-helpers.component :as h])) | ||
|
||
(h/describe "predictive-keyboard" | ||
(h/test "basic render" | ||
(h/render [predictive-keyboard/view {:type :error :text "Error message"}]) | ||
(h/is-truthy (h/get-by-label-text :predictive-keyboard))) | ||
(h/test "rendered with correct text" | ||
(h/render [predictive-keyboard/view {:type :info :text "Error message"}]) | ||
(h/is-truthy (h/get-by-text "Error message"))) | ||
(h/test "rendered with correct words" | ||
(h/render [predictive-keyboard/view {:type :words :words ["lab" "label"]}]) | ||
(h/is-truthy (h/get-by-text "lab")) | ||
(h/is-truthy (h/get-by-text "label"))) | ||
(h/test "word press event" | ||
(let [event (h/mock-fn)] | ||
(h/render [predictive-keyboard/view {:type :words :words ["lab" "label"] :on-press #(event %)}]) | ||
(h/fire-event :press (h/get-by-text "lab")) | ||
(h/was-called event)))) |
10 changes: 10 additions & 0 deletions
10
src/quo2/components/buttons/predictive_keyboard/style.cljs
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,10 @@ | ||
(ns quo2.components.buttons.predictive-keyboard.style) | ||
|
||
(defn wrapper | ||
[type] | ||
{:flex 1 | ||
:height 48 | ||
:justify-content :center | ||
:padding-horizontal (if (= type :words) 0 20)}) | ||
|
||
(def word-list {:align-items :center :padding-horizontal 20}) |
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,74 @@ | ||
(ns quo2.components.buttons.predictive-keyboard.view | ||
(:require [react-native.core :as rn] | ||
[quo2.components.buttons.predictive-keyboard.style :as style] | ||
[quo2.components.info.info-message :as info-message] | ||
[react-native.linear-gradient :as linear-gradient] | ||
[quo2.foundations.colors :as colors] | ||
[quo2.components.buttons.button :as button])) | ||
|
||
(def ^:private gradients | ||
{:light [(colors/alpha colors/neutral-40 0.05) (colors/alpha colors/neutral-40 0)] | ||
:dark [(colors/alpha colors/neutral-80 0.7) (colors/alpha colors/neutral-80 0)] | ||
:blur [colors/white-opa-5 colors/white-opa-0]}) | ||
|
||
(defn- word-component | ||
[word _ _ {:keys [blur? on-press]}] | ||
[button/button | ||
(merge {:type :blur-bg | ||
:size 32 | ||
:on-press #(on-press word)} | ||
(when blur? {:override-theme :dark})) | ||
word]) | ||
|
||
(defn- separator | ||
[] | ||
[rn/view {:style {:width 8}}]) | ||
|
||
(defn view | ||
"Options | ||
- `type` `:words`/`:error`/`:info`/`:empty`. | ||
- `blur?` Boolean to enable blur background support. | ||
- `text` error/info text. | ||
- `words` List of words to display in the keyboard. | ||
- `on-press` Callback called when a word is pressed `(fn [word])`." | ||
[{:keys [type blur? text words on-press]}] | ||
[linear-gradient/linear-gradient | ||
{:style {:flex-direction :row} | ||
:accessibility-label :predictive-keyboard | ||
:colors (if blur? | ||
(gradients :blur) | ||
(colors/theme-colors | ||
(gradients :light) | ||
(gradients :dark)))} | ||
|
||
[rn/view {:style (style/wrapper type)} | ||
(case type | ||
:words | ||
[rn/flat-list | ||
{:data words | ||
:content-container-style style/word-list | ||
:render-fn word-component | ||
:render-data {:blur? blur? | ||
:on-press on-press} | ||
:shows-horizontal-scroll-indicator false | ||
:separator [separator] | ||
:horizontal true | ||
:key-fn str}] | ||
|
||
:error | ||
[info-message/info-message | ||
{:icon :i/info | ||
:size :default | ||
:type :error} | ||
text] | ||
|
||
:info | ||
[info-message/info-message | ||
(merge {:icon :i/info | ||
:size :default | ||
:type (if (= type :error) :error :default)} | ||
(when blur? | ||
{:text-color colors/white-opa-70 | ||
:icon-color colors/white-opa-70})) | ||
text] | ||
nil)]]) |
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 |
---|---|---|
|
@@ -10,4 +10,3 @@ | |
[color] | ||
{:color color | ||
:margin-left 4}) | ||
|
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 |
---|---|---|
|
@@ -82,4 +82,3 @@ | |
:weight :medium | ||
:style (style/text color)} | ||
(or default-text text)]]])) | ||
|
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
48 changes: 48 additions & 0 deletions
48
src/status_im2/contexts/quo_preview/buttons/predictive_keyboard.cljs
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,48 @@ | ||
(ns status-im2.contexts.quo-preview.buttons.predictive-keyboard | ||
(:require [quo2.core :as quo] | ||
[quo2.foundations.colors :as colors] | ||
[react-native.blur :as blur] | ||
[react-native.core :as rn] | ||
[reagent.core :as reagent] | ||
[status-im2.contexts.quo-preview.preview :as preview])) | ||
|
||
(def descriptor | ||
[{:label "Type" | ||
:key :type | ||
:type :select | ||
:options [{:key :error :value "Error"} | ||
{:key :empty :value "Empty"} | ||
{:key :info :value "Info"} | ||
{:key :words :value "Words"}]} | ||
{:label "Text" | ||
:key :text | ||
:type :text} | ||
{:label "Blur" | ||
:key :blur? | ||
:type :boolean}]) | ||
|
||
(defn cool-preview | ||
[] | ||
(let [state (reagent/atom {:type :info :text "Enter 12, 18 or 24 words separated by a space"}) | ||
blur (reagent/cursor state [:blur?])] | ||
(fn [] | ||
[rn/touchable-without-feedback {:on-press rn/dismiss-keyboard!} | ||
[rn/view {:padding-bottom 150} | ||
[preview/customizer state descriptor] | ||
[(if @blur blur/view :<>) | ||
[rn/view {:padding-vertical 60 :align-items :center} | ||
[quo/predictive-keyboard | ||
(merge @state {:words ["label" "label" "labor" "ladder" "lady" "lake"]})]]]]]))) | ||
|
||
(defn preview-predictive-keyboard | ||
[] | ||
[rn/view | ||
{:background-color (colors/theme-colors | ||
colors/white | ||
colors/neutral-95) | ||
:flex 1} | ||
[rn/flat-list | ||
{:flex 1 | ||
:keyboard-should-persist-taps :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