Skip to content

Commit

Permalink
Add Card.withDomId
Browse files Browse the repository at this point in the history
  • Loading branch information
hojberg committed Jul 23, 2024
1 parent 5de30d8 commit 5b3a7f7
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/UI/Card.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module UI.Card exposing (..)

import Html exposing (Html, div, h3, text)
import Html.Attributes exposing (class)
import Html.Attributes exposing (class, id)


type SurfaceBackgroundColor
Expand All @@ -18,6 +18,7 @@ type CardType
type alias Card msg =
{ type_ : CardType
, classNames : List String
, domId : Maybe String
, title : Maybe String
, items : List (Html msg)
}
Expand All @@ -29,12 +30,12 @@ type alias Card msg =

card : List (Html msg) -> Card msg
card items =
{ type_ = Uncontained, classNames = [], title = Nothing, items = items }
{ type_ = Uncontained, classNames = [], title = Nothing, items = items, domId = Nothing }


titled : String -> List (Html msg) -> Card msg
titled title items =
{ type_ = Uncontained, classNames = [], title = Just title, items = items }
{ type_ = Uncontained, classNames = [], title = Just title, items = items, domId = Nothing }



Expand All @@ -51,6 +52,11 @@ withClassName className card_ =
{ card_ | classNames = className :: card_.classNames }


withDomId : String -> Card msg -> Card msg
withDomId domId card_ =
{ card_ | domId = Just domId }


withTightPadding : Card msg -> Card msg
withTightPadding card_ =
withClassName "card_tight-padding" card_
Expand Down Expand Up @@ -96,6 +102,7 @@ map toMsg cardA =
, classNames = cardA.classNames
, title = cardA.title
, items = List.map (Html.map toMsg) cardA.items
, domId = cardA.domId
}


Expand Down Expand Up @@ -131,5 +138,13 @@ view card_ =

Uncontained ->
"uncontained"

domId =
case card_.domId of
Just domId_ ->
[ id domId_ ]

Nothing ->
[]
in
div ([ class "card", class typeClass ] ++ classNames) items
div ([ class "card", class typeClass ] ++ classNames ++ domId) items

0 comments on commit 5b3a7f7

Please sign in to comment.