Challenge: Accessible, Themeable Component Library
Build a small “component library slice” that is accessible by default, themeable via design tokens, language-aware via i18n messages, and flexible via a headless dropdown API.
We'll cover the following...
Problem statement
Teams often ship UI components that look correct in one screen but fail when requirements change: a new theme, a new language, RTL layout, or a different visual treatment. The root issue is usually the same: logic, semantics, presentation, and content are coupled. Our job is to design a tiny library surface that stays stable under change by separating responsibilities:
Accessibility semantics and focus behavior are owned by the component logic.
Styling is owned by design tokens and a theme provider.
Text is owned by i18n messages with interpolation and pluralization.
Presentation is owned by consuming markup, using headless APIs.
Success criteria
By the end of the lesson, we can:
Switch themes (
light/dark) without editing component code.Switch locales (
English/Arabic) with correct direction (ltr/rtl).Render translated UI strings using message keys, interpolation, and pluralization.
Use a headless dropdown that provides behavior and a11y props, while the UI decides the markup.
Keep keyboard navigation correct (Arrow keys + Escape) and focus stable.=
Technical requirements: Implement the following features step by step:
Theme provider applies design tokens (CSS variables) to the document root.
Locale provider supports language switching and updates
dir(ltr/rtl).Translation function supports:
message lookup by key
variable interpolation (
{name})simple pluralization (
one/other)
Accessible banner uses semantic roles and stable structure:
status region announces language/theme changes without remounting the whole page
Headless dropdown:
exposes trigger/menu/item prop-getters
supports keyboard navigation (
ArrowDown/ArrowUp/Escape)uses compound components (
Dropdown.Trigger,Dropdown.Menu,Dropdown.Item)UI stays customizable (no hardcoded dropdown markup)
Project structure
Below is the hierarchy of the project files and folders: