From: Dominik Csapak <d.csapak@proxmox.com>
To: yew-devel@lists.proxmox.com
Subject: [yew-devel] [PATCH yew-widget-toolkit] touch: fab menu: intoduce sheet variant
Date: Tue, 1 Jul 2025 08:57:25 +0200 [thread overview]
Message-ID: <20250701065725.281896-1-d.csapak@proxmox.com> (raw)
which is also the new default. Exposing the items via a sheet (bottom
SideDialog) make them more readable and accessible in more situations.
Keep the old style via the `Material3` variant.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
| 125 +++++++++++++++++++++++++++++-------------
1 file changed, 87 insertions(+), 38 deletions(-)
--git a/src/touch/fab_menu.rs b/src/touch/fab_menu.rs
index 6a4f3f7..db97539 100644
--- a/src/touch/fab_menu.rs
+++ b/src/touch/fab_menu.rs
@@ -1,14 +1,24 @@
use yew::prelude::*;
-use crate::css::ColorScheme;
-use crate::props::{ContainerBuilder, EventSubscriber, WidgetBuilder};
-use crate::widget::{Button, Container};
+use crate::css::{self, ColorScheme};
+use crate::props::{ContainerBuilder, CssPaddingBuilder, EventSubscriber, WidgetBuilder};
+use crate::touch::{SideDialog, SideDialogController};
+use crate::tr;
+use crate::widget::{Button, Column, Container};
use pwt_macros::{builder, widget};
use super::fab::FabSize;
use super::Fab;
+/// [FabMenu] variant
+#[derive(Copy, Clone, PartialEq, Debug, Default)]
+pub enum FabMenuVariant {
+ #[default]
+ Sheet,
+ Material3,
+}
+
/// [FabMenu] direction.
#[derive(Copy, Clone, PartialEq)]
pub enum FabMenuDirection {
@@ -90,6 +100,11 @@ pub struct FabMenu {
#[builder]
pub align: FabMenuAlign,
+ /// Menu variant
+ #[prop_or_default]
+ #[builder]
+ pub variant: FabMenuVariant,
+
/// Child buttons, which popup when main button is pressed.
///
/// We currently support up to 5 children.
@@ -193,51 +208,85 @@ impl Component for PwtFabMenu {
FabMenuColor::Tertiary => (ColorScheme::Tertiary, ColorScheme::TertiaryContainer),
};
+ let (fab_size, fab_classes) = match (props.variant, self.show_items) {
+ (FabMenuVariant::Material3, true) => (FabSize::Small, classes!(close_color, "rounded")),
+ (_, false) | (FabMenuVariant::Sheet, true) => (props.size, classes!()),
+ };
+
let main_button = Fab::new(main_icon_class)
- .size(if self.show_items {
- FabSize::Small
- } else {
- props.size
- })
+ .size(fab_size)
.class(props.main_button_class.clone())
- .class(if self.show_items { close_color } else { color })
- .class(self.show_items.then_some("rounded"))
+ .class(fab_classes)
.on_activate(ctx.link().callback(|_| Msg::Toggle));
- let mut container = Container::new()
- .with_std_props(&props.std_props)
- .listeners(&props.listeners)
- .class("pwt-fab-menu-container")
- .class(self.show_items.then_some("active"))
- .onkeydown({
- let link = ctx.link().clone();
- move |event: KeyboardEvent| {
- if event.key() == "Escape" {
- link.send_message(Msg::Close)
- }
- }
- });
-
- for (i, child) in props.children.iter().enumerate() {
+ let btn_class = match props.variant {
+ FabMenuVariant::Sheet => classes!("pwt-button-text"),
+ FabMenuVariant::Material3 => classes!(color, "pwt-fab-menu-item", "medium"),
+ };
+
+ let children = props.children.iter().enumerate().filter_map(|(i, child)| {
if i >= 5 {
log::error!("FabMenu only supports 5 child buttons.");
- break;
+ return None;
}
let on_activate = child.on_activate.clone();
let link = ctx.link().clone();
- let child = Button::new(child.text.clone())
- .icon_class(child.icon.clone())
- .class("medium")
- .class(color)
- .class("pwt-fab-menu-item")
- .on_activate(move |event| {
- link.send_message(Msg::Toggle);
- on_activate.emit(event);
- });
- container.add_child(child);
- }
+ Some(
+ Button::new(child.text.clone())
+ .icon_class(child.icon.clone())
+ .class(btn_class.clone())
+ .on_activate(move |event| {
+ link.send_message(Msg::Toggle);
+ on_activate.emit(event);
+ })
+ .into(),
+ )
+ });
+
+ let container: Option<Html> = match props.variant {
+ FabMenuVariant::Sheet => {
+ let controller = SideDialogController::new();
+ self.show_items.then_some(
+ SideDialog::new()
+ .controller(controller.clone())
+ .location(crate::touch::SideDialogLocation::Bottom)
+ .on_close(ctx.link().callback(|_| Msg::Toggle))
+ .with_child(
+ Column::new()
+ .class(css::FlexFit)
+ .padding(2)
+ .gap(1)
+ .children(children)
+ .with_child(html!(<hr />))
+ .with_child(
+ Button::new(tr!("Cancel"))
+ .class("pwt-button-text")
+ .on_activate(move |_| controller.close_dialog()),
+ ),
+ )
+ .into(),
+ )
+ }
+ FabMenuVariant::Material3 => Some(
+ Container::new()
+ .with_std_props(&props.std_props)
+ .listeners(&props.listeners)
+ .class("pwt-fab-menu-container")
+ .class(self.show_items.then_some("active"))
+ .onkeydown({
+ let link = ctx.link().clone();
+ move |event: KeyboardEvent| {
+ if event.key() == "Escape" {
+ link.send_message(Msg::Close)
+ }
+ }
+ })
+ .children(children)
+ .into(),
+ ),
+ };
Container::new()
.with_std_props(&props.std_props)
@@ -261,7 +310,7 @@ impl Component for PwtFabMenu {
})
.with_child(main_button),
)
- .with_child(container)
+ .with_optional_child(container)
.into()
}
}
--
2.39.5
_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel
next reply other threads:[~2025-07-01 6:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-01 6:57 Dominik Csapak [this message]
2025-07-01 9:24 ` [yew-devel] applied: " Dietmar Maurer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250701065725.281896-1-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=yew-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.