🎨 Refina algunos constructores de componentes

This commit is contained in:
Manuel Cillero 2022-11-16 00:32:41 +01:00
parent 0b4d2b413d
commit a687c646f2
4 changed files with 20 additions and 32 deletions

View file

@ -75,7 +75,7 @@ impl ComponentTrait for Button {
}
impl Button {
pub fn new_with_value(value: &str) -> Self {
pub fn with(value: &str) -> Self {
Button::new().with_value(value)
}

View file

@ -49,7 +49,7 @@ impl ComponentTrait for Image {
}
impl Image {
pub fn new_with_source(source: &str) -> Self {
pub fn with(source: &str) -> Self {
Image::new().with_source(source)
}

View file

@ -83,57 +83,45 @@ impl ComponentTrait for MenuItem {
}
impl MenuItem {
#[rustfmt::skip]
pub fn label(label: &str) -> Self {
MenuItem {
weight : 0,
renderable: Renderable::default(),
item_type : MenuItemType::Label(label.to_owned()),
item_type: MenuItemType::Label(label.to_owned()),
..Default::default()
}
}
#[rustfmt::skip]
pub fn link(label: &str, path: &str) -> Self {
MenuItem {
weight : 0,
renderable: Renderable::default(),
item_type : MenuItemType::Link(label.to_owned(), path.to_owned()),
item_type: MenuItemType::Link(label.to_owned(), path.to_owned()),
..Default::default()
}
}
#[rustfmt::skip]
pub fn link_blank(label: &str, path: &str) -> Self {
MenuItem {
weight : 0,
renderable: Renderable::default(),
item_type : MenuItemType::LinkBlank(label.to_owned(), path.to_owned()),
item_type: MenuItemType::LinkBlank(label.to_owned(), path.to_owned()),
..Default::default()
}
}
#[rustfmt::skip]
pub fn html(html: Markup) -> Self {
MenuItem {
weight : 0,
renderable: Renderable::default(),
item_type : MenuItemType::Html(html),
item_type: MenuItemType::Html(html),
..Default::default()
}
}
#[rustfmt::skip]
pub fn submenu(label: &str, menu: Menu) -> Self {
MenuItem {
weight : 0,
renderable: Renderable::default(),
item_type : MenuItemType::Submenu(label.to_owned(), menu),
item_type: MenuItemType::Submenu(label.to_owned(), menu),
..Default::default()
}
}
#[rustfmt::skip]
pub fn separator() -> Self {
MenuItem {
weight : 0,
renderable: Renderable::default(),
item_type : MenuItemType::Separator,
item_type: MenuItemType::Separator,
..Default::default()
}
}

View file

@ -35,7 +35,7 @@ async fn demo() -> ResultPage<Markup, FatalError> {
.add_to("region-content", welcome())
.add_to("region-content", about_pagetop())
.add_to("region-content", promo_pagetop())
.add_to("region-content", reporting_problems())
.add_to("region-content", reporting_issues())
.render()
}
@ -90,7 +90,7 @@ fn hello_world() -> Container {
.with_column(
grid::Column::new()
.with_classes(ClassesOp::Add, "hello-col-image")
.with_component(Image::new_with_source("/theme/images/homepage-header.svg")),
.with_component(Image::with("/theme/images/homepage-header.svg")),
),
)
}
@ -129,7 +129,7 @@ fn about_pagetop() -> Container {
grid::Column::new()
.with_classes(ClassesOp::Add, "pagetop-col-image")
.with_size(grid::ColumnSize::Is5of12)
.with_component(Image::new_with_source("/theme/images/homepage-about.svg")),
.with_component(Image::with("/theme/images/homepage-about.svg")),
)
.with_column(
grid::Column::new()
@ -185,18 +185,18 @@ fn promo_pagetop() -> Container {
grid::Column::new()
.with_classes(ClassesOp::Add, "promo-col-image")
.with_size(grid::ColumnSize::Is6of12)
.with_component(Image::new_with_source("/theme/images/homepage-pagetop.png")),
.with_component(Image::with("/theme/images/homepage-pagetop.png")),
),
)
}
fn reporting_problems() -> Container {
fn reporting_issues() -> Container {
Container::new().with_id("reporting").with_component(
grid::Row::new()
.with_column(
grid::Column::new()
.with_classes(ClassesOp::Add, "reporting-col-image")
.with_component(Image::new_with_source("/theme/images/homepage-support.jpg")),
.with_component(Image::with("/theme/images/homepage-support.jpg")),
)
.with_column(
grid::Column::new()