-
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.
feat: add title input component to quo2
- Loading branch information
Showing
14 changed files
with
258 additions
and
23 deletions.
There are no files selected for viewing
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
2 changes: 1 addition & 1 deletion
2
src/quo2/components/input/style.cljs → src/quo2/components/inputs/input/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
4 changes: 2 additions & 2 deletions
4
src/quo2/components/input/view.cljs → src/quo2/components/inputs/input/view.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
40 changes: 40 additions & 0 deletions
40
src/quo2/components/inputs/title_input/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,40 @@ | ||
(ns quo2.components.inputs.title-input.component-spec | ||
(:require [quo2.components.inputs.title-input.view :as title-input] | ||
[test-helpers.component :as h])) | ||
|
||
(h/describe "profile: title-input" | ||
(h/test "renders empty" | ||
(h/render [title-input/title-input | ||
{:value "" | ||
:on-change-text (h/mock-fn)}]) | ||
(-> (js/expect (h/get-by-label-text :profile-title-input)) | ||
(.toBeTruthy))) | ||
|
||
(h/test "empty text renders with max length digits and 00" | ||
(h/render [title-input/title-input | ||
{:value "" | ||
:max-length 24 | ||
:on-change-text (h/mock-fn)}]) | ||
(-> (js/expect (h/get-by-text "00")) | ||
(.toBeTruthy)) | ||
(-> (js/expect (h/get-by-text "/24")) | ||
(.toBeTruthy))) | ||
|
||
(h/test "renders with max length digits and character count" | ||
(h/render [title-input/title-input | ||
{:default-value "abc" | ||
:max-length 24 | ||
:on-change-text (h/mock-fn)} "abc"]) | ||
(-> (js/expect (h/get-by-text "03")) | ||
(.toBeTruthy)) | ||
(-> (js/expect (h/get-by-text "/24")) | ||
(.toBeTruthy))) | ||
|
||
(h/test "text updates on change" | ||
(let [on-change-text (h/mock-fn)] | ||
(h/render [title-input/title-input | ||
{:value "mock text" | ||
:on-change-text on-change-text}]) | ||
(h/fire-event :change-text (h/get-by-label-text :profile-title-input) "mock-text-new") | ||
(-> (js/expect on-change-text) | ||
(.toHaveBeenCalled))))) |
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,52 @@ | ||
(ns quo2.components.inputs.title-input.style | ||
(:require [quo2.foundations.colors :as colors])) | ||
|
||
(defn get-focused-placeholder-color | ||
[blur?] | ||
(if blur? | ||
(colors/theme-colors colors/neutral-80-opa-20 (colors/alpha colors/white 0.2)) | ||
(colors/theme-colors colors/neutral-30 colors/neutral-60))) | ||
|
||
(defn get-placeholder-color | ||
[blur?] | ||
(if blur? | ||
(colors/theme-colors colors/neutral-80-opa-40 (colors/alpha colors/white 0.3)) | ||
(colors/theme-colors colors/neutral-40 colors/neutral-50))) | ||
|
||
(defn- get-disabled-color | ||
[blur?] | ||
(if blur? | ||
(colors/theme-colors colors/neutral-80-opa-40 (colors/alpha colors/white 0.3)) | ||
(colors/theme-colors colors/neutral-40 colors/neutral-50))) | ||
|
||
(defn- get-char-count-color | ||
[blur?] | ||
(if blur? | ||
(colors/theme-colors colors/neutral-80-opa-40 (colors/alpha colors/white 0.4)) | ||
(colors/theme-colors colors/neutral-40 colors/neutral-50))) | ||
|
||
(defn get-selection-color | ||
[customization-color blur?] | ||
(if blur? | ||
(colors/theme-colors colors/neutral-100 colors/white) | ||
(colors/custom-color customization-color (if colors/dark? 60 50)))) | ||
|
||
(def text-input-container {:flex 1}) | ||
|
||
(defn title-text | ||
[disabled? blur?] | ||
{:text-align-vertical :bottom | ||
:color (when disabled? (get-disabled-color blur?))}) | ||
|
||
(defn char-count | ||
[blur?] | ||
{:color (get-char-count-color blur?)}) | ||
|
||
(def container | ||
{:flex-direction :row | ||
:flex 1 | ||
:justify-content :center | ||
:align-items :center}) | ||
|
||
(def counter-container | ||
{:padding-top 8}) |
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,65 @@ | ||
(ns quo2.components.inputs.title-input.view | ||
(:require | ||
[quo2.components.inputs.title-input.style :as style] | ||
[quo2.components.markdown.text :as text] | ||
[reagent.core :as reagent] | ||
[react-native.core :as rn])) | ||
|
||
(defn- pad-0 | ||
[value] | ||
(if (<= (count value) 1) | ||
(str 0 value) | ||
value)) | ||
|
||
(defn title-input | ||
[{:keys [blur? | ||
on-change-text | ||
placeholder | ||
max-length | ||
default-value] | ||
:or {max-length 0 | ||
default-value ""}}] | ||
(let [focused? (reagent/atom false) | ||
value (reagent/atom default-value) | ||
on-change (fn [v] | ||
(reset! value v) | ||
(when on-change-text | ||
(on-change-text v)))] | ||
(fn [{:keys [customization-color disabled?]}] | ||
[rn/view | ||
{:style style/container} | ||
[rn/view {:style style/text-input-container} | ||
[rn/text-input | ||
{:style | ||
(text/text-style | ||
{:size :heading-2 | ||
:weight :semi-bold | ||
:style (style/title-text disabled? blur?)}) | ||
:default-value default-value | ||
:accessibility-label :profile-title-input | ||
:on-focus #(swap! focused? (fn [] true)) | ||
:on-blur #(swap! focused? (fn [] false)) | ||
:input-mode :text | ||
:on-change-text on-change | ||
:editable (not disabled?) | ||
:max-length max-length | ||
:placeholder placeholder | ||
:selection-color (style/get-selection-color customization-color blur?) | ||
:placeholder-text-color (if @focused? | ||
(style/get-focused-placeholder-color blur?) | ||
(style/get-placeholder-color blur?))}]] | ||
[rn/view | ||
{:style style/counter-container} | ||
[text/text | ||
[text/text | ||
{:style (style/char-count blur?) | ||
:size :paragraph-2} | ||
(pad-0 | ||
(str | ||
(count @value)))] | ||
[text/text | ||
{:style (style/char-count blur?) | ||
:size :paragraph-2} | ||
(str "/" | ||
(pad-0 | ||
(str max-length)))]]]]))) |
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
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
58 changes: 58 additions & 0 deletions
58
src/status_im2/contexts/quo_preview/inputs/title_input.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,58 @@ | ||
(ns status-im2.contexts.quo-preview.inputs.title-input | ||
(:require [quo2.foundations.colors :as colors] | ||
[react-native.core :as rn] | ||
[reagent.core :as reagent] | ||
[quo2.core :as quo] | ||
[react-native.blur :as blur] | ||
[status-im2.contexts.quo-preview.preview :as preview])) | ||
|
||
(def descriptor | ||
[{:label "disabled?" | ||
:key :disabled? | ||
:type :boolean} | ||
{:label "blur?" | ||
:key :blur? | ||
:type :boolean} | ||
{:label "Cursor Color" | ||
:key :color | ||
:type :select | ||
:options (map (fn [{:keys [name]}] {:key name :value name}) (quo/picker-colors))}]) | ||
|
||
(defn cool-preview | ||
[] | ||
(let [state (reagent/atom {:color nil | ||
:blur? false | ||
:disabled? false}) | ||
max-length 24 | ||
on-change-text (fn [_v] | ||
(println (str "cool-preview -> on-change-text called " _v)))] | ||
(fn [] | ||
[rn/touchable-without-feedback {:on-press rn/dismiss-keyboard!} | ||
[rn/view {:padding-bottom 150} | ||
[rn/view {:flex 1}] | ||
[preview/customizer state descriptor] | ||
|
||
[preview/blur-view | ||
{:show-blur-background? (:blur? @state) | ||
:style {:flex-direction :row | ||
:justify-content :center}} | ||
[quo/title-input | ||
{:max-length max-length | ||
:default-value "" | ||
:on-change-text on-change-text | ||
:disabled? (:disabled? @state) | ||
:customization-color (:color @state) | ||
:blur? (:blur? @state) | ||
:placeholder "type something here"}]]]]))) | ||
|
||
(defn preview-title-input | ||
[] | ||
[rn/view | ||
{:background-color (colors/theme-colors colors/white | ||
colors/neutral-90) | ||
: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
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