-----------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE MultilineStrings  #-}
{-# LANGUAGE RecordWildCards   #-}
-----------------------------------------------------------------------------
module Miso.UI.Alert
  ( -- ** Props
    AlertProps (..)
  , defaultAlertProps
    -- ** Views
  , alert_
  , alertHeader_
  , alertSection_
    -- ** Sample
  , alertSample
  , alertCodeSample
  , alertPropsApi
  ) where
-----------------------------------------------------------------------------
import           Miso hiding (alert)
import qualified Miso.Html.Element as H
import qualified Miso.Html.Property as P
-----------------------------------------------------------------------------
import           Miso.UI.Icons
import           Miso.UI.Types
-----------------------------------------------------------------------------
-- | Props for 'alert_'
data AlertProps action
  = AlertProps
  { forall action. AlertProps action -> Variant
alertVariant :: Variant
    -- ^ 'Primary' (default) or 'Destructive'
  , forall action. AlertProps action -> [MisoString]
alertClasses :: [MisoString]
    -- ^ Extra classes appended to the alert
  , forall action. AlertProps action -> [Attribute action]
alertAttrs :: [Attribute action]
  }
-----------------------------------------------------------------------------
-- | Smart constructor: default (success-styled) alert
defaultAlertProps :: AlertProps action
defaultAlertProps :: forall action. AlertProps action
defaultAlertProps
  = AlertProps
  { alertVariant :: Variant
alertVariant = Variant
Primary
  , alertClasses :: [MisoString]
alertClasses = []
  , alertAttrs :: [Attribute action]
alertAttrs = []
  }
-----------------------------------------------------------------------------
-- | <https://basecoatui.com/components/alert/ Alert>, driven by 'AlertProps'.
-- Children are typically an icon, an 'alertHeader_' and an 'alertSection_'.
alert_
  :: AlertProps action
  -> [View model action]
  -> View model action
alert_ :: forall action model.
AlertProps action -> [View model action] -> View model action
alert_ AlertProps {[MisoString]
[Attribute action]
Variant
alertVariant :: forall action. AlertProps action -> Variant
alertClasses :: forall action. AlertProps action -> [MisoString]
alertAttrs :: forall action. AlertProps action -> [Attribute action]
alertVariant :: Variant
alertClasses :: [MisoString]
alertAttrs :: [Attribute action]
..} [View model action]
kids =
  [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.classes_
      ( ( case Variant
alertVariant of
            Variant
Destructive -> MisoString
"alert-destructive"
            Variant
_ -> MisoString
"alert"
        ) MisoString -> [MisoString] -> [MisoString]
forall a. a -> [a] -> [a]
: [MisoString]
alertClasses
      )
    Attribute action -> [Attribute action] -> [Attribute action]
forall a. a -> [a] -> [a]
: [Attribute action]
alertAttrs
    ) [View model action]
kids
-----------------------------------------------------------------------------
alertHeader_
  :: [Attribute action]
  -> [View model action]
  -> View model action
alertHeader_ :: forall action model.
[Attribute action] -> [View model action] -> View model action
alertHeader_ [Attribute action]
attrs [View model action]
kids = [Attribute action] -> [View model action] -> View model action
forall action model.
[Attribute action] -> [View model action] -> View model action
H.h2_ [Attribute action]
attrs [View model action]
kids
-----------------------------------------------------------------------------
alertSection_
  :: [Attribute action]
  -> [View model action]
  -> View model action
alertSection_ :: forall action model.
[Attribute action] -> [View model action] -> View model action
alertSection_ [Attribute action]
attrs [View model action]
kids = [Attribute action] -> [View model action] -> View model action
forall action model.
[Attribute action] -> [View model action] -> View model action
H.section_ [Attribute action]
attrs [View model action]
kids
-----------------------------------------------------------------------------
alertSample :: View model action
alertSample :: forall model action. View model action
alertSample =
  [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
"p-4" ]
  [ [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
"grid max-w-xl items-start gap-4" ]
    [ AlertProps action -> [View model action] -> View model action
forall action model.
AlertProps action -> [View model action] -> View model action
alert_ AlertProps action
forall action. AlertProps action
defaultAlertProps
      [ [Attribute action] -> View model action
forall action model. [Attribute action] -> View model action
circleCheckIcon []
      , [Attribute action] -> [View model action] -> View model action
forall action model.
[Attribute action] -> [View model action] -> View model action
alertHeader_ [] [ View model action
"Success!" ]
      , [Attribute action] -> [View model action] -> View model action
forall action model.
[Attribute action] -> [View model action] -> View model action
alertSection_ []
        [ View model action
"""
          Congratulations this is a
          successful alert !
          """
        ]
      ]
    , AlertProps action -> [View model action] -> View model action
forall action model.
AlertProps action -> [View model action] -> View model action
alert_ AlertProps action
forall action. AlertProps action
defaultAlertProps { alertVariant = Destructive }
      [ [Attribute action] -> View model action
forall action model. [Attribute action] -> View model action
circleAlertIcon []
      , [Attribute action] -> [View model action] -> View model action
forall action model.
[Attribute action] -> [View model action] -> View model action
alertHeader_ [] [ View model action
"Warning!" ]
      , [Attribute action] -> [View model action] -> View model action
forall action model.
[Attribute action] -> [View model action] -> View model action
alertSection_ []
        [ View model action
"""
          Something bad happened :( you're getting
          a destructive alert!
          """
        ]
      ]
    ]
  ]
-----------------------------------------------------------------------------
alertCodeSample :: View model action
alertCodeSample :: forall model action. View model action
alertCodeSample =
  View model action
"""
  -----------------------------------------------------------------------------
  module MyAlert (alertSample) where
  -----------------------------------------------------------------------------
  import           Miso hiding (alert)
  import qualified Miso.Html.Element as H
  import qualified Miso.Html.Property as P
  import           Miso.UI.Icons
  import           Miso.UI.Types
  import           Miso.UI.Alert
  -----------------------------------------------------------------------------
  alertSample :: View model action
  alertSample =
    H.div_
    [ P.class_ "p-4" ]
    [ H.div_ [ P.class_ "grid max-w-xl items-start gap-4" ]
      [ alert_ defaultAlertProps
        [ circleCheckIcon []
        , alertHeader_ [] [ "Success!" ]
        , alertSection_ []
          [ \"\"\"
            Congratulations this is a
            successful alert !
            \"\"\"
          ]
        ]
      , alert_ defaultAlertProps { alertVariant = Destructive }
        [ circleAlertIcon []
        , alertHeader_ [] [ "Warning!" ]
        , alertSection_ []
          [ \"\"\"
            Something bad happened :( you're getting
            a destructive alert!
            \"\"\"
          ]
        ]
      ]
    ]
  """
-----------------------------------------------------------------------------
alertPropsApi :: View model action
alertPropsApi :: forall model action. View model action
alertPropsApi =
  View model action
"""
  -- | Props for 'alert_'
  data AlertProps action
    = AlertProps
    { alertVariant :: Variant
      -- ^ 'Primary' (default) or 'Destructive'
    , alertClasses :: [MisoString]
      -- ^ Extra classes appended to the alert
    , alertAttrs :: [Attribute action]
    }
  -----------------------------------------------------------------------------
  -- | Smart constructor: default (success-styled) alert
  defaultAlertProps :: AlertProps action
  defaultAlertProps
    = AlertProps
    { alertVariant = Primary
    , alertClasses = []
    , alertAttrs = []
    }
  """
-----------------------------------------------------------------------------