{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE MultilineStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Miso.UI.Label
(
LabelProps (..)
, defaultLabelProps
, label_
, labelSample
, labelCodeSample
, labelPropsApi
) where
import Miso
import qualified Miso.Html.Element as H
import qualified Miso.Html.Property as P
data LabelProps action
= LabelProps
{ forall action. LabelProps action -> Maybe MisoString
labelFor :: Maybe MisoString
, forall action. LabelProps action -> [MisoString]
labelClasses :: [MisoString]
, forall action. LabelProps action -> [Attribute action]
labelAttrs :: [Attribute action]
}
defaultLabelProps :: LabelProps action
defaultLabelProps :: forall action. LabelProps action
defaultLabelProps
= LabelProps
{ labelFor :: Maybe MisoString
labelFor = Maybe MisoString
forall a. Maybe a
Nothing
, labelClasses :: [MisoString]
labelClasses = []
, labelAttrs :: [Attribute action]
labelAttrs = []
}
label_
:: LabelProps action
-> [View model action]
-> View model action
label_ :: forall action model.
LabelProps action -> [View model action] -> View model action
label_ LabelProps {[MisoString]
[Attribute action]
Maybe MisoString
labelFor :: forall action. LabelProps action -> Maybe MisoString
labelClasses :: forall action. LabelProps action -> [MisoString]
labelAttrs :: forall action. LabelProps action -> [Attribute action]
labelFor :: Maybe MisoString
labelClasses :: [MisoString]
labelAttrs :: [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.label_
( [[Attribute action]] -> [Attribute action]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
[ [ [MisoString] -> Attribute action
forall action. [MisoString] -> Attribute action
P.classes_ (MisoString
"label" MisoString -> [MisoString] -> [MisoString]
forall a. a -> [a] -> [a]
: [MisoString]
labelClasses) ]
, [ MisoString -> Attribute action
forall action. MisoString -> Attribute action
P.for_ MisoString
f | Just MisoString
f <- [Maybe MisoString
labelFor] ]
, [Attribute action]
labelAttrs
]
) [View model action]
kids
labelSample :: View model action
labelSample :: forall model action. View model action
labelSample =
[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 w-full max-w-sm gap-6" ]
[ [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 items-center gap-3" ]
[ [Attribute action] -> View model action
forall action model. [Attribute action] -> View model action
H.input_
[ MisoString -> Attribute action
forall action. MisoString -> Attribute action
P.class_ MisoString
"input"
, MisoString -> Attribute action
forall action. MisoString -> Attribute action
P.id_ MisoString
"label-demo-terms"
, MisoString -> Attribute action
forall action. MisoString -> Attribute action
P.type_ MisoString
"checkbox"
]
, 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 "label-demo-terms" }
[ View model action
"Accept terms and conditions" ]
]
, [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 "label-demo-text" } [ View model action
"Username" ]
, [Attribute action] -> View model action
forall action model. [Attribute action] -> View model action
H.input_
[ MisoString -> Attribute action
forall action. MisoString -> Attribute action
P.placeholder_ MisoString
"Username"
, MisoString -> Attribute action
forall action. MisoString -> Attribute action
P.class_ MisoString
"input"
, MisoString -> Attribute action
forall action. MisoString -> Attribute action
P.id_ MisoString
"label-demo-text"
, MisoString -> Attribute action
forall action. MisoString -> Attribute action
P.type_ MisoString
"text"
]
]
, [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 "label-demo-disabled" } [ View model action
"Disabled" ]
, [Attribute action] -> View model action
forall action model. [Attribute action] -> View model action
H.input_
[ Attribute action
forall action. Attribute action
P.disabled_
, MisoString -> Attribute action
forall action. MisoString -> Attribute action
P.placeholder_ MisoString
"Disabled"
, MisoString -> Attribute action
forall action. MisoString -> Attribute action
P.class_ MisoString
"peer input"
, MisoString -> Attribute action
forall action. MisoString -> Attribute action
P.id_ MisoString
"label-demo-disabled"
, MisoString -> Attribute action
forall action. MisoString -> Attribute action
P.type_ MisoString
"text"
]
]
]
labelCodeSample :: View model action
labelCodeSample :: forall model action. View model action
labelCodeSample =
View model action
"""
-----------------------------------------------------------------------------
module MyLabel (labelSample) where
-----------------------------------------------------------------------------
import Miso
import qualified Miso.Html.Element as H
import qualified Miso.Html.Property as P
import Miso.UI.Label
-----------------------------------------------------------------------------
labelSample :: View model action
labelSample =
H.div_
[ P.class_ "grid w-full max-w-sm gap-6" ]
[ H.div_
[ P.class_ "flex items-center gap-3" ]
[ H.input_
[ P.class_ "input"
, P.id_ "label-demo-terms"
, P.type_ "checkbox"
]
, label_ defaultLabelProps { labelFor = Just "label-demo-terms" }
[ "Accept terms and conditions" ]
]
, H.div_
[ P.class_ "grid gap-3" ]
[ label_ defaultLabelProps { labelFor = Just "label-demo-text" } [ "Username" ]
, H.input_
[ P.placeholder_ "Username"
, P.class_ "input"
, P.id_ "label-demo-text"
, P.type_ "text"
]
]
, H.div_
[ P.class_ "grid gap-3" ]
[ label_ defaultLabelProps { labelFor = Just "label-demo-disabled" } [ "Disabled" ]
, H.input_
[ P.disabled_
, P.placeholder_ "Disabled"
, P.class_ "peer input"
, P.id_ "label-demo-disabled"
, P.type_ "text"
]
]
]
"""
labelPropsApi :: View model action
labelPropsApi :: forall model action. View model action
labelPropsApi =
View model action
"""
-- | Props for 'label_'
data LabelProps action
= LabelProps
{ labelFor :: Maybe MisoString
-- ^ @for@ attribute (id of the labelled control)
, labelClasses :: [MisoString]
-- ^ Extra classes appended to @label@
, labelAttrs :: [Attribute action]
}
-----------------------------------------------------------------------------
-- | Smart constructor
defaultLabelProps :: LabelProps action
defaultLabelProps
= LabelProps
{ labelFor = Nothing
, labelClasses = []
, labelAttrs = []
}
"""