-
Notifications
You must be signed in to change notification settings - Fork 987
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement dropdown-input based on the original dropdown component
- Loading branch information
1 parent
ec4046e
commit 55819f3
Showing
7 changed files
with
260 additions
and
1 deletion.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/quo/components/dropdowns/dropdown_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,29 @@ | ||
(ns quo.components.dropdowns.dropdown-input.component-spec | ||
(:require | ||
[quo.components.dropdowns.dropdown-input.view :as dropdown-input] | ||
[test-helpers.component :as h])) | ||
|
||
(h/describe "Dropdown Input" | ||
|
||
(h/test "default render" | ||
(let [header-label "Label" | ||
label "Dropdown"] | ||
(h/render [dropdown-input/view {:label label :header-label header-label}]) | ||
(h/is-truthy (h/get-by-label-text :dropdown)) | ||
(h/is-truthy (h/get-by-text header-label)) | ||
(h/is-truthy (h/get-by-text label)))) | ||
|
||
(h/test "render with icon" | ||
(let [label "Dropdown"] | ||
(h/render [dropdown-input/view {:icon? true :icon-name :i/wallet :label label}]) | ||
(h/is-truthy (h/get-by-label-text :dropdown)) | ||
(h/is-truthy (h/get-by-label-text :left-icon)) | ||
(h/is-truthy (h/get-by-text label)))) | ||
|
||
|
||
(h/test "on-press" | ||
(let [event (h/mock-fn) | ||
label "Dropdown"] | ||
(h/render [dropdown-input/view {:on-press event :label label}]) | ||
(h/fire-event :press (h/get-by-text label)) | ||
(h/was-called event)))) |
47 changes: 47 additions & 0 deletions
47
src/quo/components/dropdowns/dropdown_input/properties.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,47 @@ | ||
(ns quo.components.dropdowns.dropdown-input.properties | ||
(:require | ||
[quo.foundations.colors :as colors])) | ||
|
||
(defn- grey-blur | ||
[theme active?] | ||
{:left-icon-color (colors/theme-colors colors/neutral-80-opa-40 colors/white-opa-70 theme) | ||
:right-icon-color (colors/theme-colors colors/neutral-80-opa-10 colors/white-opa-10 theme) | ||
:right-icon-color-2 (colors/theme-colors colors/neutral-100 colors/white theme) | ||
:label-color (colors/theme-colors colors/neutral-100 colors/white theme) | ||
:border-color (if active? | ||
(colors/theme-colors colors/neutral-80-opa-20 | ||
colors/white-opa-40 | ||
theme) | ||
(colors/theme-colors colors/neutral-80-opa-10 | ||
colors/white-opa-10 | ||
theme))}) | ||
|
||
(defn- outline | ||
[theme active?] | ||
{:left-icon-color (colors/theme-colors colors/neutral-50 colors/neutral-40 theme) | ||
:right-icon-color (colors/theme-colors colors/neutral-20 colors/neutral-80 theme) | ||
:right-icon-color-2 (colors/theme-colors colors/neutral-100 colors/white theme) | ||
:label-color (colors/theme-colors colors/neutral-100 colors/white theme) | ||
:border-color (if active? | ||
(colors/theme-colors colors/neutral-40 colors/neutral-60 theme) | ||
(colors/theme-colors colors/neutral-30 colors/neutral-70 theme))}) | ||
|
||
(defn- grey | ||
[theme active?] | ||
{:left-icon-color (colors/theme-colors colors/neutral-50 colors/neutral-40 theme) | ||
:right-icon-color (colors/theme-colors colors/neutral-20 colors/neutral-80 theme) | ||
:right-icon-color-2 (colors/theme-colors colors/neutral-100 colors/white theme) | ||
:label-color (colors/theme-colors colors/neutral-100 colors/white theme) | ||
:border-color (if active? | ||
(colors/theme-colors colors/neutral-40 colors/neutral-60 theme) | ||
(colors/theme-colors colors/neutral-20 | ||
colors/neutral-60 | ||
theme))}) | ||
|
||
(defn get-colors | ||
[{:keys [theme state blur?]}] | ||
(let [active? (= state :active)] | ||
(cond | ||
blur? (grey-blur theme active?) | ||
(= theme :dark) (outline theme active?) | ||
(= theme :light) (grey theme active?)))) |
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,63 @@ | ||
(ns quo.components.dropdowns.dropdown-input.style | ||
(:require | ||
[quo.foundations.colors :as colors])) | ||
|
||
(def gap 8) | ||
(def dropdown-width 288) | ||
|
||
(def blur-view | ||
{:position :absolute | ||
:top 0 | ||
:left 0 | ||
:right 0 | ||
:bottom 0}) | ||
|
||
(def left-icon | ||
{:margin-right gap}) | ||
|
||
(defn right-icon | ||
[theme] | ||
{:color (colors/theme-colors colors/neutral-100 colors/white theme) | ||
:margin-right gap}) | ||
|
||
(defn header-label | ||
[theme blur?] | ||
{:color (if blur? | ||
(colors/theme-colors colors/neutral-50 | ||
colors/neutral-40 | ||
theme) | ||
(colors/theme-colors colors/neutral-80-opa-40 | ||
colors/white-opa-70 | ||
theme)) | ||
:margin-bottom gap}) | ||
|
||
(def root-container | ||
{:width dropdown-width}) | ||
(defn container | ||
[{:keys [background-color border-color]} | ||
{:keys [icon? state]}] | ||
(cond-> {:height 40 | ||
:width dropdown-width | ||
:align-items :center | ||
:justify-content :space-between | ||
:flex-direction :row | ||
:padding-vertical 9 | ||
:padding-left 16 | ||
:padding-right 12 | ||
:overflow :hidden | ||
:background-color background-color | ||
:border-radius 12} | ||
|
||
icon? | ||
(assoc :padding-left 12) | ||
|
||
border-color | ||
(assoc :border-color border-color | ||
:border-width 1) | ||
|
||
(= state :disabled) | ||
(assoc :opacity 0.3))) | ||
|
||
(def right-half-container | ||
{:flex-direction :row | ||
:align-items :center}) |
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,68 @@ | ||
(ns quo.components.dropdowns.dropdown-input.view | ||
(:require | ||
[quo.components.dropdowns.dropdown-input.properties :as properties] | ||
[quo.components.dropdowns.dropdown-input.style :as style] | ||
[quo.components.icon :as icon] | ||
[quo.components.markdown.text :as text] | ||
[quo.theme :as theme] | ||
[react-native.core :as rn])) | ||
|
||
(defn- view-internal | ||
[{:keys [state theme on-press icon? | ||
label? blur? | ||
accessibility-label] | ||
:or {state :default | ||
icon? true | ||
label? true | ||
blur? false} | ||
:as props} | ||
label header-label] | ||
(let [icon-size 20 | ||
{:keys [left-icon-color right-icon-color right-icon-color-2] | ||
:as colors} (properties/get-colors props) | ||
right-icon (if (= state :active) :i/pullup :i/dropdown)] | ||
[rn/view | ||
{:style style/root-container} | ||
(when label? | ||
[text/text | ||
{:size :paragraph-2 | ||
:weight :medium | ||
:align :left | ||
:style (style/header-label theme blur?)} header-label]) | ||
[rn/pressable | ||
{:accessibility-label (or accessibility-label :dropdown) | ||
:disabled (= state :disabled) | ||
:on-press on-press | ||
:style (style/container colors props)} | ||
[rn/view | ||
{:style style/right-half-container} | ||
(when icon? | ||
[icon/icon | ||
:i/placeholder | ||
{:accessibility-label :left-icon | ||
:color left-icon-color | ||
:size icon-size | ||
:container-style style/left-icon}]) | ||
[text/text | ||
{:size :paragraph-1 | ||
:weight :regular | ||
:number-of-lines 1 | ||
:style (style/right-icon theme)} | ||
label]] | ||
[icon/icon | ||
right-icon | ||
{:size icon-size | ||
:accessibility-label :right-icon | ||
:color right-icon-color | ||
:color-2 right-icon-color-2}]]])) | ||
|
||
(def view | ||
"Props: | ||
- state: :default (default) | :active | :disabled | ||
- label: string | ||
- header-label: string | ||
- icon?: boolean | ||
- label?: boolean | ||
- blur?: boolean | ||
- on-press: function" | ||
(theme/with-theme view-internal)) |
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
46 changes: 46 additions & 0 deletions
46
src/status_im2/contexts/quo_preview/dropdowns/dropdown_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,46 @@ | ||
(ns status-im2.contexts.quo-preview.dropdowns.dropdown-input | ||
(:require | ||
[quo.core :as quo] | ||
[reagent.core :as reagent] | ||
[status-im2.contexts.quo-preview.preview :as preview])) | ||
|
||
(def descriptor | ||
[{:key :state | ||
:type :select | ||
:options [{:key :default} | ||
{:key :active} | ||
{:key :disabled}]} | ||
{:key :icon? | ||
:type :boolean} | ||
{:key :label? | ||
:type :boolean} | ||
{:key :blur? | ||
:type :boolean} | ||
{:key :header-label | ||
:type :text} | ||
{:key :label | ||
:type :text}]) | ||
|
||
(defn view | ||
[] | ||
(let [state (reagent/atom {:state :default | ||
:label "Dropdown" | ||
:header-label "Label" | ||
:icon? true | ||
:label? true | ||
:blur? false}) | ||
label (reagent/cursor state [:label]) | ||
header-label (reagent/cursor state [:header-label]) | ||
blur? (reagent/cursor state [:blur?])] | ||
[:f> | ||
(fn [] | ||
[preview/preview-container | ||
{:state state | ||
:descriptor descriptor | ||
:component-container-style (when-not @blur? {:align-items :center}) | ||
:blur-container-style {:align-items :center} | ||
:blur? @blur? | ||
:show-blur-background? true} | ||
[quo/dropdown-input | ||
(assoc @state :on-press #(js/alert "Pressed dropdown")) | ||
@label @header-label]])])) |
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