jinjor/elm-contextmenu/1.1.0

NOTE: this package is not compatible with Elm 0.19.1

ContextMenu

The ContextMenu component that follows the Elm Architecture.

See How to use.

TEA Parts

The boilerplace functions. See The Elm Architecture for more information.

type ContextMenu context

The Model. Put whatever context you like, which is used to create menu items.

type Msg context

The Message.

init : ( ContextMenu context, Cmd (Msg context) )

The init function.

Msg context
-> ContextMenu context
-> ( ContextMenu context, Cmd (Msg context) )

The update function.

subscriptions : ContextMenu context -> Sub (Msg context)

The Subscription.

Item

type Item

The menu item. You can construct it with pipe-friendly functions.

ContextMenu.item "Take photos"
  |> ContextMenu.icon FontAwesome.camera Color.green
  |> ContextMenu.disabled True
item : String -> Item

Creates a simple text item.

itemWithAnnotation : String -> String -> Item

Creates an item with annotation which will displayed just below the item name.

disabled : Bool -> Item -> Item

Disables the item. True = disabled, False = enabled.

icon : (Color -> Int -> Html Never) -> Color -> Item -> Item

Shows the icon.

The first function creates the icon. This fuction is compatible with elm-material-icons and elm-font-awesome.

shortcut : String -> Item -> Item

Displays the shortcut key at the right.

Config

type alias Config =
{ width : Int
, direction : Direction
, overflowX : Overflow
, overflowY : Overflow
, containerColor : Color
, hoverColor : Color
, invertText : Bool
, cursor : Cursor
, rounded : Bool
, fontFamily : String
}

Defines the styles of the menu. See examples.

= LeftBottom
| RightBottom

The default direction the menu will be shown at.

= Shift
| Mirror

The strategies how to show the menu when it goes out of window.

type Cursor
= Arrow
| Pointer

The shape of cursor during hovering on the menu.

defaultConfig : Config

The default config.

defaultConfig =
  { width = 300
  , direction = RightBottom
  , overflowX = Mirror
  , overflowY = Mirror
  , containerColor = Color.white
  , hoverColor = Color.rgb 240 240 240
  , invertText = False
  , cursor = Pointer
  , rounded = False
  , fontFamily = "initial"
  }

View

Config
-> (Msg context -> msg)
-> (context -> List (List ( Item, msg )))
-> ContextMenu context
-> Html msg

Shows the menu. This should be called at only one place.

Arguments:

  1. the Config

  2. function to transform component's message into user's message

  3. function to create item groups

  4. the Model

open : (Msg context -> msg) -> context -> Attribute msg

Makes the attribute that triggers to open the menu. This attribute is passed for each element that needs a menu.

Arguments:

  1. function to transform component's message into user's message

  2. the context which is used to create items

openIf : Bool -> (Msg context -> msg) -> context -> Attribute msg

Similar to open but only works under particular condition.

This is useful for debugging on browser.

Advanced

setOnDehover : Bool -> ContextMenu context -> ContextMenu context

This switches when the menu should be closed.

  • True: Closes when mouse leaves the menu (keeps opening on cliking)
  • False(default): Closes when somewhere in the window is clicked