Version component contracts
Treat behavior and accessibility as public API
A component contract includes documented props, defaults, emitted events, keyboard behavior, accessible names, supported styling hooks and dependency requirements. Changing a default button type or removing a documented token can break applications even if TypeScript still compiles. Semantic versioning 2.0.0 expects a declared public API: for stable releases, incompatible public changes increment major, backward-compatible additions increment minor and backward-compatible fixes increment patch. A visual change may be breaking if exact styling was explicitly promised. Versioning is a communication convention, not a guarantee of compatibility. The following fixture assumes React 18+ APIs, TypeScript TSX and a modern browser with native dialog support; exact dependency patches and browser support must be verified before release.
import React, {useState} from 'react';import {Button} from './Button';import {TextField} from './TextField';import {Card} from './Card';import {Dialog} from './Dialog';import './system.css';export default function ReservationPanel() { const [name, setName] = useState(''); const [attempted, setAttempted] = useState(false); const [saved, setSaved] = useState(''); const error = attempted && !name.trim() ? 'Enter a shelf label.' : undefined; return <main className="tool-system"> <Card title="Reserve a tool" footer={<Dialog title="Loan terms" triggerLabel="Read terms"> <p>Return the tool to the same shelf after the practice session.</p> </Dialog>}> <form noValidate onSubmit={e => {e.preventDefault(); setAttempted(true); setSaved(name.trim() ? `Draft saved for ${name.trim()}` : 'Draft not saved: enter a shelf label.');}}> <TextField name="shelf" label="Shelf label" value={name} onChange={setName} error={error} hint="Use a fictional label." required /> <Button type="submit">Save draft</Button> </form> <p role="status">{saved}</p> </Card> </main>;}This consumer saves only a local display message, not a database record. Empty or whitespace-only input produces an error message, while a nonempty label produces a draft confirmation. The form uses noValidate to demonstrate its custom validation policy; do not copy this setting without providing equivalent accessible error handling. The status region is present before submission. The draft state remains until another submit; the label is not a credential and no actual request is sent. Test the form inside and outside RTL direction, the dialog independently, and contrast in each theme. Document the expected statuses and required labels as part of the contract.
Create a release policy that can be tested independently
export function minimumBump({breaking, addition, fix}) { if (![breaking, addition, fix].every(v => typeof v === 'boolean')) { throw new TypeError('Expected three boolean change flags'); } return breaking ? 'major' : addition ? 'minor' : fix ? 'patch' : 'none';}export function acceptsBump(required, proposed) { const ranks = ['none', 'patch', 'minor', 'major']; if (!ranks.includes(required) || !ranks.includes(proposed)) throw new RangeError('Unknown bump'); return ranks.indexOf(proposed) >= ranks.indexOf(required);}This small policy ranks already-reviewed change classifications. It does not infer a breaking change from code, parse semantic versions, or handle prereleases and 0.x packages. A reviewer must decide whether changing a variant name, disabling a focusable control, adding an optional prop or correcting a bug changes the promised API. The policy rejects a patch release when the team has classified a change as major. Keep a changelog, migration example, deprecation window and consumer compatibility test alongside the components. Avoid silently preserving deprecated behavior forever; announce removal and schedule an appropriate release.
Check the policy before publishing anything
import test from 'node:test';import assert from 'node:assert/strict';import {minimumBump, acceptsBump} from './contract.mjs';const flags = (breaking=false, addition=false, fix=false) => ({breaking, addition, fix});test('removing a public variant is major', () => assert.equal(minimumBump(flags(true)), 'major'));test('breaking change takes priority', () => assert.equal(minimumBump(flags(true,true,true)), 'major'));test('new optional prop is minor', () => assert.equal(minimumBump(flags(false,true,true)), 'minor'));test('compatible fix is patch', () => assert.equal(minimumBump(flags(false,false,true)), 'patch'));test('no change', () => assert.equal(minimumBump(flags()), 'none'));test('reject too-small release', () => assert.equal(acceptsBump('major','minor'), false));test('allow larger release', () => assert.equal(acceptsBump('patch','minor'), true));test('allow exact release', () => assert.equal(acceptsBump('minor','minor'), true));test('invalid change flags', () => assert.throws(() => minimumBump({breaking: 1}), TypeError));test('invalid bump', () => assert.throws(() => acceptsBump('unknown','major'), RangeError));Run node --test contract.test.mjs in the fixture directory. These tests establish only the local release decision rule. Before distributing the UI library, run TypeScript with actual React declarations, render each primitive in a real consumer, test keyboard behavior and focus, verify RTL/reduced motion and contrast, and review package exports, dependency ranges and licensing. A screenshot comparison catches some visual differences but not all semantic regressions. Use a consumer migration rehearsal and a documented approval step; publishing and package distribution are deferred to the next chapter. Practice: classify changing the default Button type from button to submit and adding an optional hint to TextField. Write a migration note and a consumer regression test plan.