Skip to main content

wavefunk_ui/
components.rs

1use crate::assets;
2use askama::Template;
3use std::fmt::{self, Write as _};
4
5#[derive(Clone, Copy, Debug, Eq, PartialEq)]
6pub struct HtmlAttr<'a> {
7    pub name: &'a str,
8    pub value: &'a str,
9}
10
11impl<'a> HtmlAttr<'a> {
12    pub const fn new(name: &'a str, value: &'a str) -> Self {
13        Self { name, value }
14    }
15
16    pub const fn hx_get(value: &'a str) -> Self {
17        Self::new("hx-get", value)
18    }
19
20    pub const fn hx_post(value: &'a str) -> Self {
21        Self::new("hx-post", value)
22    }
23
24    pub const fn hx_put(value: &'a str) -> Self {
25        Self::new("hx-put", value)
26    }
27
28    pub const fn hx_patch(value: &'a str) -> Self {
29        Self::new("hx-patch", value)
30    }
31
32    pub const fn hx_delete(value: &'a str) -> Self {
33        Self::new("hx-delete", value)
34    }
35
36    pub const fn hx_target(value: &'a str) -> Self {
37        Self::new("hx-target", value)
38    }
39
40    pub const fn hx_swap(value: &'a str) -> Self {
41        Self::new("hx-swap", value)
42    }
43
44    pub const fn hx_trigger(value: &'a str) -> Self {
45        Self::new("hx-trigger", value)
46    }
47
48    pub const fn hx_confirm(value: &'a str) -> Self {
49        Self::new("hx-confirm", value)
50    }
51}
52
53#[derive(Clone, Copy, Debug, Eq, PartialEq)]
54pub struct TrustedHtml<'a> {
55    html: &'a str,
56}
57
58impl<'a> TrustedHtml<'a> {
59    pub const fn new(html: &'a str) -> Self {
60        Self { html }
61    }
62
63    pub const fn as_str(self) -> &'a str {
64        self.html
65    }
66}
67
68impl fmt::Display for TrustedHtml<'_> {
69    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
70        f.write_str(self.html)
71    }
72}
73
74impl askama::FastWritable for TrustedHtml<'_> {
75    #[inline]
76    fn write_into(&self, dest: &mut dyn fmt::Write, _: &dyn askama::Values) -> askama::Result<()> {
77        Ok(dest.write_str(self.html)?)
78    }
79}
80
81impl askama::filters::HtmlSafe for TrustedHtml<'_> {}
82
83#[derive(Clone, Copy, Debug, Eq, PartialEq)]
84pub enum ButtonVariant {
85    Default,
86    Primary,
87    Ghost,
88    Danger,
89}
90
91impl ButtonVariant {
92    fn class(self) -> &'static str {
93        match self {
94            Self::Default => "",
95            Self::Primary => " primary",
96            Self::Ghost => " ghost",
97            Self::Danger => " danger",
98        }
99    }
100}
101
102#[derive(Clone, Copy, Debug, Eq, PartialEq)]
103pub enum ButtonSize {
104    Default,
105    Small,
106    Large,
107}
108
109impl ButtonSize {
110    fn class(self) -> &'static str {
111        match self {
112            Self::Default => "",
113            Self::Small => " sm",
114            Self::Large => " lg",
115        }
116    }
117}
118
119#[derive(Debug, Template)]
120#[non_exhaustive]
121#[template(path = "components/button.html")]
122pub struct Button<'a> {
123    pub label: &'a str,
124    pub href: Option<&'a str>,
125    pub variant: ButtonVariant,
126    pub size: ButtonSize,
127    pub attrs: &'a [HtmlAttr<'a>],
128    pub disabled: bool,
129    pub button_type: &'a str,
130}
131
132impl<'a> Button<'a> {
133    pub const fn new(label: &'a str) -> Self {
134        Self {
135            label,
136            href: None,
137            variant: ButtonVariant::Default,
138            size: ButtonSize::Default,
139            attrs: &[],
140            disabled: false,
141            button_type: "button",
142        }
143    }
144
145    pub const fn primary(label: &'a str) -> Self {
146        Self {
147            variant: ButtonVariant::Primary,
148            ..Self::new(label)
149        }
150    }
151
152    pub const fn link(label: &'a str, href: &'a str) -> Self {
153        Self {
154            href: Some(href),
155            ..Self::new(label)
156        }
157    }
158
159    pub const fn with_href(mut self, href: &'a str) -> Self {
160        self.href = Some(href);
161        self
162    }
163
164    pub const fn with_variant(mut self, variant: ButtonVariant) -> Self {
165        self.variant = variant;
166        self
167    }
168
169    pub const fn with_size(mut self, size: ButtonSize) -> Self {
170        self.size = size;
171        self
172    }
173
174    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
175        self.attrs = attrs;
176        self
177    }
178
179    pub const fn disabled(mut self) -> Self {
180        self.disabled = true;
181        self
182    }
183
184    pub const fn with_button_type(mut self, button_type: &'a str) -> Self {
185        self.button_type = button_type;
186        self
187    }
188
189    pub fn class_name(&self) -> String {
190        format!("wf-btn{}{}", self.variant.class(), self.size.class())
191    }
192}
193
194impl<'a> askama::filters::HtmlSafe for Button<'a> {}
195
196#[derive(Clone, Copy, Debug, Eq, PartialEq)]
197pub enum FeedbackKind {
198    Info,
199    Ok,
200    Warn,
201    Error,
202}
203
204impl FeedbackKind {
205    fn class(self) -> &'static str {
206        match self {
207            Self::Info => "info",
208            Self::Ok => "ok",
209            Self::Warn => "warn",
210            Self::Error => "err",
211        }
212    }
213}
214
215#[derive(Debug, Template)]
216#[non_exhaustive]
217#[template(path = "components/alert.html")]
218pub struct Alert<'a> {
219    pub kind: FeedbackKind,
220    pub title: Option<&'a str>,
221    pub message: &'a str,
222}
223
224impl<'a> Alert<'a> {
225    pub const fn new(kind: FeedbackKind, message: &'a str) -> Self {
226        Self {
227            kind,
228            title: None,
229            message,
230        }
231    }
232
233    pub const fn with_title(mut self, title: &'a str) -> Self {
234        self.title = Some(title);
235        self
236    }
237
238    pub fn class_name(&self) -> String {
239        format!("wf-alert {}", self.kind.class())
240    }
241}
242
243impl<'a> askama::filters::HtmlSafe for Alert<'a> {}
244
245#[derive(Debug, Template)]
246#[non_exhaustive]
247#[template(path = "components/tag.html")]
248pub struct Tag<'a> {
249    pub kind: Option<FeedbackKind>,
250    pub label: &'a str,
251    pub dot: bool,
252}
253
254impl<'a> Tag<'a> {
255    pub const fn new(label: &'a str) -> Self {
256        Self {
257            kind: None,
258            label,
259            dot: false,
260        }
261    }
262
263    pub const fn status(kind: FeedbackKind, label: &'a str) -> Self {
264        Self {
265            kind: Some(kind),
266            label,
267            dot: true,
268        }
269    }
270
271    pub const fn with_kind(mut self, kind: FeedbackKind) -> Self {
272        self.kind = Some(kind);
273        self
274    }
275
276    pub const fn with_dot(mut self) -> Self {
277        self.dot = true;
278        self
279    }
280
281    pub fn class_name(&self) -> String {
282        match self.kind {
283            Some(kind) => format!("wf-tag {}", kind.class()),
284            None => "wf-tag".to_owned(),
285        }
286    }
287}
288
289impl<'a> askama::filters::HtmlSafe for Tag<'a> {}
290
291#[derive(Clone, Copy, Debug, Eq, PartialEq)]
292pub enum FieldState {
293    Default,
294    Error,
295    Success,
296}
297
298impl FieldState {
299    fn class(self) -> &'static str {
300        match self {
301            Self::Default => "",
302            Self::Error => " is-error",
303            Self::Success => " is-success",
304        }
305    }
306}
307
308#[derive(Debug, Template)]
309#[non_exhaustive]
310#[template(path = "components/field.html")]
311pub struct Field<'a> {
312    pub label: &'a str,
313    pub control_html: TrustedHtml<'a>,
314    pub hint: Option<&'a str>,
315    pub state: FieldState,
316}
317
318impl<'a> Field<'a> {
319    pub const fn new(label: &'a str, control_html: TrustedHtml<'a>) -> Self {
320        Self {
321            label,
322            control_html,
323            hint: None,
324            state: FieldState::Default,
325        }
326    }
327
328    pub const fn with_hint(mut self, hint: &'a str) -> Self {
329        self.hint = Some(hint);
330        self
331    }
332
333    pub const fn with_state(mut self, state: FieldState) -> Self {
334        self.state = state;
335        self
336    }
337
338    pub fn class_name(&self) -> String {
339        format!("wf-field{}", self.state.class())
340    }
341}
342
343impl<'a> askama::filters::HtmlSafe for Field<'a> {}
344
345#[derive(Debug, Template)]
346#[non_exhaustive]
347#[template(path = "components/form.html")]
348pub struct Form<'a> {
349    pub body_html: TrustedHtml<'a>,
350    pub action: Option<&'a str>,
351    pub method: &'a str,
352    pub enctype: Option<&'a str>,
353    pub attrs: &'a [HtmlAttr<'a>],
354}
355
356impl<'a> Form<'a> {
357    pub const fn new(body_html: TrustedHtml<'a>) -> Self {
358        Self {
359            body_html,
360            action: None,
361            method: "post",
362            enctype: None,
363            attrs: &[],
364        }
365    }
366
367    pub const fn with_action(mut self, action: &'a str) -> Self {
368        self.action = Some(action);
369        self
370    }
371
372    pub const fn with_method(mut self, method: &'a str) -> Self {
373        self.method = method;
374        self
375    }
376
377    pub const fn with_enctype(mut self, enctype: &'a str) -> Self {
378        self.enctype = Some(enctype);
379        self
380    }
381
382    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
383        self.attrs = attrs;
384        self
385    }
386}
387
388impl<'a> askama::filters::HtmlSafe for Form<'a> {}
389
390#[derive(Debug, Template)]
391#[non_exhaustive]
392#[template(path = "components/form_section.html")]
393pub struct FormSection<'a> {
394    pub title: &'a str,
395    pub body_html: TrustedHtml<'a>,
396    pub description: Option<&'a str>,
397    pub actions_html: Option<TrustedHtml<'a>>,
398}
399
400impl<'a> FormSection<'a> {
401    pub const fn new(title: &'a str, body_html: TrustedHtml<'a>) -> Self {
402        Self {
403            title,
404            body_html,
405            description: None,
406            actions_html: None,
407        }
408    }
409
410    pub const fn with_description(mut self, description: &'a str) -> Self {
411        self.description = Some(description);
412        self
413    }
414
415    pub const fn with_actions(mut self, actions_html: TrustedHtml<'a>) -> Self {
416        self.actions_html = Some(actions_html);
417        self
418    }
419}
420
421impl<'a> askama::filters::HtmlSafe for FormSection<'a> {}
422
423#[derive(Debug, Template)]
424#[non_exhaustive]
425#[template(path = "components/form_actions.html")]
426pub struct FormActions<'a> {
427    pub primary_html: TrustedHtml<'a>,
428    pub secondary_html: Option<TrustedHtml<'a>>,
429}
430
431impl<'a> FormActions<'a> {
432    pub const fn new(primary_html: TrustedHtml<'a>) -> Self {
433        Self {
434            primary_html,
435            secondary_html: None,
436        }
437    }
438
439    pub const fn with_secondary(mut self, secondary_html: TrustedHtml<'a>) -> Self {
440        self.secondary_html = Some(secondary_html);
441        self
442    }
443}
444
445impl<'a> askama::filters::HtmlSafe for FormActions<'a> {}
446
447#[derive(Debug, Template)]
448#[non_exhaustive]
449#[template(path = "components/object_fieldset.html")]
450pub struct ObjectFieldset<'a> {
451    pub legend: &'a str,
452    pub body_html: TrustedHtml<'a>,
453    pub description: Option<&'a str>,
454    pub actions_html: Option<TrustedHtml<'a>>,
455}
456
457impl<'a> ObjectFieldset<'a> {
458    pub const fn new(legend: &'a str, body_html: TrustedHtml<'a>) -> Self {
459        Self {
460            legend,
461            body_html,
462            description: None,
463            actions_html: None,
464        }
465    }
466
467    pub const fn with_description(mut self, description: &'a str) -> Self {
468        self.description = Some(description);
469        self
470    }
471
472    pub const fn with_actions(mut self, actions_html: TrustedHtml<'a>) -> Self {
473        self.actions_html = Some(actions_html);
474        self
475    }
476}
477
478impl<'a> askama::filters::HtmlSafe for ObjectFieldset<'a> {}
479
480#[derive(Debug, Template)]
481#[non_exhaustive]
482#[template(path = "components/repeatable_array.html")]
483pub struct RepeatableArray<'a> {
484    pub label: &'a str,
485    pub items_html: TrustedHtml<'a>,
486    pub description: Option<&'a str>,
487    pub action_html: Option<TrustedHtml<'a>>,
488}
489
490impl<'a> RepeatableArray<'a> {
491    pub const fn new(label: &'a str, items_html: TrustedHtml<'a>) -> Self {
492        Self {
493            label,
494            items_html,
495            description: None,
496            action_html: None,
497        }
498    }
499
500    pub const fn with_description(mut self, description: &'a str) -> Self {
501        self.description = Some(description);
502        self
503    }
504
505    pub const fn with_action(mut self, action_html: TrustedHtml<'a>) -> Self {
506        self.action_html = Some(action_html);
507        self
508    }
509}
510
511impl<'a> askama::filters::HtmlSafe for RepeatableArray<'a> {}
512
513#[derive(Debug, Template)]
514#[non_exhaustive]
515#[template(path = "components/repeatable_item.html")]
516pub struct RepeatableItem<'a> {
517    pub label: &'a str,
518    pub body_html: TrustedHtml<'a>,
519    pub actions_html: Option<TrustedHtml<'a>>,
520}
521
522impl<'a> RepeatableItem<'a> {
523    pub const fn new(label: &'a str, body_html: TrustedHtml<'a>) -> Self {
524        Self {
525            label,
526            body_html,
527            actions_html: None,
528        }
529    }
530
531    pub const fn with_actions(mut self, actions_html: TrustedHtml<'a>) -> Self {
532        self.actions_html = Some(actions_html);
533        self
534    }
535}
536
537impl<'a> askama::filters::HtmlSafe for RepeatableItem<'a> {}
538
539#[derive(Debug, Template)]
540#[non_exhaustive]
541#[template(path = "components/current_upload.html")]
542pub struct CurrentUpload<'a> {
543    pub label: &'a str,
544    pub href: &'a str,
545    pub filename: &'a str,
546    pub meta: Option<&'a str>,
547    pub thumbnail_html: Option<TrustedHtml<'a>>,
548    pub actions_html: Option<TrustedHtml<'a>>,
549}
550
551impl<'a> CurrentUpload<'a> {
552    pub const fn new(label: &'a str, href: &'a str, filename: &'a str) -> Self {
553        Self {
554            label,
555            href,
556            filename,
557            meta: None,
558            thumbnail_html: None,
559            actions_html: None,
560        }
561    }
562
563    pub const fn with_meta(mut self, meta: &'a str) -> Self {
564        self.meta = Some(meta);
565        self
566    }
567
568    pub const fn with_thumbnail(mut self, thumbnail_html: TrustedHtml<'a>) -> Self {
569        self.thumbnail_html = Some(thumbnail_html);
570        self
571    }
572
573    pub const fn with_actions(mut self, actions_html: TrustedHtml<'a>) -> Self {
574        self.actions_html = Some(actions_html);
575        self
576    }
577}
578
579impl<'a> askama::filters::HtmlSafe for CurrentUpload<'a> {}
580
581#[derive(Debug, Template)]
582#[non_exhaustive]
583#[template(path = "components/reference_select.html")]
584pub struct ReferenceSelect<'a> {
585    pub label: &'a str,
586    pub select_html: TrustedHtml<'a>,
587    pub hint: Option<&'a str>,
588}
589
590impl<'a> ReferenceSelect<'a> {
591    pub const fn new(label: &'a str, select_html: TrustedHtml<'a>) -> Self {
592        Self {
593            label,
594            select_html,
595            hint: None,
596        }
597    }
598
599    pub const fn with_hint(mut self, hint: &'a str) -> Self {
600        self.hint = Some(hint);
601        self
602    }
603}
604
605impl<'a> askama::filters::HtmlSafe for ReferenceSelect<'a> {}
606
607#[derive(Debug, Template)]
608#[non_exhaustive]
609#[template(path = "components/markdown_textarea.html")]
610pub struct MarkdownTextarea<'a> {
611    pub name: &'a str,
612    pub value: Option<&'a str>,
613    pub placeholder: Option<&'a str>,
614    pub rows: u16,
615    pub attrs: &'a [HtmlAttr<'a>],
616}
617
618impl<'a> MarkdownTextarea<'a> {
619    pub const fn new(name: &'a str) -> Self {
620        Self {
621            name,
622            value: None,
623            placeholder: None,
624            rows: 6,
625            attrs: &[],
626        }
627    }
628
629    pub const fn with_value(mut self, value: &'a str) -> Self {
630        self.value = Some(value);
631        self
632    }
633
634    pub const fn with_placeholder(mut self, placeholder: &'a str) -> Self {
635        self.placeholder = Some(placeholder);
636        self
637    }
638
639    pub const fn with_rows(mut self, rows: u16) -> Self {
640        self.rows = rows;
641        self
642    }
643
644    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
645        self.attrs = attrs;
646        self
647    }
648}
649
650impl<'a> askama::filters::HtmlSafe for MarkdownTextarea<'a> {}
651
652#[derive(Debug, Template)]
653#[non_exhaustive]
654#[template(path = "components/rich_text_host.html")]
655pub struct RichTextHost<'a> {
656    pub id: &'a str,
657    pub name: &'a str,
658    pub value: Option<&'a str>,
659    pub toolbar_html: Option<TrustedHtml<'a>>,
660    pub body_html: Option<TrustedHtml<'a>>,
661}
662
663impl<'a> RichTextHost<'a> {
664    pub const fn new(id: &'a str, name: &'a str) -> Self {
665        Self {
666            id,
667            name,
668            value: None,
669            toolbar_html: None,
670            body_html: None,
671        }
672    }
673
674    pub const fn with_value(mut self, value: &'a str) -> Self {
675        self.value = Some(value);
676        self
677    }
678
679    pub const fn with_toolbar(mut self, toolbar_html: TrustedHtml<'a>) -> Self {
680        self.toolbar_html = Some(toolbar_html);
681        self
682    }
683
684    pub const fn with_body(mut self, body_html: TrustedHtml<'a>) -> Self {
685        self.body_html = Some(body_html);
686        self
687    }
688}
689
690impl<'a> askama::filters::HtmlSafe for RichTextHost<'a> {}
691
692#[derive(Debug, Template)]
693#[non_exhaustive]
694#[template(path = "components/button_group.html")]
695pub struct ButtonGroup<'a> {
696    pub buttons: &'a [Button<'a>],
697    pub attrs: &'a [HtmlAttr<'a>],
698}
699
700impl<'a> ButtonGroup<'a> {
701    pub const fn new(buttons: &'a [Button<'a>]) -> Self {
702        Self {
703            buttons,
704            attrs: &[],
705        }
706    }
707
708    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
709        self.attrs = attrs;
710        self
711    }
712}
713
714impl<'a> askama::filters::HtmlSafe for ButtonGroup<'a> {}
715
716#[derive(Debug, Template)]
717#[non_exhaustive]
718#[template(path = "components/split_button.html")]
719pub struct SplitButton<'a> {
720    pub action: Button<'a>,
721    pub menu: Button<'a>,
722    pub attrs: &'a [HtmlAttr<'a>],
723}
724
725impl<'a> SplitButton<'a> {
726    pub const fn new(action: Button<'a>, menu: Button<'a>) -> Self {
727        Self {
728            action,
729            menu,
730            attrs: &[],
731        }
732    }
733
734    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
735        self.attrs = attrs;
736        self
737    }
738}
739
740impl<'a> askama::filters::HtmlSafe for SplitButton<'a> {}
741
742#[derive(Debug, Template)]
743#[non_exhaustive]
744#[template(path = "components/icon_button.html")]
745pub struct IconButton<'a> {
746    pub icon: TrustedHtml<'a>,
747    pub label: &'a str,
748    pub href: Option<&'a str>,
749    pub variant: ButtonVariant,
750    pub attrs: &'a [HtmlAttr<'a>],
751    pub disabled: bool,
752    pub button_type: &'a str,
753}
754
755impl<'a> IconButton<'a> {
756    pub const fn new(icon: TrustedHtml<'a>, label: &'a str) -> Self {
757        Self {
758            icon,
759            label,
760            href: None,
761            variant: ButtonVariant::Default,
762            attrs: &[],
763            disabled: false,
764            button_type: "button",
765        }
766    }
767
768    pub const fn with_href(mut self, href: &'a str) -> Self {
769        self.href = Some(href);
770        self
771    }
772
773    pub const fn with_variant(mut self, variant: ButtonVariant) -> Self {
774        self.variant = variant;
775        self
776    }
777
778    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
779        self.attrs = attrs;
780        self
781    }
782
783    pub const fn disabled(mut self) -> Self {
784        self.disabled = true;
785        self
786    }
787
788    pub const fn with_button_type(mut self, button_type: &'a str) -> Self {
789        self.button_type = button_type;
790        self
791    }
792
793    pub fn class_name(&self) -> String {
794        format!("wf-icon-btn{}", self.variant.class())
795    }
796}
797
798impl<'a> askama::filters::HtmlSafe for IconButton<'a> {}
799
800#[derive(Clone, Copy, Debug, Eq, PartialEq)]
801pub enum ControlSize {
802    Default,
803    Small,
804}
805
806impl ControlSize {
807    fn class(self) -> &'static str {
808        match self {
809            Self::Default => "",
810            Self::Small => " sm",
811        }
812    }
813}
814
815#[derive(Debug, Template)]
816#[non_exhaustive]
817#[template(path = "components/input.html")]
818pub struct Input<'a> {
819    pub name: &'a str,
820    pub input_type: &'a str,
821    pub value: Option<&'a str>,
822    pub placeholder: Option<&'a str>,
823    pub size: ControlSize,
824    pub attrs: &'a [HtmlAttr<'a>],
825    pub disabled: bool,
826    pub required: bool,
827}
828
829impl<'a> Input<'a> {
830    pub const fn new(name: &'a str) -> Self {
831        Self {
832            name,
833            input_type: "text",
834            value: None,
835            placeholder: None,
836            size: ControlSize::Default,
837            attrs: &[],
838            disabled: false,
839            required: false,
840        }
841    }
842
843    pub const fn email(name: &'a str) -> Self {
844        Self {
845            input_type: "email",
846            ..Self::new(name)
847        }
848    }
849
850    pub const fn url(name: &'a str) -> Self {
851        Self {
852            input_type: "url",
853            ..Self::new(name)
854        }
855    }
856
857    pub const fn search(name: &'a str) -> Self {
858        Self {
859            input_type: "search",
860            ..Self::new(name)
861        }
862    }
863
864    pub const fn with_type(mut self, input_type: &'a str) -> Self {
865        self.input_type = input_type;
866        self
867    }
868
869    pub const fn with_value(mut self, value: &'a str) -> Self {
870        self.value = Some(value);
871        self
872    }
873
874    pub const fn with_placeholder(mut self, placeholder: &'a str) -> Self {
875        self.placeholder = Some(placeholder);
876        self
877    }
878
879    pub const fn with_size(mut self, size: ControlSize) -> Self {
880        self.size = size;
881        self
882    }
883
884    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
885        self.attrs = attrs;
886        self
887    }
888
889    pub const fn disabled(mut self) -> Self {
890        self.disabled = true;
891        self
892    }
893
894    pub const fn required(mut self) -> Self {
895        self.required = true;
896        self
897    }
898
899    pub fn class_name(&self) -> String {
900        format!("wf-input{}", self.size.class())
901    }
902}
903
904impl<'a> askama::filters::HtmlSafe for Input<'a> {}
905
906#[derive(Debug, Template)]
907#[non_exhaustive]
908#[template(path = "components/textarea.html")]
909pub struct Textarea<'a> {
910    pub name: &'a str,
911    pub value: Option<&'a str>,
912    pub placeholder: Option<&'a str>,
913    pub rows: Option<u16>,
914    pub attrs: &'a [HtmlAttr<'a>],
915    pub disabled: bool,
916    pub required: bool,
917}
918
919impl<'a> Textarea<'a> {
920    pub const fn new(name: &'a str) -> Self {
921        Self {
922            name,
923            value: None,
924            placeholder: None,
925            rows: None,
926            attrs: &[],
927            disabled: false,
928            required: false,
929        }
930    }
931
932    pub const fn with_value(mut self, value: &'a str) -> Self {
933        self.value = Some(value);
934        self
935    }
936
937    pub const fn with_placeholder(mut self, placeholder: &'a str) -> Self {
938        self.placeholder = Some(placeholder);
939        self
940    }
941
942    pub const fn with_rows(mut self, rows: u16) -> Self {
943        self.rows = Some(rows);
944        self
945    }
946
947    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
948        self.attrs = attrs;
949        self
950    }
951
952    pub const fn disabled(mut self) -> Self {
953        self.disabled = true;
954        self
955    }
956
957    pub const fn required(mut self) -> Self {
958        self.required = true;
959        self
960    }
961}
962
963impl<'a> askama::filters::HtmlSafe for Textarea<'a> {}
964
965#[derive(Clone, Copy, Debug, Eq, PartialEq)]
966pub struct SelectOption<'a> {
967    pub value: &'a str,
968    pub label: &'a str,
969    pub selected: bool,
970    pub disabled: bool,
971}
972
973impl<'a> SelectOption<'a> {
974    pub const fn new(value: &'a str, label: &'a str) -> Self {
975        Self {
976            value,
977            label,
978            selected: false,
979            disabled: false,
980        }
981    }
982
983    pub const fn selected(mut self) -> Self {
984        self.selected = true;
985        self
986    }
987
988    pub const fn disabled(mut self) -> Self {
989        self.disabled = true;
990        self
991    }
992}
993
994#[derive(Debug, Template)]
995#[non_exhaustive]
996#[template(path = "components/select.html")]
997pub struct Select<'a> {
998    pub name: &'a str,
999    pub options: &'a [SelectOption<'a>],
1000    pub size: ControlSize,
1001    pub attrs: &'a [HtmlAttr<'a>],
1002    pub disabled: bool,
1003    pub required: bool,
1004}
1005
1006impl<'a> Select<'a> {
1007    pub const fn new(name: &'a str, options: &'a [SelectOption<'a>]) -> Self {
1008        Self {
1009            name,
1010            options,
1011            size: ControlSize::Default,
1012            attrs: &[],
1013            disabled: false,
1014            required: false,
1015        }
1016    }
1017
1018    pub const fn with_size(mut self, size: ControlSize) -> Self {
1019        self.size = size;
1020        self
1021    }
1022
1023    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
1024        self.attrs = attrs;
1025        self
1026    }
1027
1028    pub const fn disabled(mut self) -> Self {
1029        self.disabled = true;
1030        self
1031    }
1032
1033    pub const fn required(mut self) -> Self {
1034        self.required = true;
1035        self
1036    }
1037
1038    pub fn class_name(&self) -> String {
1039        format!("wf-select{}", self.size.class())
1040    }
1041}
1042
1043impl<'a> askama::filters::HtmlSafe for Select<'a> {}
1044
1045#[derive(Debug, Template)]
1046#[non_exhaustive]
1047#[template(path = "components/input_group.html")]
1048pub struct InputGroup<'a> {
1049    pub control_html: TrustedHtml<'a>,
1050    pub prefix: Option<&'a str>,
1051    pub suffix: Option<&'a str>,
1052    pub attrs: &'a [HtmlAttr<'a>],
1053}
1054
1055impl<'a> InputGroup<'a> {
1056    pub const fn new(control_html: TrustedHtml<'a>) -> Self {
1057        Self {
1058            control_html,
1059            prefix: None,
1060            suffix: None,
1061            attrs: &[],
1062        }
1063    }
1064
1065    pub const fn with_prefix(mut self, prefix: &'a str) -> Self {
1066        self.prefix = Some(prefix);
1067        self
1068    }
1069
1070    pub const fn with_suffix(mut self, suffix: &'a str) -> Self {
1071        self.suffix = Some(suffix);
1072        self
1073    }
1074
1075    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
1076        self.attrs = attrs;
1077        self
1078    }
1079}
1080
1081impl<'a> askama::filters::HtmlSafe for InputGroup<'a> {}
1082
1083#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1084pub enum CheckKind {
1085    Checkbox,
1086    Radio,
1087}
1088
1089impl CheckKind {
1090    fn input_type(self) -> &'static str {
1091        match self {
1092            Self::Checkbox => "checkbox",
1093            Self::Radio => "radio",
1094        }
1095    }
1096}
1097
1098#[derive(Debug, Template)]
1099#[non_exhaustive]
1100#[template(path = "components/check_row.html")]
1101pub struct CheckRow<'a> {
1102    pub kind: CheckKind,
1103    pub name: &'a str,
1104    pub value: &'a str,
1105    pub label: &'a str,
1106    pub attrs: &'a [HtmlAttr<'a>],
1107    pub checked: bool,
1108    pub disabled: bool,
1109}
1110
1111impl<'a> CheckRow<'a> {
1112    pub const fn checkbox(name: &'a str, value: &'a str, label: &'a str) -> Self {
1113        Self {
1114            kind: CheckKind::Checkbox,
1115            name,
1116            value,
1117            label,
1118            attrs: &[],
1119            checked: false,
1120            disabled: false,
1121        }
1122    }
1123
1124    pub const fn radio(name: &'a str, value: &'a str, label: &'a str) -> Self {
1125        Self {
1126            kind: CheckKind::Radio,
1127            ..Self::checkbox(name, value, label)
1128        }
1129    }
1130
1131    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
1132        self.attrs = attrs;
1133        self
1134    }
1135
1136    pub const fn checked(mut self) -> Self {
1137        self.checked = true;
1138        self
1139    }
1140
1141    pub const fn disabled(mut self) -> Self {
1142        self.disabled = true;
1143        self
1144    }
1145
1146    pub fn input_type(&self) -> &'static str {
1147        self.kind.input_type()
1148    }
1149}
1150
1151impl<'a> askama::filters::HtmlSafe for CheckRow<'a> {}
1152
1153#[derive(Debug, Template)]
1154#[non_exhaustive]
1155#[template(path = "components/switch.html")]
1156pub struct Switch<'a> {
1157    pub name: &'a str,
1158    pub value: &'a str,
1159    pub attrs: &'a [HtmlAttr<'a>],
1160    pub checked: bool,
1161    pub disabled: bool,
1162}
1163
1164impl<'a> Switch<'a> {
1165    pub const fn new(name: &'a str) -> Self {
1166        Self {
1167            name,
1168            value: "on",
1169            attrs: &[],
1170            checked: false,
1171            disabled: false,
1172        }
1173    }
1174
1175    pub const fn with_value(mut self, value: &'a str) -> Self {
1176        self.value = value;
1177        self
1178    }
1179
1180    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
1181        self.attrs = attrs;
1182        self
1183    }
1184
1185    pub const fn checked(mut self) -> Self {
1186        self.checked = true;
1187        self
1188    }
1189
1190    pub const fn disabled(mut self) -> Self {
1191        self.disabled = true;
1192        self
1193    }
1194}
1195
1196impl<'a> askama::filters::HtmlSafe for Switch<'a> {}
1197
1198#[derive(Debug, Template)]
1199#[non_exhaustive]
1200#[template(path = "components/range.html")]
1201pub struct Range<'a> {
1202    pub name: &'a str,
1203    pub value: Option<&'a str>,
1204    pub min: Option<&'a str>,
1205    pub max: Option<&'a str>,
1206    pub step: Option<&'a str>,
1207    pub attrs: &'a [HtmlAttr<'a>],
1208    pub disabled: bool,
1209}
1210
1211impl<'a> Range<'a> {
1212    pub const fn new(name: &'a str) -> Self {
1213        Self {
1214            name,
1215            value: None,
1216            min: None,
1217            max: None,
1218            step: None,
1219            attrs: &[],
1220            disabled: false,
1221        }
1222    }
1223
1224    pub const fn with_value(mut self, value: &'a str) -> Self {
1225        self.value = Some(value);
1226        self
1227    }
1228
1229    pub const fn with_bounds(mut self, min: &'a str, max: &'a str) -> Self {
1230        self.min = Some(min);
1231        self.max = Some(max);
1232        self
1233    }
1234
1235    pub const fn with_step(mut self, step: &'a str) -> Self {
1236        self.step = Some(step);
1237        self
1238    }
1239
1240    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
1241        self.attrs = attrs;
1242        self
1243    }
1244
1245    pub const fn disabled(mut self) -> Self {
1246        self.disabled = true;
1247        self
1248    }
1249}
1250
1251impl<'a> askama::filters::HtmlSafe for Range<'a> {}
1252
1253#[derive(Debug, Template)]
1254#[non_exhaustive]
1255#[template(path = "components/dropzone.html")]
1256pub struct Dropzone<'a> {
1257    pub name: &'a str,
1258    pub title: &'a str,
1259    pub hint: Option<&'a str>,
1260    pub accept: Option<&'a str>,
1261    pub attrs: &'a [HtmlAttr<'a>],
1262    pub multiple: bool,
1263    pub disabled: bool,
1264    pub dragover: bool,
1265}
1266
1267impl<'a> Dropzone<'a> {
1268    pub const fn new(name: &'a str) -> Self {
1269        Self {
1270            name,
1271            title: "Drop files or click",
1272            hint: None,
1273            accept: None,
1274            attrs: &[],
1275            multiple: false,
1276            disabled: false,
1277            dragover: false,
1278        }
1279    }
1280
1281    pub const fn with_title(mut self, title: &'a str) -> Self {
1282        self.title = title;
1283        self
1284    }
1285
1286    pub const fn with_hint(mut self, hint: &'a str) -> Self {
1287        self.hint = Some(hint);
1288        self
1289    }
1290
1291    pub const fn with_accept(mut self, accept: &'a str) -> Self {
1292        self.accept = Some(accept);
1293        self
1294    }
1295
1296    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
1297        self.attrs = attrs;
1298        self
1299    }
1300
1301    pub const fn multiple(mut self) -> Self {
1302        self.multiple = true;
1303        self
1304    }
1305
1306    pub const fn disabled(mut self) -> Self {
1307        self.disabled = true;
1308        self
1309    }
1310
1311    pub const fn dragover(mut self) -> Self {
1312        self.dragover = true;
1313        self
1314    }
1315
1316    pub fn class_name(&self) -> String {
1317        let dragover = if self.dragover { " is-dragover" } else { "" };
1318        let disabled = if self.disabled { " is-disabled" } else { "" };
1319        format!("wf-dropzone{dragover}{disabled}")
1320    }
1321}
1322
1323impl<'a> askama::filters::HtmlSafe for Dropzone<'a> {}
1324
1325#[derive(Debug, Template)]
1326#[non_exhaustive]
1327#[template(path = "components/panel.html")]
1328pub struct Panel<'a> {
1329    pub title: &'a str,
1330    pub body_html: TrustedHtml<'a>,
1331    pub action_html: Option<TrustedHtml<'a>>,
1332    pub danger: bool,
1333    pub attrs: &'a [HtmlAttr<'a>],
1334}
1335
1336impl<'a> Panel<'a> {
1337    pub const fn new(title: &'a str, body_html: TrustedHtml<'a>) -> Self {
1338        Self {
1339            title,
1340            body_html,
1341            action_html: None,
1342            danger: false,
1343            attrs: &[],
1344        }
1345    }
1346
1347    pub const fn with_action(mut self, action_html: TrustedHtml<'a>) -> Self {
1348        self.action_html = Some(action_html);
1349        self
1350    }
1351
1352    pub const fn danger(mut self) -> Self {
1353        self.danger = true;
1354        self
1355    }
1356
1357    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
1358        self.attrs = attrs;
1359        self
1360    }
1361
1362    pub fn class_name(&self) -> &'static str {
1363        if self.danger {
1364            "wf-panel is-danger"
1365        } else {
1366            "wf-panel"
1367        }
1368    }
1369}
1370
1371impl<'a> askama::filters::HtmlSafe for Panel<'a> {}
1372
1373#[derive(Debug, Template)]
1374#[non_exhaustive]
1375#[template(path = "components/form_panel.html")]
1376pub struct FormPanel<'a> {
1377    pub title: &'a str,
1378    pub body_html: TrustedHtml<'a>,
1379    pub subtitle: Option<&'a str>,
1380    pub actions_html: Option<TrustedHtml<'a>>,
1381    pub meta_html: Option<TrustedHtml<'a>>,
1382    pub attrs: &'a [HtmlAttr<'a>],
1383}
1384
1385impl<'a> FormPanel<'a> {
1386    pub const fn new(title: &'a str, body_html: TrustedHtml<'a>) -> Self {
1387        Self {
1388            title,
1389            body_html,
1390            subtitle: None,
1391            actions_html: None,
1392            meta_html: None,
1393            attrs: &[],
1394        }
1395    }
1396
1397    pub const fn with_subtitle(mut self, subtitle: &'a str) -> Self {
1398        self.subtitle = Some(subtitle);
1399        self
1400    }
1401
1402    pub const fn with_actions(mut self, actions_html: TrustedHtml<'a>) -> Self {
1403        self.actions_html = Some(actions_html);
1404        self
1405    }
1406
1407    pub const fn with_meta(mut self, meta_html: TrustedHtml<'a>) -> Self {
1408        self.meta_html = Some(meta_html);
1409        self
1410    }
1411
1412    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
1413        self.attrs = attrs;
1414        self
1415    }
1416}
1417
1418impl<'a> askama::filters::HtmlSafe for FormPanel<'a> {}
1419
1420#[derive(Debug, Template)]
1421#[non_exhaustive]
1422#[template(path = "components/split_shell.html")]
1423pub struct SplitShell<'a> {
1424    pub content_html: TrustedHtml<'a>,
1425    pub visual_html: Option<TrustedHtml<'a>>,
1426    pub top_html: Option<TrustedHtml<'a>>,
1427    pub footer_html: Option<TrustedHtml<'a>>,
1428    pub mode: Option<&'a str>,
1429    pub mode_locked: bool,
1430    pub asset_base_path: &'a str,
1431    pub attrs: &'a [HtmlAttr<'a>],
1432}
1433
1434impl<'a> SplitShell<'a> {
1435    pub const fn new(content_html: TrustedHtml<'a>) -> Self {
1436        Self {
1437            content_html,
1438            visual_html: None,
1439            top_html: None,
1440            footer_html: None,
1441            mode: None,
1442            mode_locked: false,
1443            asset_base_path: assets::DEFAULT_BASE_PATH,
1444            attrs: &[],
1445        }
1446    }
1447
1448    pub const fn with_visual(mut self, visual_html: TrustedHtml<'a>) -> Self {
1449        self.visual_html = Some(visual_html);
1450        self
1451    }
1452
1453    pub const fn with_top(mut self, top_html: TrustedHtml<'a>) -> Self {
1454        self.top_html = Some(top_html);
1455        self
1456    }
1457
1458    pub const fn with_footer(mut self, footer_html: TrustedHtml<'a>) -> Self {
1459        self.footer_html = Some(footer_html);
1460        self
1461    }
1462
1463    pub const fn with_mode(mut self, mode: &'a str) -> Self {
1464        self.mode = Some(mode);
1465        self
1466    }
1467
1468    pub const fn mode_locked(mut self) -> Self {
1469        self.mode_locked = true;
1470        self
1471    }
1472
1473    pub const fn with_asset_base_path(mut self, asset_base_path: &'a str) -> Self {
1474        self.asset_base_path = asset_base_path;
1475        self
1476    }
1477
1478    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
1479        self.attrs = attrs;
1480        self
1481    }
1482}
1483
1484impl<'a> askama::filters::HtmlSafe for SplitShell<'a> {}
1485
1486#[derive(Debug, Template)]
1487#[non_exhaustive]
1488#[template(path = "components/settings_section.html")]
1489pub struct SettingsSection<'a> {
1490    pub title: &'a str,
1491    pub body_html: TrustedHtml<'a>,
1492    pub description: Option<&'a str>,
1493    pub action_html: Option<TrustedHtml<'a>>,
1494    pub danger: bool,
1495    pub attrs: &'a [HtmlAttr<'a>],
1496}
1497
1498impl<'a> SettingsSection<'a> {
1499    pub const fn new(title: &'a str, body_html: TrustedHtml<'a>) -> Self {
1500        Self {
1501            title,
1502            body_html,
1503            description: None,
1504            action_html: None,
1505            danger: false,
1506            attrs: &[],
1507        }
1508    }
1509
1510    pub const fn with_description(mut self, description: &'a str) -> Self {
1511        self.description = Some(description);
1512        self
1513    }
1514
1515    pub const fn with_action(mut self, action_html: TrustedHtml<'a>) -> Self {
1516        self.action_html = Some(action_html);
1517        self
1518    }
1519
1520    pub const fn danger(mut self) -> Self {
1521        self.danger = true;
1522        self
1523    }
1524
1525    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
1526        self.attrs = attrs;
1527        self
1528    }
1529
1530    pub fn class_name(&self) -> &'static str {
1531        if self.danger {
1532            "wf-panel wf-settings-section is-danger"
1533        } else {
1534            "wf-panel wf-settings-section"
1535        }
1536    }
1537}
1538
1539impl<'a> askama::filters::HtmlSafe for SettingsSection<'a> {}
1540
1541#[derive(Debug, Template)]
1542#[non_exhaustive]
1543#[template(path = "components/inline_form_row.html")]
1544pub struct InlineFormRow<'a> {
1545    pub label: &'a str,
1546    pub control_html: TrustedHtml<'a>,
1547    pub hint: Option<&'a str>,
1548    pub action_html: Option<TrustedHtml<'a>>,
1549}
1550
1551impl<'a> InlineFormRow<'a> {
1552    pub const fn new(label: &'a str, control_html: TrustedHtml<'a>) -> Self {
1553        Self {
1554            label,
1555            control_html,
1556            hint: None,
1557            action_html: None,
1558        }
1559    }
1560
1561    pub const fn with_hint(mut self, hint: &'a str) -> Self {
1562        self.hint = Some(hint);
1563        self
1564    }
1565
1566    pub const fn with_action(mut self, action_html: TrustedHtml<'a>) -> Self {
1567        self.action_html = Some(action_html);
1568        self
1569    }
1570}
1571
1572impl<'a> askama::filters::HtmlSafe for InlineFormRow<'a> {}
1573
1574#[derive(Debug, Template)]
1575#[non_exhaustive]
1576#[template(path = "components/copyable_value.html")]
1577pub struct CopyableValue<'a> {
1578    pub label: &'a str,
1579    pub id: &'a str,
1580    pub value: &'a str,
1581    pub button_label: &'a str,
1582    pub secret: bool,
1583}
1584
1585impl<'a> CopyableValue<'a> {
1586    pub const fn new(label: &'a str, id: &'a str, value: &'a str) -> Self {
1587        Self {
1588            label,
1589            id,
1590            value,
1591            button_label: "Copy",
1592            secret: false,
1593        }
1594    }
1595
1596    pub const fn with_button_label(mut self, button_label: &'a str) -> Self {
1597        self.button_label = button_label;
1598        self
1599    }
1600
1601    pub const fn secret(mut self) -> Self {
1602        self.secret = true;
1603        self
1604    }
1605
1606    pub fn value_class(&self) -> &'static str {
1607        if self.secret {
1608            "wf-copyable-value is-secret"
1609        } else {
1610            "wf-copyable-value"
1611        }
1612    }
1613}
1614
1615impl<'a> askama::filters::HtmlSafe for CopyableValue<'a> {}
1616
1617#[derive(Debug, Template)]
1618#[non_exhaustive]
1619#[template(path = "components/secret_value.html")]
1620pub struct SecretValue<'a> {
1621    pub label: &'a str,
1622    pub id: &'a str,
1623    pub value: &'a str,
1624    pub button_label: &'a str,
1625    pub revealed: bool,
1626    pub copy_raw_value: bool,
1627    pub warning: Option<&'a str>,
1628    pub help_html: Option<TrustedHtml<'a>>,
1629    pub attrs: &'a [HtmlAttr<'a>],
1630}
1631
1632impl<'a> SecretValue<'a> {
1633    pub const fn new(label: &'a str, id: &'a str, value: &'a str) -> Self {
1634        Self {
1635            label,
1636            id,
1637            value,
1638            button_label: "Copy",
1639            revealed: false,
1640            copy_raw_value: false,
1641            warning: None,
1642            help_html: None,
1643            attrs: &[],
1644        }
1645    }
1646
1647    pub const fn revealed(mut self) -> Self {
1648        self.revealed = true;
1649        self
1650    }
1651
1652    pub const fn copy_raw_value(mut self) -> Self {
1653        self.copy_raw_value = true;
1654        self
1655    }
1656
1657    pub const fn with_button_label(mut self, button_label: &'a str) -> Self {
1658        self.button_label = button_label;
1659        self
1660    }
1661
1662    pub const fn with_warning(mut self, warning: &'a str) -> Self {
1663        self.warning = Some(warning);
1664        self
1665    }
1666
1667    pub const fn with_help(mut self, help_html: TrustedHtml<'a>) -> Self {
1668        self.help_html = Some(help_html);
1669        self
1670    }
1671
1672    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
1673        self.attrs = attrs;
1674        self
1675    }
1676
1677    pub const fn display_value(&self) -> &str {
1678        if self.revealed {
1679            self.value
1680        } else {
1681            "********"
1682        }
1683    }
1684
1685    pub fn value_class(&self) -> &'static str {
1686        if self.revealed {
1687            "wf-secret-code is-revealed"
1688        } else {
1689            "wf-secret-code is-masked"
1690        }
1691    }
1692}
1693
1694impl<'a> askama::filters::HtmlSafe for SecretValue<'a> {}
1695
1696#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1697pub struct ChecklistItem<'a> {
1698    pub label: &'a str,
1699    pub description: Option<&'a str>,
1700    pub kind: FeedbackKind,
1701    pub status_label: Option<&'a str>,
1702    pub icon_html: Option<TrustedHtml<'a>>,
1703}
1704
1705impl<'a> ChecklistItem<'a> {
1706    pub const fn new(label: &'a str, kind: FeedbackKind) -> Self {
1707        Self {
1708            label,
1709            description: None,
1710            kind,
1711            status_label: None,
1712            icon_html: None,
1713        }
1714    }
1715
1716    pub const fn info(label: &'a str) -> Self {
1717        Self::new(label, FeedbackKind::Info)
1718    }
1719
1720    pub const fn ok(label: &'a str) -> Self {
1721        Self::new(label, FeedbackKind::Ok)
1722    }
1723
1724    pub const fn warn(label: &'a str) -> Self {
1725        Self::new(label, FeedbackKind::Warn)
1726    }
1727
1728    pub const fn error(label: &'a str) -> Self {
1729        Self::new(label, FeedbackKind::Error)
1730    }
1731
1732    pub const fn with_description(mut self, description: &'a str) -> Self {
1733        self.description = Some(description);
1734        self
1735    }
1736
1737    pub const fn with_status_label(mut self, status_label: &'a str) -> Self {
1738        self.status_label = Some(status_label);
1739        self
1740    }
1741
1742    pub const fn with_icon(mut self, icon_html: TrustedHtml<'a>) -> Self {
1743        self.icon_html = Some(icon_html);
1744        self
1745    }
1746
1747    pub fn class_name(&self) -> &'static str {
1748        match self.kind {
1749            FeedbackKind::Info => "wf-checklist-item is-info",
1750            FeedbackKind::Ok => "wf-checklist-item is-ok",
1751            FeedbackKind::Warn => "wf-checklist-item is-warn",
1752            FeedbackKind::Error => "wf-checklist-item is-err",
1753        }
1754    }
1755
1756    pub fn status_text(&self) -> &'a str {
1757        self.status_label.unwrap_or(match self.kind {
1758            FeedbackKind::Info => "info",
1759            FeedbackKind::Ok => "ok",
1760            FeedbackKind::Warn => "warn",
1761            FeedbackKind::Error => "error",
1762        })
1763    }
1764}
1765
1766#[derive(Debug, Template)]
1767#[non_exhaustive]
1768#[template(path = "components/checklist.html")]
1769pub struct Checklist<'a> {
1770    pub items: &'a [ChecklistItem<'a>],
1771    pub attrs: &'a [HtmlAttr<'a>],
1772}
1773
1774impl<'a> Checklist<'a> {
1775    pub const fn new(items: &'a [ChecklistItem<'a>]) -> Self {
1776        Self { items, attrs: &[] }
1777    }
1778
1779    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
1780        self.attrs = attrs;
1781        self
1782    }
1783}
1784
1785impl<'a> askama::filters::HtmlSafe for Checklist<'a> {}
1786
1787#[derive(Debug, Template)]
1788#[non_exhaustive]
1789#[template(path = "components/code_grid.html")]
1790pub struct CodeGrid<'a> {
1791    pub codes: &'a [&'a str],
1792    pub label: Option<&'a str>,
1793    pub attrs: &'a [HtmlAttr<'a>],
1794}
1795
1796impl<'a> CodeGrid<'a> {
1797    pub const fn new(codes: &'a [&'a str]) -> Self {
1798        Self {
1799            codes,
1800            label: None,
1801            attrs: &[],
1802        }
1803    }
1804
1805    pub const fn with_label(mut self, label: &'a str) -> Self {
1806        self.label = Some(label);
1807        self
1808    }
1809
1810    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
1811        self.attrs = attrs;
1812        self
1813    }
1814}
1815
1816impl<'a> askama::filters::HtmlSafe for CodeGrid<'a> {}
1817
1818#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1819pub struct CredentialStatusItem<'a> {
1820    pub label: &'a str,
1821    pub value: &'a str,
1822    pub kind: FeedbackKind,
1823    pub status_label: &'a str,
1824}
1825
1826impl<'a> CredentialStatusItem<'a> {
1827    pub const fn new(
1828        label: &'a str,
1829        value: &'a str,
1830        kind: FeedbackKind,
1831        status_label: &'a str,
1832    ) -> Self {
1833        Self {
1834            label,
1835            value,
1836            kind,
1837            status_label,
1838        }
1839    }
1840
1841    pub const fn ok(label: &'a str, value: &'a str) -> Self {
1842        Self::new(label, value, FeedbackKind::Ok, "ok")
1843    }
1844
1845    pub const fn warn(label: &'a str, value: &'a str) -> Self {
1846        Self::new(label, value, FeedbackKind::Warn, "warn")
1847    }
1848
1849    pub const fn error(label: &'a str, value: &'a str) -> Self {
1850        Self::new(label, value, FeedbackKind::Error, "error")
1851    }
1852
1853    pub const fn info(label: &'a str, value: &'a str) -> Self {
1854        Self::new(label, value, FeedbackKind::Info, "info")
1855    }
1856
1857    pub fn kind_class(&self) -> String {
1858        format!("wf-tag {}", self.kind.class())
1859    }
1860}
1861
1862#[derive(Debug, Template)]
1863#[non_exhaustive]
1864#[template(path = "components/credential_status_list.html")]
1865pub struct CredentialStatusList<'a> {
1866    pub items: &'a [CredentialStatusItem<'a>],
1867}
1868
1869impl<'a> CredentialStatusList<'a> {
1870    pub const fn new(items: &'a [CredentialStatusItem<'a>]) -> Self {
1871        Self { items }
1872    }
1873}
1874
1875impl<'a> askama::filters::HtmlSafe for CredentialStatusList<'a> {}
1876
1877#[derive(Debug, Template)]
1878#[non_exhaustive]
1879#[template(path = "components/confirm_action.html")]
1880pub struct ConfirmAction<'a> {
1881    pub label: &'a str,
1882    pub action: &'a str,
1883    pub method: &'a str,
1884    pub message: Option<&'a str>,
1885    pub confirm: Option<&'a str>,
1886    pub attrs: &'a [HtmlAttr<'a>],
1887}
1888
1889impl<'a> ConfirmAction<'a> {
1890    pub const fn new(label: &'a str, action: &'a str) -> Self {
1891        Self {
1892            label,
1893            action,
1894            method: "post",
1895            message: None,
1896            confirm: None,
1897            attrs: &[],
1898        }
1899    }
1900
1901    pub const fn with_method(mut self, method: &'a str) -> Self {
1902        self.method = method;
1903        self
1904    }
1905
1906    pub const fn with_message(mut self, message: &'a str) -> Self {
1907        self.message = Some(message);
1908        self
1909    }
1910
1911    pub const fn with_confirm(mut self, confirm: &'a str) -> Self {
1912        self.confirm = Some(confirm);
1913        self
1914    }
1915
1916    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
1917        self.attrs = attrs;
1918        self
1919    }
1920}
1921
1922impl<'a> askama::filters::HtmlSafe for ConfirmAction<'a> {}
1923
1924#[derive(Debug, Template)]
1925#[non_exhaustive]
1926#[template(path = "components/card.html")]
1927pub struct Card<'a> {
1928    pub title: &'a str,
1929    pub body_html: TrustedHtml<'a>,
1930    pub kicker: Option<&'a str>,
1931    pub foot_html: Option<TrustedHtml<'a>>,
1932    pub raised: bool,
1933    pub attrs: &'a [HtmlAttr<'a>],
1934}
1935
1936impl<'a> Card<'a> {
1937    pub const fn new(title: &'a str, body_html: TrustedHtml<'a>) -> Self {
1938        Self {
1939            title,
1940            body_html,
1941            kicker: None,
1942            foot_html: None,
1943            raised: false,
1944            attrs: &[],
1945        }
1946    }
1947
1948    pub const fn with_kicker(mut self, kicker: &'a str) -> Self {
1949        self.kicker = Some(kicker);
1950        self
1951    }
1952
1953    pub const fn with_foot(mut self, foot_html: TrustedHtml<'a>) -> Self {
1954        self.foot_html = Some(foot_html);
1955        self
1956    }
1957
1958    pub const fn raised(mut self) -> Self {
1959        self.raised = true;
1960        self
1961    }
1962
1963    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
1964        self.attrs = attrs;
1965        self
1966    }
1967
1968    pub fn class_name(&self) -> &'static str {
1969        if self.raised {
1970            "wf-card is-raised"
1971        } else {
1972            "wf-card"
1973        }
1974    }
1975}
1976
1977impl<'a> askama::filters::HtmlSafe for Card<'a> {}
1978
1979#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1980pub enum BadgeKind {
1981    Default,
1982    Muted,
1983    Error,
1984}
1985
1986impl BadgeKind {
1987    fn class(self) -> &'static str {
1988        match self {
1989            Self::Default => "",
1990            Self::Muted => " muted",
1991            Self::Error => " err",
1992        }
1993    }
1994}
1995
1996#[derive(Debug, Template)]
1997#[non_exhaustive]
1998#[template(path = "components/badge.html")]
1999pub struct Badge<'a> {
2000    pub label: &'a str,
2001    pub kind: BadgeKind,
2002}
2003
2004impl<'a> Badge<'a> {
2005    pub const fn new(label: &'a str) -> Self {
2006        Self {
2007            label,
2008            kind: BadgeKind::Default,
2009        }
2010    }
2011
2012    pub const fn muted(label: &'a str) -> Self {
2013        Self {
2014            kind: BadgeKind::Muted,
2015            ..Self::new(label)
2016        }
2017    }
2018
2019    pub const fn error(label: &'a str) -> Self {
2020        Self {
2021            kind: BadgeKind::Error,
2022            ..Self::new(label)
2023        }
2024    }
2025
2026    pub fn class_name(&self) -> String {
2027        format!("wf-badge{}", self.kind.class())
2028    }
2029}
2030
2031impl<'a> askama::filters::HtmlSafe for Badge<'a> {}
2032
2033#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2034pub enum AvatarSize {
2035    Default,
2036    Small,
2037    Large,
2038    ExtraLarge,
2039}
2040
2041impl AvatarSize {
2042    fn class(self) -> &'static str {
2043        match self {
2044            Self::Default => "",
2045            Self::Small => " sm",
2046            Self::Large => " lg",
2047            Self::ExtraLarge => " xl",
2048        }
2049    }
2050}
2051
2052#[derive(Debug, Template)]
2053#[non_exhaustive]
2054#[template(path = "components/avatar.html")]
2055pub struct Avatar<'a> {
2056    pub initials: &'a str,
2057    pub image_src: Option<&'a str>,
2058    pub size: AvatarSize,
2059    pub accent: bool,
2060}
2061
2062impl<'a> Avatar<'a> {
2063    pub const fn new(initials: &'a str) -> Self {
2064        Self {
2065            initials,
2066            image_src: None,
2067            size: AvatarSize::Default,
2068            accent: false,
2069        }
2070    }
2071
2072    pub const fn with_image(mut self, image_src: &'a str) -> Self {
2073        self.image_src = Some(image_src);
2074        self
2075    }
2076
2077    pub const fn with_size(mut self, size: AvatarSize) -> Self {
2078        self.size = size;
2079        self
2080    }
2081
2082    pub const fn accent(mut self) -> Self {
2083        self.accent = true;
2084        self
2085    }
2086
2087    pub fn class_name(&self) -> String {
2088        let accent = if self.accent { " accent" } else { "" };
2089        format!("wf-avatar{}{}", self.size.class(), accent)
2090    }
2091}
2092
2093impl<'a> askama::filters::HtmlSafe for Avatar<'a> {}
2094
2095#[derive(Debug, Template)]
2096#[non_exhaustive]
2097#[template(path = "components/avatar_group.html")]
2098pub struct AvatarGroup<'a> {
2099    pub avatars: &'a [Avatar<'a>],
2100}
2101
2102impl<'a> AvatarGroup<'a> {
2103    pub const fn new(avatars: &'a [Avatar<'a>]) -> Self {
2104        Self { avatars }
2105    }
2106}
2107
2108impl<'a> askama::filters::HtmlSafe for AvatarGroup<'a> {}
2109
2110#[derive(Debug, Template)]
2111#[non_exhaustive]
2112#[template(path = "components/user_button.html")]
2113pub struct UserButton<'a> {
2114    pub name: &'a str,
2115    pub email: &'a str,
2116    pub avatar: Avatar<'a>,
2117    pub compact: bool,
2118    pub attrs: &'a [HtmlAttr<'a>],
2119}
2120
2121impl<'a> UserButton<'a> {
2122    pub const fn new(name: &'a str, email: &'a str, avatar: Avatar<'a>) -> Self {
2123        Self {
2124            name,
2125            email,
2126            avatar,
2127            compact: false,
2128            attrs: &[],
2129        }
2130    }
2131
2132    pub const fn compact(mut self) -> Self {
2133        self.compact = true;
2134        self
2135    }
2136
2137    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
2138        self.attrs = attrs;
2139        self
2140    }
2141
2142    pub fn class_name(&self) -> &'static str {
2143        if self.compact {
2144            "wf-user compact"
2145        } else {
2146            "wf-user"
2147        }
2148    }
2149}
2150
2151impl<'a> askama::filters::HtmlSafe for UserButton<'a> {}
2152
2153#[derive(Debug, Template)]
2154#[non_exhaustive]
2155#[template(path = "components/wordmark.html")]
2156pub struct Wordmark<'a> {
2157    pub name: &'a str,
2158    pub mark_html: Option<TrustedHtml<'a>>,
2159}
2160
2161impl<'a> Wordmark<'a> {
2162    pub const fn new(name: &'a str) -> Self {
2163        Self {
2164            name,
2165            mark_html: None,
2166        }
2167    }
2168
2169    pub const fn with_mark(mut self, mark_html: TrustedHtml<'a>) -> Self {
2170        self.mark_html = Some(mark_html);
2171        self
2172    }
2173}
2174
2175impl<'a> askama::filters::HtmlSafe for Wordmark<'a> {}
2176
2177#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2178pub enum DeltaKind {
2179    Neutral,
2180    Up,
2181    Down,
2182}
2183
2184impl DeltaKind {
2185    fn class(self) -> &'static str {
2186        match self {
2187            Self::Neutral => "",
2188            Self::Up => " up",
2189            Self::Down => " down",
2190        }
2191    }
2192}
2193
2194#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2195pub struct Stat<'a> {
2196    pub label: &'a str,
2197    pub value: &'a str,
2198    pub unit: Option<&'a str>,
2199    pub delta: Option<&'a str>,
2200    pub delta_kind: DeltaKind,
2201    pub foot: Option<&'a str>,
2202}
2203
2204impl<'a> Stat<'a> {
2205    pub const fn new(label: &'a str, value: &'a str) -> Self {
2206        Self {
2207            label,
2208            value,
2209            unit: None,
2210            delta: None,
2211            delta_kind: DeltaKind::Neutral,
2212            foot: None,
2213        }
2214    }
2215
2216    pub const fn with_unit(mut self, unit: &'a str) -> Self {
2217        self.unit = Some(unit);
2218        self
2219    }
2220
2221    pub const fn with_delta(mut self, delta: &'a str, kind: DeltaKind) -> Self {
2222        self.delta = Some(delta);
2223        self.delta_kind = kind;
2224        self
2225    }
2226
2227    pub const fn with_foot(mut self, foot: &'a str) -> Self {
2228        self.foot = Some(foot);
2229        self
2230    }
2231
2232    pub fn delta_class(&self) -> String {
2233        format!("wf-stat-delta{}", self.delta_kind.class())
2234    }
2235}
2236
2237#[derive(Debug, Template)]
2238#[non_exhaustive]
2239#[template(path = "components/stat_row.html")]
2240pub struct StatRow<'a> {
2241    pub stats: &'a [Stat<'a>],
2242}
2243
2244impl<'a> StatRow<'a> {
2245    pub const fn new(stats: &'a [Stat<'a>]) -> Self {
2246        Self { stats }
2247    }
2248}
2249
2250impl<'a> askama::filters::HtmlSafe for StatRow<'a> {}
2251
2252#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2253pub struct BreadcrumbItem<'a> {
2254    pub label: &'a str,
2255    pub href: Option<&'a str>,
2256    pub current: bool,
2257}
2258
2259impl<'a> BreadcrumbItem<'a> {
2260    pub const fn link(label: &'a str, href: &'a str) -> Self {
2261        Self {
2262            label,
2263            href: Some(href),
2264            current: false,
2265        }
2266    }
2267
2268    pub const fn current(label: &'a str) -> Self {
2269        Self {
2270            label,
2271            href: None,
2272            current: true,
2273        }
2274    }
2275}
2276
2277#[derive(Debug, Template)]
2278#[non_exhaustive]
2279#[template(path = "components/breadcrumbs.html")]
2280pub struct Breadcrumbs<'a> {
2281    pub items: &'a [BreadcrumbItem<'a>],
2282}
2283
2284impl<'a> Breadcrumbs<'a> {
2285    pub const fn new(items: &'a [BreadcrumbItem<'a>]) -> Self {
2286        Self { items }
2287    }
2288}
2289
2290impl<'a> askama::filters::HtmlSafe for Breadcrumbs<'a> {}
2291
2292#[derive(Debug, Template)]
2293#[non_exhaustive]
2294#[template(path = "components/page_header.html")]
2295pub struct PageHeader<'a> {
2296    pub title: &'a str,
2297    pub subtitle: Option<&'a str>,
2298    pub back_href: Option<&'a str>,
2299    pub back_label: &'a str,
2300    pub meta_html: Option<TrustedHtml<'a>>,
2301    pub primary_html: Option<TrustedHtml<'a>>,
2302    pub secondary_html: Option<TrustedHtml<'a>>,
2303}
2304
2305impl<'a> PageHeader<'a> {
2306    pub const fn new(title: &'a str) -> Self {
2307        Self {
2308            title,
2309            subtitle: None,
2310            back_href: None,
2311            back_label: "Back",
2312            meta_html: None,
2313            primary_html: None,
2314            secondary_html: None,
2315        }
2316    }
2317
2318    pub const fn with_subtitle(mut self, subtitle: &'a str) -> Self {
2319        self.subtitle = Some(subtitle);
2320        self
2321    }
2322
2323    pub const fn with_back(mut self, href: &'a str, label: &'a str) -> Self {
2324        self.back_href = Some(href);
2325        self.back_label = label;
2326        self
2327    }
2328
2329    pub const fn with_meta(mut self, meta_html: TrustedHtml<'a>) -> Self {
2330        self.meta_html = Some(meta_html);
2331        self
2332    }
2333
2334    pub const fn with_primary(mut self, primary_html: TrustedHtml<'a>) -> Self {
2335        self.primary_html = Some(primary_html);
2336        self
2337    }
2338
2339    pub const fn with_secondary(mut self, secondary_html: TrustedHtml<'a>) -> Self {
2340        self.secondary_html = Some(secondary_html);
2341        self
2342    }
2343
2344    pub const fn has_actions(&self) -> bool {
2345        self.primary_html.is_some() || self.secondary_html.is_some()
2346    }
2347}
2348
2349impl<'a> askama::filters::HtmlSafe for PageHeader<'a> {}
2350
2351#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2352pub struct TabItem<'a> {
2353    pub label: &'a str,
2354    pub href: &'a str,
2355    pub active: bool,
2356}
2357
2358impl<'a> TabItem<'a> {
2359    pub const fn link(label: &'a str, href: &'a str) -> Self {
2360        Self {
2361            label,
2362            href,
2363            active: false,
2364        }
2365    }
2366
2367    pub const fn active(mut self) -> Self {
2368        self.active = true;
2369        self
2370    }
2371}
2372
2373#[derive(Debug, Template)]
2374#[non_exhaustive]
2375#[template(path = "components/tabs.html")]
2376pub struct Tabs<'a> {
2377    pub items: &'a [TabItem<'a>],
2378}
2379
2380impl<'a> Tabs<'a> {
2381    pub const fn new(items: &'a [TabItem<'a>]) -> Self {
2382        Self { items }
2383    }
2384}
2385
2386impl<'a> askama::filters::HtmlSafe for Tabs<'a> {}
2387
2388#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2389pub struct SegmentOption<'a> {
2390    pub label: &'a str,
2391    pub value: &'a str,
2392    pub active: bool,
2393}
2394
2395impl<'a> SegmentOption<'a> {
2396    pub const fn new(label: &'a str, value: &'a str) -> Self {
2397        Self {
2398            label,
2399            value,
2400            active: false,
2401        }
2402    }
2403
2404    pub const fn active(mut self) -> Self {
2405        self.active = true;
2406        self
2407    }
2408}
2409
2410#[derive(Debug, Template)]
2411#[non_exhaustive]
2412#[template(path = "components/segmented_control.html")]
2413pub struct SegmentedControl<'a> {
2414    pub options: &'a [SegmentOption<'a>],
2415    pub small: bool,
2416}
2417
2418impl<'a> SegmentedControl<'a> {
2419    pub const fn new(options: &'a [SegmentOption<'a>]) -> Self {
2420        Self {
2421            options,
2422            small: false,
2423        }
2424    }
2425
2426    pub const fn small(mut self) -> Self {
2427        self.small = true;
2428        self
2429    }
2430
2431    pub fn class_name(&self) -> &'static str {
2432        if self.small { "wf-seg sm" } else { "wf-seg" }
2433    }
2434}
2435
2436impl<'a> askama::filters::HtmlSafe for SegmentedControl<'a> {}
2437
2438#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2439pub struct PageLink<'a> {
2440    pub label: &'a str,
2441    pub href: Option<&'a str>,
2442    pub active: bool,
2443    pub disabled: bool,
2444    pub ellipsis: bool,
2445}
2446
2447impl<'a> PageLink<'a> {
2448    pub const fn link(label: &'a str, href: &'a str) -> Self {
2449        Self {
2450            label,
2451            href: Some(href),
2452            active: false,
2453            disabled: false,
2454            ellipsis: false,
2455        }
2456    }
2457
2458    pub const fn disabled(label: &'a str) -> Self {
2459        Self {
2460            label,
2461            href: None,
2462            active: false,
2463            disabled: true,
2464            ellipsis: false,
2465        }
2466    }
2467
2468    pub const fn ellipsis() -> Self {
2469        Self {
2470            label: "...",
2471            href: None,
2472            active: false,
2473            disabled: false,
2474            ellipsis: true,
2475        }
2476    }
2477
2478    pub const fn active(mut self) -> Self {
2479        self.active = true;
2480        self
2481    }
2482}
2483
2484#[derive(Debug, Template)]
2485#[non_exhaustive]
2486#[template(path = "components/pagination.html")]
2487pub struct Pagination<'a> {
2488    pub pages: &'a [PageLink<'a>],
2489}
2490
2491impl<'a> Pagination<'a> {
2492    pub const fn new(pages: &'a [PageLink<'a>]) -> Self {
2493        Self { pages }
2494    }
2495}
2496
2497impl<'a> askama::filters::HtmlSafe for Pagination<'a> {}
2498
2499#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2500pub enum StepState {
2501    Upcoming,
2502    Active,
2503    Done,
2504}
2505
2506#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2507pub struct StepItem<'a> {
2508    pub label: &'a str,
2509    pub href: Option<&'a str>,
2510    pub state: StepState,
2511}
2512
2513impl<'a> StepItem<'a> {
2514    pub const fn new(label: &'a str) -> Self {
2515        Self {
2516            label,
2517            href: None,
2518            state: StepState::Upcoming,
2519        }
2520    }
2521
2522    pub const fn with_href(mut self, href: &'a str) -> Self {
2523        self.href = Some(href);
2524        self
2525    }
2526
2527    pub const fn active(mut self) -> Self {
2528        self.state = StepState::Active;
2529        self
2530    }
2531
2532    pub const fn done(mut self) -> Self {
2533        self.state = StepState::Done;
2534        self
2535    }
2536
2537    pub fn class_name(&self) -> &'static str {
2538        match self.state {
2539            StepState::Upcoming => "wf-step",
2540            StepState::Active => "wf-step is-active",
2541            StepState::Done => "wf-step is-done",
2542        }
2543    }
2544
2545    pub fn is_active(&self) -> bool {
2546        self.state == StepState::Active
2547    }
2548}
2549
2550#[derive(Debug, Template)]
2551#[non_exhaustive]
2552#[template(path = "components/stepper.html")]
2553pub struct Stepper<'a> {
2554    pub steps: &'a [StepItem<'a>],
2555}
2556
2557impl<'a> Stepper<'a> {
2558    pub const fn new(steps: &'a [StepItem<'a>]) -> Self {
2559        Self { steps }
2560    }
2561}
2562
2563impl<'a> askama::filters::HtmlSafe for Stepper<'a> {}
2564
2565#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2566pub struct AccordionItem<'a> {
2567    pub title: &'a str,
2568    pub body_html: TrustedHtml<'a>,
2569    pub open: bool,
2570}
2571
2572impl<'a> AccordionItem<'a> {
2573    pub const fn new(title: &'a str, body_html: TrustedHtml<'a>) -> Self {
2574        Self {
2575            title,
2576            body_html,
2577            open: false,
2578        }
2579    }
2580
2581    pub const fn open(mut self) -> Self {
2582        self.open = true;
2583        self
2584    }
2585}
2586
2587#[derive(Debug, Template)]
2588#[non_exhaustive]
2589#[template(path = "components/accordion.html")]
2590pub struct Accordion<'a> {
2591    pub items: &'a [AccordionItem<'a>],
2592}
2593
2594impl<'a> Accordion<'a> {
2595    pub const fn new(items: &'a [AccordionItem<'a>]) -> Self {
2596        Self { items }
2597    }
2598}
2599
2600impl<'a> askama::filters::HtmlSafe for Accordion<'a> {}
2601
2602#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2603pub struct FaqItem<'a> {
2604    pub question: &'a str,
2605    pub answer_html: TrustedHtml<'a>,
2606}
2607
2608impl<'a> FaqItem<'a> {
2609    pub const fn new(question: &'a str, answer_html: TrustedHtml<'a>) -> Self {
2610        Self {
2611            question,
2612            answer_html,
2613        }
2614    }
2615}
2616
2617#[derive(Debug, Template)]
2618#[non_exhaustive]
2619#[template(path = "components/faq.html")]
2620pub struct Faq<'a> {
2621    pub items: &'a [FaqItem<'a>],
2622}
2623
2624impl<'a> Faq<'a> {
2625    pub const fn new(items: &'a [FaqItem<'a>]) -> Self {
2626        Self { items }
2627    }
2628}
2629
2630impl<'a> askama::filters::HtmlSafe for Faq<'a> {}
2631
2632#[derive(Debug, Template)]
2633#[non_exhaustive]
2634#[template(path = "components/nav_section.html")]
2635pub struct NavSection<'a> {
2636    pub label: &'a str,
2637}
2638
2639impl<'a> NavSection<'a> {
2640    pub const fn new(label: &'a str) -> Self {
2641        Self { label }
2642    }
2643}
2644
2645impl<'a> askama::filters::HtmlSafe for NavSection<'a> {}
2646
2647#[derive(Debug, Template)]
2648#[non_exhaustive]
2649#[template(path = "components/nav_item.html")]
2650pub struct NavItem<'a> {
2651    pub label: &'a str,
2652    pub href: &'a str,
2653    pub count: Option<&'a str>,
2654    pub active: bool,
2655}
2656
2657impl<'a> NavItem<'a> {
2658    pub const fn new(label: &'a str, href: &'a str) -> Self {
2659        Self {
2660            label,
2661            href,
2662            count: None,
2663            active: false,
2664        }
2665    }
2666
2667    pub const fn active(mut self) -> Self {
2668        self.active = true;
2669        self
2670    }
2671
2672    pub const fn with_count(mut self, count: &'a str) -> Self {
2673        self.count = Some(count);
2674        self
2675    }
2676
2677    pub fn class_name(&self) -> &'static str {
2678        if self.active {
2679            "wf-nav-item is-active"
2680        } else {
2681            "wf-nav-item"
2682        }
2683    }
2684}
2685
2686impl<'a> askama::filters::HtmlSafe for NavItem<'a> {}
2687
2688#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2689pub struct ContextSwitcherItem<'a> {
2690    pub label: &'a str,
2691    pub href: &'a str,
2692    pub meta: Option<&'a str>,
2693    pub badge_html: Option<TrustedHtml<'a>>,
2694    pub active: bool,
2695    pub disabled: bool,
2696}
2697
2698impl<'a> ContextSwitcherItem<'a> {
2699    pub const fn link(label: &'a str, href: &'a str) -> Self {
2700        Self {
2701            label,
2702            href,
2703            meta: None,
2704            badge_html: None,
2705            active: false,
2706            disabled: false,
2707        }
2708    }
2709
2710    pub const fn with_meta(mut self, meta: &'a str) -> Self {
2711        self.meta = Some(meta);
2712        self
2713    }
2714
2715    pub const fn with_badge(mut self, badge_html: TrustedHtml<'a>) -> Self {
2716        self.badge_html = Some(badge_html);
2717        self
2718    }
2719
2720    pub const fn active(mut self) -> Self {
2721        self.active = true;
2722        self
2723    }
2724
2725    pub const fn disabled(mut self) -> Self {
2726        self.disabled = true;
2727        self
2728    }
2729
2730    pub fn class_name(&self) -> &'static str {
2731        match (self.active, self.disabled) {
2732            (true, true) => "wf-context-switcher-item is-active is-disabled",
2733            (true, false) => "wf-context-switcher-item is-active",
2734            (false, true) => "wf-context-switcher-item is-disabled",
2735            (false, false) => "wf-context-switcher-item",
2736        }
2737    }
2738}
2739
2740#[derive(Debug, Template)]
2741#[non_exhaustive]
2742#[template(path = "components/context_switcher.html")]
2743pub struct ContextSwitcher<'a> {
2744    pub label: &'a str,
2745    pub current: &'a str,
2746    pub items: &'a [ContextSwitcherItem<'a>],
2747    pub meta_html: Option<TrustedHtml<'a>>,
2748    pub open: bool,
2749    pub attrs: &'a [HtmlAttr<'a>],
2750}
2751
2752impl<'a> ContextSwitcher<'a> {
2753    pub const fn new(
2754        label: &'a str,
2755        current: &'a str,
2756        items: &'a [ContextSwitcherItem<'a>],
2757    ) -> Self {
2758        Self {
2759            label,
2760            current,
2761            items,
2762            meta_html: None,
2763            open: false,
2764            attrs: &[],
2765        }
2766    }
2767
2768    pub const fn with_meta(mut self, meta_html: TrustedHtml<'a>) -> Self {
2769        self.meta_html = Some(meta_html);
2770        self
2771    }
2772
2773    pub const fn open(mut self) -> Self {
2774        self.open = true;
2775        self
2776    }
2777
2778    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
2779        self.attrs = attrs;
2780        self
2781    }
2782}
2783
2784impl<'a> askama::filters::HtmlSafe for ContextSwitcher<'a> {}
2785
2786#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2787pub struct SidenavItem<'a> {
2788    pub label: &'a str,
2789    pub href: &'a str,
2790    pub badge: Option<&'a str>,
2791    pub coming_soon: Option<&'a str>,
2792    pub active: bool,
2793    pub muted: bool,
2794    pub disabled: bool,
2795    pub attrs: &'a [HtmlAttr<'a>],
2796}
2797
2798impl<'a> SidenavItem<'a> {
2799    pub const fn link(label: &'a str, href: &'a str) -> Self {
2800        Self {
2801            label,
2802            href,
2803            badge: None,
2804            coming_soon: None,
2805            active: false,
2806            muted: false,
2807            disabled: false,
2808            attrs: &[],
2809        }
2810    }
2811
2812    pub const fn active(mut self) -> Self {
2813        self.active = true;
2814        self
2815    }
2816
2817    pub const fn muted(mut self) -> Self {
2818        self.muted = true;
2819        self
2820    }
2821
2822    pub const fn disabled(mut self) -> Self {
2823        self.disabled = true;
2824        self
2825    }
2826
2827    pub const fn with_badge(mut self, badge: &'a str) -> Self {
2828        self.badge = Some(badge);
2829        self
2830    }
2831
2832    pub const fn with_coming_soon(mut self, coming_soon: &'a str) -> Self {
2833        self.coming_soon = Some(coming_soon);
2834        self
2835    }
2836
2837    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
2838        self.attrs = attrs;
2839        self
2840    }
2841
2842    pub fn class_name(&self) -> &'static str {
2843        match (self.active, self.muted, self.disabled) {
2844            (true, true, true) => "wf-sidenav-item is-active is-muted is-disabled",
2845            (true, true, false) => "wf-sidenav-item is-active is-muted",
2846            (true, false, true) => "wf-sidenav-item is-active is-disabled",
2847            (true, false, false) => "wf-sidenav-item is-active",
2848            (false, true, true) => "wf-sidenav-item is-muted is-disabled",
2849            (false, true, false) => "wf-sidenav-item is-muted",
2850            (false, false, true) => "wf-sidenav-item is-disabled",
2851            (false, false, false) => "wf-sidenav-item",
2852        }
2853    }
2854}
2855
2856#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2857pub struct SidenavSection<'a> {
2858    pub label: &'a str,
2859    pub items: &'a [SidenavItem<'a>],
2860}
2861
2862impl<'a> SidenavSection<'a> {
2863    pub const fn new(label: &'a str, items: &'a [SidenavItem<'a>]) -> Self {
2864        Self { label, items }
2865    }
2866}
2867
2868#[derive(Debug, Template)]
2869#[non_exhaustive]
2870#[template(path = "components/sidenav.html")]
2871pub struct Sidenav<'a> {
2872    pub sections: &'a [SidenavSection<'a>],
2873    pub attrs: &'a [HtmlAttr<'a>],
2874}
2875
2876impl<'a> Sidenav<'a> {
2877    pub const fn new(sections: &'a [SidenavSection<'a>]) -> Self {
2878        Self {
2879            sections,
2880            attrs: &[],
2881        }
2882    }
2883
2884    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
2885        self.attrs = attrs;
2886        self
2887    }
2888}
2889
2890impl<'a> askama::filters::HtmlSafe for Sidenav<'a> {}
2891
2892#[derive(Debug, Template)]
2893#[non_exhaustive]
2894#[template(path = "components/topbar.html")]
2895pub struct Topbar<'a> {
2896    pub breadcrumbs_html: TrustedHtml<'a>,
2897    pub actions_html: TrustedHtml<'a>,
2898}
2899
2900impl<'a> Topbar<'a> {
2901    pub const fn new(breadcrumbs_html: TrustedHtml<'a>, actions_html: TrustedHtml<'a>) -> Self {
2902        Self {
2903            breadcrumbs_html,
2904            actions_html,
2905        }
2906    }
2907}
2908
2909impl<'a> askama::filters::HtmlSafe for Topbar<'a> {}
2910
2911#[derive(Debug, Template)]
2912#[non_exhaustive]
2913#[template(path = "components/statusbar.html")]
2914pub struct Statusbar<'a> {
2915    pub left: &'a str,
2916    pub right: &'a str,
2917}
2918
2919impl<'a> Statusbar<'a> {
2920    pub const fn new(left: &'a str, right: &'a str) -> Self {
2921        Self { left, right }
2922    }
2923}
2924
2925impl<'a> askama::filters::HtmlSafe for Statusbar<'a> {}
2926
2927#[derive(Debug, Template)]
2928#[non_exhaustive]
2929#[template(path = "components/empty_state.html")]
2930pub struct EmptyState<'a> {
2931    pub title: &'a str,
2932    pub body: &'a str,
2933    pub glyph_html: Option<TrustedHtml<'a>>,
2934    pub actions_html: Option<TrustedHtml<'a>>,
2935    pub bordered: bool,
2936    pub dense: bool,
2937}
2938
2939impl<'a> EmptyState<'a> {
2940    pub const fn new(title: &'a str, body: &'a str) -> Self {
2941        Self {
2942            title,
2943            body,
2944            glyph_html: None,
2945            actions_html: None,
2946            bordered: false,
2947            dense: false,
2948        }
2949    }
2950
2951    pub const fn with_glyph(mut self, glyph_html: TrustedHtml<'a>) -> Self {
2952        self.glyph_html = Some(glyph_html);
2953        self
2954    }
2955
2956    pub const fn with_actions(mut self, actions_html: TrustedHtml<'a>) -> Self {
2957        self.actions_html = Some(actions_html);
2958        self
2959    }
2960
2961    pub const fn bordered(mut self) -> Self {
2962        self.bordered = true;
2963        self
2964    }
2965
2966    pub const fn dense(mut self) -> Self {
2967        self.dense = true;
2968        self
2969    }
2970
2971    pub fn class_name(&self) -> String {
2972        let bordered = if self.bordered { " bordered" } else { "" };
2973        let dense = if self.dense { " dense" } else { "" };
2974        format!("wf-empty{bordered}{dense}")
2975    }
2976}
2977
2978impl<'a> askama::filters::HtmlSafe for EmptyState<'a> {}
2979
2980#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2981pub enum SortDirection {
2982    Ascending,
2983    Descending,
2984}
2985
2986impl SortDirection {
2987    fn arrow(self) -> &'static str {
2988        match self {
2989            Self::Ascending => "^",
2990            Self::Descending => "v",
2991        }
2992    }
2993}
2994
2995#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2996pub enum TableColumnWidth {
2997    Auto,
2998    ExtraSmall,
2999    Small,
3000    Medium,
3001    Large,
3002    ExtraLarge,
3003    Id,
3004    Checkbox,
3005    Action,
3006}
3007
3008#[derive(Clone, Copy, Debug, Eq, PartialEq)]
3009pub struct TableHeader<'a> {
3010    pub label: &'a str,
3011    pub numeric: bool,
3012}
3013
3014impl<'a> TableHeader<'a> {
3015    pub const fn new(label: &'a str) -> Self {
3016        Self {
3017            label,
3018            numeric: false,
3019        }
3020    }
3021
3022    pub const fn numeric(label: &'a str) -> Self {
3023        Self {
3024            label,
3025            numeric: true,
3026        }
3027    }
3028
3029    pub fn class_name(&self) -> &'static str {
3030        if self.numeric { "num" } else { "" }
3031    }
3032}
3033
3034#[derive(Clone, Copy, Debug, Eq, PartialEq)]
3035pub struct TableCell<'a> {
3036    pub text: &'a str,
3037    pub numeric: bool,
3038    pub strong: bool,
3039    pub muted: bool,
3040}
3041
3042impl<'a> TableCell<'a> {
3043    pub const fn new(text: &'a str) -> Self {
3044        Self {
3045            text,
3046            numeric: false,
3047            strong: false,
3048            muted: false,
3049        }
3050    }
3051
3052    pub const fn numeric(text: &'a str) -> Self {
3053        Self {
3054            numeric: true,
3055            ..Self::new(text)
3056        }
3057    }
3058
3059    pub const fn strong(text: &'a str) -> Self {
3060        Self {
3061            strong: true,
3062            ..Self::new(text)
3063        }
3064    }
3065
3066    pub const fn muted(text: &'a str) -> Self {
3067        Self {
3068            muted: true,
3069            ..Self::new(text)
3070        }
3071    }
3072
3073    pub fn class_name(&self) -> &'static str {
3074        match (self.numeric, self.strong, self.muted) {
3075            (false, false, false) => "",
3076            (true, false, false) => "num",
3077            (false, true, false) => "strong",
3078            (false, false, true) => "muted",
3079            (true, true, false) => "num strong",
3080            (true, false, true) => "num muted",
3081            (false, true, true) => "strong muted",
3082            (true, true, true) => "num strong muted",
3083        }
3084    }
3085}
3086
3087#[derive(Clone, Copy, Debug, Eq, PartialEq)]
3088pub struct TableRow<'a> {
3089    pub cells: &'a [TableCell<'a>],
3090    pub selected: bool,
3091}
3092
3093impl<'a> TableRow<'a> {
3094    pub const fn new(cells: &'a [TableCell<'a>]) -> Self {
3095        Self {
3096            cells,
3097            selected: false,
3098        }
3099    }
3100
3101    pub const fn selected(mut self) -> Self {
3102        self.selected = true;
3103        self
3104    }
3105}
3106
3107#[derive(Debug, Template)]
3108#[non_exhaustive]
3109#[template(path = "components/table.html")]
3110pub struct Table<'a> {
3111    pub headers: &'a [TableHeader<'a>],
3112    pub rows: &'a [TableRow<'a>],
3113    pub flush: bool,
3114    pub interactive: bool,
3115    pub sticky: bool,
3116    pub pin_last: bool,
3117}
3118
3119impl<'a> Table<'a> {
3120    pub const fn new(headers: &'a [TableHeader<'a>], rows: &'a [TableRow<'a>]) -> Self {
3121        Self {
3122            headers,
3123            rows,
3124            flush: false,
3125            interactive: false,
3126            sticky: false,
3127            pin_last: false,
3128        }
3129    }
3130
3131    pub const fn flush(mut self) -> Self {
3132        self.flush = true;
3133        self
3134    }
3135
3136    pub const fn interactive(mut self) -> Self {
3137        self.interactive = true;
3138        self
3139    }
3140
3141    pub const fn sticky(mut self) -> Self {
3142        self.sticky = true;
3143        self
3144    }
3145
3146    pub const fn pin_last(mut self) -> Self {
3147        self.pin_last = true;
3148        self
3149    }
3150
3151    pub fn class_name(&self) -> String {
3152        let flush = if self.flush { " flush" } else { "" };
3153        let interactive = if self.interactive {
3154            " is-interactive"
3155        } else {
3156            ""
3157        };
3158        let sticky = if self.sticky { " sticky" } else { "" };
3159        let pin_last = if self.pin_last { " pin-last" } else { "" };
3160        format!("wf-table{flush}{interactive}{sticky}{pin_last}")
3161    }
3162}
3163
3164impl<'a> askama::filters::HtmlSafe for Table<'a> {}
3165
3166#[derive(Clone, Copy, Debug, Eq, PartialEq)]
3167pub struct DataTableHeader<'a> {
3168    pub label: &'a str,
3169    pub numeric: bool,
3170    pub sort_key: Option<&'a str>,
3171    pub sort_direction: Option<SortDirection>,
3172    pub width: TableColumnWidth,
3173}
3174
3175impl<'a> DataTableHeader<'a> {
3176    pub const fn new(label: &'a str) -> Self {
3177        Self {
3178            label,
3179            numeric: false,
3180            sort_key: None,
3181            sort_direction: None,
3182            width: TableColumnWidth::Auto,
3183        }
3184    }
3185
3186    pub const fn numeric(label: &'a str) -> Self {
3187        Self {
3188            numeric: true,
3189            ..Self::new(label)
3190        }
3191    }
3192
3193    pub const fn sort(label: &'a str, sort_key: &'a str) -> Self {
3194        Self {
3195            sort_key: Some(sort_key),
3196            ..Self::new(label)
3197        }
3198    }
3199
3200    pub const fn sorted(label: &'a str, sort_key: &'a str, direction: SortDirection) -> Self {
3201        Self {
3202            sort_direction: Some(direction),
3203            ..Self::sort(label, sort_key)
3204        }
3205    }
3206
3207    pub const fn sortable(mut self, sort_key: &'a str, direction: SortDirection) -> Self {
3208        self.sort_key = Some(sort_key);
3209        self.sort_direction = Some(direction);
3210        self
3211    }
3212
3213    pub const fn with_width(mut self, width: TableColumnWidth) -> Self {
3214        self.width = width;
3215        self
3216    }
3217
3218    pub const fn action_column(mut self) -> Self {
3219        self.width = TableColumnWidth::Action;
3220        self
3221    }
3222
3223    pub fn class_name(&self) -> &'static str {
3224        match (self.width, self.numeric) {
3225            (TableColumnWidth::Auto, false) => "",
3226            (TableColumnWidth::Auto, true) => "num",
3227            (TableColumnWidth::ExtraSmall, false) => "wf-col-xs",
3228            (TableColumnWidth::ExtraSmall, true) => "wf-col-xs num",
3229            (TableColumnWidth::Small, false) => "wf-col-sm",
3230            (TableColumnWidth::Small, true) => "wf-col-sm num",
3231            (TableColumnWidth::Medium, false) => "wf-col-md",
3232            (TableColumnWidth::Medium, true) => "wf-col-md num",
3233            (TableColumnWidth::Large, false) => "wf-col-lg",
3234            (TableColumnWidth::Large, true) => "wf-col-lg num",
3235            (TableColumnWidth::ExtraLarge, false) => "wf-col-xl",
3236            (TableColumnWidth::ExtraLarge, true) => "wf-col-xl num",
3237            (TableColumnWidth::Id, false) => "wf-col-id",
3238            (TableColumnWidth::Id, true) => "wf-col-id num",
3239            (TableColumnWidth::Checkbox, false) => "wf-col-chk",
3240            (TableColumnWidth::Checkbox, true) => "wf-col-chk num",
3241            (TableColumnWidth::Action, false) => "wf-col-act",
3242            (TableColumnWidth::Action, true) => "wf-col-act num",
3243        }
3244    }
3245
3246    pub fn sort_arrow(&self) -> &'static str {
3247        self.sort_direction.map(SortDirection::arrow).unwrap_or("-")
3248    }
3249}
3250
3251#[derive(Clone, Copy, Debug, Eq, PartialEq)]
3252pub struct DataTableCell<'a> {
3253    pub text: &'a str,
3254    pub html: Option<TrustedHtml<'a>>,
3255    pub numeric: bool,
3256    pub strong: bool,
3257    pub muted: bool,
3258}
3259
3260impl<'a> DataTableCell<'a> {
3261    pub const fn new(text: &'a str) -> Self {
3262        Self {
3263            text,
3264            html: None,
3265            numeric: false,
3266            strong: false,
3267            muted: false,
3268        }
3269    }
3270
3271    pub const fn numeric(text: &'a str) -> Self {
3272        Self {
3273            numeric: true,
3274            ..Self::new(text)
3275        }
3276    }
3277
3278    pub const fn strong(text: &'a str) -> Self {
3279        Self {
3280            strong: true,
3281            ..Self::new(text)
3282        }
3283    }
3284
3285    pub const fn muted(text: &'a str) -> Self {
3286        Self {
3287            muted: true,
3288            ..Self::new(text)
3289        }
3290    }
3291
3292    pub const fn html(html: TrustedHtml<'a>) -> Self {
3293        Self {
3294            text: "",
3295            html: Some(html),
3296            numeric: false,
3297            strong: false,
3298            muted: false,
3299        }
3300    }
3301
3302    pub fn class_name(&self) -> &'static str {
3303        match (self.numeric, self.strong, self.muted) {
3304            (false, false, false) => "",
3305            (true, false, false) => "num",
3306            (false, true, false) => "strong",
3307            (false, false, true) => "muted",
3308            (true, true, false) => "num strong",
3309            (true, false, true) => "num muted",
3310            (false, true, true) => "strong muted",
3311            (true, true, true) => "num strong muted",
3312        }
3313    }
3314}
3315
3316#[derive(Clone, Copy, Debug, Eq, PartialEq)]
3317pub struct DataTableRow<'a> {
3318    pub cells: &'a [DataTableCell<'a>],
3319    pub selected: bool,
3320}
3321
3322impl<'a> DataTableRow<'a> {
3323    pub const fn new(cells: &'a [DataTableCell<'a>]) -> Self {
3324        Self {
3325            cells,
3326            selected: false,
3327        }
3328    }
3329
3330    pub const fn selected(mut self) -> Self {
3331        self.selected = true;
3332        self
3333    }
3334}
3335
3336#[derive(Debug, Template)]
3337#[non_exhaustive]
3338#[template(path = "components/data_table.html")]
3339pub struct DataTable<'a> {
3340    pub headers: &'a [DataTableHeader<'a>],
3341    pub rows: &'a [DataTableRow<'a>],
3342    pub flush: bool,
3343    pub interactive: bool,
3344    pub sticky: bool,
3345    pub pin_last: bool,
3346}
3347
3348impl<'a> DataTable<'a> {
3349    pub const fn new(headers: &'a [DataTableHeader<'a>], rows: &'a [DataTableRow<'a>]) -> Self {
3350        Self {
3351            headers,
3352            rows,
3353            flush: false,
3354            interactive: false,
3355            sticky: false,
3356            pin_last: false,
3357        }
3358    }
3359
3360    pub const fn flush(mut self) -> Self {
3361        self.flush = true;
3362        self
3363    }
3364
3365    pub const fn interactive(mut self) -> Self {
3366        self.interactive = true;
3367        self
3368    }
3369
3370    pub const fn sticky(mut self) -> Self {
3371        self.sticky = true;
3372        self
3373    }
3374
3375    pub const fn pin_last(mut self) -> Self {
3376        self.pin_last = true;
3377        self
3378    }
3379
3380    pub fn class_name(&self) -> String {
3381        let flush = if self.flush { " flush" } else { "" };
3382        let interactive = if self.interactive {
3383            " is-interactive"
3384        } else {
3385            ""
3386        };
3387        let sticky = if self.sticky { " sticky" } else { "" };
3388        let pin_last = if self.pin_last { " pin-last" } else { "" };
3389        format!("wf-table{flush}{interactive}{sticky}{pin_last}")
3390    }
3391}
3392
3393impl<'a> askama::filters::HtmlSafe for DataTable<'a> {}
3394
3395#[derive(Debug, Template)]
3396#[non_exhaustive]
3397#[template(path = "components/filter_bar.html")]
3398pub struct FilterBar<'a> {
3399    pub controls_html: TrustedHtml<'a>,
3400    pub actions_html: Option<TrustedHtml<'a>>,
3401    pub attrs: &'a [HtmlAttr<'a>],
3402}
3403
3404impl<'a> FilterBar<'a> {
3405    pub const fn new(controls_html: TrustedHtml<'a>) -> Self {
3406        Self {
3407            controls_html,
3408            actions_html: None,
3409            attrs: &[],
3410        }
3411    }
3412
3413    pub const fn with_actions(mut self, actions_html: TrustedHtml<'a>) -> Self {
3414        self.actions_html = Some(actions_html);
3415        self
3416    }
3417
3418    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
3419        self.attrs = attrs;
3420        self
3421    }
3422}
3423
3424impl<'a> askama::filters::HtmlSafe for FilterBar<'a> {}
3425
3426#[derive(Debug, Template)]
3427#[non_exhaustive]
3428#[template(path = "components/bulk_action_bar.html")]
3429pub struct BulkActionBar<'a> {
3430    pub count_label: &'a str,
3431    pub actions_html: TrustedHtml<'a>,
3432    pub attrs: &'a [HtmlAttr<'a>],
3433}
3434
3435impl<'a> BulkActionBar<'a> {
3436    pub const fn new(count_label: &'a str, actions_html: TrustedHtml<'a>) -> Self {
3437        Self {
3438            count_label,
3439            actions_html,
3440            attrs: &[],
3441        }
3442    }
3443
3444    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
3445        self.attrs = attrs;
3446        self
3447    }
3448}
3449
3450impl<'a> askama::filters::HtmlSafe for BulkActionBar<'a> {}
3451
3452#[derive(Debug, Template)]
3453#[non_exhaustive]
3454#[template(path = "components/table_footer.html")]
3455pub struct TableFooter<'a> {
3456    pub content_html: TrustedHtml<'a>,
3457    pub actions_html: Option<TrustedHtml<'a>>,
3458    pub attrs: &'a [HtmlAttr<'a>],
3459}
3460
3461impl<'a> TableFooter<'a> {
3462    pub const fn new(content_html: TrustedHtml<'a>) -> Self {
3463        Self {
3464            content_html,
3465            actions_html: None,
3466            attrs: &[],
3467        }
3468    }
3469
3470    pub const fn with_actions(mut self, actions_html: TrustedHtml<'a>) -> Self {
3471        self.actions_html = Some(actions_html);
3472        self
3473    }
3474
3475    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
3476        self.attrs = attrs;
3477        self
3478    }
3479}
3480
3481impl<'a> askama::filters::HtmlSafe for TableFooter<'a> {}
3482
3483#[derive(Debug, Template)]
3484#[non_exhaustive]
3485#[template(path = "components/row_select.html")]
3486pub struct RowSelect<'a> {
3487    pub name: &'a str,
3488    pub value: &'a str,
3489    pub label: &'a str,
3490    pub checked: bool,
3491    pub disabled: bool,
3492    pub attrs: &'a [HtmlAttr<'a>],
3493}
3494
3495impl<'a> RowSelect<'a> {
3496    pub const fn new(name: &'a str, value: &'a str, label: &'a str) -> Self {
3497        Self {
3498            name,
3499            value,
3500            label,
3501            checked: false,
3502            disabled: false,
3503            attrs: &[],
3504        }
3505    }
3506
3507    pub const fn checked(mut self) -> Self {
3508        self.checked = true;
3509        self
3510    }
3511
3512    pub const fn disabled(mut self) -> Self {
3513        self.disabled = true;
3514        self
3515    }
3516
3517    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
3518        self.attrs = attrs;
3519        self
3520    }
3521}
3522
3523impl<'a> askama::filters::HtmlSafe for RowSelect<'a> {}
3524
3525#[derive(Debug, Template)]
3526#[non_exhaustive]
3527#[template(path = "components/table_wrap.html")]
3528pub struct TableWrap<'a> {
3529    pub table_html: TrustedHtml<'a>,
3530    pub filterbar_html: Option<TrustedHtml<'a>>,
3531    pub filterbar_component_html: Option<TrustedHtml<'a>>,
3532    pub bulk_count: Option<&'a str>,
3533    pub bulk_actions_html: Option<TrustedHtml<'a>>,
3534    pub bulkbar_component_html: Option<TrustedHtml<'a>>,
3535    pub footer_html: Option<TrustedHtml<'a>>,
3536    pub footer_component_html: Option<TrustedHtml<'a>>,
3537}
3538
3539impl<'a> TableWrap<'a> {
3540    pub const fn new(table_html: TrustedHtml<'a>) -> Self {
3541        Self {
3542            table_html,
3543            filterbar_html: None,
3544            filterbar_component_html: None,
3545            bulk_count: None,
3546            bulk_actions_html: None,
3547            bulkbar_component_html: None,
3548            footer_html: None,
3549            footer_component_html: None,
3550        }
3551    }
3552
3553    pub const fn with_filterbar(mut self, filterbar_html: TrustedHtml<'a>) -> Self {
3554        self.filterbar_html = Some(filterbar_html);
3555        self
3556    }
3557
3558    pub const fn with_filterbar_component(mut self, filterbar_html: TrustedHtml<'a>) -> Self {
3559        self.filterbar_component_html = Some(filterbar_html);
3560        self
3561    }
3562
3563    pub const fn with_bulkbar(
3564        mut self,
3565        bulk_count: &'a str,
3566        bulk_actions_html: TrustedHtml<'a>,
3567    ) -> Self {
3568        self.bulk_count = Some(bulk_count);
3569        self.bulk_actions_html = Some(bulk_actions_html);
3570        self
3571    }
3572
3573    pub const fn with_bulkbar_component(mut self, bulkbar_html: TrustedHtml<'a>) -> Self {
3574        self.bulkbar_component_html = Some(bulkbar_html);
3575        self
3576    }
3577
3578    pub const fn with_footer(mut self, footer_html: TrustedHtml<'a>) -> Self {
3579        self.footer_html = Some(footer_html);
3580        self
3581    }
3582
3583    pub const fn with_footer_component(mut self, footer_html: TrustedHtml<'a>) -> Self {
3584        self.footer_component_html = Some(footer_html);
3585        self
3586    }
3587}
3588
3589impl<'a> askama::filters::HtmlSafe for TableWrap<'a> {}
3590
3591#[derive(Clone, Copy, Debug, Eq, PartialEq)]
3592pub struct DefinitionItem<'a> {
3593    pub term: &'a str,
3594    pub description: &'a str,
3595}
3596
3597impl<'a> DefinitionItem<'a> {
3598    pub const fn new(term: &'a str, description: &'a str) -> Self {
3599        Self { term, description }
3600    }
3601}
3602
3603#[derive(Debug, Template)]
3604#[non_exhaustive]
3605#[template(path = "components/definition_list.html")]
3606pub struct DefinitionList<'a> {
3607    pub items: &'a [DefinitionItem<'a>],
3608    pub flush: bool,
3609}
3610
3611impl<'a> DefinitionList<'a> {
3612    pub const fn new(items: &'a [DefinitionItem<'a>]) -> Self {
3613        Self {
3614            items,
3615            flush: false,
3616        }
3617    }
3618
3619    pub const fn flush(mut self) -> Self {
3620        self.flush = true;
3621        self
3622    }
3623
3624    pub fn class_name(&self) -> &'static str {
3625        if self.flush { "wf-dl flush" } else { "wf-dl" }
3626    }
3627}
3628
3629impl<'a> askama::filters::HtmlSafe for DefinitionList<'a> {}
3630
3631#[derive(Clone, Copy, Debug, Eq, PartialEq)]
3632pub struct RankRow<'a> {
3633    pub label: &'a str,
3634    pub value: &'a str,
3635    pub percent: u8,
3636}
3637
3638impl<'a> RankRow<'a> {
3639    pub const fn new(label: &'a str, value: &'a str, percent: u8) -> Self {
3640        Self {
3641            label,
3642            value,
3643            percent,
3644        }
3645    }
3646
3647    pub fn bounded_percent(&self) -> u8 {
3648        self.percent.min(100)
3649    }
3650}
3651
3652#[derive(Debug, Template)]
3653#[non_exhaustive]
3654#[template(path = "components/rank_list.html")]
3655pub struct RankList<'a> {
3656    pub rows: &'a [RankRow<'a>],
3657}
3658
3659impl<'a> RankList<'a> {
3660    pub const fn new(rows: &'a [RankRow<'a>]) -> Self {
3661        Self { rows }
3662    }
3663}
3664
3665impl<'a> askama::filters::HtmlSafe for RankList<'a> {}
3666
3667#[derive(Clone, Copy, Debug, Eq, PartialEq)]
3668pub struct FeedRow<'a> {
3669    pub time: &'a str,
3670    pub kicker: &'a str,
3671    pub text: &'a str,
3672}
3673
3674impl<'a> FeedRow<'a> {
3675    pub const fn new(time: &'a str, kicker: &'a str, text: &'a str) -> Self {
3676        Self { time, kicker, text }
3677    }
3678}
3679
3680#[derive(Debug, Template)]
3681#[non_exhaustive]
3682#[template(path = "components/feed.html")]
3683pub struct Feed<'a> {
3684    pub rows: &'a [FeedRow<'a>],
3685}
3686
3687impl<'a> Feed<'a> {
3688    pub const fn new(rows: &'a [FeedRow<'a>]) -> Self {
3689        Self { rows }
3690    }
3691}
3692
3693impl<'a> askama::filters::HtmlSafe for Feed<'a> {}
3694
3695#[derive(Clone, Copy, Debug, Eq, PartialEq)]
3696pub struct TimelineItem<'a> {
3697    pub time: &'a str,
3698    pub title: &'a str,
3699    pub body_html: TrustedHtml<'a>,
3700    pub active: bool,
3701}
3702
3703impl<'a> TimelineItem<'a> {
3704    pub const fn new(time: &'a str, title: &'a str, body_html: TrustedHtml<'a>) -> Self {
3705        Self {
3706            time,
3707            title,
3708            body_html,
3709            active: false,
3710        }
3711    }
3712
3713    pub const fn active(mut self) -> Self {
3714        self.active = true;
3715        self
3716    }
3717
3718    pub fn class_name(&self) -> &'static str {
3719        if self.active {
3720            "wf-timeline-item is-active"
3721        } else {
3722            "wf-timeline-item"
3723        }
3724    }
3725}
3726
3727#[derive(Debug, Template)]
3728#[non_exhaustive]
3729#[template(path = "components/timeline.html")]
3730pub struct Timeline<'a> {
3731    pub items: &'a [TimelineItem<'a>],
3732}
3733
3734impl<'a> Timeline<'a> {
3735    pub const fn new(items: &'a [TimelineItem<'a>]) -> Self {
3736        Self { items }
3737    }
3738}
3739
3740impl<'a> askama::filters::HtmlSafe for Timeline<'a> {}
3741
3742#[derive(Clone, Copy, Debug, Eq, PartialEq)]
3743pub enum TreeItemKind {
3744    Folder,
3745    File,
3746}
3747
3748#[derive(Clone, Copy, Debug, Eq, PartialEq)]
3749pub struct TreeItem<'a> {
3750    pub kind: TreeItemKind,
3751    pub label: &'a str,
3752    pub active: bool,
3753    pub collapsed: bool,
3754    pub children_html: Option<TrustedHtml<'a>>,
3755}
3756
3757impl<'a> TreeItem<'a> {
3758    pub const fn folder(label: &'a str) -> Self {
3759        Self {
3760            kind: TreeItemKind::Folder,
3761            label,
3762            active: false,
3763            collapsed: false,
3764            children_html: None,
3765        }
3766    }
3767
3768    pub const fn file(label: &'a str) -> Self {
3769        Self {
3770            kind: TreeItemKind::File,
3771            label,
3772            active: false,
3773            collapsed: false,
3774            children_html: None,
3775        }
3776    }
3777
3778    pub const fn active(mut self) -> Self {
3779        self.active = true;
3780        self
3781    }
3782
3783    pub const fn collapsed(mut self) -> Self {
3784        self.collapsed = true;
3785        self
3786    }
3787
3788    pub const fn with_children(mut self, children_html: TrustedHtml<'a>) -> Self {
3789        self.children_html = Some(children_html);
3790        self
3791    }
3792
3793    pub fn item_class(&self) -> &'static str {
3794        if self.collapsed { "is-collapsed" } else { "" }
3795    }
3796
3797    pub fn label_class(&self) -> &'static str {
3798        match (self.kind, self.active) {
3799            (TreeItemKind::Folder, _) => "tree-folder",
3800            (TreeItemKind::File, true) => "tree-file is-active",
3801            (TreeItemKind::File, false) => "tree-file",
3802        }
3803    }
3804}
3805
3806#[derive(Debug, Template)]
3807#[non_exhaustive]
3808#[template(path = "components/tree_view.html")]
3809pub struct TreeView<'a> {
3810    pub items: &'a [TreeItem<'a>],
3811    pub nested: bool,
3812}
3813
3814impl<'a> TreeView<'a> {
3815    pub const fn new(items: &'a [TreeItem<'a>]) -> Self {
3816        Self {
3817            items,
3818            nested: false,
3819        }
3820    }
3821
3822    pub const fn nested(mut self) -> Self {
3823        self.nested = true;
3824        self
3825    }
3826
3827    pub fn class_name(&self) -> &'static str {
3828        if self.nested { "" } else { "wf-tree" }
3829    }
3830}
3831
3832impl<'a> askama::filters::HtmlSafe for TreeView<'a> {}
3833
3834#[derive(Debug, Template)]
3835#[non_exhaustive]
3836#[template(path = "components/framed.html")]
3837pub struct Framed<'a> {
3838    pub content_html: TrustedHtml<'a>,
3839    pub dense: bool,
3840    pub dashed: bool,
3841}
3842
3843impl<'a> Framed<'a> {
3844    pub const fn new(content_html: TrustedHtml<'a>) -> Self {
3845        Self {
3846            content_html,
3847            dense: false,
3848            dashed: false,
3849        }
3850    }
3851
3852    pub const fn dense(mut self) -> Self {
3853        self.dense = true;
3854        self
3855    }
3856
3857    pub const fn dashed(mut self) -> Self {
3858        self.dashed = true;
3859        self
3860    }
3861
3862    pub fn class_name(&self) -> String {
3863        let dense = if self.dense { " dense" } else { "" };
3864        let dashed = if self.dashed { " dashed" } else { "" };
3865        format!("wf-framed{dense}{dashed}")
3866    }
3867}
3868
3869impl<'a> askama::filters::HtmlSafe for Framed<'a> {}
3870
3871#[derive(Debug, Template)]
3872#[non_exhaustive]
3873#[template(path = "components/grid.html")]
3874pub struct Grid<'a> {
3875    pub content_html: TrustedHtml<'a>,
3876    pub columns: u8,
3877}
3878
3879impl<'a> Grid<'a> {
3880    pub const fn new(content_html: TrustedHtml<'a>) -> Self {
3881        Self {
3882            content_html,
3883            columns: 2,
3884        }
3885    }
3886
3887    pub const fn with_columns(mut self, columns: u8) -> Self {
3888        self.columns = columns;
3889        self
3890    }
3891
3892    pub fn class_name(&self) -> String {
3893        format!("wf-grid cols-{}", self.columns)
3894    }
3895}
3896
3897impl<'a> askama::filters::HtmlSafe for Grid<'a> {}
3898
3899#[derive(Debug, Template)]
3900#[non_exhaustive]
3901#[template(path = "components/split.html")]
3902pub struct Split<'a> {
3903    pub content_html: TrustedHtml<'a>,
3904    pub vertical: bool,
3905}
3906
3907impl<'a> Split<'a> {
3908    pub const fn new(content_html: TrustedHtml<'a>) -> Self {
3909        Self {
3910            content_html,
3911            vertical: false,
3912        }
3913    }
3914
3915    pub const fn vertical(mut self) -> Self {
3916        self.vertical = true;
3917        self
3918    }
3919
3920    pub fn class_name(&self) -> &'static str {
3921        if self.vertical {
3922            "wf-split vertical"
3923        } else {
3924            "wf-split"
3925        }
3926    }
3927}
3928
3929impl<'a> askama::filters::HtmlSafe for Split<'a> {}
3930
3931#[derive(Debug, Template)]
3932#[non_exhaustive]
3933#[template(path = "components/callout.html")]
3934pub struct Callout<'a> {
3935    pub kind: FeedbackKind,
3936    pub title: Option<&'a str>,
3937    pub body_html: TrustedHtml<'a>,
3938}
3939
3940impl<'a> Callout<'a> {
3941    pub const fn new(kind: FeedbackKind, body_html: TrustedHtml<'a>) -> Self {
3942        Self {
3943            kind,
3944            title: None,
3945            body_html,
3946        }
3947    }
3948
3949    pub const fn with_title(mut self, title: &'a str) -> Self {
3950        self.title = Some(title);
3951        self
3952    }
3953
3954    pub fn class_name(&self) -> String {
3955        format!("wf-callout {}", self.kind.class())
3956    }
3957}
3958
3959impl<'a> askama::filters::HtmlSafe for Callout<'a> {}
3960
3961#[derive(Debug, Template)]
3962#[non_exhaustive]
3963#[template(path = "components/toast.html")]
3964pub struct Toast<'a> {
3965    pub kind: FeedbackKind,
3966    pub message: &'a str,
3967}
3968
3969impl<'a> Toast<'a> {
3970    pub const fn new(kind: FeedbackKind, message: &'a str) -> Self {
3971        Self { kind, message }
3972    }
3973
3974    pub fn class_name(&self) -> String {
3975        format!("wf-toast {}", self.kind.class())
3976    }
3977}
3978
3979impl<'a> askama::filters::HtmlSafe for Toast<'a> {}
3980
3981#[derive(Debug, Template)]
3982#[non_exhaustive]
3983#[template(path = "components/toast_host.html")]
3984pub struct ToastHost<'a> {
3985    pub id: &'a str,
3986}
3987
3988impl<'a> ToastHost<'a> {
3989    pub const fn new() -> Self {
3990        Self { id: "toast-host" }
3991    }
3992
3993    pub const fn with_id(mut self, id: &'a str) -> Self {
3994        self.id = id;
3995        self
3996    }
3997}
3998
3999impl<'a> Default for ToastHost<'a> {
4000    fn default() -> Self {
4001        Self::new()
4002    }
4003}
4004
4005impl<'a> askama::filters::HtmlSafe for ToastHost<'a> {}
4006
4007#[derive(Debug, Template)]
4008#[non_exhaustive]
4009#[template(path = "components/tooltip.html")]
4010pub struct Tooltip<'a> {
4011    pub tip: &'a str,
4012    pub content_html: TrustedHtml<'a>,
4013}
4014
4015impl<'a> Tooltip<'a> {
4016    pub const fn new(tip: &'a str, content_html: TrustedHtml<'a>) -> Self {
4017        Self { tip, content_html }
4018    }
4019}
4020
4021impl<'a> askama::filters::HtmlSafe for Tooltip<'a> {}
4022
4023#[derive(Clone, Copy, Debug, Eq, PartialEq)]
4024pub enum MenuItemKind {
4025    Button,
4026    Link,
4027    Separator,
4028}
4029
4030#[derive(Clone, Copy, Debug, Eq, PartialEq)]
4031pub struct MenuItem<'a> {
4032    pub kind: MenuItemKind,
4033    pub label: &'a str,
4034    pub href: Option<&'a str>,
4035    pub danger: bool,
4036    pub disabled: bool,
4037    pub kbd: Option<&'a str>,
4038    pub attrs: &'a [HtmlAttr<'a>],
4039}
4040
4041impl<'a> MenuItem<'a> {
4042    pub const fn button(label: &'a str) -> Self {
4043        Self {
4044            kind: MenuItemKind::Button,
4045            label,
4046            href: None,
4047            danger: false,
4048            disabled: false,
4049            kbd: None,
4050            attrs: &[],
4051        }
4052    }
4053
4054    pub const fn link(label: &'a str, href: &'a str) -> Self {
4055        Self {
4056            kind: MenuItemKind::Link,
4057            href: Some(href),
4058            ..Self::button(label)
4059        }
4060    }
4061
4062    pub const fn separator() -> Self {
4063        Self {
4064            kind: MenuItemKind::Separator,
4065            label: "",
4066            href: None,
4067            danger: false,
4068            disabled: false,
4069            kbd: None,
4070            attrs: &[],
4071        }
4072    }
4073
4074    pub const fn danger(mut self) -> Self {
4075        self.danger = true;
4076        self
4077    }
4078
4079    pub const fn disabled(mut self) -> Self {
4080        self.disabled = true;
4081        self
4082    }
4083
4084    pub const fn with_kbd(mut self, kbd: &'a str) -> Self {
4085        self.kbd = Some(kbd);
4086        self
4087    }
4088
4089    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
4090        self.attrs = attrs;
4091        self
4092    }
4093
4094    pub fn class_name(&self) -> &'static str {
4095        if self.danger {
4096            "wf-menu-item danger"
4097        } else {
4098            "wf-menu-item"
4099        }
4100    }
4101}
4102
4103#[derive(Debug, Template)]
4104#[non_exhaustive]
4105#[template(path = "components/menu.html")]
4106pub struct Menu<'a> {
4107    pub items: &'a [MenuItem<'a>],
4108}
4109
4110impl<'a> Menu<'a> {
4111    pub const fn new(items: &'a [MenuItem<'a>]) -> Self {
4112        Self { items }
4113    }
4114}
4115
4116impl<'a> askama::filters::HtmlSafe for Menu<'a> {}
4117
4118#[derive(Debug, Template)]
4119#[non_exhaustive]
4120#[template(path = "components/popover.html")]
4121pub struct Popover<'a> {
4122    pub trigger_html: TrustedHtml<'a>,
4123    pub body_html: TrustedHtml<'a>,
4124    pub heading: Option<&'a str>,
4125    pub side: &'a str,
4126    pub open: bool,
4127}
4128
4129impl<'a> Popover<'a> {
4130    pub const fn new(trigger_html: TrustedHtml<'a>, body_html: TrustedHtml<'a>) -> Self {
4131        Self {
4132            trigger_html,
4133            body_html,
4134            heading: None,
4135            side: "bottom",
4136            open: false,
4137        }
4138    }
4139
4140    pub const fn with_heading(mut self, heading: &'a str) -> Self {
4141        self.heading = Some(heading);
4142        self
4143    }
4144
4145    pub const fn with_side(mut self, side: &'a str) -> Self {
4146        self.side = side;
4147        self
4148    }
4149
4150    pub const fn open(mut self) -> Self {
4151        self.open = true;
4152        self
4153    }
4154
4155    pub fn popover_class(&self) -> &'static str {
4156        if self.open {
4157            "wf-popover is-open"
4158        } else {
4159            "wf-popover"
4160        }
4161    }
4162}
4163
4164impl<'a> askama::filters::HtmlSafe for Popover<'a> {}
4165
4166#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
4167pub enum ModalSize {
4168    #[default]
4169    Default,
4170    Large,
4171}
4172
4173impl ModalSize {
4174    fn class(self) -> &'static str {
4175        match self {
4176            Self::Default => "",
4177            Self::Large => " wf-modal--lg",
4178        }
4179    }
4180}
4181
4182#[derive(Debug, Template)]
4183#[non_exhaustive]
4184#[template(path = "components/modal.html")]
4185pub struct Modal<'a> {
4186    pub title: &'a str,
4187    pub body_html: TrustedHtml<'a>,
4188    pub footer_html: Option<TrustedHtml<'a>>,
4189    pub open: bool,
4190    pub size: ModalSize,
4191}
4192
4193impl<'a> Modal<'a> {
4194    pub const fn new(title: &'a str, body_html: TrustedHtml<'a>) -> Self {
4195        Self {
4196            title,
4197            body_html,
4198            footer_html: None,
4199            open: false,
4200            size: ModalSize::Default,
4201        }
4202    }
4203
4204    pub const fn with_footer(mut self, footer_html: TrustedHtml<'a>) -> Self {
4205        self.footer_html = Some(footer_html);
4206        self
4207    }
4208
4209    pub const fn open(mut self) -> Self {
4210        self.open = true;
4211        self
4212    }
4213
4214    pub const fn with_size(mut self, size: ModalSize) -> Self {
4215        self.size = size;
4216        self
4217    }
4218
4219    pub const fn large(self) -> Self {
4220        self.with_size(ModalSize::Large)
4221    }
4222
4223    pub fn overlay_class(&self) -> &'static str {
4224        if self.open {
4225            "wf-overlay is-open"
4226        } else {
4227            "wf-overlay"
4228        }
4229    }
4230
4231    pub fn modal_class(&self) -> String {
4232        let open = if self.open { " is-open" } else { "" };
4233        let size = self.size.class();
4234        format!("wf-modal{open}{size}")
4235    }
4236}
4237
4238impl<'a> Default for Modal<'a> {
4239    fn default() -> Self {
4240        Self::new("", TrustedHtml::new(""))
4241    }
4242}
4243
4244impl<'a> askama::filters::HtmlSafe for Modal<'a> {}
4245
4246#[derive(Debug, Template)]
4247#[non_exhaustive]
4248#[template(path = "components/drawer.html")]
4249pub struct Drawer<'a> {
4250    pub title: &'a str,
4251    pub body_html: TrustedHtml<'a>,
4252    pub footer_html: Option<TrustedHtml<'a>>,
4253    pub open: bool,
4254    pub left: bool,
4255}
4256
4257impl<'a> Drawer<'a> {
4258    pub const fn new(title: &'a str, body_html: TrustedHtml<'a>) -> Self {
4259        Self {
4260            title,
4261            body_html,
4262            footer_html: None,
4263            open: false,
4264            left: false,
4265        }
4266    }
4267
4268    pub const fn with_footer(mut self, footer_html: TrustedHtml<'a>) -> Self {
4269        self.footer_html = Some(footer_html);
4270        self
4271    }
4272
4273    pub const fn open(mut self) -> Self {
4274        self.open = true;
4275        self
4276    }
4277
4278    pub const fn left(mut self) -> Self {
4279        self.left = true;
4280        self
4281    }
4282
4283    pub fn overlay_class(&self) -> &'static str {
4284        if self.open {
4285            "wf-overlay is-open"
4286        } else {
4287            "wf-overlay"
4288        }
4289    }
4290
4291    pub fn drawer_class(&self) -> String {
4292        let open = if self.open { " is-open" } else { "" };
4293        let left = if self.left { " left" } else { "" };
4294        format!("wf-drawer{open}{left}")
4295    }
4296}
4297
4298impl<'a> askama::filters::HtmlSafe for Drawer<'a> {}
4299
4300#[derive(Debug, Template)]
4301#[non_exhaustive]
4302#[template(path = "components/progress.html")]
4303pub struct Progress {
4304    pub value: Option<u8>,
4305}
4306
4307impl Progress {
4308    pub const fn new(value: u8) -> Self {
4309        Self { value: Some(value) }
4310    }
4311
4312    pub const fn indeterminate() -> Self {
4313        Self { value: None }
4314    }
4315
4316    pub fn class_name(&self) -> &'static str {
4317        if self.value.is_some() {
4318            "wf-progress"
4319        } else {
4320            "wf-progress indeterminate"
4321        }
4322    }
4323
4324    pub fn bounded_value(&self) -> u8 {
4325        self.value.unwrap_or(0).min(100)
4326    }
4327}
4328
4329impl askama::filters::HtmlSafe for Progress {}
4330
4331#[derive(Clone, Copy, Debug, Eq, PartialEq)]
4332pub enum MeterColor {
4333    Accent,
4334    Ok,
4335    Warn,
4336    Error,
4337    Info,
4338}
4339
4340impl MeterColor {
4341    fn css_var(self) -> &'static str {
4342        match self {
4343            Self::Accent => "var(--accent)",
4344            Self::Ok => "var(--ok)",
4345            Self::Warn => "var(--warn)",
4346            Self::Error => "var(--err)",
4347            Self::Info => "var(--info)",
4348        }
4349    }
4350}
4351
4352#[derive(Debug, Template)]
4353#[non_exhaustive]
4354#[template(path = "components/meter.html")]
4355pub struct Meter {
4356    pub value: u8,
4357    pub width_px: Option<u16>,
4358    pub height_px: Option<u16>,
4359    pub color: Option<MeterColor>,
4360}
4361
4362impl Meter {
4363    pub const fn new(value: u8) -> Self {
4364        Self {
4365            value,
4366            width_px: None,
4367            height_px: None,
4368            color: None,
4369        }
4370    }
4371
4372    pub const fn with_size_px(mut self, width_px: u16, height_px: u16) -> Self {
4373        self.width_px = Some(width_px);
4374        self.height_px = Some(height_px);
4375        self
4376    }
4377
4378    pub const fn with_color(mut self, color: MeterColor) -> Self {
4379        self.color = Some(color);
4380        self
4381    }
4382
4383    pub fn style(&self) -> String {
4384        let mut style = String::with_capacity(72);
4385        let _ = write!(&mut style, "--meter: {}%", self.value.min(100));
4386        if let Some(width) = self.width_px {
4387            let _ = write!(&mut style, "; --meter-w: {width}px");
4388        }
4389        if let Some(height) = self.height_px {
4390            let _ = write!(&mut style, "; --meter-h: {height}px");
4391        }
4392        if let Some(color) = self.color {
4393            style.push_str("; --meter-c: ");
4394            style.push_str(color.css_var());
4395        }
4396        style
4397    }
4398}
4399
4400impl askama::filters::HtmlSafe for Meter {}
4401
4402#[derive(Debug, Template)]
4403#[non_exhaustive]
4404#[template(path = "components/code_block.html")]
4405pub struct CodeBlock<'a> {
4406    pub code: &'a str,
4407    pub language: Option<&'a str>,
4408    pub label: Option<&'a str>,
4409    pub copy_target_id: Option<&'a str>,
4410    pub attrs: &'a [HtmlAttr<'a>],
4411}
4412
4413impl<'a> CodeBlock<'a> {
4414    pub const fn new(code: &'a str) -> Self {
4415        Self {
4416            code,
4417            language: None,
4418            label: None,
4419            copy_target_id: None,
4420            attrs: &[],
4421        }
4422    }
4423
4424    pub const fn with_language(mut self, language: &'a str) -> Self {
4425        self.language = Some(language);
4426        self
4427    }
4428
4429    pub const fn with_label(mut self, label: &'a str) -> Self {
4430        self.label = Some(label);
4431        self
4432    }
4433
4434    pub const fn with_copy_target(mut self, copy_target_id: &'a str) -> Self {
4435        self.copy_target_id = Some(copy_target_id);
4436        self
4437    }
4438
4439    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
4440        self.attrs = attrs;
4441        self
4442    }
4443}
4444
4445impl<'a> askama::filters::HtmlSafe for CodeBlock<'a> {}
4446
4447#[derive(Clone, Copy, Debug, Eq, PartialEq)]
4448pub struct SnippetTab<'a> {
4449    pub label: &'a str,
4450    pub code: &'a str,
4451    pub language: Option<&'a str>,
4452    pub active: bool,
4453}
4454
4455impl<'a> SnippetTab<'a> {
4456    pub const fn new(label: &'a str, code: &'a str) -> Self {
4457        Self {
4458            label,
4459            code,
4460            language: None,
4461            active: false,
4462        }
4463    }
4464
4465    pub const fn with_language(mut self, language: &'a str) -> Self {
4466        self.language = Some(language);
4467        self
4468    }
4469
4470    pub const fn active(mut self) -> Self {
4471        self.active = true;
4472        self
4473    }
4474
4475    pub fn tab_class(&self) -> &'static str {
4476        if self.active {
4477            "wf-snippet-tab is-active"
4478        } else {
4479            "wf-snippet-tab"
4480        }
4481    }
4482
4483    pub fn panel_class(&self) -> &'static str {
4484        if self.active {
4485            "wf-snippet-panel is-active"
4486        } else {
4487            "wf-snippet-panel"
4488        }
4489    }
4490}
4491
4492#[derive(Debug, Template)]
4493#[non_exhaustive]
4494#[template(path = "components/snippet_tabs.html")]
4495pub struct SnippetTabs<'a> {
4496    pub id: &'a str,
4497    pub tabs: &'a [SnippetTab<'a>],
4498    pub attrs: &'a [HtmlAttr<'a>],
4499}
4500
4501impl<'a> SnippetTabs<'a> {
4502    pub const fn new(id: &'a str, tabs: &'a [SnippetTab<'a>]) -> Self {
4503        Self {
4504            id,
4505            tabs,
4506            attrs: &[],
4507        }
4508    }
4509
4510    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
4511        self.attrs = attrs;
4512        self
4513    }
4514}
4515
4516impl<'a> askama::filters::HtmlSafe for SnippetTabs<'a> {}
4517
4518#[derive(Debug, Template)]
4519#[non_exhaustive]
4520#[template(path = "components/strength_meter.html")]
4521pub struct StrengthMeter<'a> {
4522    pub value: u8,
4523    pub max: u8,
4524    pub text: &'a str,
4525    pub label: Option<&'a str>,
4526    pub kind: Option<FeedbackKind>,
4527    pub live: bool,
4528}
4529
4530impl<'a> StrengthMeter<'a> {
4531    pub const fn new(value: u8, max: u8, text: &'a str) -> Self {
4532        Self {
4533            value,
4534            max,
4535            text,
4536            label: None,
4537            kind: None,
4538            live: false,
4539        }
4540    }
4541
4542    pub const fn with_label(mut self, label: &'a str) -> Self {
4543        self.label = Some(label);
4544        self
4545    }
4546
4547    pub const fn with_feedback(mut self, feedback: FeedbackKind) -> Self {
4548        self.kind = Some(feedback);
4549        self
4550    }
4551
4552    pub const fn live(mut self) -> Self {
4553        self.live = true;
4554        self
4555    }
4556
4557    pub fn class_name(&self) -> &'static str {
4558        match self.kind {
4559            Some(FeedbackKind::Info) => "wf-strength-meter is-info",
4560            Some(FeedbackKind::Ok) => "wf-strength-meter is-ok",
4561            Some(FeedbackKind::Warn) => "wf-strength-meter is-warn",
4562            Some(FeedbackKind::Error) => "wf-strength-meter is-err",
4563            None => "wf-strength-meter",
4564        }
4565    }
4566
4567    pub fn bounded_value(&self) -> u8 {
4568        self.value.min(self.max)
4569    }
4570
4571    pub fn percentage(&self) -> u8 {
4572        if self.max == 0 {
4573            0
4574        } else {
4575            ((u16::from(self.bounded_value()) * 100) / u16::from(self.max)) as u8
4576        }
4577    }
4578
4579    pub fn style(&self) -> String {
4580        format!("--strength: {}%", self.percentage())
4581    }
4582}
4583
4584impl<'a> askama::filters::HtmlSafe for StrengthMeter<'a> {}
4585
4586#[derive(Debug, Template)]
4587#[non_exhaustive]
4588#[template(path = "components/kbd.html")]
4589pub struct Kbd<'a> {
4590    pub label: &'a str,
4591}
4592
4593impl<'a> Kbd<'a> {
4594    pub const fn new(label: &'a str) -> Self {
4595        Self { label }
4596    }
4597}
4598
4599impl<'a> askama::filters::HtmlSafe for Kbd<'a> {}
4600
4601#[derive(Clone, Copy, Debug, Eq, PartialEq)]
4602pub enum SkeletonKind {
4603    Line,
4604    Title,
4605    Block,
4606}
4607
4608impl SkeletonKind {
4609    fn class(self) -> &'static str {
4610        match self {
4611            Self::Line => "line",
4612            Self::Title => "title",
4613            Self::Block => "block",
4614        }
4615    }
4616}
4617
4618#[derive(Debug, Template)]
4619#[non_exhaustive]
4620#[template(path = "components/skeleton.html")]
4621pub struct Skeleton {
4622    pub kind: SkeletonKind,
4623}
4624
4625impl Skeleton {
4626    pub const fn line() -> Self {
4627        Self {
4628            kind: SkeletonKind::Line,
4629        }
4630    }
4631
4632    pub const fn title() -> Self {
4633        Self {
4634            kind: SkeletonKind::Title,
4635        }
4636    }
4637
4638    pub const fn block() -> Self {
4639        Self {
4640            kind: SkeletonKind::Block,
4641        }
4642    }
4643
4644    pub fn class_name(&self) -> String {
4645        format!("wf-skeleton {}", self.kind.class())
4646    }
4647}
4648
4649impl askama::filters::HtmlSafe for Skeleton {}
4650
4651#[derive(Debug, Template)]
4652#[non_exhaustive]
4653#[template(path = "components/spinner.html")]
4654pub struct Spinner {
4655    pub large: bool,
4656}
4657
4658impl Spinner {
4659    pub const fn new() -> Self {
4660        Self { large: false }
4661    }
4662
4663    pub const fn large() -> Self {
4664        Self { large: true }
4665    }
4666
4667    pub fn class_name(&self) -> &'static str {
4668        if self.large {
4669            "wf-spinner lg"
4670        } else {
4671            "wf-spinner"
4672        }
4673    }
4674}
4675
4676impl Default for Spinner {
4677    fn default() -> Self {
4678        Self::new()
4679    }
4680}
4681
4682impl askama::filters::HtmlSafe for Spinner {}
4683
4684#[derive(Clone, Copy, Debug, Eq, PartialEq)]
4685pub enum ModelineSegmentKind {
4686    Default,
4687    Chevron,
4688    Flag,
4689    Buffer,
4690    Mode,
4691    Position,
4692    Progress,
4693}
4694
4695impl ModelineSegmentKind {
4696    fn class(self) -> &'static str {
4697        match self {
4698            Self::Default => "wf-ml-seg",
4699            Self::Chevron => "wf-ml-seg wf-ml-chevron",
4700            Self::Flag => "wf-ml-seg wf-ml-flag",
4701            Self::Buffer => "wf-ml-seg wf-ml-buffer",
4702            Self::Mode => "wf-ml-seg wf-ml-mode",
4703            Self::Position => "wf-ml-seg wf-ml-pos",
4704            Self::Progress => "wf-ml-seg wf-ml-progress",
4705        }
4706    }
4707}
4708
4709#[derive(Debug, Template)]
4710#[non_exhaustive]
4711#[template(path = "components/modeline_segment.html")]
4712pub struct ModelineSegment<'a> {
4713    pub label: &'a str,
4714    pub kind: ModelineSegmentKind,
4715    pub state: Option<FeedbackKind>,
4716    pub href: Option<&'a str>,
4717    pub button: bool,
4718    pub button_type: &'a str,
4719    pub active: bool,
4720    pub kbd: Option<&'a str>,
4721    pub html: Option<TrustedHtml<'a>>,
4722    pub attrs: &'a [HtmlAttr<'a>],
4723}
4724
4725impl<'a> ModelineSegment<'a> {
4726    pub const fn text(label: &'a str) -> Self {
4727        Self {
4728            label,
4729            kind: ModelineSegmentKind::Default,
4730            state: None,
4731            href: None,
4732            button: false,
4733            button_type: "button",
4734            active: false,
4735            kbd: None,
4736            html: None,
4737            attrs: &[],
4738        }
4739    }
4740
4741    pub const fn chevron(label: &'a str) -> Self {
4742        Self {
4743            kind: ModelineSegmentKind::Chevron,
4744            ..Self::text(label)
4745        }
4746    }
4747
4748    pub const fn flag(label: &'a str) -> Self {
4749        Self {
4750            kind: ModelineSegmentKind::Flag,
4751            ..Self::text(label)
4752        }
4753    }
4754
4755    pub const fn buffer(label: &'a str) -> Self {
4756        Self {
4757            kind: ModelineSegmentKind::Buffer,
4758            ..Self::text(label)
4759        }
4760    }
4761
4762    pub const fn mode(label: &'a str) -> Self {
4763        Self {
4764            kind: ModelineSegmentKind::Mode,
4765            ..Self::text(label)
4766        }
4767    }
4768
4769    pub const fn position(label: &'a str) -> Self {
4770        Self {
4771            kind: ModelineSegmentKind::Position,
4772            ..Self::text(label)
4773        }
4774    }
4775
4776    pub const fn progress(label: &'a str) -> Self {
4777        Self {
4778            kind: ModelineSegmentKind::Progress,
4779            ..Self::text(label)
4780        }
4781    }
4782
4783    pub const fn link(label: &'a str, href: &'a str) -> Self {
4784        Self {
4785            href: Some(href),
4786            ..Self::text(label)
4787        }
4788    }
4789
4790    pub const fn button(label: &'a str) -> Self {
4791        Self {
4792            button: true,
4793            ..Self::text(label)
4794        }
4795    }
4796
4797    pub const fn with_feedback(mut self, feedback: FeedbackKind) -> Self {
4798        self.state = Some(feedback);
4799        self
4800    }
4801
4802    pub const fn active(mut self) -> Self {
4803        self.active = true;
4804        self
4805    }
4806
4807    pub const fn with_kbd(mut self, kbd: &'a str) -> Self {
4808        self.kbd = Some(kbd);
4809        self
4810    }
4811
4812    pub const fn with_html(mut self, html: TrustedHtml<'a>) -> Self {
4813        self.html = Some(html);
4814        self
4815    }
4816
4817    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
4818        self.attrs = attrs;
4819        self
4820    }
4821
4822    pub const fn with_button_type(mut self, button_type: &'a str) -> Self {
4823        self.button_type = button_type;
4824        self
4825    }
4826
4827    pub fn class_name(&self) -> String {
4828        let mut class = String::from(self.kind.class());
4829        if self.href.is_some() || self.button || !self.attrs.is_empty() {
4830            class.push_str(" is-interactive");
4831        }
4832        if self.active {
4833            class.push_str(" is-active");
4834        }
4835        if let Some(kind) = self.state {
4836            class.push_str(" is-");
4837            class.push_str(kind.class());
4838        }
4839        class
4840    }
4841}
4842
4843impl<'a> askama::filters::HtmlSafe for ModelineSegment<'a> {}
4844
4845#[derive(Debug, Template)]
4846#[non_exhaustive]
4847#[template(path = "components/modeline.html")]
4848pub struct Modeline<'a> {
4849    pub left_segments: &'a [ModelineSegment<'a>],
4850    pub right_segments: &'a [ModelineSegment<'a>],
4851    pub fill: bool,
4852    pub attrs: &'a [HtmlAttr<'a>],
4853}
4854
4855impl<'a> Modeline<'a> {
4856    pub const fn new(left_segments: &'a [ModelineSegment<'a>]) -> Self {
4857        Self {
4858            left_segments,
4859            right_segments: &[],
4860            fill: true,
4861            attrs: &[],
4862        }
4863    }
4864
4865    pub const fn with_right(mut self, right_segments: &'a [ModelineSegment<'a>]) -> Self {
4866        self.right_segments = right_segments;
4867        self
4868    }
4869
4870    pub const fn without_fill(mut self) -> Self {
4871        self.fill = false;
4872        self
4873    }
4874
4875    pub const fn with_attrs(mut self, attrs: &'a [HtmlAttr<'a>]) -> Self {
4876        self.attrs = attrs;
4877        self
4878    }
4879}
4880
4881impl<'a> askama::filters::HtmlSafe for Modeline<'a> {}
4882
4883#[derive(Clone, Copy, Debug, Eq, PartialEq)]
4884pub struct MinibufferHistoryRow<'a> {
4885    pub time: &'a str,
4886    pub message: &'a str,
4887    pub kind: Option<FeedbackKind>,
4888}
4889
4890impl<'a> MinibufferHistoryRow<'a> {
4891    pub const fn new(time: &'a str, message: &'a str) -> Self {
4892        Self {
4893            time,
4894            message,
4895            kind: None,
4896        }
4897    }
4898
4899    pub const fn with_feedback(mut self, feedback: FeedbackKind) -> Self {
4900        self.kind = Some(feedback);
4901        self
4902    }
4903
4904    pub fn class_name(&self) -> &'static str {
4905        match self.kind {
4906            Some(FeedbackKind::Info) => "row is-info",
4907            Some(FeedbackKind::Ok) => "row is-ok",
4908            Some(FeedbackKind::Warn) => "row is-warn",
4909            Some(FeedbackKind::Error) => "row is-err",
4910            None => "row",
4911        }
4912    }
4913}
4914
4915#[derive(Debug, Template)]
4916#[non_exhaustive]
4917#[template(path = "components/minibuffer.html")]
4918pub struct Minibuffer<'a> {
4919    pub prompt: &'a str,
4920    pub message: Option<&'a str>,
4921    pub kind: Option<FeedbackKind>,
4922    pub time: Option<&'a str>,
4923    pub history: &'a [MinibufferHistoryRow<'a>],
4924}
4925
4926impl<'a> Minibuffer<'a> {
4927    pub const fn new() -> Self {
4928        Self {
4929            prompt: ">",
4930            message: None,
4931            kind: None,
4932            time: None,
4933            history: &[],
4934        }
4935    }
4936
4937    pub const fn with_prompt(mut self, prompt: &'a str) -> Self {
4938        self.prompt = prompt;
4939        self
4940    }
4941
4942    pub const fn with_message(mut self, kind: FeedbackKind, message: &'a str) -> Self {
4943        self.kind = Some(kind);
4944        self.message = Some(message);
4945        self
4946    }
4947
4948    pub const fn with_time(mut self, time: &'a str) -> Self {
4949        self.time = Some(time);
4950        self
4951    }
4952
4953    pub const fn with_history(mut self, history: &'a [MinibufferHistoryRow<'a>]) -> Self {
4954        self.history = history;
4955        self
4956    }
4957
4958    pub const fn has_history(&self) -> bool {
4959        !self.history.is_empty()
4960    }
4961
4962    pub fn message_class(&self) -> String {
4963        match self.kind {
4964            Some(kind) if self.message.is_some() => {
4965                format!("wf-minibuffer-msg is-visible is-{}", kind.class())
4966            }
4967            _ => "wf-minibuffer-msg".to_owned(),
4968        }
4969    }
4970}
4971
4972impl<'a> Default for Minibuffer<'a> {
4973    fn default() -> Self {
4974        Self::new()
4975    }
4976}
4977
4978impl<'a> askama::filters::HtmlSafe for Minibuffer<'a> {}
4979
4980#[derive(Debug, Template)]
4981#[non_exhaustive]
4982#[template(path = "components/minibuffer_echo.html")]
4983pub struct MinibufferEcho<'a> {
4984    pub kind: FeedbackKind,
4985    pub message: &'a str,
4986}
4987
4988impl<'a> MinibufferEcho<'a> {
4989    pub const fn new(kind: FeedbackKind, message: &'a str) -> Self {
4990        Self { kind, message }
4991    }
4992
4993    pub const fn info(message: &'a str) -> Self {
4994        Self::new(FeedbackKind::Info, message)
4995    }
4996
4997    pub const fn ok(message: &'a str) -> Self {
4998        Self::new(FeedbackKind::Ok, message)
4999    }
5000
5001    pub const fn warn(message: &'a str) -> Self {
5002        Self::new(FeedbackKind::Warn, message)
5003    }
5004
5005    pub const fn error(message: &'a str) -> Self {
5006        Self::new(FeedbackKind::Error, message)
5007    }
5008
5009    pub fn kind_class(&self) -> &'static str {
5010        self.kind.class()
5011    }
5012}
5013
5014impl<'a> askama::filters::HtmlSafe for MinibufferEcho<'a> {}
5015
5016#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5017pub struct FeatureItem<'a> {
5018    pub title: &'a str,
5019    pub body: &'a str,
5020}
5021
5022impl<'a> FeatureItem<'a> {
5023    pub const fn new(title: &'a str, body: &'a str) -> Self {
5024        Self { title, body }
5025    }
5026}
5027
5028#[derive(Debug, Template)]
5029#[non_exhaustive]
5030#[template(path = "components/feature_grid.html")]
5031pub struct FeatureGrid<'a> {
5032    pub items: &'a [FeatureItem<'a>],
5033}
5034
5035impl<'a> FeatureGrid<'a> {
5036    pub const fn new(items: &'a [FeatureItem<'a>]) -> Self {
5037        Self { items }
5038    }
5039}
5040
5041impl<'a> askama::filters::HtmlSafe for FeatureGrid<'a> {}
5042
5043#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5044pub struct MarketingStep<'a> {
5045    pub title: &'a str,
5046    pub body: &'a str,
5047}
5048
5049impl<'a> MarketingStep<'a> {
5050    pub const fn new(title: &'a str, body: &'a str) -> Self {
5051        Self { title, body }
5052    }
5053}
5054
5055#[derive(Debug, Template)]
5056#[non_exhaustive]
5057#[template(path = "components/marketing_step_grid.html")]
5058pub struct MarketingStepGrid<'a> {
5059    pub steps: &'a [MarketingStep<'a>],
5060}
5061
5062impl<'a> MarketingStepGrid<'a> {
5063    pub const fn new(steps: &'a [MarketingStep<'a>]) -> Self {
5064        Self { steps }
5065    }
5066}
5067
5068impl<'a> askama::filters::HtmlSafe for MarketingStepGrid<'a> {}
5069
5070#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5071pub struct PricingPlan<'a> {
5072    pub name: &'a str,
5073    pub price: &'a str,
5074    pub unit: Option<&'a str>,
5075    pub blurb: Option<&'a str>,
5076    pub featured: bool,
5077}
5078
5079impl<'a> PricingPlan<'a> {
5080    pub const fn new(name: &'a str, price: &'a str) -> Self {
5081        Self {
5082            name,
5083            price,
5084            unit: None,
5085            blurb: None,
5086            featured: false,
5087        }
5088    }
5089
5090    pub const fn with_unit(mut self, unit: &'a str) -> Self {
5091        self.unit = Some(unit);
5092        self
5093    }
5094
5095    pub const fn with_blurb(mut self, blurb: &'a str) -> Self {
5096        self.blurb = Some(blurb);
5097        self
5098    }
5099
5100    pub const fn featured(mut self) -> Self {
5101        self.featured = true;
5102        self
5103    }
5104
5105    pub fn class_name(&self) -> &'static str {
5106        if self.featured {
5107            "wf-plan is-featured"
5108        } else {
5109            "wf-plan"
5110        }
5111    }
5112}
5113
5114#[derive(Debug, Template)]
5115#[non_exhaustive]
5116#[template(path = "components/pricing_plans.html")]
5117pub struct PricingPlans<'a> {
5118    pub plans: &'a [PricingPlan<'a>],
5119}
5120
5121impl<'a> PricingPlans<'a> {
5122    pub const fn new(plans: &'a [PricingPlan<'a>]) -> Self {
5123        Self { plans }
5124    }
5125}
5126
5127impl<'a> askama::filters::HtmlSafe for PricingPlans<'a> {}
5128
5129#[derive(Debug, Template)]
5130#[non_exhaustive]
5131#[template(path = "components/testimonial.html")]
5132pub struct Testimonial<'a> {
5133    pub quote_html: TrustedHtml<'a>,
5134    pub name: &'a str,
5135    pub role: &'a str,
5136}
5137
5138impl<'a> Testimonial<'a> {
5139    pub const fn new(quote_html: TrustedHtml<'a>, name: &'a str, role: &'a str) -> Self {
5140        Self {
5141            quote_html,
5142            name,
5143            role,
5144        }
5145    }
5146}
5147
5148impl<'a> askama::filters::HtmlSafe for Testimonial<'a> {}
5149
5150#[derive(Debug, Template)]
5151#[non_exhaustive]
5152#[template(path = "components/marketing_section.html")]
5153pub struct MarketingSection<'a> {
5154    pub title: &'a str,
5155    pub content_html: TrustedHtml<'a>,
5156    pub kicker: Option<&'a str>,
5157    pub subtitle: Option<&'a str>,
5158}
5159
5160impl<'a> MarketingSection<'a> {
5161    pub const fn new(title: &'a str, content_html: TrustedHtml<'a>) -> Self {
5162        Self {
5163            title,
5164            content_html,
5165            kicker: None,
5166            subtitle: None,
5167        }
5168    }
5169
5170    pub const fn with_kicker(mut self, kicker: &'a str) -> Self {
5171        self.kicker = Some(kicker);
5172        self
5173    }
5174
5175    pub const fn with_subtitle(mut self, subtitle: &'a str) -> Self {
5176        self.subtitle = Some(subtitle);
5177        self
5178    }
5179}
5180
5181impl<'a> askama::filters::HtmlSafe for MarketingSection<'a> {}
5182
5183#[cfg(test)]
5184mod tests {
5185    use super::*;
5186
5187    #[test]
5188    fn renders_button_with_htmx_attrs() {
5189        let attrs = [HtmlAttr::hx_post("/save?next=<home>")];
5190        let html = Button::primary("Save").with_attrs(&attrs).render().unwrap();
5191
5192        assert!(html.contains(r#"class="wf-btn primary""#));
5193        assert!(html.contains(r#"hx-post="/save?next="#));
5194        assert!(!html.contains(r#"hx-post="/save?next=<home>""#));
5195    }
5196
5197    #[test]
5198    fn field_escapes_copy_and_renders_trusted_control_html() {
5199        let html = Field::new(
5200            "Email <required>",
5201            TrustedHtml::new(r#"<input class="wf-input" name="email">"#),
5202        )
5203        .with_hint("Use <work> address")
5204        .render()
5205        .unwrap();
5206
5207        assert!(html.contains("Email"));
5208        assert!(!html.contains("Email <required>"));
5209        assert!(html.contains(r#"<input class="wf-input" name="email">"#));
5210        assert!(html.contains("Use"));
5211        assert!(!html.contains("Use <work> address"));
5212    }
5213
5214    #[test]
5215    fn trusted_html_writes_without_formatter_allocation() {
5216        let mut html = String::new();
5217
5218        askama::FastWritable::write_into(
5219            &TrustedHtml::new("<strong>Ready</strong>"),
5220            &mut html,
5221            askama::NO_VALUES,
5222        )
5223        .unwrap();
5224
5225        assert_eq!(html, "<strong>Ready</strong>");
5226    }
5227
5228    #[derive(Template)]
5229    #[template(source = "{{ button }}", ext = "html")]
5230    struct NestedButton<'a> {
5231        button: Button<'a>,
5232    }
5233
5234    #[test]
5235    fn nested_components_render_as_html() {
5236        let html = NestedButton {
5237            button: Button::primary("Save"),
5238        }
5239        .render()
5240        .unwrap();
5241
5242        assert!(html.contains("<button"));
5243        assert!(!html.contains("&lt;button"));
5244    }
5245
5246    #[test]
5247    fn action_primitives_render_wave_funk_markup() {
5248        let attrs = [HtmlAttr::hx_post("/actions/archive")];
5249        let buttons = [
5250            Button::new("Left"),
5251            Button::primary("Archive").with_attrs(&attrs),
5252        ];
5253
5254        let group_html = ButtonGroup::new(&buttons).render().unwrap();
5255        let split_html = SplitButton::new(Button::primary("Run"), Button::new("More"))
5256            .render()
5257            .unwrap();
5258        let icon_html = IconButton::new(TrustedHtml::new("&times;"), "Close")
5259            .with_variant(ButtonVariant::Ghost)
5260            .render()
5261            .unwrap();
5262
5263        assert!(group_html.contains(r#"class="wf-btn-group""#));
5264        assert!(group_html.contains(r#"hx-post="/actions/archive""#));
5265        assert!(split_html.contains(r#"class="wf-btn-split""#));
5266        assert!(split_html.contains(r#"class="wf-btn caret""#));
5267        assert!(icon_html.contains(r#"class="wf-icon-btn ghost""#));
5268        assert!(icon_html.contains(r#"aria-label="Close""#));
5269        assert!(icon_html.contains("&times;"));
5270    }
5271
5272    #[test]
5273    fn text_form_primitives_escape_copy_and_attrs() {
5274        let attrs = [HtmlAttr::hx_get("/validate/email")];
5275        let input_html = Input::email("email")
5276            .with_value("sandeep<wavefunk>")
5277            .with_placeholder("Email <address>")
5278            .with_attrs(&attrs)
5279            .render()
5280            .unwrap();
5281        let textarea_html = Textarea::new("notes")
5282            .with_value("Hello <team>")
5283            .with_placeholder("Notes <optional>")
5284            .render()
5285            .unwrap();
5286        let options = [
5287            SelectOption::new("starter", "Starter"),
5288            SelectOption::new("pro", "Pro <team>").selected(),
5289        ];
5290        let select_html = Select::new("plan", &options).render().unwrap();
5291
5292        assert!(input_html.contains(r#"class="wf-input""#));
5293        assert!(input_html.contains(r#"type="email""#));
5294        assert!(input_html.contains(r#"hx-get="/validate/email""#));
5295        assert!(!input_html.contains("sandeep<wavefunk>"));
5296        assert!(!input_html.contains("Email <address>"));
5297        assert!(textarea_html.contains(r#"class="wf-textarea""#));
5298        assert!(!textarea_html.contains("Hello <team>"));
5299        assert!(select_html.contains(r#"class="wf-select""#));
5300        assert!(select_html.contains(r#"value="pro" selected"#));
5301        assert!(!select_html.contains("Pro <team>"));
5302    }
5303
5304    #[test]
5305    fn grouped_choice_and_range_primitives_render_expected_classes() {
5306        let input_html = Input::url("site_url").render().unwrap();
5307        let group_html = InputGroup::new(TrustedHtml::new(&input_html))
5308            .with_prefix("https://")
5309            .with_suffix(".wavefunk.test")
5310            .render()
5311            .unwrap();
5312        let checkbox_html = CheckRow::checkbox("terms", "yes", "Accept <terms>")
5313            .checked()
5314            .render()
5315            .unwrap();
5316        let radio_html = CheckRow::radio("plan", "pro", "Pro").render().unwrap();
5317        let switch_html = Switch::new("enabled").checked().render().unwrap();
5318        let range_html = Range::new("volume")
5319            .with_bounds("0", "100")
5320            .with_value("50")
5321            .render()
5322            .unwrap();
5323        let field_html = Field::new("URL", TrustedHtml::new(&group_html))
5324            .with_state(FieldState::Success)
5325            .render()
5326            .unwrap();
5327
5328        assert!(group_html.contains(r#"class="wf-input-group""#));
5329        assert!(group_html.contains(r#"class="wf-input-addon">https://"#));
5330        assert!(checkbox_html.contains(r#"class="wf-check-row""#));
5331        assert!(checkbox_html.contains(r#"type="checkbox""#));
5332        assert!(checkbox_html.contains("checked"));
5333        assert!(!checkbox_html.contains("Accept <terms>"));
5334        assert!(radio_html.contains(r#"type="radio""#));
5335        assert!(switch_html.contains(r#"class="wf-switch""#));
5336        assert!(switch_html.contains("checked"));
5337        assert!(range_html.contains(r#"class="wf-range""#));
5338        assert!(range_html.contains(r#"min="0""#));
5339        assert!(field_html.contains(r#"class="wf-field is-success""#));
5340    }
5341
5342    #[test]
5343    fn layout_navigation_and_data_primitives_render_expected_markup() {
5344        let panel = Panel::new("Deployments", TrustedHtml::new("<p>Ready</p>"))
5345            .with_action(TrustedHtml::new(
5346                r#"<a class="wf-panel-link" href="/all">All</a>"#,
5347            ))
5348            .render()
5349            .unwrap();
5350        let card = Card::new("Project <alpha>", TrustedHtml::new("<p>Live</p>"))
5351            .with_kicker("Status")
5352            .raised()
5353            .render()
5354            .unwrap();
5355        let stats = [Stat::new("Requests", "42").with_unit("rpm")];
5356        let stat_row = StatRow::new(&stats).render().unwrap();
5357        let badge = Badge::muted("beta").render().unwrap();
5358        let avatar = Avatar::new("SN").accent().render().unwrap();
5359        let crumbs = [
5360            BreadcrumbItem::link("Projects", "/projects"),
5361            BreadcrumbItem::current("Wavefunk <UI>"),
5362        ];
5363        let breadcrumbs = Breadcrumbs::new(&crumbs).render().unwrap();
5364        let tabs = [
5365            TabItem::link("Overview", "/").active(),
5366            TabItem::link("Settings", "/settings"),
5367        ];
5368        let tab_html = Tabs::new(&tabs).render().unwrap();
5369        let segments = [
5370            SegmentOption::new("List", "list").active(),
5371            SegmentOption::new("Grid", "grid"),
5372        ];
5373        let seg_html = SegmentedControl::new(&segments).render().unwrap();
5374        let pages = [
5375            PageLink::link("1", "/page/1").active(),
5376            PageLink::ellipsis(),
5377            PageLink::disabled("Next"),
5378        ];
5379        let pagination = Pagination::new(&pages).render().unwrap();
5380        let nav_section = NavSection::new("Workspace").render().unwrap();
5381        let nav_item = NavItem::new("Dashboard", "/").active().with_count("3");
5382        let topbar = Topbar::new(TrustedHtml::new(&breadcrumbs), TrustedHtml::new(&badge))
5383            .render()
5384            .unwrap();
5385        let statusbar = Statusbar::new("Connected", "v0.1").render().unwrap();
5386        let empty = EmptyState::new("No hooks", "Create a hook to start.")
5387            .with_glyph(TrustedHtml::new("&empty;"))
5388            .bordered()
5389            .render()
5390            .unwrap();
5391        let table_headers = [TableHeader::new("Name"), TableHeader::numeric("Runs")];
5392        let table_cells = [TableCell::strong("Build <main>"), TableCell::numeric("12")];
5393        let table_rows = [TableRow::new(&table_cells).selected()];
5394        let table = Table::new(&table_headers, &table_rows)
5395            .interactive()
5396            .render()
5397            .unwrap();
5398        let dl_items = [DefinitionItem::new("Runtime", "Rust <stable>")];
5399        let dl = DefinitionList::new(&dl_items).render().unwrap();
5400        let grid = Grid::new(TrustedHtml::new(&card))
5401            .with_columns(2)
5402            .render()
5403            .unwrap();
5404        let split = Split::new(TrustedHtml::new(&panel))
5405            .vertical()
5406            .render()
5407            .unwrap();
5408
5409        assert!(panel.contains(r#"class="wf-panel""#));
5410        assert!(card.contains(r#"class="wf-card is-raised""#));
5411        assert!(!card.contains("Project <alpha>"));
5412        assert!(stat_row.contains(r#"class="wf-stat-row""#));
5413        assert!(badge.contains(r#"class="wf-badge muted""#));
5414        assert!(avatar.contains(r#"class="wf-avatar accent""#));
5415        assert!(breadcrumbs.contains(r#"class="wf-crumbs""#));
5416        assert!(!breadcrumbs.contains("Wavefunk <UI>"));
5417        assert!(tab_html.contains(r#"class="wf-tabs""#));
5418        assert!(seg_html.contains(r#"class="wf-seg""#));
5419        assert!(pagination.contains(r#"class="wf-pagination""#));
5420        assert!(nav_section.contains(r#"class="wf-nav-section""#));
5421        assert!(
5422            nav_item
5423                .render()
5424                .unwrap()
5425                .contains(r#"class="wf-nav-item is-active""#)
5426        );
5427        assert!(topbar.contains(r#"class="wf-topbar""#));
5428        assert!(statusbar.contains(r#"class="wf-statusbar wf-hair""#));
5429        assert!(empty.contains(r#"class="wf-empty bordered""#));
5430        assert!(table.contains(r#"class="wf-table is-interactive""#));
5431        assert!(!table.contains("Build <main>"));
5432        assert!(dl.contains(r#"class="wf-dl""#));
5433        assert!(!dl.contains("Rust <stable>"));
5434        assert!(grid.contains(r#"class="wf-grid cols-2""#));
5435        assert!(split.contains(r#"class="wf-split vertical""#));
5436    }
5437
5438    #[test]
5439    fn page_header_supports_title_meta_back_and_action_slots() {
5440        let primary = Button::primary("Create").render().unwrap();
5441        let secondary = Button::new("Export").render().unwrap();
5442        let header = PageHeader::new("Deployments <prod>")
5443            .with_subtitle("Filtered by team <ops>")
5444            .with_back("/settings", "Settings")
5445            .with_meta(TrustedHtml::new(
5446                r#"<span class="wf-badge muted">12</span>"#,
5447            ))
5448            .with_primary(TrustedHtml::new(&primary))
5449            .with_secondary(TrustedHtml::new(&secondary))
5450            .render()
5451            .unwrap();
5452
5453        assert!(header.contains(r#"class="wf-pageheader""#));
5454        assert!(header.contains(r#"class="wf-pageheader-main""#));
5455        assert!(header.contains(r#"<a class="wf-backlink" href="/settings">"#));
5456        assert!(header.contains(">Settings<"));
5457        assert!(header.contains(r#"class="wf-pagetitle""#));
5458        assert!(!header.contains("Deployments <prod>"));
5459        assert!(header.contains(r#"class="wf-pageheader-subtitle""#));
5460        assert!(!header.contains("Filtered by team <ops>"));
5461        assert!(header.contains(r#"<span class="wf-badge muted">12</span>"#));
5462        assert!(header.contains(r#"class="wf-pageheader-actions""#));
5463        assert!(header.contains(">Create<"));
5464        assert!(header.contains(">Export<"));
5465    }
5466
5467    #[test]
5468    fn feedback_overlay_and_loading_primitives_render_expected_markup() {
5469        let callout = Callout::new(FeedbackKind::Warn, TrustedHtml::new("<p>Heads up</p>"))
5470            .with_title("Warning")
5471            .render()
5472            .unwrap();
5473        let toast = Toast::new(FeedbackKind::Ok, "Saved <now>")
5474            .render()
5475            .unwrap();
5476        let toast_host = ToastHost::new().render().unwrap();
5477        let tooltip = Tooltip::new("Copy id", TrustedHtml::new(r#"<button>copy</button>"#))
5478            .render()
5479            .unwrap();
5480        let menu_items = [
5481            MenuItem::button("Open"),
5482            MenuItem::link("Settings", "/settings"),
5483            MenuItem::separator(),
5484            MenuItem::button("Delete").danger(),
5485        ];
5486        let menu = Menu::new(&menu_items).render().unwrap();
5487        let popover = Popover::new(
5488            TrustedHtml::new(r#"<button data-popover-toggle>Open</button>"#),
5489            TrustedHtml::new(&menu),
5490        )
5491        .with_heading("Menu")
5492        .open()
5493        .render()
5494        .unwrap();
5495        let modal = Modal::new("Confirm", TrustedHtml::new("<p>Continue?</p>"))
5496            .with_footer(TrustedHtml::new(
5497                r#"<button class="wf-btn primary">Confirm</button>"#,
5498            ))
5499            .open()
5500            .render()
5501            .unwrap();
5502        let drawer = Drawer::new("Details", TrustedHtml::new("<p>Side sheet</p>"))
5503            .left()
5504            .open()
5505            .render()
5506            .unwrap();
5507        let skeleton = Skeleton::title().render().unwrap();
5508        let spinner = Spinner::large().render().unwrap();
5509        let minibuffer = Minibuffer::new()
5510            .with_message(FeedbackKind::Info, "Queued <job>")
5511            .with_time("09:41")
5512            .render()
5513            .unwrap();
5514        let minibuffer_echo = MinibufferEcho::warn("Queued <job>").render().unwrap();
5515
5516        assert!(callout.contains(r#"class="wf-callout warn""#));
5517        assert!(toast.contains(r#"class="wf-toast ok""#));
5518        assert!(!toast.contains("Saved <now>"));
5519        assert!(toast_host.contains(r#"class="wf-toast-host""#));
5520        assert!(tooltip.contains(r#"class="wf-tooltip""#));
5521        assert!(tooltip.contains(r#"data-tip="Copy id""#));
5522        assert!(menu.contains(r#"class="wf-menu""#));
5523        assert!(menu.contains(r#"class="wf-menu-sep""#));
5524        assert!(popover.contains(r#"class="wf-popover is-open""#));
5525        assert!(modal.contains(r#"class="wf-modal is-open""#));
5526        assert!(modal.contains(r#"class="wf-overlay is-open""#));
5527        assert!(modal.contains(r#"data-wf-dismiss="overlay""#));
5528        assert!(drawer.contains(r#"class="wf-drawer is-open left""#));
5529        assert!(drawer.contains(r#"data-wf-dismiss="overlay""#));
5530        assert!(skeleton.contains(r#"class="wf-skeleton title""#));
5531        assert!(spinner.contains(r#"class="wf-spinner lg""#));
5532        assert!(minibuffer.contains(r#"class="wf-minibuffer""#));
5533        assert!(minibuffer.contains("data-wf-echo"));
5534        assert!(!minibuffer.contains("Queued <job>"));
5535        assert!(minibuffer_echo.contains(r#"hidden"#));
5536        assert!(minibuffer_echo.contains(r#"data-wf-echo-kind="warn""#));
5537        assert!(minibuffer_echo.contains(r#"data-wf-echo-message="Queued "#));
5538        assert!(!minibuffer_echo.contains("Queued <job>"));
5539    }
5540
5541    #[test]
5542    fn modal_size_and_spacing_utilities_cover_large_overlay_layouts() {
5543        let modal = Modal::new("Edit record", TrustedHtml::new("<p>Large form</p>"))
5544            .large()
5545            .open()
5546            .render()
5547            .unwrap();
5548        let components_css = include_str!("../static/wavefunk/css/04-components.css");
5549        let utilities_css = include_str!("../static/wavefunk/css/05-utilities.css");
5550
5551        assert!(modal.contains(r#"class="wf-modal is-open wf-modal--lg""#));
5552        assert!(components_css.contains(".wf-modal--lg"));
5553        assert!(utilities_css.contains(".wf-mb-1 { margin-bottom: 4px; }"));
5554        assert!(utilities_css.contains(".wf-mb-8 { margin-bottom: 32px; }"));
5555        assert!(utilities_css.contains(".wf-ml-2 { margin-left: 8px; }"));
5556    }
5557
5558    #[test]
5559    fn form_composition_and_dropzone_components_render_expected_markup() {
5560        let input_html = Input::email("email")
5561            .with_placeholder("you@example.test")
5562            .render()
5563            .unwrap();
5564        let field_html = Field::new("Email", TrustedHtml::new(&input_html))
5565            .with_hint("Use <work> address")
5566            .render()
5567            .unwrap();
5568        let actions_html = FormActions::new(TrustedHtml::new(
5569            r#"<button class="wf-btn primary">Save</button>"#,
5570        ))
5571        .with_secondary(TrustedHtml::new(
5572            r#"<button class="wf-btn">Cancel</button>"#,
5573        ))
5574        .render()
5575        .unwrap();
5576        let section_html = FormSection::new("Profile <setup>", TrustedHtml::new(&field_html))
5577            .with_description("Shown to teammates <public>")
5578            .render()
5579            .unwrap();
5580        let attrs = [HtmlAttr::hx_post("/profile")];
5581        let form_html = Form::new(TrustedHtml::new(&section_html))
5582            .with_action("/profile/save?next=<home>")
5583            .with_method("post")
5584            .with_attrs(&attrs)
5585            .render()
5586            .unwrap();
5587        let dropzone_attrs = [HtmlAttr::new("data-intent", "avatar <upload>")];
5588        let dropzone_html = Dropzone::new("avatar")
5589            .with_title("Drop avatar <image>")
5590            .with_hint("PNG or JPG <2MB>")
5591            .with_accept("image/png,image/jpeg")
5592            .with_attrs(&dropzone_attrs)
5593            .multiple()
5594            .disabled()
5595            .dragover()
5596            .render()
5597            .unwrap();
5598
5599        assert!(actions_html.contains(r#"class="wf-form-actions""#));
5600        assert!(section_html.contains(r#"class="wf-form-section""#));
5601        assert!(!section_html.contains("Profile <setup>"));
5602        assert!(!section_html.contains("Shown to teammates <public>"));
5603        assert!(form_html.contains(r#"<form class="wf-form""#));
5604        assert!(form_html.contains(r#"method="post""#));
5605        assert!(form_html.contains(r#"hx-post="/profile""#));
5606        assert!(!form_html.contains(r#"action="/profile/save?next=<home>""#));
5607        assert!(dropzone_html.contains(r#"class="wf-dropzone is-dragover is-disabled""#));
5608        assert!(dropzone_html.contains("data-upload-zone"));
5609        assert!(dropzone_html.contains(r#"type="file""#));
5610        assert!(dropzone_html.contains(r#"multiple"#));
5611        assert!(dropzone_html.contains(r#"disabled"#));
5612        assert!(dropzone_html.contains(r#"accept="image/png,image/jpeg""#));
5613        assert!(dropzone_html.contains(r#"data-intent="avatar "#));
5614        assert!(!dropzone_html.contains(r#"data-intent="avatar <upload>""#));
5615        assert!(!dropzone_html.contains("Drop avatar <image>"));
5616        assert!(!dropzone_html.contains("PNG or JPG <2MB>"));
5617    }
5618
5619    #[test]
5620    fn generated_form_building_blocks_render_generic_schema_shapes() {
5621        let title = Input::new("title").render().unwrap();
5622        let title_field = Field::new("Title", TrustedHtml::new(&title))
5623            .render()
5624            .unwrap();
5625        let object = ObjectFieldset::new("Metadata", TrustedHtml::new(&title_field))
5626            .with_description("Nested object fields")
5627            .render()
5628            .unwrap();
5629        let item = RepeatableItem::new("Link 1", TrustedHtml::new(&title_field))
5630            .with_actions(TrustedHtml::new(
5631                r#"<button class="wf-btn sm">Remove</button>"#,
5632            ))
5633            .render()
5634            .unwrap();
5635        let array = RepeatableArray::new("Links", TrustedHtml::new(&item))
5636            .with_description("Zero or more external links.")
5637            .with_action(TrustedHtml::new(
5638                r#"<button class="wf-btn sm">Add link</button>"#,
5639            ))
5640            .render()
5641            .unwrap();
5642        let upload = CurrentUpload::new("Hero image", "/media/hero.jpg", "hero.jpg")
5643            .with_meta("1200x630 JPG")
5644            .with_thumbnail(TrustedHtml::new(r#"<img src="/media/hero.jpg" alt="">"#))
5645            .render()
5646            .unwrap();
5647        let options = [
5648            SelectOption::new("home", "Home"),
5649            SelectOption::new("about", "About").selected(),
5650        ];
5651        let select = Select::new("related_page", &options).render().unwrap();
5652        let reference = ReferenceSelect::new("Related page", TrustedHtml::new(&select))
5653            .with_hint("Search and choose another record.")
5654            .render()
5655            .unwrap();
5656        let markdown = MarkdownTextarea::new("body")
5657            .with_value("# Hello")
5658            .with_rows(8)
5659            .render()
5660            .unwrap();
5661        let richtext = RichTextHost::new("body-editor", "body_html")
5662            .with_value("<p>Hello</p>")
5663            .with_toolbar(TrustedHtml::new(
5664                r#"<button class="wf-btn sm">Bold</button>"#,
5665            ))
5666            .render()
5667            .unwrap();
5668
5669        assert!(object.contains(r#"<fieldset class="wf-object-fieldset">"#));
5670        assert!(object.contains(r#"<legend class="wf-object-legend">Metadata</legend>"#));
5671        assert!(array.contains(r#"class="wf-repeatable-array""#));
5672        assert!(array.contains(r#"class="wf-repeatable-item""#));
5673        assert!(upload.contains(r#"class="wf-current-upload""#));
5674        assert!(upload.contains(r#"<a href="/media/hero.jpg">hero.jpg</a>"#));
5675        assert!(reference.contains(r#"class="wf-reference-select""#));
5676        assert!(markdown.contains(r#"class="wf-textarea wf-markdown-textarea""#));
5677        assert!(markdown.contains("data-wf-markdown"));
5678        assert!(richtext.contains(r#"class="wf-richtext""#));
5679        assert!(richtext.contains("data-wf-richtext"));
5680        assert!(richtext.contains(r#"data-wf-richtext-modal-host"#));
5681    }
5682
5683    #[test]
5684    fn table_workflow_components_support_sorting_actions_and_chrome() {
5685        let _source_compatible_header = TableHeader {
5686            label: "Legacy",
5687            numeric: false,
5688        };
5689        let _source_compatible_cell = TableCell {
5690            text: "Legacy",
5691            numeric: false,
5692            strong: false,
5693            muted: false,
5694        };
5695        let headers = [
5696            DataTableHeader::new("Name").sortable("name", SortDirection::Ascending),
5697            DataTableHeader::numeric("Runs").with_width(TableColumnWidth::Small),
5698            DataTableHeader::new("Actions").action_column(),
5699        ];
5700        let actions = IconButton::new(TrustedHtml::new("&times;"), "Stop")
5701            .with_variant(ButtonVariant::Danger)
5702            .render()
5703            .unwrap();
5704        let row_cells = [
5705            DataTableCell::strong("Build <main>"),
5706            DataTableCell::numeric("12"),
5707            DataTableCell::html(TrustedHtml::new(&actions)),
5708        ];
5709        let rows = [DataTableRow::new(&row_cells).selected()];
5710        let filter_html = Input::new("q")
5711            .with_size(ControlSize::Small)
5712            .with_placeholder("Search")
5713            .render()
5714            .unwrap();
5715        let bulk_html = Button::new("Delete").render().unwrap();
5716        let table_html = DataTable::new(&headers, &rows)
5717            .interactive()
5718            .sticky()
5719            .pin_last()
5720            .render()
5721            .unwrap();
5722        let wrap_html = TableWrap::new(TrustedHtml::new(&table_html))
5723            .with_filterbar(TrustedHtml::new(&filter_html))
5724            .with_bulkbar("1 selected", TrustedHtml::new(&bulk_html))
5725            .with_footer(TrustedHtml::new("Showing 1-1 of 1"))
5726            .render()
5727            .unwrap();
5728
5729        assert!(table_html.contains(r#"class="wf-sort-h is-active""#));
5730        assert!(table_html.contains(r#"data-sort-key="name""#));
5731        assert!(table_html.contains(r#"class="wf-sort-arrow">^"#));
5732        assert!(table_html.contains(r#"class="wf-col-sm num""#));
5733        assert!(table_html.contains(r#"class="wf-col-act""#));
5734        assert!(table_html.contains("&times;"));
5735        assert!(!table_html.contains("Build <main>"));
5736        assert!(wrap_html.contains(r#"class="wf-tablewrap""#));
5737        assert!(wrap_html.contains(r#"class="wf-filterbar""#));
5738        assert!(wrap_html.contains(r#"class="wf-bulkbar""#));
5739        assert!(wrap_html.contains(r#"class="wf-tablefoot""#));
5740    }
5741
5742    #[test]
5743    fn resource_table_chrome_components_compose_filter_bulk_footer_and_selection() {
5744        let filter_input = Input::search("q")
5745            .with_placeholder("Search resources")
5746            .with_size(ControlSize::Small)
5747            .render()
5748            .unwrap();
5749        let filter_action = Button::new("Refresh").render().unwrap();
5750        let filterbar = FilterBar::new(TrustedHtml::new(&filter_input))
5751            .with_actions(TrustedHtml::new(&filter_action))
5752            .render()
5753            .unwrap();
5754        let bulk_action = Button::new("Delete")
5755            .with_variant(ButtonVariant::Danger)
5756            .render()
5757            .unwrap();
5758        let bulkbar = BulkActionBar::new("2 selected", TrustedHtml::new(&bulk_action))
5759            .render()
5760            .unwrap();
5761        let footer_action = Pagination::new(&[
5762            PageLink::link("1", "/page/1").active(),
5763            PageLink::link("2", "/page/2"),
5764        ])
5765        .render()
5766        .unwrap();
5767        let footer = TableFooter::new(TrustedHtml::new("Showing 1-2 of 8"))
5768            .with_actions(TrustedHtml::new(&footer_action))
5769            .render()
5770            .unwrap();
5771        let selector = RowSelect::new("selected", "build", "Select Build")
5772            .checked()
5773            .render()
5774            .unwrap();
5775        let headers = [
5776            DataTableHeader::new("").with_width(TableColumnWidth::Checkbox),
5777            DataTableHeader::sorted("Name", "name", SortDirection::Ascending),
5778        ];
5779        let cells = [
5780            DataTableCell::html(TrustedHtml::new(&selector)),
5781            DataTableCell::strong("Build"),
5782        ];
5783        let rows = [DataTableRow::new(&cells).selected()];
5784        let table = DataTable::new(&headers, &rows)
5785            .interactive()
5786            .render()
5787            .unwrap();
5788        let wrap = TableWrap::new(TrustedHtml::new(&table))
5789            .with_filterbar_component(TrustedHtml::new(&filterbar))
5790            .with_bulkbar_component(TrustedHtml::new(&bulkbar))
5791            .with_footer_component(TrustedHtml::new(&footer))
5792            .render()
5793            .unwrap();
5794
5795        assert!(filterbar.contains(r#"class="wf-filterbar""#));
5796        assert!(filterbar.contains(r#"class="wf-filterbar-actions""#));
5797        assert!(bulkbar.contains(r#"class="wf-bulkbar""#));
5798        assert!(bulkbar.contains(r#"class="wf-sel-count">2 selected"#));
5799        assert!(footer.contains(r#"class="wf-tablefoot""#));
5800        assert!(footer.contains(r#"class="wf-tablefoot-actions""#));
5801        assert!(selector.contains(r#"class="wf-check wf-rowselect""#));
5802        assert!(selector.contains(r#"aria-label="Select Build""#));
5803        assert!(selector.contains("checked"));
5804        assert!(table.contains(r#"data-sort-key="name""#));
5805        assert!(wrap.matches(r#"class="wf-filterbar""#).count() == 1);
5806        assert!(wrap.matches(r#"class="wf-bulkbar""#).count() == 1);
5807        assert!(wrap.matches(r#"class="wf-tablefoot""#).count() == 1);
5808    }
5809
5810    #[test]
5811    fn progress_stepper_and_disclosure_components_render_expected_markup() {
5812        let progress = Progress::new(60).render().unwrap();
5813        let indeterminate = Progress::indeterminate().render().unwrap();
5814        let meter = Meter::new(75)
5815            .with_size_px(96, 6)
5816            .with_color(MeterColor::Ok)
5817            .render()
5818            .unwrap();
5819        let kbd = Kbd::new("Ctrl <K>").render().unwrap();
5820        let steps = [
5821            StepItem::new("Account").done(),
5822            StepItem::new("Profile <public>")
5823                .active()
5824                .with_href("/profile"),
5825            StepItem::new("Invite"),
5826        ];
5827        let stepper = Stepper::new(&steps).render().unwrap();
5828        let accordion_items = [
5829            AccordionItem::new("What is <UI>?", TrustedHtml::new("<p>Typed</p>")).open(),
5830            AccordionItem::new("Can it htmx?", TrustedHtml::new("<p>Yes</p>")),
5831        ];
5832        let accordion = Accordion::new(&accordion_items).render().unwrap();
5833        let faq_items = [FaqItem::new(
5834            "Why typed?",
5835            TrustedHtml::new("<p>To preserve semver.</p>"),
5836        )];
5837        let faq = Faq::new(&faq_items).render().unwrap();
5838
5839        assert!(progress.contains(r#"class="wf-progress""#));
5840        assert!(progress.contains(r#"style="--progress: 60%""#));
5841        assert!(indeterminate.contains(r#"class="wf-progress indeterminate""#));
5842        assert!(meter.contains(
5843            r#"style="--meter: 75%; --meter-w: 96px; --meter-h: 6px; --meter-c: var(--ok)""#
5844        ));
5845        assert!(kbd.contains(r#"class="wf-kbd""#));
5846        assert!(!kbd.contains("Ctrl <K>"));
5847        assert!(stepper.contains(r#"class="wf-step is-done""#));
5848        assert!(stepper.contains(r#"aria-current="step""#));
5849        assert!(!stepper.contains("Profile <public>"));
5850        assert!(accordion.contains(r#"class="wf-accordion""#));
5851        assert!(accordion.contains(r#"<details class="wf-accordion-item" open>"#));
5852        assert!(!accordion.contains("What is <UI>?"));
5853        assert!(faq.contains(r#"class="wf-faq""#));
5854        assert!(faq.contains("<p>To preserve semver.</p>"));
5855    }
5856
5857    #[test]
5858    fn identity_brand_and_operational_components_render_expected_markup() {
5859        let avatars = [
5860            Avatar::new("SN").with_image("/avatar.png").accent(),
5861            Avatar::new("WF").with_size(AvatarSize::Small),
5862        ];
5863        let avatar_group = AvatarGroup::new(&avatars).render().unwrap();
5864        let full_user = UserButton::new("Wave Funk", "team@example.test", Avatar::new("WF"))
5865            .render()
5866            .unwrap();
5867        let user = UserButton::new(
5868            "Sandeep <Nambiar>",
5869            "sandeep@example.test",
5870            Avatar::new("SN"),
5871        )
5872        .compact()
5873        .render()
5874        .unwrap();
5875        let wordmark = Wordmark::new("Wave <Funk>")
5876            .with_mark(TrustedHtml::new(r#"<svg class="wf-mark"></svg>"#))
5877            .render()
5878            .unwrap();
5879        let ranks = [RankRow::new("Builds <main>", "42", 72)];
5880        let rank_list = RankList::new(&ranks).render().unwrap();
5881        let feed_rows = [FeedRow::new("09:41", "Deploy <prod>", "Released <v1>")];
5882        let feed = Feed::new(&feed_rows).render().unwrap();
5883        let timeline_items =
5884            [
5885                TimelineItem::new("09:42", "Queued <job>", TrustedHtml::new("<p>Pending</p>"))
5886                    .active(),
5887            ];
5888        let timeline = Timeline::new(&timeline_items).render().unwrap();
5889        let tree_children = [TreeItem::file("components.rs").active()];
5890        let tree_child_html = TreeView::new(&tree_children).nested().render().unwrap();
5891        let tree_items = [TreeItem::folder("src <root>")
5892            .collapsed()
5893            .with_children(TrustedHtml::new(&tree_child_html))];
5894        let tree = TreeView::new(&tree_items).render().unwrap();
5895        let framed = Framed::new(TrustedHtml::new("<code>cargo test</code>"))
5896            .dense()
5897            .dashed()
5898            .render()
5899            .unwrap();
5900
5901        assert!(avatar_group.contains(r#"class="wf-avatar-group""#));
5902        assert!(avatar_group.contains(r#"<img src="/avatar.png" alt="SN">"#));
5903        assert!(full_user.contains(r#"class="wf-user""#));
5904        assert!(!full_user.contains(r#"class="wf-user compact""#));
5905        assert!(user.contains(r#"class="wf-user compact""#));
5906        assert!(!user.contains("Sandeep <Nambiar>"));
5907        assert!(wordmark.contains(r#"class="wf-wordmark""#));
5908        assert!(wordmark.contains(r#"<svg class="wf-mark"></svg>"#));
5909        assert!(!wordmark.contains("Wave <Funk>"));
5910        assert!(rank_list.contains(r#"class="wf-rank""#));
5911        assert!(rank_list.contains(r#"style="width: 72%""#));
5912        assert!(!rank_list.contains("Builds <main>"));
5913        assert!(feed.contains(r#"class="wf-feed""#));
5914        assert!(!feed.contains("Deploy <prod>"));
5915        assert!(!feed.contains("Released <v1>"));
5916        assert!(timeline.contains(r#"class="wf-timeline-item is-active""#));
5917        assert!(!timeline.contains("Queued <job>"));
5918        assert!(tree.contains(r#"class="wf-tree""#));
5919        assert!(tree.contains(r#"class="is-collapsed""#));
5920        assert!(!tree.contains("src <root>"));
5921        assert!(framed.contains(r#"class="wf-framed dense dashed""#));
5922    }
5923
5924    #[test]
5925    fn settings_and_admin_workflow_primitives_render_generic_markup() {
5926        let input = Input::email("email").render().unwrap();
5927        let save = Button::primary("Save")
5928            .with_button_type("submit")
5929            .render()
5930            .unwrap();
5931        let row = InlineFormRow::new("Notification email", TrustedHtml::new(&input))
5932            .with_hint("Used for account notices <private>")
5933            .with_action(TrustedHtml::new(&save))
5934            .render()
5935            .unwrap();
5936        let copy = CopyableValue::new("Webhook URL", "webhook-url", "https://example.test/hook")
5937            .with_button_label("Copy URL")
5938            .render()
5939            .unwrap();
5940        let statuses = [
5941            CredentialStatusItem::ok("Mail", "Configured"),
5942            CredentialStatusItem::warn("Backups", "Rotation due"),
5943        ];
5944        let status_list = CredentialStatusList::new(&statuses).render().unwrap();
5945        let confirm = ConfirmAction::new("Delete workspace", "/settings/delete")
5946            .with_message("This cannot be undone.")
5947            .with_confirm("Delete this workspace?")
5948            .render()
5949            .unwrap();
5950        let section_body = format!("{row}{copy}{status_list}{confirm}");
5951        let section = SettingsSection::new("Workspace settings", TrustedHtml::new(&section_body))
5952            .with_description("Operational settings for this app.")
5953            .danger()
5954            .render()
5955            .unwrap();
5956
5957        assert!(row.contains(r#"class="wf-inline-form-row""#));
5958        assert!(!row.contains("account notices <private>"));
5959        assert!(copy.contains(r#"class="wf-copyable""#));
5960        assert!(copy.contains(r#"id="webhook-url""#));
5961        assert!(copy.contains(r##"data-wf-copy="#webhook-url""##));
5962        assert!(copy.contains(">Copy URL<"));
5963        assert!(status_list.contains(r#"class="wf-credential-list""#));
5964        assert!(status_list.contains(r#"class="wf-tag ok""#));
5965        assert!(status_list.contains(r#"class="wf-tag warn""#));
5966        assert!(confirm.contains(
5967            r#"<form class="wf-confirm-action" action="/settings/delete" method="post">"#
5968        ));
5969        assert!(confirm.contains(r#"hx-confirm="Delete this workspace?""#));
5970        assert!(confirm.contains(r#"class="wf-btn danger""#));
5971        assert!(section.contains(r#"class="wf-panel wf-settings-section is-danger""#));
5972        assert!(section.contains("Operational settings for this app."));
5973    }
5974
5975    #[test]
5976    fn split_shell_and_form_panel_render_generic_setup_surfaces() {
5977        let actions = Button::primary("Continue").render().unwrap();
5978        let panel = FormPanel::new(
5979            "Setup <workspace>",
5980            TrustedHtml::new(r#"<form class="wf-form">Fields</form>"#),
5981        )
5982        .with_subtitle("Use generic product copy <only>")
5983        .with_actions(TrustedHtml::new(&actions))
5984        .render()
5985        .unwrap();
5986        let attrs = [HtmlAttr::new("data-surface", "setup <flow>")];
5987        let shell = SplitShell::new(TrustedHtml::new(&panel))
5988            .with_top(TrustedHtml::new(
5989                r#"<a class="wf-btn ghost" href="/">Back</a>"#,
5990            ))
5991            .with_visual(TrustedHtml::new(r#"<pre aria-label="preview">wave</pre>"#))
5992            .with_footer(TrustedHtml::new(r#"<div class="wf-statusbar">Ready</div>"#))
5993            .with_mode("light")
5994            .mode_locked()
5995            .with_asset_base_path("/assets/wavefunk")
5996            .with_attrs(&attrs)
5997            .render()
5998            .unwrap();
5999
6000        assert!(panel.contains(r#"class="wf-form-panel""#));
6001        assert!(!panel.contains("Setup <workspace>"));
6002        assert!(!panel.contains("generic product copy <only>"));
6003        assert!(panel.contains(r#"<form class="wf-form">Fields</form>"#));
6004        assert!(shell.contains(r#"class="wf-split-shell""#));
6005        assert!(shell.contains(r#"data-mode="light""#));
6006        assert!(shell.contains(r#"data-mode-locked"#));
6007        assert!(shell.contains(r#"data-wf-asset-base="/assets/wavefunk""#));
6008        assert!(shell.contains(r#"data-surface="setup "#));
6009        assert!(!shell.contains(r#"data-surface="setup <flow>""#));
6010        assert!(shell.contains(r#"<pre aria-label="preview">wave</pre>"#));
6011    }
6012
6013    #[test]
6014    fn modeline_minibuffer_history_context_switcher_and_sidenav_are_generic() {
6015        let toggle_attrs = [HtmlAttr::new("data-mode-toggle", "")];
6016        let left = [
6017            ModelineSegment::chevron("WF"),
6018            ModelineSegment::buffer("workspace.rs"),
6019            ModelineSegment::button("Mode").with_attrs(&toggle_attrs),
6020        ];
6021        let right = [
6022            ModelineSegment::position("L12:C4"),
6023            ModelineSegment::text("Ready").with_feedback(FeedbackKind::Ok),
6024        ];
6025        let modeline = Modeline::new(&left).with_right(&right).render().unwrap();
6026        let history =
6027            [MinibufferHistoryRow::new("09:41", "Saved <draft>").with_feedback(FeedbackKind::Ok)];
6028        let minibuffer = Minibuffer::new()
6029            .with_prompt("wf")
6030            .with_message(FeedbackKind::Info, "Queued <job>")
6031            .with_history(&history)
6032            .render()
6033            .unwrap();
6034        let switcher_items = [
6035            ContextSwitcherItem::link("Production <east>", "/contexts/prod")
6036                .with_meta("3 apps")
6037                .active(),
6038            ContextSwitcherItem::link("Sandbox", "/contexts/sandbox")
6039                .with_badge(TrustedHtml::new(r#"<span class="wf-tag">test</span>"#)),
6040        ];
6041        let switcher = ContextSwitcher::new("Workspace", "Production", &switcher_items)
6042            .with_meta(TrustedHtml::new(r#"<span class="wf-tag ok">live</span>"#))
6043            .open()
6044            .render()
6045            .unwrap();
6046        let side_items = [
6047            SidenavItem::link("Overview", "/overview").active(),
6048            SidenavItem::link("Reports <beta>", "/reports")
6049                .muted()
6050                .with_badge("Soon"),
6051            SidenavItem::link("Billing", "/billing")
6052                .disabled()
6053                .with_coming_soon("coming soon"),
6054        ];
6055        let side_sections = [SidenavSection::new("Manage <workspace>", &side_items)];
6056        let sidenav = Sidenav::new(&side_sections).render().unwrap();
6057
6058        assert!(modeline.contains(r#"class="wf-modeline""#));
6059        assert!(modeline.contains(r#"class="wf-ml-seg wf-ml-chevron""#));
6060        assert!(modeline.contains(r#"data-mode-toggle="""#));
6061        assert!(modeline.contains(r#"class="wf-ml-seg wf-ml-pos""#));
6062        assert!(modeline.contains(r#"class="wf-ml-seg is-ok""#));
6063        assert!(modeline.contains(r#"class="wf-ml-fill""#));
6064        assert!(minibuffer.contains(r#"class="wf-minibuffer-history""#));
6065        assert!(!minibuffer.contains("Queued <job>"));
6066        assert!(!minibuffer.contains("Saved <draft>"));
6067        assert!(switcher.contains(r#"class="wf-context-switcher""#));
6068        assert!(switcher.contains(r#"<details class="wf-context-switcher" open>"#));
6069        assert!(!switcher.contains("Production <east>"));
6070        assert!(switcher.contains(r#"<span class="wf-tag">test</span>"#));
6071        assert!(sidenav.contains(r#"class="wf-sidenav""#));
6072        assert!(sidenav.contains(r#"class="wf-sidenav-item is-active""#));
6073        assert!(sidenav.contains(r#"class="wf-sidenav-item is-muted""#));
6074        assert!(sidenav.contains(r#"aria-disabled="true""#));
6075        assert!(!sidenav.contains("Manage <workspace>"));
6076        assert!(!sidenav.contains("Reports <beta>"));
6077    }
6078
6079    #[test]
6080    fn secret_checklist_code_grid_snippets_and_strength_meter_are_product_neutral() {
6081        let secret = SecretValue::new("Recovery token", "recovery-token", "tok_<secret>")
6082            .with_warning("Shown once <store it>")
6083            .with_help(TrustedHtml::new(
6084                "<strong>Store this value securely.</strong>",
6085            ))
6086            .render()
6087            .unwrap();
6088        let checklist_items = [
6089            ChecklistItem::ok("DNS configured <edge>").with_description("Records verified."),
6090            ChecklistItem::warn("Webhook retry").with_status_label("review"),
6091        ];
6092        let checklist = Checklist::new(&checklist_items).render().unwrap();
6093        let codes = ["ABCD-EFGH", "IJKL<MNOP>"];
6094        let code_grid = CodeGrid::new(&codes)
6095            .with_label("One-time codes <backup>")
6096            .render()
6097            .unwrap();
6098        let block = CodeBlock::new("cargo add wavefunk-ui <latest>")
6099            .with_label("Install")
6100            .with_language("shell")
6101            .with_copy_target("install-command")
6102            .render()
6103            .unwrap();
6104        let tabs = [
6105            SnippetTab::new("Rust", r#"let value = "<typed>";"#)
6106                .with_language("rust")
6107                .active(),
6108            SnippetTab::new("Shell", "cargo test").with_language("shell"),
6109        ];
6110        let snippets = SnippetTabs::new("quickstart", &tabs).render().unwrap();
6111        let strength = StrengthMeter::new(3, 4, "Strong <enough>")
6112            .with_label("Key strength")
6113            .with_feedback(FeedbackKind::Ok)
6114            .live()
6115            .render()
6116            .unwrap();
6117
6118        assert!(secret.contains(r#"class="wf-secret-value""#));
6119        assert!(secret.contains(r##"data-wf-copy="#recovery-token""##));
6120        assert!(!secret.contains("data-wf-copy-value"));
6121        assert!(secret.contains("********"));
6122        assert!(!secret.contains("tok_<secret>"));
6123        assert!(!secret.contains("Shown once <store it>"));
6124        assert!(secret.contains("<strong>Store this value securely.</strong>"));
6125        let copyable_masked = SecretValue::new("Raw token", "raw-token", "raw-secret")
6126            .copy_raw_value()
6127            .render()
6128            .unwrap();
6129        assert!(copyable_masked.contains(r#"data-wf-copy-value="raw-secret""#));
6130        assert!(checklist.contains(r#"class="wf-checklist""#));
6131        assert!(checklist.contains(r#"class="wf-checklist-item is-ok""#));
6132        assert!(checklist.contains(r#"class="wf-checklist-item is-warn""#));
6133        assert!(!checklist.contains("DNS configured <edge>"));
6134        assert!(code_grid.contains(r#"class="wf-code-grid""#));
6135        assert!(!code_grid.contains("IJKL<MNOP>"));
6136        assert!(!code_grid.contains("One-time codes <backup>"));
6137        assert!(block.contains(r#"class="wf-code-block""#));
6138        assert!(block.contains(r#"data-language="shell""#));
6139        assert!(block.contains(r##"data-wf-copy="#install-command""##));
6140        assert!(!block.contains("wavefunk-ui <latest>"));
6141        assert!(snippets.contains(r#"class="wf-snippet-tabs""#));
6142        assert!(snippets.contains(r#"role="tablist""#));
6143        assert!(snippets.contains(r##"data-wf-snippet-tab="#quickstart-panel-1""##));
6144        assert!(snippets.contains(r#"aria-controls="quickstart-panel-1""#));
6145        assert!(snippets.contains(r#"id="quickstart-panel-2""#));
6146        assert!(snippets.contains(r#"hidden"#));
6147        assert!(!snippets.contains(r#"let value = "<typed>";"#));
6148        assert!(strength.contains(r#"class="wf-strength-meter is-ok""#));
6149        assert!(strength.contains(r#"role="progressbar""#));
6150        assert!(strength.contains(r#"aria-valuenow="3""#));
6151        assert!(strength.contains(r#"aria-valuemax="4""#));
6152        assert!(strength.contains(r#"style="--strength: 75%""#));
6153        assert!(!strength.contains("Strong <enough>"));
6154    }
6155
6156    #[test]
6157    fn marketing_primitives_render_stable_typed_sections() {
6158        let features = [
6159            FeatureItem::new("Typed <APIs>", "No struct literal churn."),
6160            FeatureItem::new("Embedded assets", "Self-contained binaries."),
6161        ];
6162        let feature_grid = FeatureGrid::new(&features).render().unwrap();
6163        let steps = [
6164            MarketingStep::new("Install", "Add the crate."),
6165            MarketingStep::new("Render", "Use Askama templates."),
6166        ];
6167        let step_grid = MarketingStepGrid::new(&steps).render().unwrap();
6168        let plans = [
6169            PricingPlan::new("Starter", "$9")
6170                .with_blurb("For small teams.")
6171                .featured(),
6172            PricingPlan::new("Scale", "$29"),
6173        ];
6174        let pricing = PricingPlans::new(&plans).render().unwrap();
6175        let testimonial = Testimonial::new(
6176            TrustedHtml::new("<p>Fast to wire.</p>"),
6177            "Operator <one>",
6178            "Founder",
6179        )
6180        .render()
6181        .unwrap();
6182        let section = MarketingSection::new("Component <system>", TrustedHtml::new(&feature_grid))
6183            .with_kicker("Wave Funk")
6184            .with_subtitle("Typed primitives for Rust apps.")
6185            .render()
6186            .unwrap();
6187
6188        assert!(feature_grid.contains(r#"class="mk-features""#));
6189        assert!(!feature_grid.contains("Typed <APIs>"));
6190        assert!(step_grid.contains(r#"class="mk-steps""#));
6191        assert!(pricing.contains(r#"class="wf-plans""#));
6192        assert!(pricing.contains(r#"class="wf-plan is-featured""#));
6193        assert!(testimonial.contains(r#"class="wf-testimonial""#));
6194        assert!(!testimonial.contains("Operator <one>"));
6195        assert!(section.contains(r#"class="mk-sect""#));
6196        assert!(!section.contains("Component <system>"));
6197    }
6198}