1use alloc::{borrow::Cow, string::String};
7
8use crate::Attribute;
9
10impl<T: Into<Cow<'static, str>>> From<(&'static str, T)> for Attribute {
11 fn from((key, value): (&'static str, T)) -> Self {
12 Attribute::new(key, value)
13 }
14}
15
16pub fn none() -> Attribute {
30 Attribute(crate::AttributeInner::None)
31}
32
33pub fn id(id: impl Into<Cow<'static, str>>) -> Attribute {
35 Attribute::new("id", id)
36}
37
38pub fn class<'a>(classes: impl IntoIterator<Item = &'a str>) -> Attribute {
53 let mut values = String::new();
54 let mut iter = classes.into_iter();
55 if let Some(value) = iter.next() {
56 values.push_str(value);
57 }
58 for value in iter {
59 values.push(' ');
60 values.push_str(value);
61 }
62 Attribute::new("class", values)
63}
64
65pub fn lang(lang: impl Into<Cow<'static, str>>) -> Attribute {
67 Attribute::new("lang", lang)
68}
69
70#[derive(Debug, Clone)]
72pub enum AnchorTarget {
73 Blank,
75 Self_,
77 Parent,
79 Top,
81 Frame(Cow<'static, str>),
83}
84
85pub fn target(target: AnchorTarget) -> Attribute {
87 Attribute::new(
88 "target",
89 match target {
90 AnchorTarget::Blank => "_blank".into(),
91 AnchorTarget::Self_ => "_self".into(),
92 AnchorTarget::Parent => "_parent".into(),
93 AnchorTarget::Top => "_top".into(),
94 AnchorTarget::Frame(name) => name,
95 },
96 )
97}
98
99pub fn target_blank() -> Attribute {
101 target(AnchorTarget::Blank)
102}
103
104pub fn href(value: impl Into<Cow<'static, str>>) -> Attribute {
106 Attribute::new("href", value)
107}
108
109pub fn rel(value: impl Into<Cow<'static, str>>) -> Attribute {
111 Attribute::new("rel", value)
112}
113
114pub fn src(value: impl Into<Cow<'static, str>>) -> Attribute {
116 Attribute::new("src", value)
117}
118
119pub fn alt(value: impl Into<Cow<'static, str>>) -> Attribute {
121 Attribute::new("alt", value)
122}
123
124pub fn width(value: impl Into<Cow<'static, str>>) -> Attribute {
126 Attribute::new("width", value)
127}
128
129pub fn height(value: impl Into<Cow<'static, str>>) -> Attribute {
131 Attribute::new("height", value)
132}
133
134pub fn width_int(value: i32) -> Attribute {
136 Attribute::new_int("width", value)
137}
138
139pub fn height_int(value: i32) -> Attribute {
141 Attribute::new_int("height", value)
142}
143
144pub fn style(value: impl Into<Cow<'static, str>>) -> Attribute {
146 Attribute::new("style", value)
147}
148
149pub fn cols(value: i32) -> Attribute {
151 Attribute::new_int("cols", value)
152}
153
154pub fn rows(value: i32) -> Attribute {
156 Attribute::new_int("rows", value)
157}
158
159pub fn type_(value: impl Into<Cow<'static, str>>) -> Attribute {
161 Attribute::new("type", value)
162}
163
164pub fn type_text() -> Attribute {
166 Attribute::new("type", "text")
167}
168
169pub fn type_password() -> Attribute {
171 Attribute::new("type", "password")
172}
173
174pub fn type_number() -> Attribute {
176 Attribute::new("type", "number")
177}
178
179pub fn type_tel() -> Attribute {
181 Attribute::new("type", "tel")
182}
183
184pub fn type_file() -> Attribute {
186 Attribute::new("type", "file")
187}
188
189pub fn type_checkbox() -> Attribute {
191 Attribute::new("type", "checkbox")
192}
193
194pub fn type_radio() -> Attribute {
196 Attribute::new("type", "radio")
197}
198
199pub fn type_range() -> Attribute {
201 Attribute::new("type", "range")
202}
203
204pub fn type_email() -> Attribute {
206 Attribute::new("type", "email")
207}
208
209pub fn type_date() -> Attribute {
211 Attribute::new("type", "date")
212}
213
214pub fn type_month() -> Attribute {
216 Attribute::new("type", "month")
217}
218
219pub fn type_hidden() -> Attribute {
221 Attribute::new("type", "hidden")
222}
223
224pub fn type_reset() -> Attribute {
226 Attribute::new("type", "reset")
227}
228
229pub fn type_submit() -> Attribute {
231 Attribute::new("type", "submit")
232}
233
234pub fn integrity(value: impl Into<Cow<'static, str>>) -> Attribute {
236 Attribute::new("integrity", value)
237}
238
239pub fn defer() -> Attribute {
241 Attribute::new_flag("defer")
242}
243
244pub fn async_() -> Attribute {
246 Attribute::new_flag("async")
247}
248
249pub fn crossorigin_anonymous() -> Attribute {
251 Attribute::new("crossorigin", "anonymous")
252}
253
254pub fn crossorigin_use_credentials() -> Attribute {
256 Attribute::new("crossorigin", "use-credentials")
257}
258
259pub fn download() -> Attribute {
261 Attribute::new_flag("download")
262}
263
264pub fn download_with_name(name: impl Into<Cow<'static, str>>) -> Attribute {
266 Attribute::new("download", name)
267}
268
269pub fn charset(charset: impl Into<Cow<'static, str>>) -> Attribute {
271 Attribute::new("charset", charset)
272}
273
274#[deprecated(since = "1.5.0", note = "renamed to 'meta_charset_utf8'")]
276pub fn charset_utf_8() -> Attribute {
277 charset("UTF-8")
278}
279
280pub fn charset_utf8() -> Attribute {
282 charset("UTF-8")
283}
284
285pub fn name(name: impl Into<Cow<'static, str>>) -> Attribute {
287 Attribute::new("name", name)
288}
289
290pub fn content(content: impl Into<Cow<'static, str>>) -> Attribute {
292 Attribute::new("content", content)
293}
294
295pub fn action(action: impl Into<Cow<'static, str>>) -> Attribute {
297 Attribute::new("action", action)
298}
299
300pub fn method_get() -> Attribute {
302 Attribute::new("method", "get")
303}
304
305pub fn method_post() -> Attribute {
307 Attribute::new("method", "post")
308}
309
310pub fn for_(value: impl Into<Cow<'static, str>>) -> Attribute {
312 Attribute::new("for", value)
313}
314
315pub fn value(value: impl Into<Cow<'static, str>>) -> Attribute {
317 Attribute::new("value", value)
318}
319
320pub fn required() -> Attribute {
322 Attribute::new_flag("required")
323}
324pub fn autofocus() -> Attribute {
326 Attribute::new_flag("autofocus")
327}
328
329pub fn autocomplete(type_: impl Into<Cow<'static, str>>) -> Attribute {
331 Attribute::new("autocomplete", type_)
332}
333
334pub fn autocomplete_on() -> Attribute {
336 Attribute::new("autocomplete", "on")
337}
338
339pub fn autocomplete_off() -> Attribute {
341 Attribute::new("autocomplete", "off")
342}
343
344pub fn disabled() -> Attribute {
346 Attribute::new_flag("disabled")
347}
348
349pub fn pattern(value: impl Into<Cow<'static, str>>) -> Attribute {
351 Attribute::new("pattern", value)
352}
353
354pub fn min(value: impl Into<Cow<'static, str>>) -> Attribute {
356 Attribute::new("min", value)
357}
358
359pub fn max(value: impl Into<Cow<'static, str>>) -> Attribute {
361 Attribute::new("max", value)
362}
363
364pub fn minlength(value: impl Into<Cow<'static, str>>) -> Attribute {
366 Attribute::new("minlength", value)
367}
368
369pub fn minlength_u16(value: u16) -> Attribute {
371 Attribute::new_int("minlength", value.into())
372}
373
374pub fn maxlength(value: impl Into<Cow<'static, str>>) -> Attribute {
376 Attribute::new("maxlength", value)
377}
378
379pub fn maxlength_u16(value: u16) -> Attribute {
381 Attribute::new_int("maxlength", value.into())
382}
383
384pub fn multiple() -> Attribute {
386 Attribute::new_flag("multiple")
387}
388
389pub fn placeholder(value: impl Into<Cow<'static, str>>) -> Attribute {
391 Attribute::new("placeholder", value)
392}
393
394pub fn role_str(value: impl Into<Cow<'static, str>>) -> Attribute {
396 Attribute::new("role", value)
397}