]> git.proxmox.com Git - ui/proxmox-yew-widget-toolkit.git/commitdiff
add new list tile widget
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 27 Nov 2024 11:56:51 +0000 (12:56 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 27 Nov 2024 11:56:51 +0000 (12:56 +0100)
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
src/widget/list_tile.rs [new file with mode: 0644]
src/widget/mod.rs

diff --git a/src/widget/list_tile.rs b/src/widget/list_tile.rs
new file mode 100644 (file)
index 0000000..9a595f5
--- /dev/null
@@ -0,0 +1,68 @@
+use std::borrow::Cow;
+
+use yew::prelude::*;
+use yew::virtual_dom::VTag;
+
+use crate::props::{ListenersWrapper, WidgetStdProps};
+
+use pwt_macros::{builder, widget};
+
+/// List tile. A container with flex row layout.
+///
+/// ```
+/// # use pwt::prelude::*;
+/// # use pwt::widget::ListTile;
+/// # fn create_list_tile() -> ListTile {
+///   ListTile::new()
+///       .with_child(html!{<span>{"A simple list tile"}</span>})
+///       .with_child(html!{<span>{"second column"}</span>})
+///       .interactive(true)
+///       .disabled(false)
+///       .style("justify-content", "space-between")
+///       .class(pwt::css::ColorScheme::Primary)
+/// # }
+/// ```
+#[widget(pwt=crate, @element, @container)]
+#[derive(Default, Debug, Clone, PartialEq, Properties)]
+#[builder]
+pub struct ListTile {
+    #[prop_or_default]
+    #[builder]
+    interactive: bool,
+
+    #[prop_or_default]
+    #[builder]
+    disabled: bool,
+}
+
+impl ListTile {
+    /// Creates new ListTile instance
+    pub fn new() -> Self {
+        yew::props! { Self {} }
+    }
+
+    /// Creates a new instance from existing properties
+    pub fn from_widget_props(
+        std_props: WidgetStdProps,
+        listeners: Option<ListenersWrapper>,
+    ) -> Self {
+        yew::props! { Self { std_props, listeners: listeners.unwrap_or_default() } }
+    }
+}
+
+impl Into<VTag> for ListTile {
+    fn into(self) -> VTag {
+        let classes = classes!(
+            "pwt-list-tile",
+            self.interactive.then(|| "pwt-interactive"),
+            self.disabled.then(|| "disabled")
+        );
+
+        self.std_props.into_vtag(
+            Cow::Borrowed("div"),
+            Some(classes),
+            Some(self.listeners),
+            Some(self.children),
+        )
+    }
+}
index 12056ea7f45bb599c6e9f529ffdc1ddecd754eba..159eea9d03dfdeaabf35aefbb52a70c8530e74d4 100644 (file)
@@ -62,6 +62,9 @@ pub use language_selector::{LanguageSelector, ProxmoxLanguageSelector};
 mod list;
 pub use list::{List, PwtList};
 
+mod list_tile;
+pub use list_tile::ListTile;
+
 mod mask;
 pub use mask::{Mask, PwtMask};