Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Background.blur #239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Element/Background.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Element.Background exposing
( color, gradient
, image, uncropped, tiled, tiledX, tiledY
, blur
)

{-|
Expand All @@ -14,6 +15,10 @@ module Element.Background exposing

**Note** if you want more control over a background image than is provided here, you should try just using a normal `Element.image` with something like `Element.behindContent`.

# Effects

@docs blur

-}

import Element exposing (Attr, Attribute, Color)
Expand Down Expand Up @@ -126,6 +131,16 @@ gradient { angle, steps } =
"background-image"
("linear-gradient(" ++ (String.join ", " <| (String.fromFloat angle ++ "rad") :: List.map Internal.formatColor steps) ++ ")")

{-| Creates a blurred background effect.

-}
blur : Float -> Attribute msg
blur radius =
Internal.BatchAttr
[ VirtualDom.style "-webkit-backdrop-filter" ("blur(" ++ String.fromFloat radius ++ "px)")
, VirtualDom.style "backdrop-filter" ("blur(" ++ String.fromFloat radius ++ "px)")
]



-- {-| -}
Expand Down
13 changes: 13 additions & 0 deletions src/Internal/Model.elm
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ type alias Angle =
type Attribute aligned msg
= NoAttribute
| Attr (VirtualDom.Attribute msg)
| BatchAttr (List (VirtualDom.Attribute msg))
| Describe Description
-- invalidation key and literal class
| Class Flag String
Expand Down Expand Up @@ -934,6 +935,9 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
Attr actualAttribute ->
gatherAttrRecursive classes node has transform styles (actualAttribute :: attrs) children remaining

BatchAttr actualAttributes ->
gatherAttrRecursive classes node has transform styles (actualAttributes ++ attrs) children remaining

StyleClass flag style ->
if Flag.present flag has then
gatherAttrRecursive classes node has transform styles attrs children remaining
Expand Down Expand Up @@ -1859,6 +1863,9 @@ filter attrs =
Attr attr ->
( x :: found, has )

BatchAttr domAttrs ->
( x :: found, has )

StyleClass _ style ->
( x :: found, has )

Expand Down Expand Up @@ -3376,6 +3383,9 @@ mapAttr fn attr =
Attr htmlAttr ->
Attr (VirtualDom.mapAttribute fn htmlAttr)

BatchAttr htmlAttrs ->
BatchAttr (List.map (VirtualDom.mapAttribute fn) htmlAttrs)

TransformComponent fl trans ->
TransformComponent fl trans

Expand Down Expand Up @@ -3414,6 +3424,9 @@ mapAttrFromStyle fn attr =
Attr htmlAttr ->
Attr (VirtualDom.mapAttribute fn htmlAttr)

BatchAttr htmlAttrs ->
BatchAttr (List.map (VirtualDom.mapAttribute fn) htmlAttrs)

TransformComponent fl trans ->
TransformComponent fl trans

Expand Down