🎨 Use default() for component constructors

This commit is contained in:
Manuel Cillero 2023-11-03 17:39:05 +01:00
parent 306cf5dc43
commit c3c5e46508
6 changed files with 20 additions and 20 deletions

View file

@ -66,11 +66,11 @@ impl ComponentTrait for Button {
impl Button { impl Button {
pub fn with(value: L10n) -> Self { pub fn with(value: L10n) -> Self {
Button::new().with_value(value) Button::default().with_value(value)
} }
pub fn submit(value: L10n) -> Self { pub fn submit(value: L10n) -> Self {
let mut button = Button::new() let mut button = Button::default()
.with_classes(ClassesOp::Replace("form-button".to_owned()), "form-submit") .with_classes(ClassesOp::Replace("form-button".to_owned()), "form-submit")
.with_value(value); .with_value(value);
button.button_type = ButtonType::Submit; button.button_type = ButtonType::Submit;
@ -78,7 +78,7 @@ impl Button {
} }
pub fn reset(value: L10n) -> Self { pub fn reset(value: L10n) -> Self {
let mut button = Button::new() let mut button = Button::default()
.with_classes(ClassesOp::Replace("form-button".to_owned()), "form-reset") .with_classes(ClassesOp::Replace("form-button".to_owned()), "form-reset")
.with_value(value); .with_value(value);
button.button_type = ButtonType::Reset; button.button_type = ButtonType::Reset;

View file

@ -33,7 +33,7 @@ impl ComponentTrait for Hidden {
impl Hidden { impl Hidden {
pub fn set(name: &str, value: &str) -> Self { pub fn set(name: &str, value: &str) -> Self {
Hidden::new().with_name(name).with_value(value) Hidden::default().with_name(name).with_value(value)
} }
// Hidden BUILDER. // Hidden BUILDER.

View file

@ -104,11 +104,11 @@ impl ComponentTrait for Input {
impl Input { impl Input {
pub fn textfield() -> Self { pub fn textfield() -> Self {
Input::new() Input::default()
} }
pub fn password() -> Self { pub fn password() -> Self {
let mut input = Input::new().with_classes( let mut input = Input::default().with_classes(
ClassesOp::Replace("form-type-textfield".to_owned()), ClassesOp::Replace("form-type-textfield".to_owned()),
"form-type-password", "form-type-password",
); );
@ -117,7 +117,7 @@ impl Input {
} }
pub fn search() -> Self { pub fn search() -> Self {
let mut input = Input::new().with_classes( let mut input = Input::default().with_classes(
ClassesOp::Replace("form-type-textfield".to_owned()), ClassesOp::Replace("form-type-textfield".to_owned()),
"form-type-search", "form-type-search",
); );
@ -126,7 +126,7 @@ impl Input {
} }
pub fn email() -> Self { pub fn email() -> Self {
let mut input = Input::new().with_classes( let mut input = Input::default().with_classes(
ClassesOp::Replace("form-type-textfield".to_owned()), ClassesOp::Replace("form-type-textfield".to_owned()),
"form-type-email", "form-type-email",
); );
@ -135,7 +135,7 @@ impl Input {
} }
pub fn telephone() -> Self { pub fn telephone() -> Self {
let mut input = Input::new().with_classes( let mut input = Input::default().with_classes(
ClassesOp::Replace("form-type-textfield".to_owned()), ClassesOp::Replace("form-type-textfield".to_owned()),
"form-type-telephone", "form-type-telephone",
); );
@ -144,7 +144,7 @@ impl Input {
} }
pub fn url() -> Self { pub fn url() -> Self {
let mut input = Input::new().with_classes( let mut input = Input::default().with_classes(
ClassesOp::Replace("form-type-textfield".to_owned()), ClassesOp::Replace("form-type-textfield".to_owned()),
"form-type-url", "form-type-url",
); );

View file

@ -89,37 +89,37 @@ impl ComponentTrait for Heading {
impl Heading { impl Heading {
pub fn h1(text: L10n) -> Self { pub fn h1(text: L10n) -> Self {
Heading::new() Heading::default()
.with_heading_type(HeadingType::H1) .with_heading_type(HeadingType::H1)
.with_text(text) .with_text(text)
} }
pub fn h2(text: L10n) -> Self { pub fn h2(text: L10n) -> Self {
Heading::new() Heading::default()
.with_heading_type(HeadingType::H2) .with_heading_type(HeadingType::H2)
.with_text(text) .with_text(text)
} }
pub fn h3(text: L10n) -> Self { pub fn h3(text: L10n) -> Self {
Heading::new() Heading::default()
.with_heading_type(HeadingType::H3) .with_heading_type(HeadingType::H3)
.with_text(text) .with_text(text)
} }
pub fn h4(text: L10n) -> Self { pub fn h4(text: L10n) -> Self {
Heading::new() Heading::default()
.with_heading_type(HeadingType::H4) .with_heading_type(HeadingType::H4)
.with_text(text) .with_text(text)
} }
pub fn h5(text: L10n) -> Self { pub fn h5(text: L10n) -> Self {
Heading::new() Heading::default()
.with_heading_type(HeadingType::H5) .with_heading_type(HeadingType::H5)
.with_text(text) .with_text(text)
} }
pub fn h6(text: L10n) -> Self { pub fn h6(text: L10n) -> Self {
Heading::new() Heading::default()
.with_heading_type(HeadingType::H6) .with_heading_type(HeadingType::H6)
.with_text(text) .with_text(text)
} }

View file

@ -14,7 +14,7 @@ pub struct Icon {
impl ComponentTrait for Icon { impl ComponentTrait for Icon {
fn new() -> Self { fn new() -> Self {
Icon::default().with_icon_name("question-circle-fill") Icon::default()
} }
fn handle(&self) -> Handle { fn handle(&self) -> Handle {
@ -40,7 +40,7 @@ impl ComponentTrait for Icon {
impl Icon { impl Icon {
pub fn with(icon_name: &str) -> Self { pub fn with(icon_name: &str) -> Self {
Icon::new().with_icon_name(icon_name) Icon::default().with_icon_name(icon_name)
} }
// Icon BUILDER. // Icon BUILDER.

View file

@ -48,11 +48,11 @@ impl ComponentTrait for Paragraph {
impl Paragraph { impl Paragraph {
pub fn with(component: impl ComponentTrait) -> Self { pub fn with(component: impl ComponentTrait) -> Self {
Paragraph::new().add_component(component) Paragraph::default().add_component(component)
} }
pub fn translated(l10n: L10n) -> Self { pub fn translated(l10n: L10n) -> Self {
Paragraph::new().add_translated(l10n) Paragraph::default().add_translated(l10n)
} }
// Paragraph BUILDER. // Paragraph BUILDER.