1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use dioxus::prelude::*;
use dioxus_router::prelude::*;
use freya_components::{ButtonStatus, ScrollView};
use freya_elements::elements as dioxus_elements;
use freya_hooks::use_get_theme;

use crate::Route;

#[derive(Props)]
pub struct TabsBarProps<'a> {
    pub children: Element<'a>,
}

#[allow(non_snake_case)]
pub fn TabsBar<'a>(cx: Scope<'a, TabsBarProps<'a>>) -> Element<'a> {
    render!(
        ScrollView {
            direction: "horizontal",
            height: "35",
            width: "100%",
            &cx.props.children
        }
    )
}

#[derive(Props)]
pub struct TabButtonProps<'a> {
    pub to: Route,
    pub label: &'a str,
}

#[allow(non_snake_case)]
pub fn TabButton<'a>(cx: Scope<'a, TabButtonProps<'a>>) -> Element<'a> {
    let router = use_navigator(cx);
    let theme = use_get_theme(cx);
    let status = use_state(cx, ButtonStatus::default);

    let onclick = |_| {
        router.replace(cx.props.to.clone());
    };

    let onmouseover = move |_| {
        if *status.get() != ButtonStatus::Hovering {
            status.set(ButtonStatus::Hovering);
        }
    };

    let onmouseleave = move |_| {
        status.set(ButtonStatus::default());
    };

    let background = match *status.get() {
        ButtonStatus::Hovering => theme.button.hover_background,
        ButtonStatus::Idle => theme.button.background,
    };
    let color = theme.button.font_theme.color;
    let border_fill = theme.button.border_fill;
    let content = cx.props.label;

    render!(
        rect {
            margin: "2",
            overflow: "clip",
            background: "{background}",
            onclick: onclick,
            onmouseover: onmouseover,
            onmouseleave: onmouseleave,
            corner_radius: "7",
            height: "100%",
            color: "{color}",
            padding: "6 14",
            shadow: "0 4 5 0 rgb(0, 0, 0, 30)",
            border: "1 solid {border_fill}",
            main_align: "center",
            label {
                content
            }
        }
    )
}