2024-07-27 18:04:36 +08:00
|
|
|
# Menu
|
2024-07-24 13:22:46 +00:00
|
|
|
|
|
|
|
```rust demo
|
2024-07-29 16:09:41 +08:00
|
|
|
let toaster = ToasterInjection::expect_context();
|
2024-07-24 13:22:46 +00:00
|
|
|
|
2024-07-29 16:09:41 +08:00
|
|
|
let on_select = move |key: String| {
|
2024-07-29 01:13:04 +00:00
|
|
|
leptos::logging::warn!("{}", key);
|
|
|
|
toaster.dispatch_toast(view! {
|
|
|
|
<Toast>
|
|
|
|
<ToastBody>
|
|
|
|
"key"
|
|
|
|
</ToastBody>
|
|
|
|
</Toast>
|
|
|
|
}.into_any(), Default::default());
|
|
|
|
};
|
2024-07-24 13:22:46 +00:00
|
|
|
|
|
|
|
view! {
|
|
|
|
<Space>
|
|
|
|
<Menu on_select trigger_type=MenuTriggerType::Hover>
|
|
|
|
<MenuTrigger slot>
|
|
|
|
<Button>"Hover"</Button>
|
|
|
|
</MenuTrigger>
|
2024-07-27 18:04:36 +08:00
|
|
|
<MenuItem value="facebook" icon=icondata::AiFacebookOutlined>"Facebook"</MenuItem>
|
|
|
|
<MenuItem value="twitter" disabled=true icon=icondata::AiTwitterOutlined>"Twitter"</MenuItem>
|
2024-07-24 13:22:46 +00:00
|
|
|
</Menu>
|
|
|
|
|
|
|
|
<Menu on_select>
|
|
|
|
<MenuTrigger slot>
|
|
|
|
<Button>"Click"</Button>
|
|
|
|
</MenuTrigger>
|
2024-07-27 18:04:36 +08:00
|
|
|
<MenuItem value="facebook" icon=icondata::AiFacebookOutlined>"Facebook"</MenuItem>
|
|
|
|
<MenuItem value="twitter" icon=icondata::AiTwitterOutlined>"Twitter"</MenuItem>
|
|
|
|
<MenuItem value="no_icon" disabled=true>"Mastodon"</MenuItem>
|
2024-07-24 13:22:46 +00:00
|
|
|
</Menu>
|
|
|
|
</Space>
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Placement
|
|
|
|
|
|
|
|
```rust demo
|
|
|
|
use leptos_meta::Style;
|
|
|
|
|
2024-07-29 01:13:04 +00:00
|
|
|
let on_select = move |value| leptos::logging::warn!("{}", value);
|
2024-07-24 13:22:46 +00:00
|
|
|
|
|
|
|
view! {
|
|
|
|
<Style>
|
|
|
|
".demo-menu .thaw-button { width: 100% } .demo-menu .thaw-menu-trigger { display: block }"
|
|
|
|
</Style>
|
|
|
|
<Grid x_gap=8 y_gap=8 cols=3 class="demo-menu">
|
|
|
|
<GridItem>
|
2024-07-27 18:04:36 +08:00
|
|
|
<Menu on_select position=MenuPosition::TopStart>
|
2024-07-24 13:22:46 +00:00
|
|
|
<MenuTrigger slot>
|
|
|
|
<Button>"Top Start"</Button>
|
|
|
|
</MenuTrigger>
|
2024-07-29 01:13:04 +00:00
|
|
|
<MenuItem value="content">"Content"</MenuItem>
|
2024-07-24 13:22:46 +00:00
|
|
|
</Menu>
|
|
|
|
</GridItem>
|
|
|
|
<GridItem>
|
2024-07-27 18:04:36 +08:00
|
|
|
<Menu on_select position=MenuPosition::Top>
|
2024-07-24 13:22:46 +00:00
|
|
|
<MenuTrigger slot>
|
|
|
|
<Button>"Top"</Button>
|
|
|
|
</MenuTrigger>
|
2024-07-29 01:13:04 +00:00
|
|
|
<MenuItem value="content">"Content"</MenuItem>
|
2024-07-24 13:22:46 +00:00
|
|
|
</Menu>
|
|
|
|
</GridItem>
|
|
|
|
<GridItem>
|
2024-07-27 18:04:36 +08:00
|
|
|
<Menu on_select position=MenuPosition::TopEnd>
|
2024-07-24 13:22:46 +00:00
|
|
|
<MenuTrigger slot>
|
|
|
|
<Button>"Top End"</Button>
|
|
|
|
</MenuTrigger>
|
2024-07-29 01:13:04 +00:00
|
|
|
<MenuItem value="content">"Content"</MenuItem>
|
2024-07-24 13:22:46 +00:00
|
|
|
</Menu>
|
|
|
|
</GridItem>
|
|
|
|
<GridItem>
|
2024-07-27 18:04:36 +08:00
|
|
|
<Menu on_select position=MenuPosition::LeftStart>
|
2024-07-24 13:22:46 +00:00
|
|
|
<MenuTrigger slot>
|
|
|
|
<Button>"Left Start"</Button>
|
|
|
|
</MenuTrigger>
|
2024-07-29 01:13:04 +00:00
|
|
|
<MenuItem value="content">"Content"</MenuItem>
|
2024-07-24 13:22:46 +00:00
|
|
|
</Menu>
|
|
|
|
</GridItem>
|
|
|
|
<GridItem offset=1>
|
2024-07-27 18:04:36 +08:00
|
|
|
<Menu on_select position=MenuPosition::RightStart>
|
2024-07-24 13:22:46 +00:00
|
|
|
<MenuTrigger slot>
|
|
|
|
<Button>"Right Start"</Button>
|
|
|
|
</MenuTrigger>
|
2024-07-29 01:13:04 +00:00
|
|
|
<MenuItem value="content">"Content"</MenuItem>
|
2024-07-24 13:22:46 +00:00
|
|
|
</Menu>
|
|
|
|
</GridItem>
|
|
|
|
<GridItem>
|
2024-07-27 18:04:36 +08:00
|
|
|
<Menu on_select position=MenuPosition::Left>
|
2024-07-24 13:22:46 +00:00
|
|
|
<MenuTrigger slot>
|
|
|
|
<Button>"Left"</Button>
|
|
|
|
</MenuTrigger>
|
2024-07-29 01:13:04 +00:00
|
|
|
<MenuItem value="content">"Content"</MenuItem>
|
2024-07-24 13:22:46 +00:00
|
|
|
</Menu>
|
|
|
|
</GridItem>
|
|
|
|
<GridItem offset=1>
|
2024-07-27 18:04:36 +08:00
|
|
|
<Menu on_select position=MenuPosition::Right>
|
2024-07-24 13:22:46 +00:00
|
|
|
<MenuTrigger slot>
|
|
|
|
<Button>"Right"</Button>
|
|
|
|
</MenuTrigger>
|
2024-07-29 01:13:04 +00:00
|
|
|
<MenuItem value="content">"Content"</MenuItem>
|
2024-07-24 13:22:46 +00:00
|
|
|
</Menu>
|
|
|
|
</GridItem>
|
|
|
|
<GridItem>
|
2024-07-27 18:04:36 +08:00
|
|
|
<Menu on_select position=MenuPosition::LeftEnd>
|
2024-07-24 13:22:46 +00:00
|
|
|
<MenuTrigger slot>
|
|
|
|
<Button>"Left End"</Button>
|
|
|
|
</MenuTrigger>
|
2024-07-29 01:13:04 +00:00
|
|
|
<MenuItem value="content">"Content"</MenuItem>
|
2024-07-24 13:22:46 +00:00
|
|
|
</Menu>
|
|
|
|
</GridItem>
|
|
|
|
<GridItem offset=1>
|
2024-07-27 18:04:36 +08:00
|
|
|
<Menu on_select position=MenuPosition::RightEnd>
|
2024-07-24 13:22:46 +00:00
|
|
|
<MenuTrigger slot>
|
|
|
|
<Button>"Right End"</Button>
|
|
|
|
</MenuTrigger>
|
2024-07-29 01:13:04 +00:00
|
|
|
<MenuItem value="content">"Content"</MenuItem>
|
2024-07-24 13:22:46 +00:00
|
|
|
</Menu>
|
|
|
|
</GridItem>
|
|
|
|
<GridItem>
|
2024-07-27 18:04:36 +08:00
|
|
|
<Menu on_select position=MenuPosition::BottomStart>
|
2024-07-24 13:22:46 +00:00
|
|
|
<MenuTrigger slot>
|
|
|
|
<Button>"Bottom Start"</Button>
|
|
|
|
</MenuTrigger>
|
2024-07-29 01:13:04 +00:00
|
|
|
<MenuItem value="content">"Content"</MenuItem>
|
2024-07-24 13:22:46 +00:00
|
|
|
</Menu>
|
|
|
|
</GridItem>
|
|
|
|
<GridItem>
|
2024-07-27 18:04:36 +08:00
|
|
|
<Menu on_select position=MenuPosition::Bottom>
|
2024-07-24 13:22:46 +00:00
|
|
|
<MenuTrigger slot>
|
|
|
|
<Button>"Bottom"</Button>
|
|
|
|
</MenuTrigger>
|
2024-07-29 01:13:04 +00:00
|
|
|
<MenuItem value="content">"Content"</MenuItem>
|
2024-07-24 13:22:46 +00:00
|
|
|
</Menu>
|
|
|
|
</GridItem>
|
|
|
|
<GridItem>
|
2024-07-27 18:04:36 +08:00
|
|
|
<Menu on_select position=MenuPosition::BottomEnd>
|
2024-07-24 13:22:46 +00:00
|
|
|
<MenuTrigger slot>
|
|
|
|
<Button>"Bottom End"</Button>
|
|
|
|
</MenuTrigger>
|
2024-07-29 01:13:04 +00:00
|
|
|
<MenuItem value="content">"Content"</MenuItem>
|
2024-07-24 13:22:46 +00:00
|
|
|
</Menu>
|
|
|
|
</GridItem>
|
|
|
|
</Grid>
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Menu Props
|
|
|
|
|
2024-07-27 18:04:36 +08:00
|
|
|
| Name | Type | Default | Description |
|
|
|
|
| --- | --- | --- | --- |
|
|
|
|
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Addtional classes for the menu element. |
|
|
|
|
| on_select | `Callback<String>` | | Called when item is selected. |
|
|
|
|
| trigger_type | `MenuTriggerType` | `MenuTriggerType::Click` | Action that displays the menu. |
|
|
|
|
| position | `MenuPosition` | `MenuPosition::Bottom` | Menu position. |
|
|
|
|
| children | `Children` | | The content inside menu. |
|
2024-07-24 13:22:46 +00:00
|
|
|
|
|
|
|
### MenuItem Props
|
|
|
|
|
2024-07-27 18:04:36 +08:00
|
|
|
| Name | Type | Default | Description |
|
|
|
|
| --- | --- | --- | --- |
|
|
|
|
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Addtional classes for the menu item element. |
|
|
|
|
| value | `MaybeSignal<String>` | `Default::default()` | The value of the menu item. |
|
|
|
|
| label | `MaybeSignal<String>` | `Default::default()` | The label of the menu item. |
|
|
|
|
| icon | `OptionalMaybeSignal<icondata_core::Icon>` | `None` | The icon of the menu item. |
|
|
|
|
| disabled | `MaybeSignal<bool>` | `false` | Whether the menu item is disabled. |
|
2024-07-24 13:22:46 +00:00
|
|
|
|
|
|
|
### Menu Slots
|
|
|
|
|
2024-07-27 18:04:36 +08:00
|
|
|
| Name | Default | Description |
|
|
|
|
| ----------- | ------- | -------------------------------------------- |
|
2024-07-24 13:22:46 +00:00
|
|
|
| MenuTrigger | `None` | The element or component that triggers menu. |
|
|
|
|
|
|
|
|
### MenuTriger Props
|
|
|
|
|
2024-07-27 18:04:36 +08:00
|
|
|
| Name | Type | Default | Description |
|
|
|
|
| --- | --- | --- | --- |
|
|
|
|
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Addtional classes for the menu trigger element. |
|
|
|
|
| children | `Children` | | The content inside menu trigger. |
|