Skip to content

Commit

Permalink
only render the cover button if there's a messsage for it
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed May 14, 2020
1 parent 8a2d1ae commit 778f8c3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
47 changes: 26 additions & 21 deletions src/Content.elm
Expand Up @@ -72,7 +72,7 @@ toList (Content guts) =


toHtml :
{ activate : msg
{ activate : Maybe msg
, navigate : Content -> msg
, navigateUrl : Content -> String
}
Expand All @@ -81,26 +81,31 @@ toHtml :
-> Html msg
toHtml { activate, navigate, navigateUrl } attrs ((Content guts) as outer) =
Html.div (Attrs.css [ Css.position Css.relative ] :: attrs)
[ Html.button
[ Events.onClick activate
, Attrs.css
[ Css.width (Css.pct 100)
, Css.height (Css.pct 100)
, Css.position Css.absolute
, Css.margin Css.zero
, Css.padding Css.zero
, Css.border Css.zero
, Css.opacity Css.zero
, Css.top (Css.px 0)
, Css.left (Css.px 0)

-- interactive elements under this just need to set
-- `position: relative` and a `z-index` higher than 0 to
-- pop above and be clickable!
, Css.zIndex (Css.int 0)
]
]
[ Html.text (toString outer) ]
[ case activate of
Just msg ->
Html.button
[ Events.onClick msg
, Attrs.css
[ Css.width (Css.pct 100)
, Css.height (Css.pct 100)
, Css.position Css.absolute
, Css.margin Css.zero
, Css.padding Css.zero
, Css.border Css.zero
, Css.opacity Css.zero
, Css.top (Css.px 0)
, Css.left (Css.px 0)

-- interactive elements under this just need to set
-- `position: relative` and a `z-index` higher than 0 to
-- pop above and be clickable!
, Css.zIndex (Css.int 0)
]
]
[ Html.text (toString outer) ]

Nothing ->
Html.text ""
, Html.div []
(List.map
(snippetToHtml
Expand Down
6 changes: 3 additions & 3 deletions tests/ContentTest.elm
Expand Up @@ -135,7 +135,7 @@ contentTest =
[ test "clicking the result activates the content" <|
\_ ->
fromList [ text "Hello" ]
|> toHtml { activate = "Clicked", navigate = \_ -> "Navigate", navigateUrl = \_ -> "" } []
|> toHtml { activate = Just "Clicked", navigate = \_ -> "Navigate", navigateUrl = \_ -> "" } []
|> Html.toUnstyled
|> Query.fromHtml
|> Query.find
Expand All @@ -147,7 +147,7 @@ contentTest =
, test "renders clickable links" <|
\_ ->
fromList [ link { children = [ text "bytes.zone" ], href = "https://bytes.zone" } ]
|> toHtml { activate = (), navigate = \_ -> (), navigateUrl = \_ -> "" } []
|> toHtml { activate = Just (), navigate = \_ -> (), navigateUrl = \_ -> "" } []
|> Html.toUnstyled
|> Query.fromHtml
|> Query.has
Expand All @@ -162,7 +162,7 @@ contentTest =
text "A Test Note!"
in
fromList [ noteLink [ title ] ]
|> toHtml { activate = (), navigate = \_ -> (), navigateUrl = \_ -> "" } []
|> toHtml { activate = Just (), navigate = \_ -> (), navigateUrl = \_ -> "" } []
|> Html.toUnstyled
|> Query.fromHtml
|> Query.has
Expand Down

0 comments on commit 778f8c3

Please sign in to comment.