whisker_css/prop/
animation.rs1use crate::css::Css;
4use crate::data_type::Time;
5use crate::data_type_ext::EasingFunction;
6use crate::keyword::{
7 AnimationDirection, AnimationFillMode, AnimationIterationCount, AnimationPlayState,
8};
9
10impl Css {
11 pub fn animation_name(self, name: impl Into<String>) -> Self {
14 self.push_raw("animation-name", name)
16 }
17
18 pub fn animation_duration(self, v: Time) -> Self {
21 self.push("animation-duration", v)
22 }
23
24 pub fn animation_timing_function(self, v: EasingFunction) -> Self {
27 self.push("animation-timing-function", v)
28 }
29
30 pub fn animation_delay(self, v: Time) -> Self {
33 self.push("animation-delay", v)
34 }
35
36 pub fn animation_iteration_count(self, v: AnimationIterationCount) -> Self {
39 self.push("animation-iteration-count", v)
40 }
41
42 pub fn animation_direction(self, v: AnimationDirection) -> Self {
45 self.push("animation-direction", v)
46 }
47
48 pub fn animation_fill_mode(self, v: AnimationFillMode) -> Self {
51 self.push("animation-fill-mode", v)
52 }
53
54 pub fn animation_play_state(self, v: AnimationPlayState) -> Self {
57 self.push("animation-play-state", v)
58 }
59}
60
61#[cfg(test)]
62mod tests {
63 use crate::data_type_ext::EasingFunction;
64 use crate::ext::*;
65 use crate::keyword::*;
66 use crate::Css;
67
68 #[test]
69 fn animation_full_set() {
70 let s = Css::new()
71 .animation_name("spin")
72 .animation_duration(2.s())
73 .animation_timing_function(EasingFunction::Linear)
74 .animation_delay(100.ms())
75 .animation_iteration_count(AnimationIterationCount::Infinite)
76 .animation_direction(AnimationDirection::Alternate)
77 .animation_fill_mode(AnimationFillMode::Forwards)
78 .animation_play_state(AnimationPlayState::Running);
79 assert_eq!(
80 s.to_string(),
81 "animation-name: spin; animation-duration: 2s; animation-timing-function: linear; animation-delay: 100ms; animation-iteration-count: infinite; animation-direction: alternate; animation-fill-mode: forwards; animation-play-state: running;"
82 );
83 }
84
85 #[test]
86 fn iteration_count_explicit() {
87 let s = Css::new().animation_iteration_count(AnimationIterationCount::Count(3.0));
88 assert_eq!(s.to_string(), "animation-iteration-count: 3;");
89 }
90}