496303471d
---ci--- project: atelier phase: 7 milestone: v0.1 status: complete phase_role: final milestone_complete: true requirements: covered: [ATELIER-01, ATELIER-02, ATELIER-03, ATELIER-04, ATELIER-05, ATELIER-06, ATELIER-07, ATELIER-08, ATELIER-09, ATELIER-10, ATELIER-11, ATELIER-12, ATELIER-13, ATELIER-14, ATELIER-15, ATELIER-16, ATELIER-17, ATELIER-18, ATELIER-19, ATELIER-20, ATELIER-21, ATELIER-22, ATELIER-23, ATELIER-24, ATELIER-25, ATELIER-26, ATELIER-27, ATELIER-28, ATELIER-29, ATELIER-30, ATELIER-31, ATELIER-32, ATELIER-33, ATELIER-34, ATELIER-35] partial: [] ship: milestone: v0.1 type: NFR tag: v0.0.7 merge: milestone/v0.1-atelier -> main release: https://git.cloudinit.dev/cloudinit-bot/atelier/releases/tag/v0.0.7 ---/ci--- Milestone v0.1 — Initial Framework (NFR, complete). 8 core principles (C1-C8), 11 domains, 110 domain principles, 27 derived docs, 4 good + 3 bad examples, 4 language docs, full matrix, 3 review docs. All 35 requirements covered. 7 patches (v0.0.0 pre-execution through v0.0.7 final). v0.0.7 IS the v0.1.0 milestone release.
108 lines
4.1 KiB
Markdown
108 lines
4.1 KiB
Markdown
# Good Example: React Component
|
|
|
|
> A UI component that follows Atelier's UI/UX principles. Each aspect cites the principle it satisfies.
|
|
|
|
## The Component
|
|
|
|
```tsx
|
|
import { useId, useState } from 'react';
|
|
import { Button } from './Button';
|
|
import { Spinner } from './Spinner';
|
|
|
|
type DeleteButtonProps = {
|
|
/** The resource name to display in the confirmation */
|
|
resourceName: string;
|
|
/** Called when the user confirms deletion */
|
|
onDelete: () => Promise<void>;
|
|
};
|
|
|
|
export function DeleteButton({ resourceName, onDelete }: DeleteButtonProps) {
|
|
const [isConfirming, setIsConfirming] = useState(false);
|
|
const [isDeleting, setIsDeleting] = useState(false);
|
|
const confirmId = useId();
|
|
|
|
const handleConfirm = async () => {
|
|
setIsDeleting(true);
|
|
try {
|
|
await onDelete();
|
|
} finally {
|
|
setIsDeleting(false);
|
|
setIsConfirming(false);
|
|
}
|
|
};
|
|
|
|
if (isConfirming) {
|
|
return (
|
|
<span role="group" aria-labelledby={confirmId}>
|
|
<span id={confirmId}>Delete {resourceName}? This cannot be undone.</span>
|
|
<Button variant="danger" onClick={handleConfirm} disabled={isDeleting}>
|
|
{isDeleting ? <Spinner label="Deleting" /> : 'Yes, delete'}
|
|
</Button>
|
|
<Button variant="ghost" onClick={() => setIsConfirming(false)} disabled={isDeleting}>
|
|
Cancel
|
|
</Button>
|
|
</span>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<Button variant="danger" onClick={() => setIsConfirming(true)}>
|
|
Delete
|
|
</Button>
|
|
);
|
|
}
|
|
```
|
|
|
|
## What Makes It Good
|
|
|
|
### Single Responsibility (components.md §1)
|
|
- The component does one thing: confirm and trigger a deletion. No "And" in the name.
|
|
- The `onDelete` callback is the single output. The component owns the confirmation UI, not the deletion logic.
|
|
|
|
### Explicit Boundaries (components.md §3)
|
|
- Props are typed (`DeleteButtonProps`). Required props are required.
|
|
- `onDelete` returns a `Promise<void>` — the caller knows it's async.
|
|
- The component never reads global state. It receives `resourceName` and `onDelete`.
|
|
|
|
### Predictable State (components.md §4)
|
|
- `isConfirming` and `isDeleting` are owned by the component (only it cares).
|
|
- State is not duplicated. The parent does not know about confirmation.
|
|
- The component transitions: idle → confirming → deleting → idle.
|
|
|
|
### Render Purity (components.md §5)
|
|
- Given the same props and state, the component renders the same output.
|
|
- Side effects (`onDelete`) are in the event handler, not in render.
|
|
- `useId()` is deterministic per component instance (React guarantee).
|
|
|
|
### Accessible by Default (components.md §6, uiux P2)
|
|
- The confirmation group has `role="group"` and `aria-labelledby`.
|
|
- The Spinner has a `label` (screen reader announces "Deleting").
|
|
- Buttons have text labels (not icon-only).
|
|
- Focus order is logical (confirm → cancel).
|
|
- Keyboard-reachable (buttons are natively focusable).
|
|
|
|
### Forgiveness (UI/UX P5, P10 Reversibility)
|
|
- Destructive action requires confirmation (P5).
|
|
- "This cannot be undone" names the consequence (P3 Clarity).
|
|
- "Cancel" is offered and is not disabled during deletion (the user can cancel the *next* action).
|
|
- The state is reversible: `isConfirming` can be set back to `false` (P10).
|
|
|
|
### Style via Tokens (components.md §7)
|
|
- `variant="danger"` and `variant="ghost"` reference design tokens, not raw colors.
|
|
- No `style={{ color: 'red' }}` — the token system owns the visual.
|
|
|
|
### Feedback (UI/UX P4)
|
|
- The button shows a Spinner while deleting (P4, P6 Performance perception).
|
|
- The button is disabled while deleting (prevents double-click).
|
|
- The label changes: "Yes, delete" → Spinner (state is communicated).
|
|
|
|
### Clarity (UI/UX P3)
|
|
- "Delete {resourceName}? This cannot be undone." — specific, names the resource and the consequence.
|
|
- No "Are you sure?" — vague. No "Submit" — wrong verb.
|
|
|
|
## What This Example Does NOT Do (And Why That's Good)
|
|
|
|
- Does not use a `window.confirm()` dialog — not accessible, not styled, not composable.
|
|
- Does not render a modal — the inline confirmation is lighter and less disruptive (P9 Simplicity).
|
|
- Does not auto-delete on click — forgiveness (P5).
|
|
- Does not hardcode "Project" — the resource name is a prop (composability, components.md §3). |