MackeyRMS/elm-ui-with-context/1.0.2

NOTE: the latest version is 2.0.1

Element.WithContext.Font

import Element.WithContext as Element
import Element.WithContext.Font as Font


view =
    Element.el
        [ Font.color (Element.rgb 0 0 1)
        , Font.size 18
        , Font.family
            [ Font.typeface "Open Sans"
            , Font.sansSerif
            ]
        ]
        (Element.text "Woohoo, I'm stylish text")

Note: Font.color, Font.size, and Font.family are inherited, meaning you can set them at the top of your view and all subsequent nodes will have that value.

Other Note: If you're looking for something like line-height, it's handled by Element.spacing on a paragraph.

color : Color -> Attr context decorative msg
size : Int -> Attr context decorative msg

Font sizes are always given as px.

Typefaces

family : List Font -> Attribute context msg
import Element.WithContext as Element
import Element.WithContext.Font as Font


myElement =
    Element.el
        [ Font.family
            [ Font.typeface "Helvetica"
            , Font.sansSerif
            ]
        ]
        (text "")
type alias Font =
Font
typeface : String -> Font
serif : Font
sansSerif : Font
monospace : Font
{ url : String
, name : String
}
-> Font

Note it's likely that Font.external will cause a flash on your page on loading.

To bypass this, import your fonts using a separate stylesheet and just use Font.typeface.

It's likely that Font.external will be removed or redesigned in the future to avoid the flashing.

Font.external can be used to import font files. Let's say you found a neat font on http://fonts.google.com:

import Element
import Element.Font as Font


view =
    Element.el
        [ Font.family
            [ Font.external
                { name = "Roboto"
                , url = "https://fonts.googleapis.com/css?family=Roboto"
                }
            , Font.sansSerif
            ]
        ]
        (Element.text "Woohoo, I'm stylish text")

Alignment and Spacing

alignLeft : Attribute context msg

Align the font to the left.

alignRight : Attribute context msg

Align the font to the right.

center : Attribute context msg

Center align the font.

justify : Attribute context msg
letterSpacing : Float -> Attribute context msg

In px.

wordSpacing : Float -> Attribute context msg

In px.

Font Styles

underline : Attribute context msg
strike : Attribute context msg
italic : Attribute context msg
unitalicized : Attribute context msg

This will reset bold and italic.

Font Weight

heavy : Attribute context msg
extraBold : Attribute context msg
bold : Attribute context msg
semiBold : Attribute context msg
medium : Attribute context msg
regular : Attribute context msg
light : Attribute context msg
extraLight : Attribute context msg
hairline : Attribute context msg

Variants

type alias Variant =
Variant
variant : Variant -> Attribute context msg

You can use this to set a single variant on an element itself such as:

el
    [ Font.variant Font.smallCaps
    ]
    (text "rendered with smallCaps")

Note These will not stack. If you want multiple variants, you should use Font.variantList.

variantList : List Variant -> Attribute context msg
smallCaps : Variant

Small caps are rendered using uppercase glyphs, but at the size of lowercase glyphs.

slashedZero : Variant

Add a slash when rendering 0

ligatures : Variant
ordinal : Variant

Oridinal markers like 1st and 2nd will receive special glyphs.

tabularNumbers : Variant

Number figures will each take up the same space, allowing them to be easily aligned, such as in tables.

Render fractions with the numerator stacked on top of the denominator.

Render fractions

swash : Int -> Variant
feature : String -> Bool -> Variant

Set a feature by name and whether it should be on or off.

Feature names are four-letter names as defined in the OpenType specification.

indexed : String -> Int -> Variant

A font variant might have multiple versions within the font.

In these cases we need to specify the index of the version we want.

Shadows

glow : Color -> Float -> Attr context decorative msg

A glow is just a simplified shadow.

{ offset : ( Float, Float )
, blur : Float
, color : Color
}
-> Attr context decorative msg