mirror of
https://github.com/adoyle0/thaw.git
synced 2025-02-02 16:44:15 -05:00
✨ feat: add NavBar component
This commit is contained in:
parent
275798a64b
commit
1e57639490
8 changed files with 126 additions and 3 deletions
|
@ -17,7 +17,7 @@ leptos = { version = "0.3.0", features = ["stable"] }
|
||||||
stylers = "0.3.1"
|
stylers = "0.3.1"
|
||||||
web-sys = { version = "0.3.62", features = ["DomRect"] }
|
web-sys = { version = "0.3.62", features = ["DomRect"] }
|
||||||
leptos_dom = { version = "0.3.0" }
|
leptos_dom = { version = "0.3.0" }
|
||||||
leptos_icons = { version = "0.0.10", features = ["AiCloseOutlined", "AiCheckOutlined"] }
|
leptos_icons = { version = "0.0.10", features = ["AiCloseOutlined", "AiCheckOutlined", "AiLeftOutlined"] }
|
||||||
wasm-bindgen = "0.2.85"
|
wasm-bindgen = "0.2.85"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
|
|
|
@ -28,6 +28,9 @@ pub fn App(cx: Scope) -> impl IntoView {
|
||||||
<Route path="/tabbar" view=move |cx| view! {cx,
|
<Route path="/tabbar" view=move |cx| view! {cx,
|
||||||
<MobilePage path="/mobile/tabbar" />
|
<MobilePage path="/mobile/tabbar" />
|
||||||
} />
|
} />
|
||||||
|
<Route path="/nav-bar" view=move |cx| view! {cx,
|
||||||
|
<MobilePage path="/mobile/nav-bar" />
|
||||||
|
} />
|
||||||
<Route path="/input" view=move |cx| view! {cx,
|
<Route path="/input" view=move |cx| view! {cx,
|
||||||
<InputPage />
|
<InputPage />
|
||||||
} />
|
} />
|
||||||
|
@ -43,6 +46,9 @@ pub fn App(cx: Scope) -> impl IntoView {
|
||||||
<Route path="/tabbar" view=move |cx| view! {cx,
|
<Route path="/tabbar" view=move |cx| view! {cx,
|
||||||
<TabbarPage />
|
<TabbarPage />
|
||||||
} />
|
} />
|
||||||
|
<Route path="/nav-bar" view=move |cx| view! {cx,
|
||||||
|
<NavBarPage />
|
||||||
|
} />
|
||||||
</Routes>
|
</Routes>
|
||||||
</Router>
|
</Router>
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use leptos_router::{use_location, Outlet, use_navigate};
|
use leptos_router::{use_location, use_navigate, Outlet};
|
||||||
use melt_ui::*;
|
use melt_ui::*;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ pub fn ComponentsPage(cx: Scope) -> impl IntoView {
|
||||||
<MenuItem key="input" label="input" />
|
<MenuItem key="input" label="input" />
|
||||||
<MenuItem key="image" label="image" />
|
<MenuItem key="image" label="image" />
|
||||||
<MenuItem key="modal" label="madal" />
|
<MenuItem key="modal" label="madal" />
|
||||||
|
<MenuItem key="nav-bar" label="nav-bar" />
|
||||||
</Menu>
|
</Menu>
|
||||||
</aside>
|
</aside>
|
||||||
<main>
|
<main>
|
||||||
|
|
|
@ -5,6 +5,7 @@ mod input;
|
||||||
mod menu;
|
mod menu;
|
||||||
mod mobile;
|
mod mobile;
|
||||||
mod modal;
|
mod modal;
|
||||||
|
mod nav_bar;
|
||||||
mod slider;
|
mod slider;
|
||||||
mod tabbar;
|
mod tabbar;
|
||||||
|
|
||||||
|
@ -15,5 +16,6 @@ pub use input::*;
|
||||||
pub use menu::*;
|
pub use menu::*;
|
||||||
pub use mobile::*;
|
pub use mobile::*;
|
||||||
pub use modal::*;
|
pub use modal::*;
|
||||||
|
pub use nav_bar::*;
|
||||||
pub use slider::*;
|
pub use slider::*;
|
||||||
pub use tabbar::*;
|
pub use tabbar::*;
|
||||||
|
|
11
examples/basic/src/pages/nav_bar/mod.rs
Normal file
11
examples/basic/src/pages/nav_bar/mod.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
use leptos::*;
|
||||||
|
use melt_ui::mobile::NavBar;
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn NavBarPage(cx: Scope) -> impl IntoView {
|
||||||
|
view! { cx,
|
||||||
|
<div style="height: 100vh; background: #f5f5f5">
|
||||||
|
<NavBar title="Home" left_arrow=true left_text="back" right_text="add"/>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,5 @@
|
||||||
mod tabbar;
|
mod tabbar;
|
||||||
|
mod nav_bar;
|
||||||
|
|
||||||
pub use tabbar::*;
|
pub use tabbar::*;
|
||||||
|
pub use nav_bar::*;
|
61
src/mobile/nav_bar/mod.rs
Normal file
61
src/mobile/nav_bar/mod.rs
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
use crate::utils::mount_style::mount_style;
|
||||||
|
use leptos::*;
|
||||||
|
use leptos_icons::*;
|
||||||
|
use stylers::style_sheet_str;
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn NavBar(
|
||||||
|
cx: Scope,
|
||||||
|
#[prop(optional, into)] title: MaybeSignal<String>,
|
||||||
|
#[prop(optional, into)] left_arrow: MaybeSignal<bool>,
|
||||||
|
#[prop(optional, into)] left_text: MaybeSignal<String>,
|
||||||
|
#[prop(optional, into)] right_text: MaybeSignal<String>,
|
||||||
|
) -> impl IntoView {
|
||||||
|
let class_name = mount_style("nav-bar", || style_sheet_str!("./src/mobile/nav_bar/nav-bar.css"));
|
||||||
|
|
||||||
|
view! { cx, class=class_name,
|
||||||
|
<div class="melt-nav-bar">
|
||||||
|
{
|
||||||
|
move || {
|
||||||
|
let left_text = left_text.get();
|
||||||
|
if left_arrow.get() || !left_text.is_empty() {
|
||||||
|
view! { cx, class=class_name,
|
||||||
|
<div class="melt-nav-bar__left">
|
||||||
|
{
|
||||||
|
if left_arrow.get() {
|
||||||
|
view! { cx,
|
||||||
|
<Icon icon=AiIcon::AiLeftOutlined/>
|
||||||
|
}.into()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{ left_text }
|
||||||
|
</div>
|
||||||
|
}.into()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
<div class="melt-nav-bar__center">
|
||||||
|
{ move || title.get() }
|
||||||
|
</div>
|
||||||
|
{
|
||||||
|
move || {
|
||||||
|
let right_text = right_text.get();
|
||||||
|
if !right_text.is_empty() {
|
||||||
|
view! { cx, class=class_name,
|
||||||
|
<div class="melt-nav-bar__right">
|
||||||
|
{ right_text }
|
||||||
|
</div>
|
||||||
|
}.into()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
40
src/mobile/nav_bar/nav-bar.css
Normal file
40
src/mobile/nav_bar/nav-bar.css
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
.melt-nav-bar {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
height: 46px;
|
||||||
|
line-height: 46px;
|
||||||
|
background-color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.melt-nav-bar__center {
|
||||||
|
max-width: 60%;
|
||||||
|
font-weight: 600;
|
||||||
|
text-align: center;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.melt-nav-bar__left {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
padding: 0 12px;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.melt-nav-bar__right {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
right: 0;
|
||||||
|
padding: 0 12px;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue