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

feat: add animation timing function property #592

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
10 changes: 10 additions & 0 deletions src/Css.elm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ module Css exposing
, animationDelay
, animationDuration
, animationIterationCount
, animationTimingFunction
, FontSize, ColorValue, ColorStop, IntOrAuto
, thin, thick, blink
)
Expand Down Expand Up @@ -462,6 +463,7 @@ functions let you define custom properties and selectors, respectively.
@docs animationDelay
@docs animationDuration
@docs animationIterationCount
@docs animationTimingFunction


# Types
Expand Down Expand Up @@ -2865,6 +2867,14 @@ animationIterationCount arg =
prop1 "animation-iteration-count" arg


{-| An [`animation-timing-function`](https://developer.mozilla.org/en-US/docs/Web/CSS/animation-timing-function)
) property.
-}
animationTimingFunction : Css.Internal.TimingFunction -> Style
animationTimingFunction arg =
prop1 "animation-timing-function" { value = Css.Internal.timingFunctionToString arg }


{-| Sets [`transform`](https://developer.mozilla.org/en-US/docs/Web/CSS/transform)
with a series of transform-functions. If an empty list is provided, the CSS
output will be `none`, as if to state directly that the set of transforms
Expand Down
105 changes: 104 additions & 1 deletion src/Css/Internal.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Css.Internal exposing (AnimationProperty(..), ColorValue, ExplicitLength, IncompatibleUnits(..), Length, LengthOrAutoOrCoverOrContain, compileKeyframes, getOverloadedProperty, lengthConverter, lengthForOverloadedProperty)
module Css.Internal exposing (AnimationProperty(..), ColorValue, ExplicitLength, IncompatibleUnits(..), Length, LengthOrAutoOrCoverOrContain, TimingFunction, compileKeyframes, cubicBezier, ease, easeIn, easeInOut, easeOut, getOverloadedProperty, lengthConverter, lengthForOverloadedProperty, linear, stepEnd, stepStart, timingFunctionToString)

import Css.Preprocess as Preprocess exposing (Style)
import Css.String
Expand Down Expand Up @@ -53,6 +53,109 @@ type AnimationProperty
= Property String


type TimingFunction
= Ease
| Linear
| EaseIn
| EaseOut
| EaseInOut
| StepStart
| StepEnd
| CubicBezier Float Float Float Float


{-| CSS ease timing function
-}
ease : TimingFunction
ease =
Ease


{-| CSS linear timing function
-}
linear : TimingFunction
linear =
Linear


{-| CSS easeIn timing function
-}
easeIn : TimingFunction
easeIn =
EaseIn


{-| CSS easeOut timing function
-}
easeOut : TimingFunction
easeOut =
EaseOut


{-| CSS easeInOut timing function
-}
easeInOut : TimingFunction
easeInOut =
EaseInOut


{-| CSS stepStart timing function
-}
stepStart : TimingFunction
stepStart =
StepStart


{-| CSS stepEnd timing function
-}
stepEnd : TimingFunction
stepEnd =
StepEnd


{-| CSS cubicBezier timing function
-}
cubicBezier : Float -> Float -> Float -> Float -> TimingFunction
cubicBezier f1 f2 f3 f4 =
CubicBezier f1 f2 f3 f4


timingFunctionToString : TimingFunction -> String
timingFunctionToString tf =
case tf of
Ease ->
"ease"

Linear ->
"linear"

EaseIn ->
"ease-in"

EaseOut ->
"ease-out"

EaseInOut ->
"ease-in-out"

StepStart ->
"step-start"

StepEnd ->
"step-end"

CubicBezier float float2 float3 float4 ->
"cubic-bezier("
++ String.fromFloat float
++ " , "
++ String.fromFloat float2
++ " , "
++ String.fromFloat float3
++ " , "
++ String.fromFloat float4
++ ")"


{-| Used only for compiling keyframes. This does not compile to valid standalone
CSS, but rather to the body of an @keyframes at-rule.

Expand Down
69 changes: 13 additions & 56 deletions src/Css/Transitions.elm
Original file line number Diff line number Diff line change
Expand Up @@ -65,73 +65,66 @@ An example of this would be the [`background3`](#background3), [`background2`](#
-}

import Css
import Css.Internal


type TimingFunction
= Ease
| Linear
| EaseIn
| EaseOut
| EaseInOut
| StepStart
| StepEnd
| CubicBezier Float Float Float Float
type alias TimingFunction
= Css.Internal.TimingFunction


{-| CSS ease timing function
-}
ease : TimingFunction
ease =
Ease
Css.Internal.ease


{-| CSS linear timing function
-}
linear : TimingFunction
linear =
Linear
Css.Internal.linear


{-| CSS easeIn timing function
-}
easeIn : TimingFunction
easeIn =
EaseIn
Css.Internal.easeIn


{-| CSS easeOut timing function
-}
easeOut : TimingFunction
easeOut =
EaseOut
Css.Internal.easeOut


{-| CSS easeInOut timing function
-}
easeInOut : TimingFunction
easeInOut =
EaseInOut
Css.Internal.easeInOut


{-| CSS stepStart timing function
-}
stepStart : TimingFunction
stepStart =
StepStart
Css.Internal.stepStart


{-| CSS stepEnd timing function
-}
stepEnd : TimingFunction
stepEnd =
StepEnd
Css.Internal.stepEnd


{-| CSS cubicBezier timing function
-}
cubicBezier : Float -> Float -> Float -> Float -> TimingFunction
cubicBezier f1 f2 f3 f4 =
CubicBezier f1 f2 f3 f4
cubicBezier =
Css.Internal.cubicBezier


{-| This describes all of the aspects of a [CSS transition](https://developer.mozilla.org/en-US/docs/Web/CSS/transition), which will then be
Expand Down Expand Up @@ -2860,42 +2853,6 @@ timeToString time =
String.fromFloat time ++ "ms"


timingFunctionToString : TimingFunction -> String
timingFunctionToString tf =
case tf of
Ease ->
"ease"

Linear ->
"linear"

EaseIn ->
"ease-in"

EaseOut ->
"ease-out"

EaseInOut ->
"ease-in-out"

StepStart ->
"step-start"

StepEnd ->
"step-end"

CubicBezier float float2 float3 float4 ->
"cubic-bezier("
++ String.fromFloat float
++ " , "
++ String.fromFloat float2
++ " , "
++ String.fromFloat float3
++ " , "
++ String.fromFloat float4
++ ")"


{-| This function is used to batch up a list of supplied transitions that have been created (using the property functions listed below) and then produce a [`Css.Style`](http://package.elm-lang.org/packages/rtfeldman/elm-css/latest/Css#Style).
This can then be used with other functions (such as [`Html.Styled.Attributes.css`](http://package.elm-lang.org/packages/rtfeldman/elm-css/latest/Html-Styled-Attributes#css)) to add the desired transitions to elements / classes as required.
-}
Expand All @@ -2914,7 +2871,7 @@ transition options =
|> Maybe.withDefault ""
)
++ " "
++ (Maybe.map timingFunctionToString timing
++ (Maybe.map Css.Internal.timingFunctionToString timing
|> Maybe.withDefault ""
)
++ ","
Expand Down