Skip to content

refactor(ui): unify dropdowns on a shared floating-ui Dropdown #12

Closed

Description

@Ardnived

Summary

Consolidate the app's menu-style dropdowns onto a single shared Dropdown atom
ported from WeMeditateWeb
(@floating-ui/react-based popover + DropdownItem),
so Atlas and WeMeditateWeb share one dropdown abstraction and look. Today Atlas
has two separate NextUI dropdown implementations — LanguageSelector (active, in
the Navbar) and SelectionDropdown (dead code) — with no shared primitive. This
replaces them with one component, styled to adapt to Atlas's NextUI + accent
theme
(not WeMeditateWeb's hardcoded grays), so it respects light/dark and the
accent token.

Background

WeMeditateWeb's Dropdown
(~/Documents/Projects/WeMeditateWeb/components/atoms/Dropdown/Dropdown.tsx) is a
presentational popover built on @floating-ui/react: viewport-aware placement
(flip/shift), portaled panel (never clipped by overflow/transform/the map), and
controlled/uncontrolled open state. Its DropdownItem renders an <a>. It is
not a form control and carries no selection-state model.

Atlas's current dropdowns:

  • LanguageSelector (LanguageSelector.tsx) — NextUI Dropdown, single-select, tracks active locale, used at Navbar.tsx:50.
  • SelectionDropdown (SelectionDropdown.tsx) — generic NextUI single-select. Unused — referenced only by its own story + the atoms barrel.
  • EventRegistration's NextUI <Select> (EventRegistration.tsx:233) — a form field wired into react-hook-form. Different category; out of scope (stays on NextUI).

Proposed changes

  • Add the shared atom src/components/atoms/Dropdown/ (Dropdown.tsx,
    Dropdown.stories.tsx, index.ts) by porting WeMeditateWeb's Dropdown +
    DropdownItem more or less verbatim (floating-ui placement, portal, flip/shift,
    controlled/uncontrolled, side/align/role/ariaLabel/size props).
  • Add @floating-ui/react to dependencies (pick a React-18-compatible
    version; Atlas is react@^18.3.1).
  • Restyle to Atlas's theme: keep the structure/layout (rounded panel, shadow,
    min-w-* size variants, item padding scale, hover/transition) but swap
    WeMeditateWeb's hardcoded grays (bg-white, text-gray-700, border-gray-200,
    hover:bg-gray-100) for NextUI semantic tokens (e.g. bg-content1,
    text-foreground, border-default-200, hover:bg-default-100) so it follows
    light/dark + accent. Match the rest of the repo's styling conventions per
    .claude/rules/components.md (tailwind-variants for the size/variant axes if
    it reads cleanly; plain Tailwind otherwise).
  • Make DropdownItem work for buttons, not just links: Atlas's language items
    fire setLocale (no href), so DropdownItem should render a <button> when
    given onClick/no href (keep <a> for href) to preserve a11y semantics.
  • Rebuild LanguageSelector on the shared Dropdown: trigger keeps the
    current LanguageIcon + uppercase locale code; panel lists supportedLanguages
    via useLocale(), highlights the active locale (text-primary), calls
    setLocale on select, and keeps the aria-label={t('language_selector')}.
    Navbar usage and visible behavior unchanged.
  • Remove the dead SelectionDropdown: delete the folder, drop its barrel
    export, remove its story. The generic single-select need (currently unexercised)
    is covered by a Dropdown story/example. (If a generic selectable wrapper is
    wanted later, build it on the shared Dropdown then — YAGNI for now.)
  • Barrels: add export * from './Dropdown' to
    atoms/index.ts; remove the SelectionDropdown
    export.
  • Story + test: add a Ladle story for Dropdown/DropdownItem; add a
    node-only renderToStaticMarkup unit test asserting the closed-state trigger
    renders (the portaled open panel is interaction — covered in Ladle/browser, per
    .claude/rules/tests.md).

Out of scope

  • EventRegistration's react-hook-form <Select> stays on NextUI.
  • No new selection-state / multi-select model on the shared Dropdown beyond what
    LanguageSelector needs.

Acceptance criteria

  • New src/components/atoms/Dropdown/ atom (Dropdown + DropdownItem) ported from WeMeditateWeb on @floating-ui/react, portaled with flip/shift placement.
  • @floating-ui/react added to package.json (React-18-compatible version).
  • Panel styling uses NextUI semantic tokens and visibly follows light/dark + the accent token (no hardcoded grays).
  • DropdownItem renders a <button> for action items (no href) and an <a> for links; keyboard + aria preserved.
  • LanguageSelector rebuilt on the shared Dropdown: switches locale, highlights the active locale, keeps its aria-label, and renders unchanged in the Navbar.
  • Dead SelectionDropdown removed (component, story, barrel export); no remaining references (grep -r SelectionDropdown src is empty).
  • atoms/index.ts exports Dropdown; SelectionDropdown export removed.
  • Ladle story added for Dropdown; LanguageSelector story still renders.
  • Node-only unit test for Dropdown (closed-state renderToStaticMarkup) added.
  • Lint + typecheck + test:run + build + ladle:build pass.
  • Verified in the running widget: language switch works from the Navbar, and the panel is not clipped by the map / overflow ancestors.

Files affected

  • src/components/atoms/Dropdown/{Dropdown.tsx,Dropdown.stories.tsx,index.ts} — new
  • src/components/atoms/LanguageSelector/LanguageSelector.tsx — rewrite on shared Dropdown
  • src/components/atoms/index.ts — barrel: add Dropdown, remove SelectionDropdown
  • src/components/atoms/SelectionDropdown/** — delete
  • package.json — add @floating-ui/react

References

  • Source component: ~/Documents/Projects/WeMeditateWeb/components/atoms/Dropdown/Dropdown.tsx (+ LanguageDropdown usage example)
  • .claude/rules/components.md, DESIGN_SYSTEM.md — atomic tier, barrels, tailwind-variants, NextUI-first
  • .claude/rules/tests.md — node-only renderToStaticMarkup lane
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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