web-view-0.6.0: Type-safe HTML and CSS with intuitive layouts and composable styles.
Safe HaskellSafe-Inferred
LanguageGHC2021

Web.View.View

Synopsis

Views

newtype View context a Source #

Views are HTML fragments that carry all CSS used by any child element.

view :: View c ()
view = col (pad 10 . gap 10) $ do
  el bold "Hello"
  el_ "World"

They can also have a context which can be used to create type-safe or context-aware elements. See context or table for an example

Constructors

View 

Fields

Instances

Instances details
Applicative (View context) Source # 
Instance details

Defined in Web.View.View

Methods

pure :: a -> View context a #

(<*>) :: View context (a -> b) -> View context a -> View context b #

liftA2 :: (a -> b -> c) -> View context a -> View context b -> View context c #

(*>) :: View context a -> View context b -> View context b #

(<*) :: View context a -> View context b -> View context a #

Functor (View context) Source # 
Instance details

Defined in Web.View.View

Methods

fmap :: (a -> b) -> View context a -> View context b #

(<$) :: a -> View context b -> View context a #

Monad (View context) Source # 
Instance details

Defined in Web.View.View

Methods

(>>=) :: View context a -> (a -> View context b) -> View context b #

(>>) :: View context a -> View context b -> View context b #

return :: a -> View context a #

IsString (View context ()) Source # 
Instance details

Defined in Web.View.View

Methods

fromString :: String -> View context () #

data ViewState Source #

Constructors

ViewState 

Fields

Instances

Instances details
Semigroup ViewState Source # 
Instance details

Defined in Web.View.View

runView :: context -> View context () -> ViewState Source #

Extract the ViewState from a View

context :: View context context Source #

Views have a Reader built-in for convienient access to static data, and to add type-safety to view functions. See table and https://hackage.haskell.org/package/hyperbole/docs/Web-Hyperbole.html

numberView :: View Int ()
numberView = do
  num <- context
  el_ $ do
    "Number: "
    text (pack $ show num)

addContext :: context -> View context () -> View c () Source #

Run a view with a specific context in a parent View with a different context.

parentView :: View c ()
parentView = do
  addContext 1 numberView
  addContext 2 numberView
  addContext 3 numberView

viewModContents :: ([Content] -> [Content]) -> View context () Source #

viewModCss :: (CSS -> CSS) -> View context () Source #

viewInsertContents :: [Content] -> View c () Source #

Inserts contents into the first child element

Creating new Elements

tag :: Text -> Mod c -> View c () -> View c () Source #

Create a new element constructor with the given tag name

aside :: Mod c -> View c () -> View c ()
aside = tag "aside"

tag' :: (Attributes c -> [Content] -> Element) -> Mod c -> View c () -> View c () Source #

Create a new element constructor with a custom element - > span :: Mod c -> View c () -> View c () > span = tag' (Element True) "span"

att :: Name -> AttValue -> Mod c Source #

Set an attribute, replacing existing value

hlink :: Text -> View c () -> View c ()
hlink url content = tag "a" (att "href" url) content