nixCodeX/elm-bootstrap/3.1.1

Renamed to aDifferentJT/elm-bootstrap. That is where the repository lives now. It has not been published as a package under the new name.

Versions published as nixCodeX/elm-bootstrap still install under that name. 13 versions of 13 come from the new location (see their notes).

Rerouted (renamed, verified). The GitHub user or repository was renamed. The tag is still there, at the new name. The Lamdera package server serves a copy recovered from https://github.com/aDifferentJT/elm-bootstrap.

What we checked: The repo moved to github.com/aDifferentJT/elm-bootstrap. Rebuilt with git archive from commit c2a3c6010689 of https://github.com/aDifferentJT/elm-bootstrap (zip prefix nixCodeX-elm-bootstrap-c2a3c60/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 f4dddcc832f62240e22074da37ce3b8a1f2e9a0c.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/nixCodeX/elm-bootstrap/zipball/3.1.1/

Bootstrap.Navbar

The navbar is a wrapper that positions branding, navigation, and other elements in a concise header. The navbar is designed to be responsive by default and made interactive with a tiny sprinkle of Elm.

import Bootstrap.Navbar as Navbar




-- You need to keep track of the view state for the navbar in your model
type alias Model =
    { navbarState : Navbar.State }


-- The navbar needs to know the initial window size, so the inital state for a navbar requires a command to be run by the Elm runtime
initialState : ( Model, Cmd Msg )
initialState =
    let
        ( navbarState, navbarCmd ) =
            Navbar.initialState NavbarMsg
    in
    ( { navbarState = navbarState }, navbarCmd )


-- Define a message for the navbar
type Msg
    = NavbarMsg Navbar.State


-- You need to handle navbar messages in your update function to step the navbar state forward
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        NavbarMsg state ->
            ( { model | navbarState = state }, Cmd.none )


view : Model -> Html Msg
view model =
    Navbar.config NavbarMsg
        |> Navbar.withAnimation
        |> Navbar.brand [ href "#" ] [ text "Brand" ]
        |> Navbar.items
            [ Navbar.itemLink [ href "#" ] [ text "Item 1" ]
            , Navbar.itemLink [ href "#" ] [ text "Item 2" ]
            ]
        |> Navbar.view model.navbarState


-- If you use animations as above or you use dropdowns in your navbar you need to configure subscriptions too
subscriptions : Model -> Sub Msg
subscriptions model =
    Navbar.subscriptions model.navbarState NavbarMsg

Navbar

view : State -> Config msg -> Html msg

The main view function for displaying a navbar.

Navbar.config NavbarMsg
    |> Navbar.withAnimation
    |> Navbar.brand [ href "#" ] [ text "Brand" ]
    |> Navbar.items
        [ Navbar.itemLink [ href "#" ] [ text "Item 1" ]
        , Navbar.itemLink [ href "#" ] [ text "Item 2" ]
        ]
    |> Navbar.customItems
        [ Navbar.textItem [] [ text "Some text" ] ]
    |> Navbar.view model.navbarState
  • state Required view state the navbar uses to support interactive behavior
  • config The view configuration that determines to look and feel of the navbar
config : (State -> msg) -> Config msg

Creates a default navbar view configuration. Providing a starting point to set up your navbar how you'd like.

type Config msg

Configuration information for describing the view of the Navbar

  • options List of configuration options
  • toMsg Message function used for stepping the viewstate of the navbar forward
  • withAnimation Set to True if you wish the menu to slide up/down with an animation effect
  • brand Optional brand element (typically a logo)
  • items List of menu items that the user can select from
  • customItems List of custom (inline) items that you may place to the right of the std. navigation items

Options

Use a slide up/down animation for toggling the navbar menu when collapsed.

**NOTE: ** Do remember to set up the subscriptions function when using this option.

primary : Config msg -> Config msg

Option to color menu using the primary color

secondary : Config msg -> Config msg

Option to color menu using the secondary color

success : Config msg -> Config msg

Option to color menu using the success color

info : Config msg -> Config msg

Option to color menu using the info color

warning : Config msg -> Config msg

Option to color menu using the warning color

danger : Config msg -> Config msg

Option to color menu using the danger color

light : Config msg -> Config msg

Use a light background color (with a dark text)

dark : Config msg -> Config msg

Use a dark background color (with a light text)

fixTop : Config msg -> Config msg

Option to fix the menu to the top of the viewport

**Note: You probably need to add some margin-top to the content element following the navbar when using this option **

fixBottom : Config msg -> Config msg

Option to fix the menu to the bottom of the viewport

lightCustom : Color -> Config msg -> Config msg

Option to color menu using a light custom background color (see avh4/elm-color)

darkCustom : Color -> Config msg -> Config msg

Option to color menu using a dark custom background color (see avh4/elm-color)

lightCustomClass : String -> Config msg -> Config msg

Option to color menu using a light custom background color defined by css class(es)

darkCustomClass : String -> Config msg -> Config msg

Option to color menu using a dark custom background color defined by css class(es)

Collapse the menu at the small media breakpoint

Collapse the menu at the medium media breakpoint

Collapse the menu at the large media breakpoint

Collapse the menu at the extra large media breakpoint

container : Config msg -> Config msg

Use this option when you want a fixed width menu (typically because your main content is also configured to be fixed width)

attrs : List (Attribute msg) -> Config msg -> Config msg

Add a custom Html.Attribute to the navbar element using this function

Brand

brand : List (Attribute msg) -> List (Html msg) -> Config msg -> Config msg

Create a brand element for your navbar

Navbar.brand
    [ href "#" ]
    -- (and perhaps use onWithOptions for custom handling of clicks !)
    [ img [ src "assets/logo.svg" ] [ text "MyCompany" ] ]
    config
  • attributes List of attributes
  • children List of children
  • config Navbar config record to add/modify brand for
type Brand msg

Opaque type representing a brand element

items : List (Item msg) -> Config msg -> Config msg

Configure your navbar with a list of navigation links and/or dropdowns.

NOTE If you call this function several times, the last time "wins".

itemLinkActive : List (Attribute msg) -> List (Html msg) -> Item msg

Create a menu item that is styled as active (as an a element)

  • attributes List of attributes
  • children List of children
type Item msg

Opaque type representing a selectable menu item

Custom items

customItems : List (CustomItem msg) -> Config msg -> Config msg

You can add custom items to a navbar too. These are placed after any navigation items.

NOTE If you call this function several times, the last time "wins".

textItem : List (Attribute msg) -> List (Html msg) -> CustomItem msg

Create a custom inline text element, which will float to the right when the menu isn't collapsed

  • attributes List of attributes
  • children List of children

**Note: If you have multiple custom items you will need to provide spacing between them yourself **

formItem : List (Attribute msg) -> List (Html msg) -> CustomItem msg

Create a custom inline form element, which will float to the right when the menu isn't collapsed

Navbar.formItem []
    [ TextInput.text
        [ TextInput.small ]
    , Button.button
        [ Button.roleSuccess, Button.small]
        [ text "Submit"]]
    ]
  • attributes List of attributes
  • children List of children

**Note: If you have multiple custom items you will need to provide spacing between them yourself **

customItem : Html msg -> CustomItem msg

Create a completely custom item, which will float to the right when the menu isn't collapsed. You should ensure that you create inline elements or else your menu will break in unfortunate ways!

  • attributes List of attributes
  • children List of children

**Note: If you have multiple custom items you will need to provide spacing between them yourself **

type CustomItem msg

Opaque type representing a custom (inline) navbar item

State

initialState : (State -> msg) -> ( State, Cmd msg )

You need to call this function to initialize the view state for the navbar and store the state in your main model.

init : ( Model, Cmd Msg )
init =
    let
        ( navbarState, navCmd ) =
            Navbar.initialState NavbarMsg
    in
    ( { navbarState = navbarState }
    , navCmd
    )

The Cmd part is needed, because the navbar as implemented currently needs the window size. Hopefully a smoother solution can be devised in the future.

type State

Opaque type representing the view state of the navbar and any navbar dropdown menus

Interactive elements and subscriptions

subscriptions : State -> (State -> msg) -> Sub msg

To support animations and managing the state of dropdown you need to wire up this function in your main subscriptions function.

subscriptions : Model -> Sub Msg
subscriptions model =
    Navbar.subscriptions model.navbarState NavbarMsg

**Note: ** If you are NOT using dropdowns in your navbar AND you are using a navbar without animation you can skip this. But it's not that much work, so maybe you are better off doing it anyway.