Skip to main content

logicaffeine_web/ui/components/
main_nav.rs

1//! Unified navigation component for consistent header across all pages.
2//!
3//! Features:
4//! - Logo and brand name
5//! - Navigation links with active underline indicator (desktop)
6//! - Mobile drawer with expandable trees for Syntax Guide and Learn
7//! - GitHub icon and CTA buttons
8//! - Responsive design with 980px breakpoint
9
10use crate::content::ContentEngine;
11use crate::ui::components::icon::{Icon, IconSize, IconVariant};
12use crate::ui::pages::guide::content::SECTIONS;
13use crate::ui::router::Route;
14use dioxus::prelude::*;
15
16/// Embedded logo SVG — the single embedded copy, shared by nav and footer.
17pub(crate) const LOGO_SVG: &str = include_str!("../../../assets/logo.svg");
18
19/// Which page is currently active
20#[derive(Clone, Copy, PartialEq, Default)]
21pub enum ActivePage {
22    #[default]
23    Guide,
24    Crates,
25    Learn,
26    Studio,
27    Roadmap,
28    Contact,
29    Registry,
30    News,
31    Benchmarks,
32    Other,
33}
34
35impl ActivePage {}
36
37const MAIN_NAV_STYLE: &str = r#"
38.main-nav {
39    position: sticky;
40    top: 0;
41    z-index: 150;
42    backdrop-filter: blur(18px);
43    -webkit-backdrop-filter: blur(18px);
44    background: linear-gradient(180deg, rgba(7,10,18,0.72), rgba(7,10,18,0.44));
45    border-bottom: 1px solid rgba(255,255,255,0.06);
46}
47
48.main-nav-inner {
49    display: flex;
50    align-items: center;
51    justify-content: space-between;
52    padding: var(--spacing-lg) var(--spacing-xl);
53    max-width: 1280px;
54    margin: 0 auto;
55    gap: var(--spacing-lg);
56}
57
58.main-nav-brand {
59    display: flex;
60    align-items: center;
61    gap: var(--spacing-md);
62    text-decoration: none;
63    color: var(--text-primary);
64    z-index: 1001;
65}
66
67.main-nav-logo {
68    width: 64px;
69    height: 64px;
70    border-radius: var(--radius-lg);
71    overflow: hidden;
72    flex-shrink: 0;
73}
74
75.main-nav-logo svg {
76    width: 100%;
77    height: 100%;
78    filter: invert(1);
79}
80
81.main-nav-brand-text {
82    display: flex;
83    flex-direction: column;
84    line-height: 1.05;
85}
86
87.main-nav-brand-name {
88    font-weight: 800;
89    letter-spacing: -0.5px;
90    font-size: var(--font-body-md);
91}
92
93.main-nav-brand-subtitle {
94    font-size: var(--font-caption-sm);
95    color: var(--text-tertiary);
96}
97
98.main-nav-links {
99    display: flex;
100    gap: var(--spacing-xs);
101    align-items: center;
102}
103
104.main-nav-link {
105    position: relative;
106    text-decoration: none;
107    padding: 10px 14px;
108    font-size: var(--font-body-md);
109    font-weight: 500;
110    color: var(--text-secondary);
111    transition: color 0.18s ease;
112    border-radius: var(--radius-md);
113}
114
115.main-nav-link:hover {
116    color: var(--text-primary);
117    background: rgba(255,255,255,0.04);
118}
119
120/* Active underline indicator */
121.main-nav-link::after {
122    content: "";
123    position: absolute;
124    bottom: 2px;
125    left: 14px;
126    right: 14px;
127    height: 2px;
128    background: linear-gradient(90deg, var(--color-accent-blue), var(--color-accent-purple));
129    border-radius: 2px;
130    opacity: 0;
131    transform: scaleX(0);
132    transition: opacity 0.18s ease, transform 0.18s ease;
133}
134
135.main-nav-link.active {
136    color: var(--text-primary);
137}
138
139.main-nav-link.active::after {
140    opacity: 1;
141    transform: scaleX(1);
142}
143
144.main-nav-cta {
145    display: flex;
146    gap: 10px;
147    align-items: center;
148}
149
150.main-nav-btn {
151    display: inline-flex;
152    align-items: center;
153    justify-content: center;
154    gap: var(--spacing-sm);
155    padding: 10px var(--spacing-lg);
156    border-radius: var(--radius-lg);
157    border: 1px solid rgba(255,255,255,0.10);
158    background: rgba(255,255,255,0.05);
159    text-decoration: none;
160    font-weight: 600;
161    font-size: var(--font-body-md);
162    color: var(--text-primary);
163    transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
164}
165
166.main-nav-btn:hover {
167    transform: translateY(-1px);
168    background: rgba(255,255,255,0.08);
169    border-color: rgba(255,255,255,0.18);
170}
171
172.main-nav-btn.primary {
173    background: linear-gradient(135deg, rgba(0,212,255,0.95), rgba(129,140,248,0.95));
174    border-color: rgba(255,255,255,0.20);
175    color: #09090b;
176    box-shadow: 0 12px 30px rgba(0,212,255,0.18);
177}
178
179.main-nav-btn.primary:hover {
180    background: linear-gradient(135deg, rgba(0,212,255,1.0), rgba(129,140,248,1.0));
181}
182
183.main-nav-btn.ghost {
184    background: rgba(255,255,255,0.03);
185}
186
187.main-nav-btn-icon {
188    padding: 10px;
189    background: rgba(255,255,255,0.03);
190}
191
192.main-nav-btn-icon svg {
193    width: 20px;
194    height: 20px;
195    fill: currentColor;
196}
197
198/* Mobile hamburger button */
199.mobile-menu-btn {
200    display: none;
201    width: 44px;
202    height: 44px;
203    border-radius: 5px;
204    border: 2px solid rgba(255,255,255,0.2);
205    background: rgba(255,255,255,0.05);
206    color: var(--text-primary);
207    cursor: pointer;
208    align-items: center;
209    justify-content: center;
210    z-index: 1001;
211}
212
213.mobile-menu-btn:hover {
214    background: rgba(255,255,255,0.1);
215    border-color: rgba(255,255,255,0.3);
216}
217
218/* Mobile drawer overlay */
219.mobile-drawer-overlay {
220    display: none;
221    position: fixed;
222    inset: 0;
223    background: rgba(0,0,0,0.6);
224    z-index: 999;
225    opacity: 0;
226    pointer-events: none;
227    transition: opacity 0.3s ease;
228}
229
230.mobile-drawer-overlay.open {
231    opacity: 1;
232    pointer-events: auto;
233}
234
235/* Mobile drawer */
236.mobile-drawer {
237    position: fixed;
238    top: 0;
239    right: 0;
240    width: 320px;
241    max-width: 85vw;
242    height: 100vh;
243    background: rgba(12, 16, 24, 0.98);
244    backdrop-filter: blur(20px);
245    -webkit-backdrop-filter: blur(20px);
246    border-left: 1px solid rgba(255,255,255,0.08);
247    z-index: 1000;
248    transform: translateX(100%);
249    transition: transform 0.3s ease;
250    overflow-y: auto;
251    display: none;
252}
253
254.mobile-drawer.open {
255    transform: translateX(0);
256}
257
258.mobile-drawer-header {
259    display: flex;
260    align-items: center;
261    justify-content: space-between;
262    padding: 16px var(--spacing-lg) var(--spacing-lg);
263    border-bottom: 1px solid rgba(255,255,255,0.06);
264}
265
266.mobile-drawer-title {
267    font-weight: 700;
268    font-size: var(--font-body-lg);
269    color: var(--text-primary);
270}
271
272.mobile-drawer-close {
273    width: 36px;
274    height: 36px;
275    border-radius: var(--radius-md);
276    border: 1px solid rgba(255,255,255,0.1);
277    background: rgba(255,255,255,0.03);
278    color: var(--text-secondary);
279    cursor: pointer;
280    display: flex;
281    align-items: center;
282    justify-content: center;
283}
284
285.mobile-drawer-close:hover {
286    background: rgba(255,255,255,0.08);
287    color: var(--text-primary);
288}
289
290.mobile-drawer-content {
291    padding: var(--spacing-md);
292}
293
294/* Mobile nav section */
295.mobile-nav-section {
296    margin-bottom: var(--spacing-md);
297}
298
299.mobile-nav-header {
300    display: flex;
301    align-items: center;
302    justify-content: space-between;
303    padding: var(--spacing-md);
304    border-radius: var(--radius-md);
305    cursor: pointer;
306    transition: background 0.15s ease;
307}
308
309.mobile-nav-header:hover {
310    background: rgba(255,255,255,0.04);
311}
312
313.mobile-nav-header-left {
314    display: flex;
315    align-items: center;
316    gap: var(--spacing-sm);
317}
318
319.mobile-nav-header-icon {
320    color: var(--color-accent-blue);
321}
322
323.mobile-nav-header-title {
324    font-weight: 600;
325    font-size: var(--font-body-md);
326    color: var(--text-primary);
327}
328
329.mobile-nav-header-chevron {
330    color: var(--text-tertiary);
331    transition: transform 0.2s ease;
332}
333
334.mobile-nav-header-chevron.expanded {
335    transform: rotate(90deg);
336}
337
338.mobile-nav-tree {
339    max-height: 0;
340    overflow: hidden;
341    transition: max-height 0.3s ease;
342}
343
344.mobile-nav-tree.expanded {
345    max-height: 2000px;
346}
347
348.mobile-nav-tree-inner {
349    padding: var(--spacing-xs) 0 var(--spacing-sm) var(--spacing-xl);
350    border-left: 2px solid rgba(255,255,255,0.06);
351    margin-left: var(--spacing-lg);
352}
353
354.mobile-nav-item {
355    display: block;
356    padding: var(--spacing-sm) var(--spacing-md);
357    border-radius: var(--radius-sm);
358    color: var(--text-secondary);
359    font-size: var(--font-body-sm);
360    text-decoration: none;
361    transition: all 0.15s ease;
362}
363
364.mobile-nav-item:hover {
365    background: rgba(255,255,255,0.04);
366    color: var(--text-primary);
367}
368
369.mobile-nav-item.active {
370    background: rgba(0,212,255,0.12);
371    color: #00d4ff;
372}
373
374/* Simple mobile link (no tree) */
375.mobile-nav-link {
376    display: flex;
377    align-items: center;
378    gap: var(--spacing-sm);
379    padding: var(--spacing-md);
380    border-radius: var(--radius-md);
381    color: var(--text-secondary);
382    text-decoration: none;
383    transition: all 0.15s ease;
384}
385
386.mobile-nav-link:hover {
387    background: rgba(255,255,255,0.04);
388    color: var(--text-primary);
389}
390
391.mobile-nav-link.active {
392    background: rgba(0,212,255,0.12);
393    color: #00d4ff;
394}
395
396.mobile-nav-link-icon {
397    color: var(--color-accent-blue);
398}
399
400.mobile-nav-divider {
401    height: 1px;
402    background: rgba(255,255,255,0.06);
403    margin: var(--spacing-md) 0;
404}
405
406/* Responsive */
407@media (max-width: 980px) {
408    .main-nav-links {
409        display: none;
410    }
411    .main-nav-brand-text {
412        display: none;
413    }
414    .mobile-menu-btn {
415        display: flex;
416    }
417    .mobile-drawer {
418        display: block;
419    }
420    .mobile-drawer-overlay {
421        display: block;
422    }
423}
424
425@media (max-width: 640px) {
426    .main-nav-inner {
427        padding: var(--spacing-md) var(--spacing-lg);
428    }
429    .main-nav-btn {
430        padding: var(--spacing-sm) var(--spacing-md);
431        font-size: var(--font-caption-md);
432    }
433    .main-nav-logo {
434        width: 48px;
435        height: 48px;
436    }
437}
438"#;
439
440/// Main navigation component with consistent styling and active page underline
441#[component]
442pub fn MainNav(
443    /// The currently active page
444    #[props(default)]
445    active: ActivePage,
446    /// Optional subtitle for the brand (e.g., "Programmer's Guide")
447    #[props(default)]
448    subtitle: Option<&'static str>,
449    /// Whether to show the full nav links (default true)
450    #[props(default = true)]
451    show_nav_links: bool,
452) -> Element {
453    let mut drawer_open = use_signal(|| false);
454    let mut guide_expanded = use_signal(|| false);
455    let mut learn_expanded = use_signal(|| false);
456
457    // Get content for trees
458    let content_engine = ContentEngine::shared();
459    let eras = content_engine.eras();
460
461    // Get guide sections grouped by part
462    let guide_parts: Vec<(&str, Vec<&crate::ui::pages::guide::content::Section>)> = {
463        let mut parts: Vec<(&str, Vec<&crate::ui::pages::guide::content::Section>)> = Vec::new();
464        for section in SECTIONS.iter() {
465            if let Some(part) = parts.iter_mut().find(|(p, _)| *p == section.part) {
466                part.1.push(section);
467            } else {
468                parts.push((section.part, vec![section]));
469            }
470        }
471        parts
472    };
473
474    rsx! {
475        style { "{MAIN_NAV_STYLE}" }
476
477        header { class: "main-nav",
478            div { class: "main-nav-inner",
479                // Brand
480                Link {
481                    to: Route::Landing {},
482                    class: "main-nav-brand",
483                    div {
484                        class: "main-nav-logo",
485                        dangerous_inner_html: "{LOGO_SVG}"
486                    }
487                    div { class: "main-nav-brand-text",
488                        span { class: "main-nav-brand-name", "LOGICAFFEINE" }
489                        if let Some(sub) = subtitle {
490                            span { class: "main-nav-brand-subtitle", "{sub}" }
491                        } else {
492                            span { class: "main-nav-brand-subtitle", "Debug your thoughts." }
493                        }
494                    }
495                }
496
497                // Desktop navigation links with active underline
498                if show_nav_links {
499                    nav { class: "main-nav-links",
500                        Link {
501                            to: Route::Guide {},
502                            class: if active == ActivePage::Guide { "main-nav-link active" } else { "main-nav-link" },
503                            "Syntax Guide"
504                        }
505                        Link {
506                            to: Route::Crates {},
507                            class: if active == ActivePage::Crates { "main-nav-link active" } else { "main-nav-link" },
508                            "Crates"
509                        }
510                        Link {
511                            to: Route::Learn { module: String::new() },
512                            class: if active == ActivePage::Learn { "main-nav-link active" } else { "main-nav-link" },
513                            "Learn Logic"
514                        }
515                        Link {
516                            to: Route::Studio { file: None },
517                            class: if active == ActivePage::Studio { "main-nav-link active" } else { "main-nav-link" },
518                            "Studio"
519                        }
520                        Link {
521                            to: Route::Roadmap {},
522                            class: if active == ActivePage::Roadmap { "main-nav-link active" } else { "main-nav-link" },
523                            "Roadmap"
524                        }
525                        Link {
526                            to: Route::Contact { section: String::new() },
527                            class: if active == ActivePage::Contact { "main-nav-link active" } else { "main-nav-link" },
528                            "Contact"
529                        }
530                        Link {
531                            to: Route::News { tag: None },
532                            class: if active == ActivePage::News { "main-nav-link active" } else { "main-nav-link" },
533                            "News"
534                        }
535                        Link {
536                            to: Route::Benchmarks {},
537                            class: if active == ActivePage::Benchmarks { "main-nav-link active" } else { "main-nav-link" },
538                            "Benchmarks"
539                        }
540                    }
541                }
542
543                // CTA buttons
544                div { class: "main-nav-cta",
545                    // GitHub button
546                    a {
547                        href: "https://github.com/Brahmastra-Labs/logicaffeine",
548                        target: "_blank",
549                        class: "main-nav-btn main-nav-btn-icon",
550                        title: "View on GitHub",
551                        svg {
552                            xmlns: "http://www.w3.org/2000/svg",
553                            view_box: "0 0 24 24",
554                            path {
555                                d: "M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z"
556                            }
557                        }
558                    }
559                    // Mobile menu button
560                    button {
561                        class: "mobile-menu-btn",
562                        onclick: move |_| drawer_open.set(true),
563                        Icon { variant: IconVariant::Menu, size: IconSize::Medium }
564                    }
565                }
566            }
567        }
568
569        // Mobile drawer overlay
570        div {
571            class: if *drawer_open.read() { "mobile-drawer-overlay open" } else { "mobile-drawer-overlay" },
572            onclick: move |_| drawer_open.set(false),
573        }
574
575        // Mobile drawer
576        div {
577            class: if *drawer_open.read() { "mobile-drawer open" } else { "mobile-drawer" },
578
579            // Header
580            div { class: "mobile-drawer-header",
581                span { class: "mobile-drawer-title", "Navigation" }
582                button {
583                    class: "mobile-drawer-close",
584                    onclick: move |_| drawer_open.set(false),
585                    Icon { variant: IconVariant::Close, size: IconSize::Medium }
586                }
587            }
588
589            // Content
590            div { class: "mobile-drawer-content",
591                // Syntax Guide section with tree
592                div { class: "mobile-nav-section",
593                    div {
594                        class: "mobile-nav-header",
595                        onclick: move |_| {
596                            let current = *guide_expanded.read();
597                            guide_expanded.set(!current);
598                        },
599                        div { class: "mobile-nav-header-left",
600                            span { class: "mobile-nav-header-icon",
601                                Icon { variant: IconVariant::Book, size: IconSize::Medium }
602                            }
603                            span { class: "mobile-nav-header-title", "Syntax Guide" }
604                        }
605                        span {
606                            class: if *guide_expanded.read() { "mobile-nav-header-chevron expanded" } else { "mobile-nav-header-chevron" },
607                            Icon { variant: IconVariant::ChevronRight, size: IconSize::Small }
608                        }
609                    }
610                    div {
611                        class: if *guide_expanded.read() { "mobile-nav-tree expanded" } else { "mobile-nav-tree" },
612                        div { class: "mobile-nav-tree-inner",
613                            for (part_name, sections) in guide_parts.iter() {
614                                div { style: "margin-bottom: var(--spacing-sm);",
615                                    div {
616                                        style: "font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-tertiary); padding: var(--spacing-xs) var(--spacing-md); margin-bottom: var(--spacing-xs);",
617                                        "{part_name}"
618                                    }
619                                    for section in sections.iter() {
620                                        a {
621                                            href: "/guide#{section.id}",
622                                            class: "mobile-nav-item",
623                                            onclick: move |_| drawer_open.set(false),
624                                            "{section.number}. {section.title}"
625                                        }
626                                    }
627                                }
628                            }
629                        }
630                    }
631                }
632
633                // Learn section with tree
634                div { class: "mobile-nav-section",
635                    div {
636                        class: "mobile-nav-header",
637                        onclick: move |_| {
638                            let current = *learn_expanded.read();
639                            learn_expanded.set(!current);
640                        },
641                        div { class: "mobile-nav-header-left",
642                            span { class: "mobile-nav-header-icon",
643                                Icon { variant: IconVariant::GraduationCap, size: IconSize::Medium }
644                            }
645                            span { class: "mobile-nav-header-title", "Learn Logic" }
646                        }
647                        span {
648                            class: if *learn_expanded.read() { "mobile-nav-header-chevron expanded" } else { "mobile-nav-header-chevron" },
649                            Icon { variant: IconVariant::ChevronRight, size: IconSize::Small }
650                        }
651                    }
652                    div {
653                        class: if *learn_expanded.read() { "mobile-nav-tree expanded" } else { "mobile-nav-tree" },
654                        div { class: "mobile-nav-tree-inner",
655                            for era in eras.iter() {
656                                div { style: "margin-bottom: var(--spacing-sm);",
657                                    div {
658                                        style: "font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-tertiary); padding: var(--spacing-xs) var(--spacing-md); margin-bottom: var(--spacing-xs);",
659                                        "{era.meta.title}"
660                                    }
661                                    for module in era.modules.iter() {
662                                        a {
663                                            href: "/learn#{module.meta.id}",
664                                            class: "mobile-nav-item",
665                                            onclick: move |_| drawer_open.set(false),
666                                            "{module.meta.title}"
667                                        }
668                                    }
669                                }
670                            }
671                        }
672                    }
673                }
674
675                div { class: "mobile-nav-divider" }
676
677                // Simple links for other pages
678                Link {
679                    to: Route::Studio { file: None },
680                    class: if active == ActivePage::Studio { "mobile-nav-link active" } else { "mobile-nav-link" },
681                    onclick: move |_| drawer_open.set(false),
682                    span { class: "mobile-nav-link-icon",
683                        Icon { variant: IconVariant::Beaker, size: IconSize::Medium }
684                    }
685                    "Studio"
686                }
687                Link {
688                    to: Route::Crates {},
689                    class: if active == ActivePage::Crates { "mobile-nav-link active" } else { "mobile-nav-link" },
690                    onclick: move |_| drawer_open.set(false),
691                    span { class: "mobile-nav-link-icon",
692                        Icon { variant: IconVariant::Package, size: IconSize::Medium }
693                    }
694                    "Crates"
695                }
696                Link {
697                    to: Route::Roadmap {},
698                    class: if active == ActivePage::Roadmap { "mobile-nav-link active" } else { "mobile-nav-link" },
699                    onclick: move |_| drawer_open.set(false),
700                    span { class: "mobile-nav-link-icon",
701                        Icon { variant: IconVariant::Map, size: IconSize::Medium }
702                    }
703                    "Roadmap"
704                }
705                Link {
706                    to: Route::Contact { section: String::new() },
707                    class: if active == ActivePage::Contact { "mobile-nav-link active" } else { "mobile-nav-link" },
708                    onclick: move |_| drawer_open.set(false),
709                    span { class: "mobile-nav-link-icon",
710                        Icon { variant: IconVariant::Diamond, size: IconSize::Medium }
711                    }
712                    "Contact"
713                }
714                Link {
715                    to: Route::News { tag: None },
716                    class: if active == ActivePage::News { "mobile-nav-link active" } else { "mobile-nav-link" },
717                    onclick: move |_| drawer_open.set(false),
718                    span { class: "mobile-nav-link-icon",
719                        Icon { variant: IconVariant::Newspaper, size: IconSize::Medium }
720                    }
721                    "News"
722                }
723                Link {
724                    to: Route::Benchmarks {},
725                    class: if active == ActivePage::Benchmarks { "mobile-nav-link active" } else { "mobile-nav-link" },
726                    onclick: move |_| drawer_open.set(false),
727                    span { class: "mobile-nav-link-icon",
728                        Icon { variant: IconVariant::Lightning, size: IconSize::Medium }
729                    }
730                    "Benchmarks"
731                }
732
733                div { class: "mobile-nav-divider" }
734
735                a {
736                    href: "https://github.com/Brahmastra-Labs/logicaffeine",
737                    target: "_blank",
738                    class: "mobile-nav-link",
739                    span { class: "mobile-nav-link-icon",
740                        Icon { variant: IconVariant::Github, size: IconSize::Medium }
741                    }
742                    "GitHub"
743                }
744            }
745        }
746    }
747}