rustyle_css/
view_transitions.rs1use crate::style::register_global_style;
6
7#[derive(Clone, Debug)]
9pub struct ViewTransitionName(pub String);
10
11impl ViewTransitionName {
12 pub fn new(name: &str) -> Self {
14 Self(name.to_string())
15 }
16
17 pub fn to_css(&self) -> String {
19 format!("view-transition-name: {};", self.0)
20 }
21}
22
23#[derive(Clone, Debug)]
25pub struct ViewTransition {
26 pub name: Option<String>,
27 pub duration: Option<String>,
28 pub timing_function: Option<String>,
29}
30
31impl ViewTransition {
32 pub fn new() -> Self {
34 Self {
35 name: None,
36 duration: None,
37 timing_function: None,
38 }
39 }
40
41 pub fn name(mut self, name: &str) -> Self {
43 self.name = Some(name.to_string());
44 self
45 }
46
47 pub fn duration(mut self, duration: &str) -> Self {
49 self.duration = Some(duration.to_string());
50 self
51 }
52
53 pub fn timing_function(mut self, timing: &str) -> Self {
55 self.timing_function = Some(timing.to_string());
56 self
57 }
58
59 pub fn to_css(&self) -> String {
61 let mut props = Vec::new();
62
63 if let Some(ref name) = self.name {
64 props.push(format!("view-transition-name: {};", name));
65 }
66
67 if let Some(ref duration) = self.duration {
68 props.push(format!("view-transition-duration: {};", duration));
69 }
70
71 if let Some(ref timing) = self.timing_function {
72 props.push(format!("view-transition-timing-function: {};", timing));
73 }
74
75 props.join(" ")
76 }
77}
78
79impl Default for ViewTransition {
80 fn default() -> Self {
81 Self::new()
82 }
83}
84
85pub fn register_view_transition(css: &str) {
87 register_global_style(css);
88}