Skip to content

feat(ui): rework UI into a nested-drawer navigation system #30

Closed

Description

@Ardnived

Summary

Rework the entire Sahaj Atlas UI from the single floating <Panel> + <Modal>
model into a URL-driven nested-drawer navigation system built on Vaul.
Everything other than the map renders as drawers: a non-dismissable root drawer
holding search + the global region list, with nested drawers drilling down
through regions to events, registration, and sharing. On tablet/desktop the
drawers sit on the left (map fills the rest); on mobile they're bottom
sheets
with snap-to-peek and swipe-dismiss. Any view can also render
map-less (map=false), so it can be dropped into a host page or iframe as
content-only. The embeddable custom element is renamed <syatlas-map> →
<sahaj-atlas> (mode-agnostic, since it can now render with or without a
map).

The guiding principle (per review): the URL is the single source of truth.
The open drawer stack is a pure function of the current path — no bespoke
history-mirroring store, no stack that can diverge from the URL. This keeps
Back/forward/deep-link/scroll-restoration as the router's job and removes the
largest class of bugs from the design.

Scope also removes SearchBar, Navbar (→ Toolbar), Panel, Modal, and
ListHeader, and renames organisms/EventView → EventDetails. One PR (by
decision); the body is ordered to serve as the review order.

AC-0 (do this first — de-risk Vaul). Prove, as a runnable spike, that Vaul
1.1.2 supports the required combination before building on it:

  • nested drawers (Drawer.NestedRoot) that are non-modal and directional
    (left at ≥md, bottom on mobile), stacked ~4–5 deep, with the map (or,
    when map=false, the content) staying interactive behind them;
  • the RootView combo specifically: modal={false} + dismissible={false} +
    snapPoints — and dragging between peek/half/full still works;
  • portaling drawer content into the widget container (Root container
    prop / overlayContainer()), not document.body.

If the nested combination doesn't compose, STOP and consult — do not
silently switch approaches. Documented fallback (P3): render one Vaul
Drawer.Root per breakpoint whose body animates on push/pop (Framer Motion,
already a dep) instead of physically nesting; the URL-driven stack model below is
unchanged either way.


Dependency & foundation

  • Add only vaul, pinned exactly ("vaul": "1.1.2"). Investigation
    confirmed vaul standalone exports NestedRoot/Portal/Content and Root props
    modal/dismissible/direction(top,bottom,left,right)/snapPoints/
    container — full feature parity. shadcn's Drawer is the same vaul underneath
    (no Radix-native alternative), so it adds nothing here.
  • No shadcn/ui foundation swap. Keep the existing Radix + tailwind-variants
    base. Build atoms/Drawer/ (folder-per-component + story + barrel) on vaul with
    tailwind-variants slots and the overlayContainer() portal pattern
    (src/lib/overlay.ts), matching Modal/Select/Dropdown today. No
    components.json, no cn(), no CVA.
  • White-label untouched. Keep the shipped runtime brand system
    (--primary-1..12 + buildScale, palette.ts/BrandTheme.tsx, PR feat(ui): white-label brand palette for the embedded widget #23). The
    drawer inherits it for free by portaling into the theme root.
  • Vaul is unmaintained (stable/feature-complete, no future fixes) — accepted
    and pinned; revisit only if a real bug surfaces.

The navigation model (URL is the single source of truth)

  • Stack = f(pathname). The open drawer stack is derived purely from the
    current path. Extend resolvePath (src/lib/shape/path.ts) to return the
    full ancestor chain for any URL (/india/pune/123 →
    [India, Pune, event 123]), and render one drawer per entry. There is no
    drawer-stack store and no useNavigationType PUSH/POP interception — the
    router's history is the stack, so Back/forward, deep-link, and scroll
    restoration all come from the router.
  • Every navigation is a normal router navigation. Drilling a region, tapping
    a map event, opening register/share — all are navigate(path). A map-click is
    navigate(event.webPath) and rebuilds the stack to that event's ancestors (the
    stack is always the breadcrumb; it never diverges from the URL).
  • URL vs. canonical. The address bar reflects wherever the user navigated.
    webPath/webUrl are used only as the canonical URL for sharing + SEO —
    emitted as <link rel="canonical"> + og:url via react-helmet-async in the
    standalone build only
    , and as the Share target. Remove the current
    canonicalization redirects
    (region.tsx:45, event.tsx:33); legacy URLs
    (/events/:id) render in place and simply carry a canonical tag. Nothing
    redirects the address bar.
  • Camera follows the top drawer. The deepest view frames the map (region
    bounds / event point); navigating up restores the parent view's camera. Driven
    through the MapController seam (below), never by views calling the map
    directly.
  • Deep-link cold load naturally reconstructs the full ancestor chain (it's
    just resolvePath). Each ancestor view is a normal Suspense query — no
    bespoke lazy-reveal machinery. TanStack Query dedupes and the shared
    ['geojson'] feed is fetched once (fetch.ts:86); prefetch on idle only if a
    real problem is ever measured.
  • Home region. RootView (global country list) is always the base. A configured
    client.region is reached by navigating to its path on load (its RegionView
    opens over root, exactly like a deep-link); Back returns to the global list.

The Views (src/views/)

src/pages/ is replaced by src/views/. Views are routed units rendered by
a DrawerStack component that maps the resolved ancestor chain → open (nested)
Vaul drawers. Each View is folder-per-component (<Name>/<Name>.tsx +
<Name>.stories.tsx + index.ts) with one maximally-configured story, all
under a new Ladle group "Views".

View Route Header Body Drawer config
RootView / MapSearch Global list of country/regions non-dismissable, non-modal, snap points (mobile)
SearchView /search?q=&center= search field Ranked events by distance from the geocoded place / map center (nearest-N + online), stable list non-modal, dismissable
RegionView <region-path> Region name (+ back) One list: child regions first, then child events (plain concatenation, no section headers) non-modal, dismissable
EventView <event-path> none <EventDetails> (no Panel/Modal wrapper — the drawer is the chrome) non-modal, dismissable
RegistrationView <event-path>/register "Register for <Event title>" Registration form; spinner + result state non-modal, dismissable
ShareView <event-path>/share "Share <Event title>" Share content non-modal, dismissable
  • Only the root drawer is non-dismissable; every other drawer is dismissable,
    all are non-modal.
  • Each View renders a Toolbar in its DrawerFooter slot.

Responsive & drawer behavior

  • Direction by breakpoint: left at ≥md, bottom on mobile. Vaul direction
    isn't hot-swappable, so remount the drawer wrapper on the md crossing — but
    debounce/add hysteresis to useBreakpoint('md') (responsive.ts:13 is a
    raw media query) so a viewport resting near 768px can't thrash-remount. Because
    content is route-driven, a wrapper remount doesn't lose the view; explicitly
    hoist in-progress RegistrationView form state (store or URL) so a remount
    can't drop a half-filled form, and verify no camera re-fly fires purely from a
    remount.
  • Snap points: mobile RootView only (peek = MapSearch header / half / full).
    Desktop-left drawers are fixed-width panels — feed that known width to the
    map padding directly (do not DOM-measure #syatlas-main).
  • Non-modal throughout: the map (or, when map=false, the content) stays
    interactive behind open drawers.
  • Map padding: usePaddingState accounts for the fixed left-drawer width at
    ≥md so camera/controls aren't occluded.
  • Portal: drawers portal into the theme root via overlayContainer().
  • A11y: stacked non-modal drawers need care — verify focus order, Esc,
    and that background aria-hidden isn't wrongly applied (non-modal must leave the
    map reachable). Part of AC-0.

The map seam (MapController)

Put all camera control behind a single context seam so no view branches on the
map flag:

  • useMapController() exposes frameRegion(...) / frameEvent(...) /
    clearSelection() etc. Views call it unconditionally.
  • When a map is present the provider drives the real map (today's
    useMapbox().moveMap/fitBounds/setSelection).
  • When map=false the provider supplies a no-op controller of the same
    interface.
  • One place knows whether a map exists; if (hasMap) checks never leak into
    views/effects (replaces the guards currently at region.tsx:51,
    event.tsx:38, index.tsx:41).

Map-less rendering (map=false) + the <sahaj-atlas> element

The "does the widget render a map canvas?" axis is a single map flag
(default true)
— not an "embed" concept (the widget is always embedded; the
real axis is the map's presence).

  • Rename the custom element <syatlas-map> → <sahaj-atlas> (valid
    hyphenated name; mode-agnostic). Update customElements.define, the vite
    styleId, demo.html, and host-embed docs. The standalone #syatlas mount id
    stays.
  • Delivery: <sahaj-atlas map="false"> (attribute; default true) and
    ?map=0 on the standalone build (iframe-friendly). Both feed one internal
    hasMap flag. Default on both surfaces is the full map; content-only is
    opt-in.
  • Map subtree fully omitted when map=false: no MapProvider, no <Mapbox>,
    no Mapbox token required; MapController is the no-op implementation.
  • Base view inline; deeper views are overlay drawers: the targeted view fills
    the container as plain inline content (no drawer chrome). Navigating deeper opens
    Vaul drawers portaled into the widget container (not document.body),
    covering the content area. All normal interactions continue.
  • Any view can render map-less at its route.
  • Search when map-less geocodes and shows a nearest + online results list (no
    map to animate).
  • Audit viewport assumptions: window.scrollTo / scroll listeners /
    100dvh/100dvw fixed layout (event.tsx:28, Map.tsx:131, map.tsx:14,
    Panel.tsx:31) assume the widget owns the viewport — false inside a host
    container. Scope every window/document/dvh assumption to the map build or
    make it container-relative.

Component teardown / rework

  • Remove molecules/SearchBar — its MapSearch geocoder moves into RootView/
    SearchView headers; its onlineOnly toggle folds into SearchView (online events
    always included in results).
  • Remove molecules/Navbar → rename to molecules/Toolbar: no bordered
    variant, drop the dead nav links; holds LanguageSelector + ThemeSwitch + a
    small Sahaj Atlas wordmark/attribution; rendered in every drawer's
    DrawerFooter slot.
  • Remove molecules/Panel — the drawer is the container.
  • Remove atoms/Modal — Registration and Share are drawer routes now; no
    centered-dialog usage remains.
  • Remove molecules/List/ListHeader (already unused).
  • Rename organisms/EventView → organisms/EventDetails (the reusable
    content body: carousel, description, timing/contact/location cards). The new
    drawer EventView renders <EventDetails>.
  • Delete the dead useNavigationState store (store.ts:41) — confirm nothing
    (e.g. analytics previousPath) depends on it first.
  • Keep/re-home EventsList/DynamicEventsList, EventCard, RegistrationForm,
    ShareContent, List, EventDetails into the new Views.

Routing & state

  • resolvePath stays terminal-segment-only for entities (numeric tail →
    event; other tail → region) and additionally returns the full ancestor
    chain
    for stack derivation.
  • /register and /share are explicit React Router routes matched before
    the catch-all slug route (not reserved suffixes inside resolvePath). Add
    register/share to a reserved-slug guard so a CMS region can never silently
    shadow them.
  • SearchView owns /search; RootView owns /. Both build entries stay:
    standalone main (BrowserRouter, hosts ?map=0) and widget
    (HashRouter, <sahaj-atlas>).
  • useViewState (camera/selection/boundary) is preserved but driven only via
    MapController. useSearchState.onlineOnly folds into SearchView.

Analytics / misc

  • Fathom pageview fires on every location change (App.tsx:95). With per-drill
    navigations this is correct-by-default (each is a real route), but verify no
    double-count
    on map-click or replace navigations.
  • Confirm drawer navigation does not remount <Mapbox> (reuseMaps +
    worldview/language recompute on locale, Map.tsx:147) — a layout remount
    would reset the map.

Suggested implementation order (single PR)

  1. AC-0 spike: Vaul non-modal + nested + directional + snap + container
    portal, and the exact RootView combo. Consult if it fails.
  2. atoms/Drawer/ on vaul (tailwind-variants + overlayContainer()).
  3. resolvePath → ancestor chain; DrawerStack deriving drawers from the URL;
    MapController seam (real + no-op).
  4. The six Views (src/views/) + Toolbar; rename EventView→EventDetails;
    remove SearchBar/Navbar/Panel/Modal/ListHeader; explicit /register /share
    routes; remove canonicalization redirects (+ Helmet canonical in standalone).
  5. Map-less mode: rename element to <sahaj-atlas>, map attribute + ?map=0,
    map-subtree omission via MapController no-op, inline base + container-portaled
    overlay drawers, viewport-assumption audit.
  6. SearchView (distance-from-place ranking, quantized key); breakpoint hardening;
    stories ("Views" group); docs + test updates.

Risks

  • Vaul capability — mitigated by AC-0 spike + consult gate; documented
    single-drawer fallback (P3).
  • Vaul unmaintained — pinned; vendored fork remains an option if a bug bites.
  • Stacked non-modal a11y — verified in AC-0.
  • Breakpoint remount — debounce + hoisted form state.
  • Large diff (one PR) — section order = review order.

Acceptance criteria

Navigation & routing

  • The open drawer stack is a pure function of the pathname (resolvePath
    returns the full ancestor chain); there is no drawer-stack store and no
    PUSH/POP interception.
  • All navigation is normal router navigation; a map-click is
    navigate(event.webPath) and the stack always equals the URL breadcrumb.
  • Back / forward / swipe-dismiss / scroll-restore behave via the router with
    no custom history logic.
  • Cold-load deep-link renders the full ancestor chain; each ancestor is a
    normal Suspense query (no lazy-reveal machinery).
  • Camera follows the top drawer and restores the parent on navigate-up,
    driven only through MapController.
  • Configured client.region opens as a RegionView over RootView on load.
  • …/register and …/share are explicit router routes, deep-linkable, and a
    CMS region slug can never shadow them.
  • resolvePath remains a pure terminal-segment function (unit-tested).

URL / canonical / SEO

  • Address bar follows navigation; no canonicalization redirects remain
    (residual navigate(...,{replace}) removed); legacy /events/:id renders.
  • Share target is always the validated webUrl (never the live address bar).
  • <link rel="canonical"> + og:url are emitted only in the standalone build;
    the widget's hash URLs are not advertised as canonical.
  • Smoke test: a legacy /events/:id renders and carries the correct canonical.

Views & components

  • src/views/ contains RootView, SearchView, RegionView, EventView,
    RegistrationView, ShareView, each drawer-wrappable, each with one
    maximally-configured story under the Ladle "Views" group.
  • RegionView shows child regions then child events in one list (no headers).
  • EventView renders <EventDetails> with no Panel/Modal wrapper (map build).
  • RootView drawer is non-dismissable + non-modal + snap-pointed (mobile); all
    other drawers are dismissable + non-modal.
  • SearchBar, Navbar, Panel, Modal, ListHeader, and the dead
    useNavigationState are deleted with no remaining imports;
    organisms/EventView renamed to EventDetails.
  • Toolbar (no bordered variant, no dead nav links) holds Language + Theme +
    attribution and renders in every drawer footer.

Responsive & drawer behavior

  • Left at ≥md, bottom on mobile; the md hook is debounced so it can't
    thrash-remount; RegistrationView form state survives a remount.
  • Non-modal: map (or, when map-less, the content) stays interactive behind
    open drawers;
    stacked-drawer focus/Esc/aria-hidden verified (AC-0).
  • Map padding uses the known fixed left-drawer width (no DOM measurement).
  • Drawers portal into the widget container.

Map-less rendering (map=false)

  • The custom element is registered as <sahaj-atlas> (valid hyphenated name);
    customElements.define, vite styleId, demo.html, and docs updated.
  • ?map=0 (standalone) and <sahaj-atlas map="false"> both render map-less;
    the default (<sahaj-atlas> / no ?map) renders the full map.
  • Map-less renders no MapProvider/Mapbox and needs no Mapbox token; the
    MapController is a no-op and no view branches on the map flag.
  • Map-less base view renders inline; deeper navigations open drawers that
    cover the content area (portaled into the container).
  • Any view renders map-less at its route; map-less search geocodes to a
    results list.
  • window/document/100dvh viewport assumptions are scoped so they don't
    break inside a host container.

Search & data

  • SearchView ranks by distance from the geocoded place / map center (reusing
    the quantized lat/lng query key), not the live viewport; the list does not
    re-sort on map pan.

Quality

  • MapController is the only place that knows about map vs map-less.
  • Fathom pageviews are not double-counted on map-click / replace navigations.
  • <Mapbox> is not remounted by drawer navigation.
  • pnpm lint, pnpm typecheck, pnpm test:run, pnpm build, and
    pnpm ladle:build pass; unit tests updated for renamed/removed components,
    resolvePath ancestor-chain, and the new routing.
  • Docs updated: CLAUDE.md, .claude/rules/components.md,
    .claude/rules/mapbox.md, DESIGN_SYSTEM.md, STORYBOOK.md.

Files affected (indicative)

  • New: src/views/** (6 views + stories + barrel), atoms/Drawer/**,
    molecules/Toolbar/**, DrawerStack, MapController context/provider.
  • Renamed: organisms/EventView → organisms/EventDetails.
  • Removed: molecules/SearchBar, molecules/Navbar, molecules/Panel,
    atoms/Modal, molecules/List/ListHeader, src/pages/**, src/layouts/*
    (folded into DrawerStack + map-less layout), dead useNavigationState.
  • Changed: src/App.tsx, src/Widget.tsx (customElements.define('sahaj-atlas', …) + map prop), src/main.tsx, vite.config.ts (map flag + styleId
    rename), demo.html + host-embed docs, src/lib/shape/path.ts (ancestor chain
    • reserved-slug guard), src/config/store.ts, src/hooks/use-mapbox.ts (behind
      MapController), src/config/responsive.ts (debounced md), src/config/api/*
      (geocode search shaping), package.json (add [email protected]).

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Hold Until

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions