Skip to content

Commit cb37d9c

Browse files
authored
feat: MenuItem adds icon prop (#200)
1 parent 5320793 commit cb37d9c

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

demo_markdown/docs/menu/mod.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ let value = create_rw_signal(String::from("o"));
55

66
view! {
77
<Menu value>
8-
<MenuItem key="a" label="and"/>
9-
<MenuItem key="o" label="or"/>
8+
<MenuItem key="a" label="And"/>
9+
<MenuItem key="o" label="Or"/>
10+
<MenuItem icon=icondata::AiAreaChartOutlined key="area" label="Area Chart"/>
11+
<MenuItem icon=icondata::AiPieChartOutlined key="pie" label="Pie Chart"/>
12+
<MenuItem icon=icondata::AiGithubOutlined key="github" label="Github"/>
13+
<MenuItem icon=icondata::AiChromeOutlined key="chrome" label="Chrome"/>
1014
</Menu>
1115
}
1216
```
@@ -29,8 +33,9 @@ view! {
2933

3034
### MenuItem Props
3135

32-
| Name | Type | Default | Description |
33-
| ----- | ----------------------------------- | -------------------- | -------------------------------------------- |
36+
| Name | Type | Default | Description |
37+
| --- | --- | --- | --- |
3438
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Addtional classes for the menu item element. |
35-
| label | `MaybeSignal<String>` | `Default::default()` | The label of the menu item. |
36-
| key | `MaybeSignal<String>` | `Default::default()` | The indentifier of the menu item. |
39+
| label | `MaybeSignal<String>` | `Default::default()` | The label of the menu item. |
40+
| key | `MaybeSignal<String>` | `Default::default()` | The indentifier of the menu item. |
41+
| icon | `OptionalMaybeSignal<icondata_core::Icon>` | `None` | The icon of the menu item. |

thaw/src/menu/menu-item.css

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.thaw-menu-item__content {
2+
display: flex;
3+
align-items: center;
24
margin: 0.3rem 0.4rem;
35
padding: 0.5rem 0.75rem;
46
color: var(--thaw-font-color);

thaw/src/menu/menu_item.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use super::use_menu;
2-
use crate::{theme::use_theme, Theme};
2+
use crate::{theme::use_theme, Icon, Theme};
33
use leptos::*;
4-
use thaw_utils::{class_list, mount_style, OptionalProp};
4+
use thaw_components::OptionComp;
5+
use thaw_utils::{class_list, mount_style, OptionalMaybeSignal, OptionalProp};
56

67
#[component]
78
pub fn MenuItem(
89
#[prop(into)] key: MaybeSignal<String>,
10+
#[prop(optional, into)] icon: OptionalMaybeSignal<icondata_core::Icon>,
911
#[prop(into)] label: MaybeSignal<String>,
1012
#[prop(optional, into)] class: OptionalProp<MaybeSignal<String>>,
1113
) -> impl IntoView {
@@ -46,6 +48,15 @@ pub fn MenuItem(
4648
on:click=on_click
4749
style=move || css_vars.get()
4850
>
51+
{
52+
move || {
53+
view! {
54+
<OptionComp value=icon.get() let:icon>
55+
<Icon icon=icon style="font-size: 18px;margin-right: 8px"/>
56+
</OptionComp>
57+
}
58+
}
59+
}
4960
{move || label.get()}
5061
</div>
5162
</div>

thaw/src/select/raw.rs

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ where
5050
});
5151
on_cleanup(move || listener.remove());
5252
}
53+
#[cfg(not(any(feature = "csr", feature = "hydrate")))]
54+
{
55+
let _ = hide_menu;
56+
}
5357

5458
let theme = use_theme(Theme::light);
5559
let css_vars = create_memo(move |_| {

0 commit comments

Comments
 (0)