Skip to content

Commit

Permalink
nudge with number support
Browse files Browse the repository at this point in the history
  • Loading branch information
hojberg committed Aug 21, 2023
1 parent 7fd5c83 commit bba8edb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/UI/Nudge.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module UI.Nudge exposing (..)

import Html exposing (Html, div)
import Html exposing (Html, div, text)
import Html.Attributes exposing (class)
import Maybe.Extra as MaybeE
import UI
import UI.Tooltip as Tooltip exposing (Tooltip)

Expand All @@ -11,6 +12,7 @@ type Nudge msg
| Nudge
{ withTooltip : Maybe (Tooltip msg)
, pulsate : Bool
, withNumber : Maybe Int
}


Expand All @@ -25,7 +27,7 @@ empty =

nudge : Nudge msg
nudge =
Nudge { withTooltip = Nothing, pulsate = False }
Nudge { withTooltip = Nothing, pulsate = False, withNumber = Nothing }



Expand All @@ -36,6 +38,7 @@ withTooltip : Tooltip msg -> Nudge msg -> Nudge msg
withTooltip tooltip nudge_ =
case nudge_ of
NoNudge ->
-- create a new Nudge with the default settings
withTooltip tooltip nudge

Nudge n ->
Expand All @@ -46,12 +49,24 @@ pulsate : Nudge msg -> Nudge msg
pulsate nudge_ =
case nudge_ of
NoNudge ->
-- create a new Nudge with the default settings
pulsate nudge

Nudge n ->
Nudge { n | pulsate = True }


withNumber : Int -> Nudge msg -> Nudge msg
withNumber n nudge_ =
case nudge_ of
NoNudge ->
-- create a new Nudge with the default settings
withNumber n nudge

Nudge n_ ->
Nudge { n_ | withNumber = Just n }



-- MAP

Expand All @@ -66,23 +81,28 @@ map toMsg nudgeA =
Nudge
{ withTooltip = Maybe.map (Tooltip.map toMsg) n.withTooltip
, pulsate = n.pulsate
, withNumber = n.withNumber
}



-- VIEW


viewNudgeDot : Bool -> Html msg
viewNudgeDot pulsate_ =
viewNudgeDot : Bool -> Maybe Int -> Html msg
viewNudgeDot pulsate_ withNumber_ =
let
num =
MaybeE.unwrap UI.nothing (String.fromInt >> text) withNumber_
in
div
[ if pulsate_ then
class "nudge pulsate"

else
class "nudge"
]
[ div [ class "nudge_circle" ] []
[ div [ class "nudge_circle" ] [ num ]
]


Expand All @@ -95,7 +115,7 @@ view nudge_ =
Nudge settings ->
case settings.withTooltip of
Nothing ->
viewNudgeDot settings.pulsate
viewNudgeDot settings.pulsate settings.withNumber

Just tooltip ->
Tooltip.view (viewNudgeDot settings.pulsate) tooltip
Tooltip.view (viewNudgeDot settings.pulsate settings.withNumber) tooltip
3 changes: 3 additions & 0 deletions src/css/ui/components/nudge.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.nudge {
position: relative;
display: inline-flex;
font-size: var(--font-size-small);
color: var(--u-color_info_text);
font-family: var(--font-monospace);
}

.nudge .nudge_circle {
Expand Down

0 comments on commit bba8edb

Please sign in to comment.