Skip to content

Commit

Permalink
Add the NabvarDropdown component
Browse files Browse the repository at this point in the history
  • Loading branch information
photino committed May 14, 2024
1 parent fc2e701 commit c938ac9
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 20 deletions.
2 changes: 1 addition & 1 deletion examples/actix-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ version = "4.5.1"
default-features = false

[dependencies.serde]
version = "1.0.200"
version = "1.0.201"
features = ["derive"]

[dependencies.zino]
Expand Down
2 changes: 1 addition & 1 deletion examples/axum-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ version = "0.7.5"
default-features = false

[dependencies.serde]
version = "1.0.200"
version = "1.0.201"
features = ["derive"]

[dependencies.zino]
Expand Down
2 changes: 1 addition & 1 deletion examples/dioxus-desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ features = [
]

[dependencies.serde]
version = "1.0.200"
version = "1.0.201"
features = ["derive"]

[dependencies.zino]
Expand Down
2 changes: 1 addition & 1 deletion examples/ntex-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ version = "1.2.1"
default-features = false

[dependencies.serde]
version = "1.0.200"
version = "1.0.201"
features = ["derive"]

[dependencies.zino]
Expand Down
12 changes: 6 additions & 6 deletions zino-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,15 @@ version = "0.9.2"
optional = true

[dependencies.datafusion]
version = "37.1.0"
version = "38.0.0"
optional = true

[dependencies.dotenvy]
version = "0.15.7"
optional = true

[dependencies.fluent]
version = "0.16.0"
version = "0.16.1"
optional = true

[dependencies.http02]
Expand All @@ -255,7 +255,7 @@ version = "0.2.12"
optional = true

[dependencies.intl-memoizer]
version = "0.5.1"
version = "0.5.2"
optional = true

[dependencies.jwt-simple]
Expand Down Expand Up @@ -284,7 +284,7 @@ default-features = false
features = ["layers-tracing"]

[dependencies.phonenumber]
version = "0.3.4"
version = "0.3.5"
optional = true

[dependencies.random_word]
Expand All @@ -310,7 +310,7 @@ version = "0.32.3"
optional = true

[dependencies.sentry-tracing]
version = "0.32.2"
version = "0.32.3"
optional = true

[dependencies.serde]
Expand Down Expand Up @@ -372,7 +372,7 @@ features = [
]

[dependencies.unic-langid]
version = "0.9.4"
version = "0.9.5"
optional = true

[dependencies.utoipa]
Expand Down
43 changes: 43 additions & 0 deletions zino-core/src/extension/json_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ pub trait JsonObjectExt {
/// otherwise `None` is returned.
fn upsert(&mut self, key: impl Into<String>, value: impl Into<JsonValue>) -> Option<JsonValue>;

/// Copies values from the populated data corresponding to the key into `self`.
fn clone_from_populated(&mut self, key: &str, fields: &[&str]);

/// Extracts values from the populated data corresponding to the key and moves them to `self`.
fn extract_from_populated(&mut self, key: &str, fields: &[&str]);

/// Translates the map with the OpenAPI data.
fn translate_with_openapi(&mut self, name: &str);

Expand All @@ -245,6 +251,10 @@ pub trait JsonObjectExt {
/// Creates a new instance with the entry.
fn from_entry(key: impl Into<String>, value: impl Into<JsonValue>) -> Self;

/// Creates a new instance from the entries.
/// If the JSON value is not an object, an empty map will be returned.
fn from_entries(entries: JsonValue) -> Self;

/// Creates a new instance with a single key `entry`.
fn data_entry(value: Map) -> Self;

Expand Down Expand Up @@ -703,6 +713,30 @@ impl JsonObjectExt for Map {
self.insert(key.into(), value.into())
}

fn clone_from_populated(&mut self, key: &str, fields: &[&str]) {
let mut object = Map::new();
if let Some(map) = self.get_populated(key) {
for &field in fields {
object.upsert(field, map.get(field).cloned());
}
}
self.append(&mut object);
}

fn extract_from_populated(&mut self, key: &str, fields: &[&str]) {
let mut object = Map::new();
let populated_field = [key, "_populated"].concat();
if let Some(&mut ref mut map) = self
.get_mut(&populated_field)
.and_then(|v| v.as_object_mut())
{
for &field in fields {
object.upsert(field, map.remove(field));
}
}
self.append(&mut object);
}

#[inline]
fn translate_with_openapi(&mut self, name: &str) {
openapi::translate_model_entry(self, name);
Expand Down Expand Up @@ -743,6 +777,15 @@ impl JsonObjectExt for Map {
map
}

#[inline]
fn from_entries(entries: JsonValue) -> Self {
if let JsonValue::Object(map) = entries {
map
} else {
Map::new()
}
}

#[inline]
fn data_entry(value: Map) -> Self {
let mut map = Map::with_capacity(1);
Expand Down
2 changes: 1 addition & 1 deletion zino-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ proc-macro = true
convert_case = "0.6.0"
proc-macro2 = "1.0.82"
quote = "1.0.36"
syn = "2.0.61"
syn = "2.0.63"

[dependencies.zino-core]
path = "../zino-core"
Expand Down
2 changes: 1 addition & 1 deletion zino-dioxus/src/feedback/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn Notification(props: NotificationProps) -> Element {
position: "fixed",
top: "4rem",
right: "0.75rem",
z_index: 9999,
z_index: 99,
if props.on_close.is_some() {
button {
class: "{close_class}",
Expand Down
2 changes: 1 addition & 1 deletion zino-dioxus/src/feedback/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ where
position: "fixed",
top: "4rem",
right: "0.75rem",
z_index: 9999,
z_index: 99,
if !title.is_empty() {
div {
class: "message-header",
Expand Down
6 changes: 3 additions & 3 deletions zino-dioxus/src/navigation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ mod sidebar;

pub use dropdown::{Dropdown, DropdownProps};
pub use navbar::{
Navbar, NavbarBrand, NavbarBrandProps, NavbarCenter, NavbarCenterProps, NavbarEnd,
NavbarEndProps, NavbarItem, NavbarItemProps, NavbarLink, NavbarLinkProps, NavbarMenu,
NavbarMenuProps, NavbarProps, NavbarStart, NavbarStartProps,
Navbar, NavbarBrand, NavbarBrandProps, NavbarCenter, NavbarCenterProps, NavbarDropdown,
NavbarDropdownProps, NavbarEnd, NavbarEndProps, NavbarItem, NavbarItemProps, NavbarLink,
NavbarLinkProps, NavbarMenu, NavbarMenuProps, NavbarProps, NavbarStart, NavbarStartProps,
};
pub use pagination::{Pagination, PaginationProps};
pub use sidebar::{Sidebar, SidebarProps};
38 changes: 38 additions & 0 deletions zino-dioxus/src/navigation/navbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,44 @@ pub struct NavbarEndProps {
children: Element,
}

/// An interactive dropdown menu in the navbar.
pub fn NavbarDropdown(props: NavbarDropdownProps) -> Element {
let class = props.class;
let button_class = props.button_class;
let arrow_class = Class::check("is-arrowless", props.arrowless);
rsx! {
div {
class: "navbar-item has-dropdown is-hoverable",
a {
class: "{button_class} {arrow_class}",
{ props.button }
}
div {
class: "{class}",
{ props.children }
}
}
}
}

/// The [`NavbarDropdown`] properties struct for the configuration of the component.
#[derive(Clone, PartialEq, Props)]
pub struct NavbarDropdownProps {
/// The class attribute for the component.
#[props(into, default = "navbar-dropdown".into())]
pub class: Class,
/// A class to apply to the trigger button element.
#[props(into, default = "navbar-link".into())]
pub button_class: Class,
/// A flag to indicate whether the trigger button has an arrow or not.
#[props(default)]
pub arrowless: bool,
/// The trigger button for the dropdown menu.
pub button: Element,
/// The children to render within the component.
children: Element,
}

/// A link to navigate to another route in the navigation header.
pub fn NavbarLink(props: NavbarLinkProps) -> Element {
let class = props.class;
Expand Down
4 changes: 2 additions & 2 deletions zino-dioxus/src/prelude/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ pub use crate::{
icon::{Icon, IconText, SvgIcon},
layout::{Columns, Container, FluidContainer, MainContainer},
navigation::{
Dropdown, Navbar, NavbarBrand, NavbarCenter, NavbarEnd, NavbarItem, NavbarLink, NavbarMenu,
NavbarStart, Pagination, Sidebar,
Dropdown, Navbar, NavbarBrand, NavbarCenter, NavbarDropdown, NavbarEnd, NavbarItem,
NavbarLink, NavbarMenu, NavbarStart, Pagination, Sidebar,
},
theme::Theme,
typography::{Card, FixedWidthSpan, Markdown},
Expand Down
2 changes: 1 addition & 1 deletion zino-extra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ version = "0.12.3"
optional = true

[dependencies.parking_lot]
version = "0.12.1"
version = "0.12.2"
optional = true

[dependencies.printpdf]
Expand Down
2 changes: 1 addition & 1 deletion zino-model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ edition = []
tracing = "0.1.40"

[dependencies.serde]
version = "1.0.200"
version = "1.0.201"
features = ["derive"]

[dependencies.sqlx]
Expand Down

0 comments on commit c938ac9

Please sign in to comment.