Open
Description
Currently, animation
leaves off the last parameter that corresponds to animation-play-state
. It would be nice if the API included this as well. I have a forked version where I've incorporated that and it works fine - the code is pasted below. It uses AnimationPlayState
for the type and then increases the number of arguments to animation
by one.
Would folks be interested in incorporating this into the library?
module CSS.Hack.Animation where
import Prelude
import CSS.Property (class Val, Value, value)
import CSS.String (class IsString, fromString)
import CSS.Stylesheet (CSS, key)
import CSS.Time (Time)
import CSS.Transition (TimingFunction)
import Data.Foldable (for_)
import Data.Tuple.Nested (tuple8)
newtype AnimationDirection = AnimationDirection Value
derive instance eqAnimationDirection :: Eq AnimationDirection
derive instance ordAnimationDirection :: Ord AnimationDirection
instance valAnimationDirection :: Val AnimationDirection where
value (AnimationDirection v) = v
normalAnimationDirection :: AnimationDirection
normalAnimationDirection = AnimationDirection $ fromString "normal"
alternate :: AnimationDirection
alternate = AnimationDirection $ fromString "alternate"
reverse :: AnimationDirection
reverse = AnimationDirection $ fromString "reverse"
alternateReverse :: AnimationDirection
alternateReverse = AnimationDirection $ fromString "alternate-reverse"
newtype IterationCount = IterationCount Value
derive instance eqIterationCount :: Eq IterationCount
derive instance ordIterationCount :: Ord IterationCount
instance valIterationCount :: Val IterationCount where
value (IterationCount v) = v
infinite :: IterationCount
infinite = IterationCount $ fromString "infinite"
iterationCount :: Number -> IterationCount
iterationCount = IterationCount <<< value
newtype FillMode = FillMode Value
derive instance eqFillMode :: Eq FillMode
derive instance ordFillMode :: Ord FillMode
instance valFillMode :: Val FillMode where
value (FillMode v) = v
forwards :: FillMode
forwards = FillMode $ fromString "forwards"
backwards :: FillMode
backwards = FillMode $ fromString "backwards"
data AnimationPlayState = APaused | ARunning | AInitial
instance valAnimationState :: Val AnimationPlayState where
value = fromString <<< case _ of
APaused -> "paused"
ARunning -> "running"
AInitial -> "initial"
animation :: AnimationName -> Time -> TimingFunction -> Time -> IterationCount -> AnimationDirection -> FillMode -> AnimationPlayState -> CSS
animation p de f du i di fm ps = do
for_ animationKeys \k ->
key (fromString k) (tuple8 p de f du i di fm ps)
where
animationKeys =
[ "animation"
, "-webkit-animation"
, "-moz-animation"
, "-o-animation"
]
newtype AnimationName = AnimationName Value
derive instance eqAnimationName :: Eq AnimationName
derive instance ordAnimationName :: Ord AnimationName
instance valAnimationName :: Val AnimationName where
value (AnimationName v) = v
instance isStringAnimationName :: IsString AnimationName where
fromString = AnimationName <<< fromString