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

Web.View.Style

Synopsis

Styles

width :: Length -> Mod c Source #

Set to a specific width

height :: Length -> Mod c Source #

Set to a specific height

minWidth :: Length -> Mod c Source #

Allow width to grow to contents but not shrink any smaller than value

minHeight :: Length -> Mod c Source #

Allow height to grow to contents but not shrink any smaller than value

pad :: Sides Length -> Mod c Source #

Space surrounding the children of the element

To create even spacing around and between all elements:

col (pad 10 . gap 10) $ do
  el_ "one"
  el_ "two"
  el_ "three"

gap :: Length -> Mod c Source #

The space between child elements. See pad

flexRow :: Mod c Source #

Set container to be a row. Favor row when possible

flexCol :: Mod c Source #

Set container to be a column. Favor col when possible

shadow :: Mod c Source #

Adds a basic drop shadow to an element

rounded :: Length -> Mod c Source #

Round the corners of the element

bg :: ToColor clr => clr -> Mod ctx Source #

Set the background color. See ToColor

color :: ToColor clr => clr -> Mod ctx Source #

Set the text color. See ToColor

hide :: Mod c Source #

Hide an element. See parent and media

border :: Sides PxRem -> Mod c Source #

Set a border around the element

el (border 1) "all sides"
el (border (X 1)) "only left and right"

borderColor :: ToColor clr => clr -> Mod ctx Source #

Set a border color. See ToColor

pointer :: Mod c Source #

Use a button-like cursor when hovering over the element

Button-like elements:

btn = pointer . bg Primary . hover (bg PrimaryLight)

options = row id $ do
  el btn "Login"
  el btn "Sign Up"

truncate :: Mod c Source #

Cut off the contents of the element

transition :: Ms -> TransitionProperty -> Mod c Source #

Animate changes to the given property

el (transition 100 (Height 400)) "Tall"
el (transition 100 (Height 100)) "Small"

Selector Modifiers

hover :: Mod c -> Mod c Source #

Apply when hovering over an element

el (bg Primary . hover (bg PrimaryLight)) "Hover"

active :: Mod c -> Mod c Source #

Apply when the mouse is pressed down on an element

even :: Mod c -> Mod c Source #

Apply to even-numbered children

odd :: Mod c -> Mod c Source #

Apply to odd-numbered children

media :: Media -> Mod c -> Mod c Source #

Apply when the Media matches the current window. This allows for responsive designs

el (width 100 . media (MinWidth 800) (width 400))
  "Big if window > 800"

parent :: Text -> Mod c -> Mod c Source #

Apply when the element is somewhere inside an anscestor.

For example, the HTMX library applies an "htmx-request" class to the body when a request is pending. We can use this to create a loading indicator

el (pad 10) $ do
  el (parent "htmx-request" flexRow . hide) "Loading..."
  el (parent "htmx-request" hide . flexRow) "Normal Content"

mapModClass :: (Class -> Class) -> Mod c -> Mod c Source #

Creating New Styles

addClass :: Class -> Mod c Source #

Add a single class

width :: PxRem -> Mod
width n =
  addClass
    $ cls ("w" -. n)
    & prop "width" n
    & prop @Int "flex-shrink" 0

cls :: ClassName -> Class Source #

Construct a class from a ClassName

extClass :: ClassName -> Mod c Source #

Construct a mod from a ClassName with no CSS properties. Convenience for situations where external CSS classes need to be referenced.

el (extClass "btn" . extClass "btn-primary") "Click me!"

prop :: ToStyleValue val => Name -> val -> Class -> Class Source #

Add a property to a class

(-.) :: ToClassName a => ClassName -> a -> ClassName infixl 6 Source #

Hyphenate classnames