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

Adds prefers-reduced-motion media query #580

Open
wants to merge 3 commits 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
42 changes: 42 additions & 0 deletions src/Css/Media.elm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Css.Media exposing
, Fine, Coarse, fine, coarse, pointer, anyPointer, CanHover, canHover
, hover, anyHover
, InitialOnly, Enabled, initialOnly, enabled, scripting
, noPreference, prefersReducedMotion, reduce
)

{-| Functions for building [`@media` queries](https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries).
Expand Down Expand Up @@ -942,6 +943,47 @@ scripting value =
feature "scripting" value


{-| -}
type alias ReducedMotionPreference a =
{ a | value : String, reducedMotionPreference : Compatible }


{-| -}
type alias Reduce =
{ value : String, reducedMotionPreference : Compatible }


{-| -}
type alias NoPreference =
{ value : String, reducedMotionPreference : Compatible }


{-| The value [`reduce`](https://drafts.csswg.org/mediaqueries-5/#prefers-reduced-motion).
-}
reduce : Reduce
reduce =
{ value = "reduce", reducedMotionPreference = Compatible }


{-| The value [`no-preference`](https://drafts.csswg.org/mediaqueries-5/#prefers-reduced-motion).
-}
noPreference : NoPreference
noPreference =
{ value = "no-preference", reducedMotionPreference = Compatible }


{-| Media feature [`prefers-reduced-motion`](https://drafts.csswg.org/mediaqueries-5/#prefers-reduced-motion).
Queries the if the user agent's has a preference for less motion on the page.
Accepts `reduce` or `noPreference`.

media (prefersReducedMotion reduce) [ a [ hover [ transform none ] ] ]

-}
prefersReducedMotion : ReducedMotionPreference a -> Expression
prefersReducedMotion value =
feature "prefers-reduced-motion" value



-- PRIVATE HELPERS --

Expand Down
4 changes: 4 additions & 0 deletions tests/Media.elm
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ mediaFeatures =
, ( scripting initialOnly, "initial-only" )
, ( scripting Media.enabled, "enabled" )
]
, testFeature "prefers-reduced-motion"
[ ( prefersReducedMotion reduce, "reduce" )
, ( prefersReducedMotion noPreference, "no-preference" )
]
]


Expand Down