-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#17393] feat: add logout button component
- Loading branch information
1 parent
5a6cd43
commit 2cb519e
Showing
7 changed files
with
88 additions
and
7 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/quo/components/buttons/logout_button/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,35 @@ | ||
(ns quo.components.buttons.logout-button.component-spec | ||
(:require | ||
[quo.components.buttons.logout-button.view :as logout-button] | ||
[test-helpers.component :as h])) | ||
|
||
(h/describe "button tests" | ||
(h/test "default render of logout button component" | ||
(h/render [logout-button/view | ||
{:accessibility-label "test-button"}]) | ||
(h/is-truthy (h/get-by-label-text "test-button"))) | ||
|
||
(h/test "button on-press works" | ||
(let [event (h/mock-fn)] | ||
(h/render [logout-button/view | ||
{:on-press event | ||
:accessibility-label "test-button"}]) | ||
(h/fire-event :press (h/get-by-label-text "test-button")) | ||
(h/was-called event))) | ||
|
||
(h/test "button on-press disabled when disabled" | ||
(let [event (h/mock-fn)] | ||
(h/render [logout-button/view | ||
{:on-press event | ||
:accessibility-label "test-button" | ||
:disabled? true}]) | ||
(h/fire-event :press (h/get-by-label-text "test-button")) | ||
(h/was-not-called event))) | ||
|
||
(h/test "button on-long-press works" | ||
(let [event (h/mock-fn)] | ||
(h/render [logout-button/view | ||
{:on-long-press event | ||
:accessibility-label "test-button"}]) | ||
(h/fire-event :long-press (h/get-by-label-text "test-button")) | ||
(h/was-called event)))) |
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,15 @@ | ||
(ns quo.components.buttons.logout-button.style | ||
(:require | ||
[quo.foundations.colors :as colors])) | ||
|
||
(defn main | ||
[{:keys [pressed? disabled?]}] | ||
{:background-color (if pressed? colors/danger-50-opa-40 colors/danger-50-opa-30) | ||
:border-radius 12 | ||
:height 40 | ||
:gap 4 | ||
:padding-right 3 | ||
:flex-direction :row | ||
:justify-content :center | ||
:align-items :center | ||
:opacity (when disabled? 0.2)}) |
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,32 @@ | ||
(ns quo.components.buttons.logout-button.view | ||
(:require | ||
[quo.components.buttons.logout-button.style :as style] | ||
[quo.components.icon :as icon] | ||
[quo.components.markdown.text :as text] | ||
[quo.foundations.colors :as colors] | ||
[quo.theme :as theme] | ||
[react-native.core :as rn] | ||
[reagent.core :as reagent] | ||
[utils.i18n :as i18n])) | ||
|
||
(defn- view-internal | ||
[_ _] | ||
(let [pressed? (reagent/atom false)] | ||
(fn | ||
[{:keys [on-press on-long-press disabled? theme accessibility-label container-style]}] | ||
[rn/pressable | ||
{:accessibility-label (or accessibility-label :composer-button) | ||
:on-press on-press | ||
:on-press-in #(reset! pressed? true) | ||
:on-press-out #(reset! pressed? nil) | ||
:on-long-press on-long-press | ||
:disabled disabled? | ||
:style (merge (style/main {:pressed? @pressed? | ||
:theme theme | ||
:disabled? disabled?}) | ||
container-style)} | ||
[icon/icon :i/log-out {:color (if pressed? colors/white-opa-40 colors/white-opa-70)}] | ||
[text/text {:weight :medium :size :paragraph-1} | ||
(i18n/label :t/logout)]]))) | ||
|
||
(def view (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
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