pub trait AsClasses {
    fn extend(&self, classes: &mut Classes);

    fn as_classes(&self) -> Classes { ... }
}

Required Methods§

Provided Methods§

Examples found in repository?
src/utils/classes.rs (line 29)
27
28
29
30
31
    fn extend(&self, classes: &mut Classes) {
        for i in self {
            classes.extend(i.as_classes());
        }
    }
More examples
Hide additional examples
src/form/group.rs (line 36)
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>
        )
    }
src/table/mod.rs (line 287)
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
    fn render_expandable_entry(
        &self,
        ctx: &Context<Self>,
        entry: &TableModelEntry<M::Item>,
    ) -> Html {
        let expanded = entry.expanded;
        let idx = entry.index;

        let onclick = match expanded {
            true => ctx.link().callback(move |_: MouseEvent| Msg::Collapse(idx)),
            false => ctx.link().callback(move |_: MouseEvent| Msg::Expand(idx)),
        };

        let mut classes = Classes::from("pf-c-button");
        classes.push("pf-m-plain");
        if expanded {
            classes.push("pf-m-expanded");
        }

        let aria_expanded = match expanded {
            true => "true",
            false => "false",
        };

        let mut expanded_class = Classes::new();
        if expanded {
            expanded_class.push("pf-m-expanded");
        }

        let mut cols = ctx
            .props()
            .header
            .as_ref()
            .map_or(0, |header| header.props.children.len())
            + 1;

        let mut cells: Vec<Html> = Vec::with_capacity(cols);

        if !entry
            .value
            .is_full_width_details()
            .unwrap_or(ctx.props().full_width_details)
        {
            cells.push(html! {<td></td>});
            cols -= 1;
        }

        for cell in entry.value.render_details() {
            let mut classes = Classes::new();
            classes.extend(cell.modifiers.as_classes());
            cells.push(html! {
                <td class={classes} role="cell" colspan={cell.cols.to_string()}>
                    <div class="pf-c-table__expandable-row-content">
                        { cell.content }
                    </div>
                </td>
            });
            if cols > cell.cols {
                cols -= cell.cols;
            } else {
                cols = 0;
            }
            if cols == 0 {
                break;
            }
        }

        if cols > 0 {
            cells.push(html! {
                <td colspan={cols.to_string()}></td>
            });
        }

        let mut tr_classes = classes!("pf-c-table__expandable-row");
        tr_classes.extend(expanded_class.clone());

        return html! {
            <tbody role="rowgroup" class={expanded_class}>
                <tr role="row">
                    <td class="pf-c-table__toggle" role="cell">
                        <button class={classes} onclick={onclick} aria-expanded={aria_expanded}>
                            <div class="pf-c-table__toggle_icon">
                                { if expanded { Icon::AngleDown } else { Icon::AngleRight }}
                            </div>
                        </button>
                    </td>

                    { self.render_row(ctx, &entry.value) }
                </tr>

                <tr class={tr_classes} role="row">
                    { cells }
                </tr>
            </tbody>
        };
    }

Implementations on Foreign Types§

Implementors§