Skip to content

feat(components): add ladle previews + standardize component library #5

Closed

Description

@Ardnived

Summary

Introduce ladle for isolated component previews and bring
our component library in line with the methodology used by our sister project
WeMeditateWeb (atomic-design taxonomy, per-component stories, consistent export and
styling conventions, governing docs). Today AtlasReact has ~32 components organized by
domain (base/ event/ list/ mapbox/ icons/) with no way to preview a component in
isolation, no stories, inconsistent exports, and tailwind-variants shipped in deps but
never used. This makes visual review, design QA, and onboarding harder than they should be.

Scope guardrail: we keep NextUI v2 as our primitive layer. This ticket adds
structure and previews around the existing components — it does not rebuild or
replace NextUI-backed components, and is not a visual redesign.

Background / reference

WeMeditateWeb already does this well and is our template:

  • @ladle/react with .ladle/{config.mjs,vite.config.ts,components.tsx} (a global
    provider decorator so stories render with app context).
  • components/{atoms,molecules,organisms,templates}/ with a folder + barrel index.ts
    per component and co-located Component.stories.tsx.
  • Governing docs: DESIGN_SYSTEM.md (atomic classification, tokens, when-to-wrap rules)
    and STORYBOOK.md (story conventions, section ordering, helper API).
  • Stories use custom StoryWrapper/StorySection/StoryGrid helpers (documentation-grid
    matrices, light/dark, "in context" examples) rather than interactive controls.

We adopt the same shape, adapted to our NextUI + Mapbox stack. Initial stories use
ladle's native controls/args
; a follow-up doc (below) plans the optional switch to the
WeMeditate helper style.

Goals

  • pnpm ladle serves an isolated, navigable preview of every meaningful component.
  • A documented atomic-design taxonomy and component-authoring conventions for this repo.
  • Consistent exports, props typing, barrel exports, and tailwind-variants for variants.
  • A written migration plan for adopting WeMeditateWeb's story helpers later.

Non-goals

  • Rebuilding/replacing NextUI components or any visual redesign.
  • Porting the WeMeditate StoryWrapper/StorySection/StoryGrid helpers now
    (planned as a doc; implemented only if we decide to switch).
  • Adding jsdom/Testing-Library component tests — that lives in test: establish a testing strategy (local fast tests + CI smoke) #4 (testing strategy).

Proposed changes

Phase 1 — Ladle setup

  • Add @ladle/react to devDependencies (pin a version compatible with Vite 5 /
    TS 5.6 — verify before choosing).
  • Add .ladle/config.mjs: story glob src/**/*.stories.{tsx,ts}, title: "Sahaj Atlas Component Library", a dedicated port.
  • Add .ladle/vite.config.ts reusing our @/* alias (vite-tsconfig-paths) and the
    Tailwind/NextUI pipeline so stories style identically to the app.
  • Add .ladle/components.tsx global-provider decorator mirroring src/providers.tsx
    (NextUI Providers, React Query QueryClientProvider, HelmetProvider, i18n via
    src/config/i18n.ts) and import src/styles/globals.css. The widget injects CSS via
    JS in production, so stories must import globals explicitly.
  • Add scripts: "ladle": "ladle serve", "ladle:build": "ladle build".

Phase 2 — Taxonomy & conventions

  • Reorganize src/components/ into an atomic taxonomy (atoms/ molecules/ organisms/,
    plus treating src/layouts/ as templates) while keeping churn reviewable. Draft mapping
    (finalize in the doc; keep kebab-case filenames per .claude/rules/code-style.md):
    • atoms — icons/*, base/chip, base/dropdown, base/language, base/panel,
      base/lightbox-image, base/fallbacks, theme-switch
    • molecules — search-bar, navbar, list/{item,header}, event/{time,metadata,share,images,soon}
    • organisms — mapbox/{map,search}, list/events, event/{panel,details,registration}
  • Add a barrel index.ts per level (extend the existing icons/ + list/ pattern).
  • Standardize exports (one convention, documented — e.g. named exports for atoms/molecules)
    and props typing (consistent interface/type choice).
  • Adopt tailwind-variants (tv()) for components with size/color/state variants, per
    the existing .claude/rules/components.md guidance (currently unused in the repo).
  • Write a repo-level DESIGN_SYSTEM.md (taxonomy + classification + when-to-wrap-NextUI
    rules) and update .claude/rules/components.md to point at it.

Phase 3 — Stories (plain ladle controls first)

  • Add a co-located *.stories.tsx for each component using ladle's native args/controls.
  • Cover key variants and both light and dark themes (drive via useTheme()).
  • Mock data via existing zod types in src/types/; gate map/Mapbox stories behind a token
    (see risks) and mock React Query / store reads where a story needs them.

Phase 4 — Story-helper migration plan (doc deliverable)

  • Add STORYBOOK.md describing how to port WeMeditateWeb's StoryWrapper/StorySection/
    StoryGrid helpers and standard section ordering (Variants → Sizes → States → Examples)
    into a src/components/ladle/ folder, and how existing plain-control stories would be
    converted. Implementation deferred pending review of the Phase 3 result.

Phase 5 — CI / tooling

  • Ensure stories are type-checked (extend tsconfig include or run ladle build in CI).
  • Optionally add pnpm ladle:build to .github/workflows/ci.yml so broken stories fail
    the gate. Coordinate with test: establish a testing strategy (local fast tests + CI smoke) #4 (testing strategy) — ladle gives visual verification that
    complements that ticket's node-only tests.

Acceptance criteria

  • @ladle/react added; pnpm ladle serves and pnpm ladle:build succeeds.
  • .ladle/{config.mjs,vite.config.ts,components.tsx} exist; the provider decorator
    renders components with NextUI + i18n + React Query + Helmet and global styles.
  • Components reorganized into the documented atomic taxonomy with a barrel index.ts
    per level; filenames stay kebab-case; imports use @/*; app builds (pnpm build)
    and typechecks (pnpm typecheck) clean.
  • Export style and props typing are consistent and documented; tailwind-variants
    used for at least the variant-bearing components.
  • A *.stories.tsx exists for every atom and molecule and for non-map organisms,
    using native ladle controls, each covering light + dark themes.
  • DESIGN_SYSTEM.md (taxonomy + conventions) and STORYBOOK.md (helper-migration
    plan) are committed; .claude/rules/components.md references them.
  • No NextUI component is rewritten/removed and there is no intended visual change to
    the running widget.
  • Stories are type-checked in CI (and optionally ladle:build gates the workflow).

Assumptions

  • Ticket targets sydevs/AtlasReact; WeMeditateWeb is reference-only.
  • "Standardize all components / move to a structured system" means the atomic-design +
    ladle methodology above — not migrating off NextUI and not a redesign.
  • Map/Mapbox organisms may get lighter story coverage (token/network constraints).
  • Locale JSON loads over HTTP via VITE_HOST; stories may need a default locale or
    bundled strings to render text without a backend.

Risks / open questions

  • Provider isolation: components depend on i18n (HTTP-loaded locales), zustand stores,
    React Query, and HashRouter. The decorator must supply these; map components also need
    VITE_MAPBOX_ACCESSTOKEN. Map stories may need stubs or be marked "needs token".
  • Reorg churn: moving files changes many import paths; do it in reviewable commits and
    rely on @/* + barrels to limit blast radius.
  • Ladle + Vite 5 compatibility: confirm a @ladle/react version that supports our
    Vite 5 / TS 5.6 toolchain before pinning.

Files affected

  • package.json — @ladle/react devDep + ladle/ladle:build scripts.
  • .ladle/config.mjs, .ladle/vite.config.ts, .ladle/components.tsx — new.
  • src/components/** — atomic reorg, barrel index.ts per level, co-located *.stories.tsx.
  • src/components/ladle/** — new, only if/when Phase 4 helpers are adopted.
  • DESIGN_SYSTEM.md, STORYBOOK.md — new governing docs.
  • .claude/rules/components.md — reference the new docs.
  • tsconfig*.json — include stories for typecheck.
  • .github/workflows/ci.yml — optional ladle:build gate.

References

  • WeMeditateWeb: DESIGN_SYSTEM.md, STORYBOOK.md, .ladle/, components/{atoms,molecules,organisms}/.
  • This repo: .claude/rules/components.md, .claude/rules/code-style.md, src/providers.tsx,
    src/config/i18n.ts, tailwind.config.js.
  • Related: test: establish a testing strategy (local fast tests + CI smoke) #4 (testing strategy — ladle complements node-only tests with visual verification).

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