{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE MultilineStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Miso.UI.Toast
(
ToastProps (..)
, defaultToastProps
, toastTrigger_
, toaster_
, toastSample
, toastCodeSample
, toastPropsApi
) where
import Miso
import qualified Miso.Html.Event as E
import qualified Miso.Html.Element as H
import qualified Miso.Html.Property as P
import Miso.UI.Button
import Miso.UI.Types
data ToastProps
= ToastProps
{ ToastProps -> MisoString
toastCategory :: MisoString
, ToastProps -> MisoString
toastTitle :: MisoString
, ToastProps -> MisoString
toastDescription :: MisoString
, ToastProps -> MisoString
toastLabel :: MisoString
} deriving (Int -> ToastProps -> ShowS
[ToastProps] -> ShowS
ToastProps -> String
(Int -> ToastProps -> ShowS)
-> (ToastProps -> String)
-> ([ToastProps] -> ShowS)
-> Show ToastProps
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ToastProps -> ShowS
showsPrec :: Int -> ToastProps -> ShowS
$cshow :: ToastProps -> String
show :: ToastProps -> String
$cshowList :: [ToastProps] -> ShowS
showList :: [ToastProps] -> ShowS
Show, ToastProps -> ToastProps -> Bool
(ToastProps -> ToastProps -> Bool)
-> (ToastProps -> ToastProps -> Bool) -> Eq ToastProps
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ToastProps -> ToastProps -> Bool
== :: ToastProps -> ToastProps -> Bool
$c/= :: ToastProps -> ToastProps -> Bool
/= :: ToastProps -> ToastProps -> Bool
Eq)
defaultToastProps :: ToastProps
defaultToastProps :: ToastProps
defaultToastProps
= ToastProps
{ toastCategory :: MisoString
toastCategory = MisoString
"info"
, toastTitle :: MisoString
toastTitle = MisoString
""
, toastDescription :: MisoString
toastDescription = MisoString
""
, toastLabel :: MisoString
toastLabel = MisoString
"Dismiss"
}
toastTrigger_
:: (ToastProps -> action)
-> ToastProps
-> [View model action]
-> View model action
toastTrigger_ :: forall action model.
(ToastProps -> action)
-> ToastProps -> [View model action] -> View model action
toastTrigger_ ToastProps -> action
toAction ToastProps
cfg [View model action]
kids =
ButtonProps action -> [View model action] -> View model action
forall action model.
ButtonProps action -> [View model action] -> View model action
button_ ButtonProps (ZonkAny 0)
forall action. ButtonProps action
defaultButtonProps
{ buttonVariant = Outline
, buttonAttrs = [ E.onClick (toAction cfg) ]
} [View model action]
kids
toaster_ :: [Attribute action] -> View model action
toaster_ :: forall action model. [Attribute action] -> View model action
toaster_ [Attribute action]
attrs = [Attribute action] -> [View model action] -> View model action
forall action model.
[Attribute action] -> [View model action] -> View model action
H.div_ (MisoString -> Attribute action
forall action. MisoString -> Attribute action
P.id_ MisoString
"toaster" Attribute action -> [Attribute action] -> [Attribute action]
forall a. a -> [a] -> [a]
: MisoString -> Attribute action
forall action. MisoString -> Attribute action
P.class_ MisoString
"toaster" Attribute action -> [Attribute action] -> [Attribute action]
forall a. a -> [a] -> [a]
: [Attribute action]
attrs) []
toastSample :: (ToastProps -> action) -> View model action
toastSample :: forall action model. (ToastProps -> action) -> View model action
toastSample ToastProps -> action
toAction =
[Attribute action] -> [View model action] -> View model action
forall action model.
[Attribute action] -> [View model action] -> View model action
H.div_
[ MisoString -> Attribute action
forall action. MisoString -> Attribute action
P.class_ MisoString
"flex flex-wrap items-center gap-2" ]
[ (ToastProps -> action)
-> ToastProps -> [View model action] -> View model action
forall action model.
(ToastProps -> action)
-> ToastProps -> [View model action] -> View model action
toastTrigger_ ToastProps -> action
toAction
ToastProps
defaultToastProps
{ toastCategory = "success"
, toastTitle = "Success"
, toastDescription = "A successful toast !"
}
[ View model action
"Success" ]
, (ToastProps -> action)
-> ToastProps -> [View model action] -> View model action
forall action model.
(ToastProps -> action)
-> ToastProps -> [View model action] -> View model action
toastTrigger_ ToastProps -> action
toAction
ToastProps
defaultToastProps
{ toastCategory = "error"
, toastTitle = "Error"
, toastDescription = "An error toast :("
}
[ View model action
"Error" ]
, (ToastProps -> action)
-> ToastProps -> [View model action] -> View model action
forall action model.
(ToastProps -> action)
-> ToastProps -> [View model action] -> View model action
toastTrigger_ ToastProps -> action
toAction
ToastProps
defaultToastProps
{ toastCategory = "info"
, toastTitle = "Info"
, toastDescription = "An informational toast =]"
}
[ View model action
"Info" ]
, (ToastProps -> action)
-> ToastProps -> [View model action] -> View model action
forall action model.
(ToastProps -> action)
-> ToastProps -> [View model action] -> View model action
toastTrigger_ ToastProps -> action
toAction
ToastProps
defaultToastProps
{ toastCategory = "warning"
, toastTitle = "Warning"
, toastDescription = "A warning toast :/"
}
[ View model action
"Warning" ]
]
toastCodeSample :: View model action
toastCodeSample :: forall model action. View model action
toastCodeSample =
View model action
"""
-----------------------------------------------------------------------------
module MyToast (toastSample) where
-----------------------------------------------------------------------------
import Miso
import qualified Miso.Html.Event as E
import qualified Miso.Html.Element as H
import qualified Miso.Html.Property as P
import Miso.UI.Button
import Miso.UI.Types
import Miso.UI.Toast
-----------------------------------------------------------------------------
toastSample :: (ToastProps -> action) -> View model action
toastSample toAction =
H.div_
[ P.class_ "flex flex-wrap items-center gap-2" ]
[ toastTrigger_ toAction
defaultToastProps
{ toastCategory = "success"
, toastTitle = "Success"
, toastDescription = "A successful toast !"
}
[ "Success" ]
, toastTrigger_ toAction
defaultToastProps
{ toastCategory = "error"
, toastTitle = "Error"
, toastDescription = "An error toast :("
}
[ "Error" ]
, toastTrigger_ toAction
defaultToastProps
{ toastCategory = "info"
, toastTitle = "Info"
, toastDescription = "An informational toast =]"
}
[ "Info" ]
, toastTrigger_ toAction
defaultToastProps
{ toastCategory = "warning"
, toastTitle = "Warning"
, toastDescription = "A warning toast :/"
}
[ "Warning" ]
]
"""
toastPropsApi :: View model action
toastPropsApi :: forall model action. View model action
toastPropsApi =
View model action
"""
-- | Props describing a basecoat toast. Dispatched to basecoat's toaster JS
-- (a @basecoat:toast@ custom event) by the application's update function.
data ToastProps
= ToastProps
{ toastCategory :: MisoString
-- ^ @success@, @error@, @info@ or @warning@
, toastTitle :: MisoString
, toastDescription :: MisoString
, toastLabel :: MisoString
-- ^ Label of the dismiss button
} deriving (Show, Eq)
-----------------------------------------------------------------------------
-- | Smart constructor: informational toast
defaultToastProps :: ToastProps
defaultToastProps
= ToastProps
{ toastCategory = "info"
, toastTitle = ""
, toastDescription = ""
, toastLabel = "Dismiss"
}
"""