-
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.
Merge branch 'develop' into jc/promesa
- Loading branch information
Showing
25 changed files
with
624 additions
and
272 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
54 changes: 54 additions & 0 deletions
54
src/quo/components/drawers/drawer_action/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,54 @@ | ||
(ns quo.components.drawers.drawer-action.component-spec | ||
(:require | ||
[quo.components.drawers.drawer-action.view :as drawer-action] | ||
[quo.foundations.colors :as colors] | ||
[test-helpers.component :as h])) | ||
|
||
(h/describe "Drawers: drawer-action" | ||
(h/test "default render" | ||
(h/render-with-theme-provider [drawer-action/view {}]) | ||
(h/is-truthy (h/query-by-label-text :container))) | ||
|
||
(h/test "on-press-in changes internal state to :pressed" | ||
(h/render-with-theme-provider [drawer-action/view {}]) | ||
(h/fire-event :on-press-in (h/get-by-label-text :container)) | ||
(h/wait-for #(h/has-style (h/query-by-label-text :container) | ||
{:backgroundColor (colors/resolve-color :blue :light 5)}))) | ||
|
||
(h/test "render default action with state :selected" | ||
(h/render-with-theme-provider [drawer-action/view {:state :selected}]) | ||
(h/has-style (h/query-by-label-text :container) | ||
{:backgroundColor (colors/resolve-color :blue :light 5)}) | ||
(h/is-truthy (h/query-by-label-text :check-icon))) | ||
|
||
(h/test "call on-press" | ||
(let [on-press (h/mock-fn)] | ||
(h/render-with-theme-provider [drawer-action/view {:on-press on-press}]) | ||
(h/fire-event :on-press (h/get-by-label-text :container)) | ||
(h/was-called on-press))) | ||
|
||
|
||
(h/test "render :arrow action" | ||
(h/render-with-theme-provider [drawer-action/view {:action :arrow}]) | ||
(h/is-truthy (h/query-by-label-text :arrow-icon))) | ||
|
||
(h/test "render :toggle action" | ||
(h/render-with-theme-provider [drawer-action/view {:action :toggle}]) | ||
(h/is-truthy (h/query-by-label-text "toggle-off"))) | ||
|
||
(h/test "render :toggle action with state :selected" | ||
(h/render-with-theme-provider [drawer-action/view | ||
{:action :toggle | ||
:state :selected}]) | ||
(h/is-truthy (h/query-by-label-text "toggle-on")) | ||
(h/has-style (h/query-by-label-text :container) | ||
{:backgroundColor :transparent})) | ||
|
||
(h/test "render default action with icon, title, description" | ||
(h/render-with-theme-provider [drawer-action/view | ||
{:icon :i/contact | ||
:title "Check contact" | ||
:description "Just a small desc"}]) | ||
(h/is-truthy (h/query-by-label-text :left-icon)) | ||
(h/is-truthy (h/query-by-text "Check contact")) | ||
(h/is-truthy (h/query-by-text "Just a small desc")))) |
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,16 @@ | ||
(ns quo.components.drawers.drawer-action.schema) | ||
|
||
(def ?schema | ||
[:=> | ||
[:cat | ||
[:map {:closed true} | ||
[:action {:optional true} [:maybe [:enum :arrow :toggle]]] | ||
[:icon {:optional true} [:maybe :keyword]] | ||
[:description {:optional true} [:maybe :string]] | ||
[:state {:optional true} [:maybe [:enum :selected]]] | ||
[:title {:optional true} :string] | ||
[:on-press {:optional true} [:maybe fn?]] | ||
[:customization-color {:optional true} | ||
[:maybe :schema.common/customization-color]] | ||
[:blur? {:optional true} [:maybe :boolean]]]] | ||
:any]) |
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,55 @@ | ||
(ns quo.components.drawers.drawer-action.style | ||
(:require | ||
[quo.foundations.colors :as colors])) | ||
|
||
(defn- background-color | ||
[{:keys [state action customization-color theme pressed? blur?]}] | ||
(let [checked? (and (= :selected state) (nil? action))] | ||
(cond | ||
(and (or checked? pressed?) blur?) | ||
colors/white-opa-5 | ||
|
||
(or pressed? checked?) | ||
(colors/resolve-color customization-color theme 5) | ||
|
||
:else :transparent))) | ||
|
||
(defn container | ||
[{:keys [description?] :as props}] | ||
{:flex-direction :row | ||
:align-items :center | ||
:padding-vertical (if description? 8 13) | ||
:padding-horizontal 13 | ||
:border-radius 12 | ||
:background-color (background-color props)}) | ||
|
||
(defn text-container | ||
[] | ||
{:flex 1 | ||
:margin-right 12}) | ||
|
||
(defn- neutral-color | ||
[theme blur?] | ||
(if blur? | ||
colors/white-70-blur | ||
(colors/theme-colors colors/neutral-50 colors/neutral-40 theme))) | ||
|
||
(defn left-icon | ||
[] | ||
{:align-self :flex-start | ||
:margin-right 13 | ||
:margin-top 1}) | ||
|
||
(defn icon-color | ||
[{:keys [theme blur?]}] | ||
(neutral-color theme blur?)) | ||
|
||
(defn desc | ||
[{:keys [theme blur?]}] | ||
{:color (neutral-color theme blur?)}) | ||
|
||
(defn check-color | ||
[{:keys [theme blur? customization-color]}] | ||
(if blur? | ||
colors/white-70-blur | ||
(colors/resolve-color customization-color theme))) |
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,73 @@ | ||
(ns quo.components.drawers.drawer-action.view | ||
(:require | ||
[quo.components.drawers.drawer-action.schema :as component-schema] | ||
[quo.components.drawers.drawer-action.style :as style] | ||
[quo.components.icon :as icon] | ||
[quo.components.markdown.text :as text] | ||
[quo.components.selectors.selectors.view :as selectors] | ||
[quo.theme :as theme] | ||
[react-native.core :as rn] | ||
[schema.core :as schema])) | ||
|
||
(defn view-internal | ||
[{:keys [action icon description state title on-press | ||
customization-color blur?] | ||
:or {customization-color :blue | ||
blur? false}}] | ||
(let [theme (theme/use-theme-value) | ||
[pressed? set-pressed] (rn/use-state false) | ||
on-press-in (rn/use-callback #(set-pressed true)) | ||
on-press-out (rn/use-callback #(set-pressed false))] | ||
[rn/pressable | ||
{:on-press on-press | ||
:on-press-in on-press-in | ||
:on-press-out on-press-out | ||
:style (style/container {:state state | ||
:action action | ||
:customization-color customization-color | ||
:theme theme | ||
:pressed? pressed? | ||
:description? (not-empty description) | ||
:blur? blur?}) | ||
:accessibility-label :container} | ||
(when icon | ||
[icon/icon icon | ||
{:accessibility-label :left-icon | ||
:container-style (style/left-icon) | ||
:color (style/icon-color {:theme theme | ||
:blur? blur?})}]) | ||
|
||
[rn/view {:style (style/text-container)} | ||
[text/text {:weight :medium} | ||
title] | ||
|
||
(when (seq description) | ||
[text/text | ||
{:size :paragraph-2 | ||
:style (style/desc {:theme theme | ||
:blur? blur?})} | ||
description])] | ||
|
||
(cond | ||
(= action :toggle) | ||
[selectors/view | ||
{:theme theme | ||
:label-prefix "toggle" | ||
:customization-color customization-color | ||
:type :toggle | ||
:checked? (= state :selected)}] | ||
|
||
(= action :arrow) | ||
[icon/icon :i/chevron-right | ||
{:accessibility-label :arrow-icon | ||
:color (style/icon-color {:theme theme | ||
:blur? blur?})}] | ||
|
||
(= state :selected) | ||
[icon/icon :i/check | ||
{:accessibility-label :check-icon | ||
:color (style/check-color {:theme theme | ||
:blur? blur? | ||
:customization-color customization-color})}])])) | ||
|
||
(def view (schema/instrument #'view-internal component-schema/?schema)) |
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
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
Oops, something went wrong.