Merge pull request #51 from NoRedInk/add-button-link-with-tracking

Add Button.linkWithTracking
This commit is contained in:
Jasper Woudenberg 2018-05-02 11:41:50 +02:00 committed by GitHub
commit 0351cea9b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,7 @@ module Nri.Ui.Button.V2
, linkExternalWithTracking , linkExternalWithTracking
, linkSpa , linkSpa
, linkWithMethod , linkWithMethod
, linkWithTracking
, styles , styles
, submit , submit
, toggleButton , toggleButton
@ -49,7 +50,7 @@ There will generally be a `*Button` and `*Link` version of each button style.
## `<a>` Buttons ## `<a>` Buttons
@docs LinkConfig, link, linkSpa, linkExternal, linkWithMethod, linkExternalWithTracking @docs LinkConfig, link, linkSpa, linkExternal, linkWithMethod, linkWithTracking, linkExternalWithTracking
## `<input>` Buttons ## `<input>` Buttons
@ -68,6 +69,7 @@ import Html
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
import Html.Events exposing (onClick) import Html.Events exposing (onClick)
import Html.Styled import Html.Styled
import Json.Decode
import Nri.Ui.AssetPath as AssetPath exposing (Asset) import Nri.Ui.AssetPath as AssetPath exposing (Asset)
import Nri.Ui.Colors.Extra exposing (withAlpha) import Nri.Ui.Colors.Extra exposing (withAlpha)
import Nri.Ui.Colors.V1 import Nri.Ui.Colors.V1
@ -473,6 +475,20 @@ linkWithMethod method =
linkBase <| [ attribute "data-method" method ] linkBase <| [ attribute "data-method" method ]
{-| Wrap some text so it looks like a button, but actually is wrapped in an anchor to some url.
This should only take in messages that result in a Msg that triggers Analytics.trackAndRedirect. For buttons that trigger other effects on the page, please use Nri.Button.button instead
-}
linkWithTracking : msg -> LinkConfig -> Html msg
linkWithTracking onTrack =
linkBase <|
[ Html.Events.onWithOptions "click"
{ stopPropagation = False
, preventDefault = True
}
(Json.Decode.succeed onTrack)
]
{-| Wrap some text so it looks like a button, but actually is wrapped in an anchor to some url and have it open to an external site {-| Wrap some text so it looks like a button, but actually is wrapped in an anchor to some url and have it open to an external site
This should only take in messages that result in tracking events. For buttons that trigger other effects on the page, please use Nri.Ui.Button.V2.button instead This should only take in messages that result in tracking events. For buttons that trigger other effects on the page, please use Nri.Ui.Button.V2.button instead