-- | Push buttons.
module NanoUI.Widgets.Button
  ( button
  , button'
  , buttonWith
  , buttonWith'
  )
where

import Data.Text (Text)
import Effectful (Eff, type (:>))
import NanoUI.Monad (Ui)
import NanoUI.Style (Layout, defaultLayout)
import NanoUI.Widgets.Combinators (buttonStyledEx)
import NanoUI.Widgets.Node (Response, respClicked)

-- | Button with a text label. 'True' on the frame it is clicked, by pointer
-- or by Enter or Space while focused.
--
-- @
-- whenM (button "Save") saveDocument
-- @
{-# INLINE button #-}
button :: Ui :> es => Text -> Eff es Bool
button :: forall (es :: [Effect]). (Ui :> es) => Text -> Eff es Bool
button Text
txt = Response -> Bool
forall r. HasResponse r => r -> Bool
respClicked (Response -> Bool) -> Eff es Response -> Eff es Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Eff es Response
forall (es :: [Effect]). (Ui :> es) => Text -> Eff es Response
button' Text
txt

-- | 'button' returning its 'Response', for tooltips, anchored popups, or
-- hover state.
--
-- @
-- help <- button' "Help"
-- tooltip help "Open the manual"
-- when (respClicked help) openManual
-- @
{-# INLINE button' #-}
button' :: Ui :> es => Text -> Eff es Response
button' :: forall (es :: [Effect]). (Ui :> es) => Text -> Eff es Response
button' = (Layout -> Layout) -> Text -> Eff es Response
forall (es :: [Effect]).
(Ui :> es) =>
(Layout -> Layout) -> Text -> Eff es Response
buttonWith' Layout -> Layout
forall a. a -> a
id

-- | 'button' with a layout modifier.
--
-- @
-- whenM (buttonWith (fixedW 120) "Submit") submitForm
-- @
{-# INLINE buttonWith #-}
buttonWith :: Ui :> es => (Layout -> Layout) -> Text -> Eff es Bool
buttonWith :: forall (es :: [Effect]).
(Ui :> es) =>
(Layout -> Layout) -> Text -> Eff es Bool
buttonWith Layout -> Layout
f Text
txt = Response -> Bool
forall r. HasResponse r => r -> Bool
respClicked (Response -> Bool) -> Eff es Response -> Eff es Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Layout -> Layout) -> Text -> Eff es Response
forall (es :: [Effect]).
(Ui :> es) =>
(Layout -> Layout) -> Text -> Eff es Response
buttonWith' Layout -> Layout
f Text
txt

{-# INLINE buttonWith' #-}
buttonWith' :: Ui :> es => (Layout -> Layout) -> Text -> Eff es Response
buttonWith' :: forall (es :: [Effect]).
(Ui :> es) =>
(Layout -> Layout) -> Text -> Eff es Response
buttonWith' Layout -> Layout
f Text
txt = Bool -> Text -> Float -> Layout -> Int -> Eff es Response
forall (es :: [Effect]).
(Ui :> es) =>
Bool -> Text -> Float -> Layout -> Int -> Eff es Response
buttonStyledEx Bool
True Text
txt Float
0 (Layout -> Layout
f Layout
defaultLayout) Int
0