arowM/elm-neat-layout/3.2.2

NOTE: the latest version is 4.0.5

Neat.Boundary

Module for building Boundary.

Core

type alias Boundary msg =
Boundary msg

A bounded View without gap.

Convert to/from View by setGap/setBoundary.

map : (a -> b) -> Boundary a -> Boundary b
empty : Boundary msg

An empty block.

Attributes

Functions to set arbitrary attributes. The following styles are not reflected by the style attribute or CSS files.

  • padding / margin
    • Use functions for gaps.
  • min-width / max-width / min-height / max-height / line-height
    • Use functions for sizes.
  • width / height
    • Use min-* and max-*.
  • white-space
    • Determined by wrapping style
  • display / position
    • Determined automatically by its context
  • z-index
    • Enforced to be "auto"
  • box-sizing
    • Determined by each type of view.
      • scalableBlock is "content-box"
      • otherwise, "border-box"
  • overflow
    • Boundaries automatically handles overflow.
  • position
    • Use putLayer
  • line-height
    • Specify with textBlock
setMixin : Mixin msg -> Boundary msg -> Boundary msg

Append Mixin on boundaries.

setMixins : List (Mixin msg) -> Boundary msg -> Boundary msg

Same as setMixin but takes a list of Mixins.

setAttribute : Attribute msg -> Boundary msg -> Boundary msg

Append Attribute on boundaries.

setAttributes : List (Attribute msg) -> Boundary msg -> Boundary msg

Same as setAttribute but takes a list of Attributes.

setClass : String -> Boundary msg -> Boundary msg

Append class attribute.

setId : String -> Boundary msg -> Boundary msg

Append id attribute.

WAI-ARIA

setRole : String -> Boundary msg -> Boundary msg

Set "role" value for WAI-ARIA.

setAria : String -> String -> Boundary msg -> Boundary msg

Set "aria-*" value for WAI-ARIA.

e.g., setAria "required" "true" stands for "aria-required" is "true".

setBoolAria : String -> Bool -> Boundary msg -> Boundary msg

Set boolean "aria-*" value for WAI-ARIA.

i.e.,

  • setBoolAria name True is equal to setAria name "true"
  • setBoolAria name False is equal to setAria name "false"

Sizes

You can only use a limited kind of units. This may seem inconvenient, but it prevents you to build unmaintainable broken views.

Minimum width

The default minimum width is zero without enabling child overflow.

setMinWidthInBs : Float -> Boundary msg -> Boundary msg

Set the minimum width as a percentage of the base size. e.g., setMinWidthInBs 100 set the minimum width the same length as the base size.

setMinWidthInEm : Float -> Boundary msg -> Boundary msg

Set the minimum width in em.

Represents the calculated font-size of the element.

setMinWidthInRem : Float -> Boundary msg -> Boundary msg

Set the minimum width in rem.

Represents the font-size of the root element (typically <html>).

Minimum height

The default minimum height is zero without enabling child overflow.

setMinHeightInBs : Float -> Boundary msg -> Boundary msg

Set the minimum height as a percentage of the base size. e.g., setMinHeightInBs 100 set the minimum height the same length as the base size.

setMinHeightInEm : Float -> Boundary msg -> Boundary msg

Set the minimum height in em.

Represents the calculated font-size of the element.

setMinHeightInRem : Float -> Boundary msg -> Boundary msg

Set the minimum height in rem.

Represents the font-size of the root element (typically <html>).

Maximum width

The default value for maximum width is fit, which shrinks as much as its children do not overhang it.

setMaxWidthInBs : Float -> Boundary msg -> Boundary msg

Set the maximum width as a percentage of the base size. e.g., setMaxWidthInBs 100 set the maximum width the same length as the base size.

setMaxWidthInEm : Float -> Boundary msg -> Boundary msg

Set the maximum width in em.

Represents the calculated font-size of the element.

setMaxWidthInRem : Float -> Boundary msg -> Boundary msg

Set the maximum width in rem.

Represents the font-size of the root element (typically <html>).

Maximum height

The default value for maximum height is fit, which shrinks as much as its children do not overhang it.

setMaxHeightInBs : Float -> Boundary msg -> Boundary msg

Set the maximum height as a percentage of the base size. e.g., setMaxHeightInBs 100 set the maximum height the same length as the base size.

setMaxHeightInEm : Float -> Boundary msg -> Boundary msg

Set the maximum height in em.

Represents the calculated font-size of the element.

setMaxHeightInRem : Float -> Boundary msg -> Boundary msg

Set the maximum height in rem.

Represents the font-size of the root element (typically <html>).

Scroll

enableVerticalScroll : Boundary msg -> Boundary msg
enableHorizontalScroll : Boundary msg -> Boundary msg

Overlay

String
-> ( Layer, Boundary (Layered msg) )
-> Boundary msg
-> Boundary msg

Put overlay layer on the parent view.

type alias Layer =
{ top : Float
, bottom : Float
, left : Float
, right : Float
, priority : Maybe Int
}

Set the position of each edge of the overlay layer as a percentage of the base view.

The priority field specifies how much the element is superimposed on the front side in preference to other elements. If given Nothing, it is set equivalent priority comparing to other elements.

defaultLayer : Layer
defaultLayer
--> { top = 0
--> , bottom = 0
--> , left = 0
--> , right = 0
--> , priority = Nothing
--> }
type alias Layered msg =
Layered msg
mapLayered : (a -> b) -> Boundary (Layered a) -> Boundary (Layered b)
toLayered : Boundary msg -> Boundary (Layered msg)

Convert Boundary for putLayer. The Boundary (Layered msg) ignores pointer events; this feature is especially helpfull for realizing popups with clickable background.

Handle Conditions

none : Boundary a

Generates no HTML nodes. This is useful for handling elements which only appears under certain conditions.

when p v =
    if p then
        v


    else
        none
when : Bool -> Boundary msg -> Boundary msg

Insert a view only when a condition is met.

unless : Bool -> Boundary msg -> Boundary msg

Insert a view unless a condition is met.

withMaybe : Maybe a -> (a -> Boundary msg) -> Boundary msg

Insert a view only if the given value is Just.

Convert to View

setGap : IsGap gap -> Boundary msg -> View gap msg

Set Gap around a view.

Lower level functions for HTML

setNodeName : String -> Boundary msg -> Boundary msg

Set HTML node name on Boundary.

html : String -> List ( String, Boundary msg ) -> Boundary msg

Build HTML tag. When you need to build a HTML tag with its children, html will help you.

animalSelect : Maybe Animal -> Boundary msg
animalSelect animal =
    Boundary.html "select"
        [ animalOption Nothing animal
        , animalOption (Just Goat) animal
        , animalOption (Just Dog) animal
        , animalOption (Just Cat) animal
        ]
        |> Boundary.setMixin
            (Mixin.Events.onChange ChangeAnimal)
htmlNode : String -> String -> Boundary msg

A special Boundary which only has text content. For example, you can use htmlNode to build option tag.

animalOption :
    Maybe Animal
    -> Maybe Animal
    -> ( String, Boundary msg )
animalOption animal selected =
    let
        key =
            animal
                |> Maybe.map Animal.toValue
                |> Maybe.withDefault "default"


        disabled =
            animal == Nothing


        selected =
            animal == selected


        value =
            animal
                |> Maybe.map Animal.toValue
                |> Maybe.withDefault ""


        label =
            animal
                |> Maybe.map Animal.toLabel
                |> Maybe.withDefault "-- Select one --"
    in
    ( key
    , Boundary.htmlNode "option" label
        |> Boundary.setAttributes
            [ Attributes.disabled disabled
            , Attributes.selected selected
            , Attributes.value value
            ]
    )

DEPRECATED

textBlock : String -> Boundary msg

⚠ DEPRECATED ⚠

Generates a boundary view that displays a text.

It is an alias for \str -> fromTexts [ Neat.Text.fromString str ].

Note that textBlock "" is equivalent to empty.

fromTexts : List (Text msg) -> Boundary msg

⚠ DEPRECATED ⚠

Build a text block from Texts.

Unlike a Neat.View.row consist of textBlocks, the fromTexts generates a single coherent sentence.

For example, the View built by the following code will be broken as follows:

Neat.View.row
    [ textBlock "foo bar baz"
        |> setGap myGap
        |> Neat.View.rowItem "elem1"
    , textBlock "a b c d e f"
        |> setGap myGap
        |> Neat.View.rowItem "elem2"
    ]


| foo bar | a b c d |
| baz     | e f     |

In contrast, the View built by the following code will be broken as follows:

import Neat.Text as Text


fromTexts
    [ Text.fromString "foo bar baz"
    , Text.fromString "a b c d e f"
    ]


| foo bar baz a b c |
| d e f             |

The gap height between lines will be the same as the gap height set with the setGap function.