File structure

July 5, 2024 ยท View on GitHub

Status

StageStatus
Approvedโœ…
Adopted๐Ÿšง

Context

Components might be more grokable if they were structured consistently. This ADR proposes conventions

Decision

TL;DR:

primer-react/
โ”œโ”€ src/
โ”‚  โ”œโ”€ Breadcrumbs/
โ”‚  โ”‚  โ”œโ”€ index.ts                    // Just re-exporting?
โ”‚  โ”‚  โ”œโ”€ Breadcrumbs.tsx             // Primary component
โ”‚  โ”‚  โ”œโ”€ BreadcrumbsItem.tsx         // Subcomponent (include parent component name to increase findability in most IDEs)
โ”‚  โ”‚  โ”œโ”€ Breadcrumbs.mdx             // Documentation. Always .mdx, not .md
โ”‚  โ”‚  โ”œโ”€ Breadcrumbs.stories.tsx
โ”‚  โ”‚  โ”œโ”€ Breadcrumbs.test.tsx        // Unit tests
โ”‚  โ”‚  โ”œโ”€ Breadcrumbs.types.test.tsx  // Type tests
โ”‚  โ”‚  โ”œโ”€ Breadcrumbs.yml             // Component metadata (Possible future)
โ”‚  โ”‚  โ””โ”€ __snapshots__/
โ”†  โ”†

Rules

  • Every component should have its own PascalCased directory directly under src/
  • Subcomponents should be properties of the exported parent component (e.g., Breadcrumbs.Item)
  • Replacements of existing components should use an incrementing number (e.g., Breadcrumbs2 rather than NewBreadcrumbs)

Implementation

  • Migrate components into this structure (as part of Storybook refactor work)
  • Set up tests for the component structure
  • Mark this ADR as adopted