-----------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE MultilineStrings  #-}
{-# LANGUAGE RecordWildCards   #-}
-----------------------------------------------------------------------------
module Miso.UI.Textarea
  ( -- ** Props
    TextareaProps (..)
  , defaultTextareaProps
    -- ** Views
  , textarea_
    -- ** Samples
  , textareaUsage
  , textareaSample
  , textareaCodeSample
  , textareaPropsApi
  ) where
-----------------------------------------------------------------------------
import           Miso
import qualified Miso.Html.Element as H
import qualified Miso.Html.Property as P
-----------------------------------------------------------------------------
import           Miso.UI.Label
-----------------------------------------------------------------------------
-- | Props for 'textarea_'
data TextareaProps action
  = TextareaProps
  { forall action. TextareaProps action -> Maybe MisoString
textareaId :: Maybe MisoString
  , forall action. TextareaProps action -> Maybe MisoString
textareaPlaceholder :: Maybe MisoString
  , forall action. TextareaProps action -> Maybe MisoString
textareaRows :: Maybe MisoString
  , forall action. TextareaProps action -> Bool
textareaDisabled :: Bool
  , forall action. TextareaProps action -> Bool
textareaInvalid :: Bool
    -- ^ Renders with @aria-invalid@ (error styling)
  , forall action. TextareaProps action -> [MisoString]
textareaClasses :: [MisoString]
    -- ^ Extra classes appended to @textarea@
  , forall action. TextareaProps action -> [Attribute action]
textareaAttrs :: [Attribute action]
  }
-----------------------------------------------------------------------------
-- | Smart constructor: enabled, no placeholder
defaultTextareaProps :: TextareaProps action
defaultTextareaProps :: forall action. TextareaProps action
defaultTextareaProps
  = TextareaProps
  { textareaId :: Maybe MisoString
textareaId = Maybe MisoString
forall a. Maybe a
Nothing
  , textareaPlaceholder :: Maybe MisoString
textareaPlaceholder = Maybe MisoString
forall a. Maybe a
Nothing
  , textareaRows :: Maybe MisoString
textareaRows = Maybe MisoString
forall a. Maybe a
Nothing
  , textareaDisabled :: Bool
textareaDisabled = Bool
False
  , textareaInvalid :: Bool
textareaInvalid = Bool
False
  , textareaClasses :: [MisoString]
textareaClasses = []
  , textareaAttrs :: [Attribute action]
textareaAttrs = []
  }
-----------------------------------------------------------------------------
-- | <https://basecoatui.com/components/textarea/ Textarea>, driven by 'TextareaProps'
textarea_ :: TextareaProps action -> View model action
textarea_ :: forall action model. TextareaProps action -> View model action
textarea_ TextareaProps {Bool
[MisoString]
[Attribute action]
Maybe MisoString
textareaId :: forall action. TextareaProps action -> Maybe MisoString
textareaPlaceholder :: forall action. TextareaProps action -> Maybe MisoString
textareaRows :: forall action. TextareaProps action -> Maybe MisoString
textareaDisabled :: forall action. TextareaProps action -> Bool
textareaInvalid :: forall action. TextareaProps action -> Bool
textareaClasses :: forall action. TextareaProps action -> [MisoString]
textareaAttrs :: forall action. TextareaProps action -> [Attribute action]
textareaId :: Maybe MisoString
textareaPlaceholder :: Maybe MisoString
textareaRows :: Maybe MisoString
textareaDisabled :: Bool
textareaInvalid :: Bool
textareaClasses :: [MisoString]
textareaAttrs :: [Attribute action]
..} = [Attribute action] -> View model action
forall action model. [Attribute action] -> View model action
H.textarea_ ([Attribute action] -> View model action)
-> [Attribute action] -> View model action
forall a b. (a -> b) -> a -> b
$ [[Attribute action]] -> [Attribute action]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
  [ [ [MisoString] -> Attribute action
forall action. [MisoString] -> Attribute action
P.classes_ (MisoString
"textarea" MisoString -> [MisoString] -> [MisoString]
forall a. a -> [a] -> [a]
: [MisoString]
textareaClasses) ]
  , [ MisoString -> Attribute action
forall action. MisoString -> Attribute action
P.id_ MisoString
i | Just MisoString
i <- [Maybe MisoString
textareaId] ]
  , [ MisoString -> Attribute action
forall action. MisoString -> Attribute action
P.placeholder_ MisoString
p | Just MisoString
p <- [Maybe MisoString
textareaPlaceholder] ]
  , [ MisoString -> Attribute action
forall action. MisoString -> Attribute action
P.rows_ MisoString
r | Just MisoString
r <- [Maybe MisoString
textareaRows] ]
  , [ Attribute action
forall action. Attribute action
P.disabled_ | Bool
textareaDisabled ]
  , [ MisoString -> MisoString -> Attribute action
forall action. MisoString -> MisoString -> Attribute action
P.aria_ MisoString
"invalid" MisoString
"true" | Bool
textareaInvalid ]
  , [Attribute action]
textareaAttrs
  ]
-----------------------------------------------------------------------------
-- | Compact usage example (source of the kitchen sink "Code" tab)
textareaUsage :: View model action
textareaUsage :: forall model action. View model action
textareaUsage =
  [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-col gap-y-6" ]
  [ TextareaProps action -> View model action
forall action model. TextareaProps action -> View model action
textarea_ TextareaProps action
forall action. TextareaProps action
defaultTextareaProps { textareaPlaceholder = Just "Type your message here" }
  , TextareaProps action -> View model action
forall action model. TextareaProps action -> View model action
textarea_ TextareaProps action
forall action. TextareaProps action
defaultTextareaProps
    { textareaPlaceholder = Just "Type your message here"
    , textareaInvalid = True
    }
  , [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 gap-3" ]
    [ LabelProps action -> [View model action] -> View model action
forall action model.
LabelProps action -> [View model action] -> View model action
label_ LabelProps action
forall action. LabelProps action
defaultLabelProps { labelFor = Just "my-textarea" } [ View model action
"Label" ]
    , TextareaProps action -> View model action
forall action model. TextareaProps action -> View model action
textarea_ TextareaProps action
forall action. TextareaProps action
defaultTextareaProps
      { textareaPlaceholder = Just "Type your message here"
      , textareaId = Just "my-textarea"
      }
    ]
  ]
-----------------------------------------------------------------------------
textareaSample :: View model action
textareaSample :: forall model action. View model action
textareaSample =
  [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-col gap-y-10" ]
  [ TextareaProps action -> View model action
forall action model. TextareaProps action -> View model action
textarea_ TextareaProps action
forall action. TextareaProps action
defaultTextareaProps { textareaPlaceholder = Just "Type your message here" }
  , TextareaProps action -> View model action
forall action model. TextareaProps action -> View model action
textarea_ TextareaProps action
forall action. TextareaProps action
defaultTextareaProps
    { textareaPlaceholder = Just "Type your message here"
    , textareaInvalid = True
    }
  , [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 gap-3" ]
    [ LabelProps action -> [View model action] -> View model action
forall action model.
LabelProps action -> [View model action] -> View model action
label_ LabelProps action
forall action. LabelProps action
defaultLabelProps { labelFor = Just "textarea-demo-label" } [ View model action
"Label" ]
    , TextareaProps action -> View model action
forall action model. TextareaProps action -> View model action
textarea_ TextareaProps action
forall action. TextareaProps action
defaultTextareaProps
      { textareaPlaceholder = Just "Type your message here"
      , textareaId = Just "textarea-demo-label"
      }
    ]
  , [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 gap-3" ]
    [ LabelProps action -> [View model action] -> View model action
forall action model.
LabelProps action -> [View model action] -> View model action
label_ LabelProps action
forall action. LabelProps action
defaultLabelProps { labelFor = Just "textarea-demo-label-and-description" }
      [ View model action
"With label and description" ]
    , TextareaProps action -> View model action
forall action model. TextareaProps action -> View model action
textarea_ TextareaProps action
forall action. TextareaProps action
defaultTextareaProps
      { textareaPlaceholder = Just "Type your message here"
      , textareaId = Just "textarea-demo-label-and-description"
      }
    , [Attribute action] -> [View model action] -> View model action
forall action model.
[Attribute action] -> [View model action] -> View model action
H.p_
      [ MisoString -> Attribute action
forall action. MisoString -> Attribute action
P.class_ MisoString
"text-muted-foreground text-sm" ]
      [ View model action
"Type your message and press enter to send." ]
    ]
  , [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 gap-3" ]
    [ LabelProps action -> [View model action] -> View model action
forall action model.
LabelProps action -> [View model action] -> View model action
label_ LabelProps action
forall action. LabelProps action
defaultLabelProps { labelFor = Just "textarea-demo-disabled" } [ View model action
"Disabled" ]
    , TextareaProps action -> View model action
forall action model. TextareaProps action -> View model action
textarea_ TextareaProps action
forall action. TextareaProps action
defaultTextareaProps
      { textareaPlaceholder = Just "Type your message here"
      , textareaId = Just "textarea-demo-disabled"
      , textareaDisabled = True
      }
    ]
  ]
-----------------------------------------------------------------------------
textareaCodeSample :: View model action
textareaCodeSample :: forall model action. View model action
textareaCodeSample =
  View model action
"""
  -----------------------------------------------------------------------------
  module MyTextarea (textareaUsage) where
  -----------------------------------------------------------------------------
  import           Miso
  import qualified Miso.Html.Element as H
  import qualified Miso.Html.Property as P
  import           Miso.UI.Label
  import           Miso.UI.Textarea
  -----------------------------------------------------------------------------
  textareaUsage :: View model action
  textareaUsage =
    H.div_
    [ P.class_ "flex flex-col gap-y-6" ]
    [ textarea_ defaultTextareaProps { textareaPlaceholder = Just "Type your message here" }
    , textarea_ defaultTextareaProps
      { textareaPlaceholder = Just "Type your message here"
      , textareaInvalid = True
      }
    , H.div_
      [ P.class_ "grid gap-3" ]
      [ label_ defaultLabelProps { labelFor = Just "my-textarea" } [ "Label" ]
      , textarea_ defaultTextareaProps
        { textareaPlaceholder = Just "Type your message here"
        , textareaId = Just "my-textarea"
        }
      ]
    ]
  """
-----------------------------------------------------------------------------
textareaPropsApi :: View model action
textareaPropsApi :: forall model action. View model action
textareaPropsApi =
  View model action
"""
  -- | Props for 'textarea_'
  data TextareaProps action
    = TextareaProps
    { textareaId :: Maybe MisoString
    , textareaPlaceholder :: Maybe MisoString
    , textareaRows :: Maybe MisoString
    , textareaDisabled :: Bool
    , textareaInvalid :: Bool
      -- ^ Renders with @aria-invalid@ (error styling)
    , textareaClasses :: [MisoString]
      -- ^ Extra classes appended to @textarea@
    , textareaAttrs :: [Attribute action]
    }
  -----------------------------------------------------------------------------
  -- | Smart constructor: enabled, no placeholder
  defaultTextareaProps :: TextareaProps action
  defaultTextareaProps
    = TextareaProps
    { textareaId = Nothing
    , textareaPlaceholder = Nothing
    , textareaRows = Nothing
    , textareaDisabled = False
    , textareaInvalid = False
    , textareaClasses = []
    , textareaAttrs = []
    }
  """
-----------------------------------------------------------------------------