PaackEng / paack-ui / UI.Utils.Action

Describes a clickable element for components with customizable clickable action.

Building


type Action msg
    = DispatchMsg msg
    | TriggerRedirect UI.Link.Link

Either a message to be dispatched, or an link to be followed.

Helpers


type alias WithIcon msg =
{ action : Action msg
, icon : String -> UI.Icon.Icon
, label : String 
}

WithIcon assembles the required configuration for having an action element.

{ label = "Create new element"
, icon = Icon.add
, action =
    DialogMsg.OpenElementCreation
        |> Msg.ForDialog
        |> Action.DispatchMsg
}

iconMap : (a -> b) -> WithIcon a -> WithIcon b

Applies a transformation to the message in a WithIcon msg, when it exists.

Action.iconMap
    PageMsg.ForDialog
    { action = Action.DispatchMsg DialogMsg.Close
    , icon = Icon.close
    , label = "Close"
    }

iconWith : (UI.Icon.Icon -> UI.Icon.Icon) -> WithIcon msg -> WithIcon msg

Applies a transformation to the icon in a WithIcon msg.

Action.iconWith
    (Icon.withSize Size.small)
    { action = Action.DispatchMsg DialogMsg.Close
    , icon = Icon.close
    , label = "Close"
    }