pub enum InputState {
    Default,
    Success,
    Warning,
    Error,
}

Variants§

§

Default

§

Success

§

Warning

§

Error

Implementations§

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
Hide additional 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}
                />
        }
    }
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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Convert self to a value of a Properties struct.
Convert self to a value of a Properties struct.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more