dioxus_element_plug/components/
watermark.rs1use dioxus::prelude::*;
2
3#[derive(Props, Clone, PartialEq)]
5pub struct WatermarkProps {
6 #[props(default)]
7 pub children: Element,
8
9 pub content: String,
11
12 #[props(default = 16)]
14 pub font_size: u32,
15
16 #[props(default = "rgba(0,0,0,0.15)".to_string())]
18 pub font_color: String,
19
20 #[props(default = 100)]
22 pub gap_x: u32,
23
24 #[props(default = 100)]
26 pub gap_y: u32,
27
28 #[props(default = -22)]
30 pub rotate: i32,
31
32 #[props(default = 9)]
34 pub z_index: u32,
35
36 #[props(default)]
37 pub class: Option<String>,
38
39 #[props(default)]
40 pub style: Option<String>,
41}
42
43#[component]
45pub fn Watermark(props: WatermarkProps) -> Element {
46 let watermark_style = format!(
47 "position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: {}; \
48 background-image: repeating-linear-gradient({}deg, transparent, transparent {}px, transparent {}px), \
49 repeating-linear-gradient(0deg, transparent, transparent {}px, transparent {}px); \
50 pointer-events: none; opacity: 0.5;",
51 props.z_index, props.rotate, props.gap_y, props.gap_y, props.gap_x, props.gap_x
52 );
53
54 let font_size = props.font_size;
55 let font_color = props.font_color.clone();
56
57 rsx! {
58 div {
59 class: "el-watermark {props.class.clone().unwrap_or_default()}",
60 style: "position: relative; {props.style.clone().unwrap_or_default()}",
61 {props.children}
62 div {
63 class: "el-watermark__overlay",
64 style: "{watermark_style}",
65 span {
66 style: "font-size: {font_size}px; color: {font_color}; opacity: 0.3;",
67 "{props.content}"
68 }
69 }
70 }
71 }
72}