|
| 1 | +(ns quo2.components.inputs.title-input.view |
| 2 | + (:require |
| 3 | + [quo2.components.inputs.title-input.style :as style] |
| 4 | + [quo2.components.markdown.text :as text] |
| 5 | + [reagent.core :as reagent] |
| 6 | + [react-native.core :as rn])) |
| 7 | + |
| 8 | +(defn- pad-0 |
| 9 | + [value] |
| 10 | + (if (<= (count value) 1) |
| 11 | + (str 0 value) |
| 12 | + value)) |
| 13 | + |
| 14 | +(defn title-input |
| 15 | + [{:keys [blur? |
| 16 | + on-change-text |
| 17 | + placeholder |
| 18 | + max-length |
| 19 | + default-value] |
| 20 | + :or {max-length 0 |
| 21 | + default-value ""}}] |
| 22 | + (let [focused? (reagent/atom false) |
| 23 | + value (reagent/atom default-value) |
| 24 | + on-change (fn [v] |
| 25 | + (reset! value v) |
| 26 | + (when on-change-text |
| 27 | + (on-change-text v)))] |
| 28 | + (fn [{:keys [customization-color disabled?]}] |
| 29 | + [rn/view |
| 30 | + {:style style/container} |
| 31 | + [rn/view {:style style/text-input-container} |
| 32 | + [rn/text-input |
| 33 | + {:style |
| 34 | + (text/text-style |
| 35 | + {:size :heading-2 |
| 36 | + :weight :semi-bold |
| 37 | + :style (style/title-text disabled? blur?)}) |
| 38 | + :default-value default-value |
| 39 | + :accessibility-label :profile-title-input |
| 40 | + :on-focus #(swap! focused? (fn [] true)) |
| 41 | + :on-blur #(swap! focused? (fn [] false)) |
| 42 | + :input-mode :text |
| 43 | + :on-change-text on-change |
| 44 | + :editable (not disabled?) |
| 45 | + :max-length max-length |
| 46 | + :placeholder placeholder |
| 47 | + :selection-color (style/get-selection-color customization-color blur?) |
| 48 | + :placeholder-text-color (if @focused? |
| 49 | + (style/get-focused-placeholder-color blur?) |
| 50 | + (style/get-placeholder-color blur?))}]] |
| 51 | + [rn/view |
| 52 | + {:style style/counter-container} |
| 53 | + [text/text |
| 54 | + [text/text |
| 55 | + {:style (style/char-count blur?) |
| 56 | + :size :paragraph-2} |
| 57 | + (pad-0 |
| 58 | + (str |
| 59 | + (count @value)))] |
| 60 | + [text/text |
| 61 | + {:style (style/char-count blur?) |
| 62 | + :size :paragraph-2} |
| 63 | + (str "/" |
| 64 | + (pad-0 |
| 65 | + (str max-length)))]]]]))) |
0 commit comments