mdgriffith/style-elements/5.0.0

NOTE: the latest version is 5.0.2

Element.Attributes

This module is a mirror of Html.Attributes

Some attributes have been added.

The only modification to the existing library is that style has been renamed inlineStyle to avoid collision with Style.style.

Since this is a style library, you shouldn't need it very often.

Style Element Attributes

These are the new attributes that generally have to do with layout.

hidden : Attribute variation msg

Remove the element from the view.

vary : variation -> Bool -> Attribute variation msg

Apply a style variation.

el MyButton [ vary Disabled True ] (text "My Disabled Button!")

Alignment

Alignment attributes are incredibly useful for adjusting your layout.

When applied to layout elements like row and grid, alignment will affect the alignment of the children.

When applied to singular elements like el, alignment will affect the alignment of that individual element.

center : Attribute variation msg
verticalCenter : Attribute variation msg
alignTop : Attribute variation msg
alignBottom : Attribute variation msg
alignLeft : Attribute variation msg
alignRight : Attribute variation msg
spread : Attribute variation msg
verticalSpread : Attribute variation msg

Sizing

width : Length -> Attribute variation msg
minWidth : Length -> Attribute variation msg
maxWidth : Length -> Attribute variation msg
height : Length -> Attribute variation msg
minHeight : Length -> Attribute variation msg
maxHeight : Length -> Attribute variation msg
type alias Length =
Length
px : Float -> Length
fill : Length
fillPortion : Int -> Length
percent : Float -> Length
content : Length

Spacing ++ Padding

Spacing allows a layout to set the distance between the children in the layout.

So this layout:

row [ spacing 10, padding 10 ]
    [ el Box [] empty
    , el Box [] empty
    , el Box [] empty
    ]

Is rendered into something like this:

Spacing
spacing : Float -> Attribute variation msg

Set the spacing between children in a layout.

spacingXY : Float -> Float -> Attribute variation msg

Set the horizontal and vertical spacing separately.

This is generally only useful in a textLayout or a grid.

padding : Float -> Attribute variation msg
paddingXY : Float -> Float -> Attribute variation msg

Set horizontal and vertical padding.

paddingTop : Float -> Attribute variation msg
paddingRight : Float -> Attribute variation msg
paddingBottom : Float -> Attribute variation msg
paddingLeft : Float -> Attribute variation msg

Positioning

moveUp : Float -> Attribute variation msg
moveDown : Float -> Attribute variation msg
moveRight : Float -> Attribute variation msg
moveLeft : Float -> Attribute variation msg

Scrollbars

scrollbars : Attribute variation msg

Turn on scrollbars if content overflows.

yScrollbar : Attribute variation msg

Turn on scrollbars if content overflows vertically.

xScrollbar : Attribute variation msg

Turn on scrollbars if content overflows horizontally.

Overflow

clip : Attribute variation msg

Clip content that overflows.

clipX : Attribute variation msg
clipY : Attribute variation msg

Conversion

toAttr : Attribute msg -> Attribute variation msg

Convert an existing Html.Attribute to an Element.Attribute.

This is useful for working with any library that returns a Html.Attribute.

Primitives

inlineStyle : String -> String -> Attribute variation msg

This is the manual override for to specify inline css properties.

myStyle : Attribute msg
myStyle =
    inlineStyle
        [ ( "backgroundColor", "red" )
        , ( "height", "90px" )
        , ( "width", "100%" )
        ]


greeting : Html msg
greeting =
    el [ myStyle ] (text "Hello!")

Use it if you need to, though it's obviously recommended to use the Style module instead.

property : String -> Value -> Attribute variation msg

Create properties, like saying domNode.className = 'greeting' in JavaScript.

import Json.Encode as Encode


class : String -> Attribute variation msg
class =
    Html.Attributes.class

Read more about the difference between properties and attributes here.

attribute : String -> String -> Attribute variation msg

Create attributes, like saying domNode.setAttribute('class', 'greeting') in JavaScript.

class : String -> Attribute variation msg
class =
    Html.Attributes.class

Read more about the difference between properties and attributes here.

map : (a -> msg) -> Attribute variation a -> Attribute variation msg

Transform the messages produced by an Attribute.

Super Common Attributes

class : String -> Attribute variation msg

Often used with CSS to style elements with common properties.

classList : List ( String, Bool ) -> Attribute variation msg

This function makes it easier to build a space-separated class attribute. Each class can easily be added and removed depending on the boolean value it is paired with. For example, maybe we want a way to view notices:

viewNotice : Notice -> Html msg
viewNotice notice =
    div
        [ classList
            [ ( "notice", True )
            , ( "notice-important", notice.isImportant )
            , ( "notice-seen", notice.isSeen )
            ]
        ]
        [ text notice.content ]
id : String -> Attribute variation msg

Often used with CSS to style a specific element. The value of this attribute must be unique.