🍻 Tercera revista a las traducciones por contexto

This commit is contained in:
Manuel Cillero 2023-05-27 22:44:12 +02:00
parent 88d6ce2a72
commit dd443ca375
21 changed files with 415 additions and 252 deletions

View file

@ -10,6 +10,8 @@ pub enum ButtonType {
Reset,
}
pub type ButtonValue = ComponentArc;
#[rustfmt::skip]
#[derive(Default)]
pub struct Button {
@ -18,7 +20,7 @@ pub struct Button {
classes : Classes,
button_type: ButtonType,
name : AttributeValue,
value : AttributeValue,
value : ButtonValue,
autofocus : AttributeValue,
disabled : AttributeValue,
template : String,
@ -43,7 +45,7 @@ impl ComponentTrait for Button {
(self.renderable.check)(rcx)
}
fn default_render(&self, _: &mut RenderContext) -> Markup {
fn default_render(&self, rcx: &mut RenderContext) -> Markup {
let button_type = match self.button_type() {
ButtonType::Button => "button",
ButtonType::Submit => "submit",
@ -56,11 +58,11 @@ impl ComponentTrait for Button {
id=[id]
class=[self.classes().get()]
name=[self.name().get()]
value=[self.value().get()]
value=(self.value().render(rcx))
autofocus=[self.autofocus().get()]
disabled=[self.disabled().get()]
{
@if let Some(value) = self.value().get() { (value) }
(self.value().render(rcx))
}
}
}
@ -75,11 +77,11 @@ impl ComponentTrait for Button {
}
impl Button {
pub fn with(value: &str) -> Self {
pub fn with(value: L10n) -> Self {
Button::new().with_value(value)
}
pub fn submit(value: &str) -> Self {
pub fn submit(value: L10n) -> Self {
let mut button = Button::new()
.with_classes(ClassesOp::Replace("form-button"), "form-submit")
.with_value(value);
@ -87,7 +89,7 @@ impl Button {
button
}
pub fn reset(value: &str) -> Self {
pub fn reset(value: L10n) -> Self {
let mut button = Button::new()
.with_classes(ClassesOp::Replace("form-button"), "form-reset")
.with_value(value);
@ -122,8 +124,8 @@ impl Button {
}
#[fn_builder]
pub fn alter_value(&mut self, value: &str) -> &mut Self {
self.value.alter_value(value);
pub fn alter_value(&mut self, value: L10n) -> &mut Self {
self.value.set(value);
self
}
@ -165,7 +167,7 @@ impl Button {
&self.name
}
pub fn value(&self) -> &AttributeValue {
pub fn value(&self) -> &ButtonValue {
&self.value
}

View file

@ -13,6 +13,9 @@ pub enum InputType {
Url,
}
pub type InputLabel = ComponentArc;
pub type InputHelpText = ComponentArc;
#[rustfmt::skip]
#[derive(Default)]
pub struct Input {
@ -22,7 +25,7 @@ pub struct Input {
input_type : InputType,
name : NameValue,
value : AttributeValue,
label : AttributeValue,
label : InputLabel,
size : Option<u16>,
minlength : Option<u16>,
maxlength : Option<u16>,
@ -32,7 +35,7 @@ pub struct Input {
disabled : AttributeValue,
readonly : AttributeValue,
required : AttributeValue,
help_text : AttributeValue,
help_text : InputHelpText,
template : String,
}
@ -58,7 +61,7 @@ impl ComponentTrait for Input {
}
#[rustfmt::skip]
fn default_render(&self, _: &mut RenderContext) -> Markup {
fn default_render(&self, rcx: &mut RenderContext) -> Markup {
let type_input = match self.input_type() {
InputType::Textfield => "text",
InputType::Password => "password",
@ -70,7 +73,7 @@ impl ComponentTrait for Input {
let id = self.name().get().map(|name| concat_string!("edit-", name));
html! {
div class=[self.classes().get()] {
@if let Some(label) = self.label().get() {
@if let Some(label) = self.label().optional_render(rcx) {
label class="form-label" for=[&id] {
(label) " "
@if self.required().get().is_some() {
@ -95,8 +98,8 @@ impl ComponentTrait for Input {
readonly=[self.readonly().get()]
required=[self.required().get()]
disabled=[self.disabled().get()];
@if let Some(help_text) = self.help_text().get() {
div class="form-text" { (help_text) }
@if let Some(description) = self.help_text().optional_render(rcx) {
div class="form-text" { (description) }
}
}
}
@ -203,8 +206,8 @@ impl Input {
}
#[fn_builder]
pub fn alter_label(&mut self, label: &str) -> &mut Self {
self.label.alter_value(label);
pub fn alter_label(&mut self, label: L10n) -> &mut Self {
self.label.set(label);
self
}
@ -278,8 +281,8 @@ impl Input {
}
#[fn_builder]
pub fn alter_help_text(&mut self, help_text: &str) -> &mut Self {
self.help_text.alter_value(help_text);
pub fn alter_help_text(&mut self, help_text: L10n) -> &mut Self {
self.help_text.set(help_text);
self
}
@ -307,7 +310,7 @@ impl Input {
&self.value
}
pub fn label(&self) -> &AttributeValue {
pub fn label(&self) -> &InputLabel {
&self.label
}
@ -347,7 +350,7 @@ impl Input {
&self.required
}
pub fn help_text(&self) -> &AttributeValue {
pub fn help_text(&self) -> &InputHelpText {
&self.help_text
}