Created
December 20, 2012 21:42
-
-
Save ConnerPetzold/4348814 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(def initial-state | |
{:mode :search | |
:input "" | |
:completes []}) | |
(def state (atom initial-state)) | |
(def mode-map | |
{:search | |
{:placeholder "Search..." | |
:input-watch :search-watch | |
:shadow-value suggest-result | |
:key-handle search} | |
:tweet | |
{:placeholder "Tweet..." | |
:input-watch :tweet-watch | |
:shadow-value remaining-characters}}) | |
(defn render [state] | |
(let [{:keys [input completes mode]} state | |
params (mode-map mode)] | |
[:div#container | |
[:button#toggle-mode (str "Switch to " (name (other-mode mode)) " mode")] | |
[:div#input-wrapper | |
[:textarea#input {:watch (:input-watch params) | |
:value input | |
:autofocus true | |
:placeholder (:placeholder params)}] | |
[:textarea#shadow {:value ((:shadow-value params) state) | |
:disabled true}]] | |
[:div#results | |
{:class (when (or (= mode :tweet) (empty? completes)) "hide")} | |
(map #(auto-result input %) completes)]])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment