Añade componentes básicos traducibles Html/Text

This commit is contained in:
Manuel Cillero 2023-05-30 19:13:13 +02:00
parent 6c76e3519c
commit 1d83bbc80a
20 changed files with 243 additions and 369 deletions

View file

@ -3,8 +3,6 @@ pub use container::{Container, ContainerType, COMPONENT_CONTAINER};
pub mod grid;
mod html;
pub use html::{Html, COMPONENT_HTML};
mod icon;
pub use icon::{Icon, COMPONENT_ICON};
mod heading;

View file

@ -23,7 +23,7 @@ pub enum AnchorTarget {
}
type AnchorIcon = OneComponent<Icon>;
type AnchorHtml = OneComponent<L10n>;
type AnchorHtml = OneComponent<Text>;
#[rustfmt::skip]
#[derive(Default)]
@ -34,7 +34,7 @@ pub struct Anchor {
classes : Classes,
anchor_type: AnchorType,
href : AttributeValue,
html10n : AnchorHtml,
html : AnchorHtml,
left_icon : AnchorIcon,
right_icon : AnchorIcon,
target : AnchorTarget,
@ -91,15 +91,15 @@ impl ComponentTrait for Anchor {
}
impl Anchor {
pub fn link(href: &str, html10n: L10n) -> Self {
Anchor::new().with_href(href).with_html(html10n)
pub fn link(href: &str, html: Text) -> Self {
Anchor::new().with_href(href).with_html(html)
}
pub fn button(href: &str, html10n: L10n) -> Self {
pub fn button(href: &str, html: Text) -> Self {
Anchor::new()
.with_type(AnchorType::Button)
.with_href(href)
.with_html(html10n)
.with_html(html)
}
pub fn location(id: &str) -> Self {
@ -152,8 +152,8 @@ impl Anchor {
}
#[fn_builder]
pub fn alter_html(&mut self, html10n: L10n) -> &mut Self {
self.html10n.set(html10n);
pub fn alter_html(&mut self, html: Text) -> &mut Self {
self.html.set(html);
self
}
@ -200,7 +200,7 @@ impl Anchor {
}
pub fn html(&self) -> &AnchorHtml {
&self.html10n
&self.html
}
pub fn left_icon(&self) -> &AnchorIcon {

View file

@ -10,7 +10,7 @@ pub enum ButtonType {
Reset,
}
type ButtonValue = OneComponent<L10n>;
type ButtonValue = OneComponent<Text>;
#[rustfmt::skip]
#[derive(Default)]
@ -77,11 +77,11 @@ impl ComponentTrait for Button {
}
impl Button {
pub fn with(value: L10n) -> Self {
pub fn with(value: Text) -> Self {
Button::new().with_value(value)
}
pub fn submit(value: L10n) -> Self {
pub fn submit(value: Text) -> Self {
let mut button = Button::new()
.with_classes(ClassesOp::Replace("form-button"), "form-submit")
.with_value(value);
@ -89,7 +89,7 @@ impl Button {
button
}
pub fn reset(value: L10n) -> Self {
pub fn reset(value: Text) -> Self {
let mut button = Button::new()
.with_classes(ClassesOp::Replace("form-button"), "form-reset")
.with_value(value);
@ -124,7 +124,7 @@ impl Button {
}
#[fn_builder]
pub fn alter_value(&mut self, value: L10n) -> &mut Self {
pub fn alter_value(&mut self, value: Text) -> &mut Self {
self.value.set(value);
self
}

View file

@ -13,8 +13,8 @@ pub enum InputType {
Url,
}
type InputLabel = OneComponent<L10n>;
type InputHelpText = OneComponent<L10n>;
type InputLabel = OneComponent<Text>;
type InputHelpText = OneComponent<Text>;
#[rustfmt::skip]
#[derive(Default)]
@ -206,7 +206,7 @@ impl Input {
}
#[fn_builder]
pub fn alter_label(&mut self, label: L10n) -> &mut Self {
pub fn alter_label(&mut self, label: Text) -> &mut Self {
self.label.set(label);
self
}
@ -281,7 +281,7 @@ impl Input {
}
#[fn_builder]
pub fn alter_help_text(&mut self, help_text: L10n) -> &mut Self {
pub fn alter_help_text(&mut self, help_text: Text) -> &mut Self {
self.help_text.set(help_text);
self
}

View file

@ -25,7 +25,7 @@ pub enum HeadingDisplay {
Subtitle,
}
type HeadingText = OneComponent<L10n>;
type HeadingText = OneComponent<Text>;
#[rustfmt::skip]
#[derive(Default)]
@ -80,37 +80,37 @@ impl ComponentTrait for Heading {
}
impl Heading {
pub fn h1(text: L10n) -> Self {
pub fn h1(text: Text) -> Self {
Heading::new()
.with_heading_type(HeadingType::H1)
.with_text(text)
}
pub fn h2(text: L10n) -> Self {
pub fn h2(text: Text) -> Self {
Heading::new()
.with_heading_type(HeadingType::H2)
.with_text(text)
}
pub fn h3(text: L10n) -> Self {
pub fn h3(text: Text) -> Self {
Heading::new()
.with_heading_type(HeadingType::H3)
.with_text(text)
}
pub fn h4(text: L10n) -> Self {
pub fn h4(text: Text) -> Self {
Heading::new()
.with_heading_type(HeadingType::H4)
.with_text(text)
}
pub fn h5(text: L10n) -> Self {
pub fn h5(text: Text) -> Self {
Heading::new()
.with_heading_type(HeadingType::H5)
.with_text(text)
}
pub fn h6(text: L10n) -> Self {
pub fn h6(text: Text) -> Self {
Heading::new()
.with_heading_type(HeadingType::H6)
.with_text(text)
@ -149,7 +149,7 @@ impl Heading {
}
#[fn_builder]
pub fn alter_text(&mut self, text: L10n) -> &mut Self {
pub fn alter_text(&mut self, text: Text) -> &mut Self {
self.text.set(text);
self
}

View file

@ -1,84 +0,0 @@
use pagetop::prelude::*;
define_handle!(COMPONENT_HTML);
#[rustfmt::skip]
#[derive(Default)]
pub struct Html {
weight : isize,
renderable: Renderable,
html : HtmlMarkup,
template : String,
}
impl ComponentTrait for Html {
fn new() -> Self {
Html::default()
}
fn handle(&self) -> Handle {
COMPONENT_HTML
}
fn weight(&self) -> isize {
self.weight
}
fn is_renderable(&self, rcx: &RenderContext) -> bool {
(self.renderable.check)(rcx)
}
fn default_render(&self, _: &mut RenderContext) -> Markup {
html! { (*self.html()) }
}
fn as_ref_any(&self) -> &dyn AnyComponent {
self
}
fn as_mut_any(&mut self) -> &mut dyn AnyComponent {
self
}
}
impl Html {
pub fn with(html: Markup) -> Self {
Html::new().with_html(html)
}
// Html BUILDER.
#[fn_builder]
pub fn alter_weight(&mut self, weight: isize) -> &mut Self {
self.weight = weight;
self
}
#[fn_builder]
pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder]
pub fn alter_html(&mut self, html: Markup) -> &mut Self {
self.html.markup = html;
self
}
#[fn_builder]
pub fn alter_template(&mut self, template: &str) -> &mut Self {
self.template = template.to_owned();
self
}
// Html GETTERS.
pub fn html(&self) -> &Markup {
&self.html.markup
}
pub fn template(&self) -> &str {
self.template.as_str()
}
}