Enum patternfly_yew::InputState
source · pub enum InputState {
Default,
Success,
Warning,
Error,
}Variants§
Implementations§
source§impl InputState
impl InputState
sourcepub fn convert(&self, classes: Classes) -> (Classes, bool)
pub fn convert(&self, classes: Classes) -> (Classes, bool)
Examples found in repository?
src/form/area.rs (line 144)
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
fn view(&self, ctx: &Context<Self>) -> Html {
let classes = Classes::from("pf-c-form-control");
let (mut classes, aria_invalid) = self.input_state(ctx).convert(classes);
match ctx.props().resize {
ResizeOrientation::Horizontal => classes.push("pf-m-resize-horizontal"),
ResizeOrientation::Vertical => classes.push("pf-m-resize-vertical"),
_ => {}
}
let input_ref = self.input_ref.clone();
let onchange = ctx.link().batch_callback(move |_| {
input_ref
.cast::<HtmlInputElement>()
.map(|input| TextAreaMsg::Changed(input.value()))
});
let oninput = ctx
.link()
.callback(|data: InputEvent| TextAreaMsg::Input(data.data().unwrap_or_default()));
html! {
<textarea
ref={self.input_ref.clone()}
class={classes}
name={ctx.props().name.clone()}
required={ctx.props().required}
disabled={ctx.props().disabled}
readonly={ctx.props().readonly}
aria-invalid={aria_invalid.to_string()}
value={ctx.props().value.clone()}
cols={ctx.props().cols.as_ref().map(|v|v.to_string())}
rows={ctx.props().rows.as_ref().map(|v|v.to_string())}
wrap={ctx.props().wrap.to_string()}
spellcheck={ctx.props().spellcheck.map(|v|v.to_string())}
placeholder={ctx.props().placeholder.clone()}
onchange={onchange}
oninput={oninput}
/>
}
}More examples
src/form/input.rs (line 159)
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
fn view(&self, ctx: &Context<Self>) -> Html {
let mut classes = Classes::from("pf-c-form-control");
match ctx.props().icon {
TextInputIcon::None => {}
TextInputIcon::Search => classes.push("pf-m-search"),
TextInputIcon::Calendar => classes.extend(vec!["pf-m-icon", "pf-m-calendar"]),
TextInputIcon::Clock => classes.extend(vec!["pf-m-icon", "pf-m-clock"]),
TextInputIcon::Custom => classes.extend(vec!["pf-m-icon"]),
};
let (classes, aria_invalid) = self.input_state(ctx).convert(classes);
let input_ref = self.refs.input.clone();
let onchange = ctx.link().batch_callback(move |_| {
input_ref
.cast::<HtmlInputElement>()
.map(|input| TextInputMsg::Changed(input.value()))
});
let oninput = ctx
.link()
.callback(|evt: InputEvent| TextInputMsg::Input(evt.data().unwrap_or_default()));
let value = self.value(ctx);
html! {
<input
ref={self.refs.input.clone()}
class={classes}
type={ctx.props().r#type.clone()}
name={ctx.props().name.clone()}
id={ctx.props().id.clone()}
required={ctx.props().required}
disabled={ctx.props().disabled}
readonly={ctx.props().readonly}
aria-invalid={aria_invalid.to_string()}
value={value}
placeholder={ctx.props().placeholder.clone()}
form={ctx.props().form.clone()}
autocomplete={ctx.props().autocomplete.clone()}
onchange={onchange}
oninput={oninput}
/>
}
}sourcepub fn icon(&self) -> Icon
pub fn icon(&self) -> Icon
Examples found in repository?
src/form/group.rs (line 46)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
fn from(text: &HelperText) -> Self {
let mut classes = Classes::from("pf-c-helper-text__item");
classes.extend(text.input_state.as_classes());
if text.is_dynamic {
classes.push("pf-m-dynamic");
}
html!(
<div class={classes}>
if !text.no_icon {
<span class="pf-c-helper-text__item-icon">
{ text.custom_icon.unwrap_or_else(|| text.input_state.icon() )}
</span>
}
<span class="pf-c-helper-text__item-text"> { &text.message } </span>
</div>
)
}
}
impl From<&str> for HelperText {
fn from(text: &str) -> Self {
HelperText {
input_state: Default::default(),
custom_icon: None,
no_icon: true,
is_dynamic: false,
message: text.into(),
}
}
}
impl From<(&str, InputState)> for HelperText {
fn from(value: (&str, InputState)) -> Self {
Self {
input_state: value.1,
custom_icon: None,
no_icon: false,
is_dynamic: false,
message: value.0.into(),
}
}
}
pub struct FormGroup {}
impl Component for FormGroup {
type Message = ();
type Properties = FormGroupProps;
fn create(_: &Context<Self>) -> Self {
Self {}
}
fn view(&self, ctx: &Context<Self>) -> Html {
let classes = Classes::from("pf-c-form__group");
html! {
<div class={classes}>
<div class="pf-c-form__group-label">
{if !ctx.props().label.is_empty() {
html!{
<div class="pf-c-form__label">
<span class="pf-c-form__label-text">{&ctx.props().label}</span>
{if ctx.props().required {
html!{
<span class="pf-c-form__label-required" aria-hidden="true">{"*"}</span>
}
} else {
html!{}
}}
</div>
}
} else {
html!{}
}}
</div>
<div class="pf-c-form__group-control">
{ for ctx.props().children.iter() }
if let Some(text) = &ctx.props().helper_text {
{ FormGroupHelpText(text) }
}
</div>
</div>
}
}
}
pub struct FormGroupHelpText<'a>(&'a HelperText);
impl<'a> FormGroupHelpText<'a> {}
impl<'a> From<FormGroupHelpText<'a>> for VNode {
fn from(text: FormGroupHelpText<'a>) -> Self {
let mut classes = Classes::from_iter(&["pf-c-form__helper-text".to_string()]);
classes.extend(text.0.input_state.as_classes());
let icon = match text.0.no_icon {
true => None,
false => Some(
text.0
.custom_icon
.unwrap_or_else(|| text.0.input_state.icon()),
),
};
html!(
<p
class={classes}
aria-live="polite"
>
if let Some(icon) = icon {
<span class="pf-c-form__helper-text-icon">
{ icon }
</span>
}
{ &text.0.message }
</p>
)
}Trait Implementations§
source§impl AsClasses for InputState
impl AsClasses for InputState
source§impl Clone for InputState
impl Clone for InputState
source§fn clone(&self) -> InputState
fn clone(&self) -> InputState
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for InputState
impl Debug for InputState
source§impl Default for InputState
impl Default for InputState
source§impl Ord for InputState
impl Ord for InputState
source§fn cmp(&self, other: &InputState) -> Ordering
fn cmp(&self, other: &InputState) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq<InputState> for InputState
impl PartialEq<InputState> for InputState
source§fn eq(&self, other: &InputState) -> bool
fn eq(&self, other: &InputState) -> bool
source§impl PartialOrd<InputState> for InputState
impl PartialOrd<InputState> for InputState
source§fn partial_cmp(&self, other: &InputState) -> Option<Ordering>
fn partial_cmp(&self, other: &InputState) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moreimpl Copy for InputState
impl Eq for InputState
impl StructuralEq for InputState
impl StructuralPartialEq for InputState
Auto Trait Implementations§
impl RefUnwindSafe for InputState
impl Send for InputState
impl Sync for InputState
impl Unpin for InputState
impl UnwindSafe for InputState
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
Convert
self to a value of a Properties struct.source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
Convert
self to a value of a Properties struct.