♻️ Cambia en prepare_component() el tipo devuelto
Elimina `PrepareMarkup` como tipo de retorno de prepare_component() y de
`FnPrepareRender`, sustituyéndolo directamente por `Markup`. Se elimina
una capa innecesaria, ya que html! {} y html! { ... } cubren todos los
casos que ofrecía `PrepareMarkup`.
This commit is contained in:
parent
a5ee0fecb1
commit
3e1bc0fb0e
28 changed files with 241 additions and 335 deletions
|
|
@ -63,17 +63,17 @@ impl Component for Dropdown {
|
|||
);
|
||||
}
|
||||
|
||||
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
|
||||
fn prepare_component(&self, cx: &mut Context) -> Markup {
|
||||
// Si no hay elementos en el menú, no se prepara.
|
||||
let items = self.items().render(cx);
|
||||
if items.is_empty() {
|
||||
return PrepareMarkup::None;
|
||||
return html! {};
|
||||
}
|
||||
|
||||
// Título opcional para el menú desplegable.
|
||||
let title = self.title().using(cx);
|
||||
|
||||
PrepareMarkup::With(html! {
|
||||
html! {
|
||||
div id=[self.id()] class=[self.classes().get()] {
|
||||
@if !title.is_empty() {
|
||||
@let mut btn_classes = Classes::new({
|
||||
|
|
@ -156,7 +156,7 @@ impl Component for Dropdown {
|
|||
ul class="dropdown-menu" { (items) }
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,17 +62,17 @@ impl Component for Item {
|
|||
self.id.get()
|
||||
}
|
||||
|
||||
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
|
||||
fn prepare_component(&self, cx: &mut Context) -> Markup {
|
||||
match self.item_kind() {
|
||||
ItemKind::Void => PrepareMarkup::None,
|
||||
ItemKind::Void => html! {},
|
||||
|
||||
ItemKind::Label(label) => PrepareMarkup::With(html! {
|
||||
ItemKind::Label(label) => html! {
|
||||
li id=[self.id()] class=[self.classes().get()] {
|
||||
span class="dropdown-item-text" {
|
||||
(label.using(cx))
|
||||
}
|
||||
}
|
||||
}),
|
||||
},
|
||||
|
||||
ItemKind::Link {
|
||||
label,
|
||||
|
|
@ -100,7 +100,7 @@ impl Component for Item {
|
|||
let aria_disabled = disabled.then_some("true");
|
||||
let tabindex = disabled.then_some("-1");
|
||||
|
||||
PrepareMarkup::With(html! {
|
||||
html! {
|
||||
li id=[self.id()] class=[self.classes().get()] {
|
||||
a
|
||||
class=(classes)
|
||||
|
|
@ -114,7 +114,7 @@ impl Component for Item {
|
|||
(label.using(cx))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
ItemKind::Button { label, disabled } => {
|
||||
|
|
@ -126,7 +126,7 @@ impl Component for Item {
|
|||
let aria_disabled = disabled.then_some("true");
|
||||
let disabled_attr = disabled.then_some("disabled");
|
||||
|
||||
PrepareMarkup::With(html! {
|
||||
html! {
|
||||
li id=[self.id()] class=[self.classes().get()] {
|
||||
button
|
||||
class=(classes)
|
||||
|
|
@ -137,20 +137,20 @@ impl Component for Item {
|
|||
(label.using(cx))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
ItemKind::Header(label) => PrepareMarkup::With(html! {
|
||||
ItemKind::Header(label) => html! {
|
||||
li id=[self.id()] class=[self.classes().get()] {
|
||||
h6 class="dropdown-header" {
|
||||
(label.using(cx))
|
||||
}
|
||||
}
|
||||
}),
|
||||
},
|
||||
|
||||
ItemKind::Divider => PrepareMarkup::With(html! {
|
||||
ItemKind::Divider => html! {
|
||||
li id=[self.id()] class=[self.classes().get()] { hr class="dropdown-divider" {} }
|
||||
}),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue