applyTo: "js/**"
This is the @microsoft/atlas-js package, providing TypeScript/JavaScript behaviors for the Atlas Design System.
- Name:
@microsoft/atlas-js - Type: TypeScript library
- Build Tool: TypeScript compiler (tsc)
- Output: ES modules with declarations
js/
├── src/
│ ├── behaviors/ # Behavior modules (e.g., popover, modal)
│ ├── elements/ # Custom elements / web components
│ ├── utilities/ # Shared utility functions
│ └── index.ts # Main entry point
├── test/ # Unit tests (mirrors src/ structure)
└── dist/ # Compiled JavaScript output
npm run build- Compile TypeScript to JavaScriptnpm run lint- Run ESLint on TypeScript filesnpm run test- Run unit tests with Vitestnpm run test:cov- Run unit tests with code coverage reportnpm run prepublishOnly- Lint and build before publishing
Atlas prioritizes CSS-only solutions. Add JavaScript only when:
- Accessibility requirements - Markup/attributes must change on interaction for screen readers
- Web components - Pattern is a good candidate for a reusable, lightweight web component
- Use strict TypeScript - Enable all strict checks
- Export from index.ts - All public APIs must be exported from the main entry
- JSDoc comments - Document public functions and classes
- Avoid dependencies - Keep the package lightweight
- Always include ARIA attributes where appropriate
- Test with screen readers when modifying interactive behaviors
- Follow WAI-ARIA patterns for component implementations
- behaviors/: Modules that attach behavior to existing DOM elements
- elements/: Custom elements that extend HTMLElement
- utilities/: Pure functions with no side effects
Behavioral tests are in the integration package:
- Tests use Playwright
- Run from repository root:
npm run integration
Unit tests use Vitest with a jsdom environment for DOM APIs.
npm run test- Run all unit tests (fromjs/folder or repo root)npm run test:cov- Run tests with code coverage reportnpx vitest --watch- Watch mode during development (fromjs/folder)npx vitest run test/utilities/util.test.ts- Run a specific test file
- Place test files in
test/- Mirror thesrc/folder structure (e.g.,test/utilities/util.test.tsforsrc/utilities/util.ts) - Import from vitest - Use
import { describe, it, expect } from 'vitest' - Use jsdom for DOM tests - The test environment provides
document,window, etc. - Test pure functions directly - For utilities, test inputs and outputs
- Test DOM behaviors - For behaviors/elements, create DOM fixtures and assert side effects
- Coverage uses the
v8provider via@vitest/coverage-v8 - Reports are generated in
js/coverage/(text, JSON summary, and HTML) - Coverage runs automatically in CI and is reported in the GitHub Actions job summary
- Run
npm run lintbefore committing - Build with
npm run buildto verify compilation - Run
npm run testto ensure all unit tests pass - Test interactively with the site package
- Add unit tests for new utilities and pure functions
- Add integration tests for new behaviors in the
integrationpackage