@kode4/react-foundation
v0.10.0
Published
Typed router, themed UI component library, and design system for kode4 projects.
Maintainers
Readme
@kode4/react-foundation
A typed application foundation for React: a typed router that turns route definitions into the app's single source of truth, a themed UI component library, and a CSS-variable design system — built to be consumed by humans and by AI agents.
- Typed router as the app spine — declare each route once with
defineRoute(path, Zod-validated params/search, loader, typedaction, eager orlazyComponentcode-split component, documenttitle, menu/tabs metadata); the library derives the React Router v7 config plus typed links (TypedLinkwithprefetch/viewTransition,pathTo), menus, breadcrumbs, guards viachain(), scroll restoration (window + inner containers), anaria-liveroute announcer, a designed 404 (notFoundRoute), andonNavigate/onErrorobservability seams. - UI component library — 70+ components on Radix primitives (shadcn/ui as
the blueprint): the full input family (incl.
PasswordInput,OTPInput,TagInput,NumberInput,Rating,MaskInput,ComboBox), date/time pickers with a partial-aware value model +DateRangePicker, rich editors (MarkdownEditor,HtmlEditor,SignaturePad), media (Gallery,Video,ZoomImage), a multi-stepWizard(branching, persistence, per-step loaders),EmptyState,DataTable(sorting, pagination, row selection, column visibility, global filter, pinning/resizing, per-column filters, row expanding + grouping/aggregation, CSV export + a virtualization recipe — client or server mode, over TanStack Table), data display (Stat,Timeline,TreeView,CodeBlock,MarkdownViewer), split panes (Resizable), a windowedVirtualList, and the layout frames/nav chrome (AppLayout,TopBar,NavigationMenu,SideBar,Breadcrumbs,Hero, …). - Forms layer — react-hook-form + Zod with 20+ form-bound
…Fieldcomponents (label/description/error wired for you),WizardFormfor multi-step forms, and a busy-gate for async fields like uploads. - Charts —
LineChart/BarChart/PieChart/ScatterChart/RadarChartand an axis-lessSparklineover recharts, colored by design tokens (dark mode included). - File uploads — a headless upload layer (progress, cancel, hashing,
dedupe, upload-handle model) behind
FileField/ImageField(with cropper). - App utilities — SSR-guarded hooks (
useMediaQuery,useReducedMotion,useDebouncedValue,useDisclosure,useLocalStorage,useHotkeys, …), an app-wide activity registry for one shared progress bar (ActivityProvider), full-screen effects (screenEffect.confetti()with<ScreenEffects />), and anIconProviderfor swapping the built-in glyphs. - Design system — semantic CSS-variable tokens (shadcn standard names)
with light/dark mode; re-theme everything without a rebuild, no Tailwind
required in your app. Built-in label layer (
I18nProvider) for i18n with no framework dependency. - A11y + tests as a posture — every component is axe-checked in the unit suite, with Playwright end-to-end and pixel visual-regression suites over the showcase demo.
Quick start
Scaffold a ready-wired app (Vite + React + TS, provider stack, typed router, locale routing, sample routes):
npm create @kode4/react-foundation@latest my-app
cd my-app && npm install && npm run devOr add the library to an existing app:
npm install @kode4/react-foundationimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { Outlet, RouterProvider } from 'react-router-dom';
import { createAppRouter, defineRoute, ThemeProvider, Toaster } from '@kode4/react-foundation';
import '@kode4/react-foundation/styles.css'; // once, near the app root
const HomePage = () => <h1>Home</h1>;
const Shell = () => <Outlet />; // your chrome (AppLayout, TopBar, …) goes here
const homeRoute = defineRoute({ index: true, component: HomePage, title: 'Home' });
const shellRoute = defineRoute({ component: Shell, children: [homeRoute] });
const queryClient = new QueryClient();
// The second argument is the AppContext every loader receives; extend it via
// `declare module '@kode4/react-foundation/router/context'`.
const router = createAppRouter([shellRoute], { queryClient });
export const App = () => (
<ThemeProvider>
<QueryClientProvider client={queryClient}>
<RouterProvider router={router} />
<Toaster />
</QueryClientProvider>
</ThemeProvider>
);The full bootstrap (providers, menus, guards, theming) is in
docs/INSTRUCTIONS.md.
If you are an AI agent building an app on this library, read
docs/INSTRUCTIONS.mdfirst — it is written for you. It is the complete consumer contract: the mental model, the typed-router patterns, the component catalog with props and idioms, theming, data/forms recipes, and the pitfall checklist. Follow it and the app comes out idiomatic, type-safe, and themeable.
Documentation
These consumer docs ship inside the npm package, so the links below resolve
from node_modules/@kode4/react-foundation:
docs/INSTRUCTIONS.md— start here. The consumer contract: read it when building or extending an app on the library (router, catalog, theming, data, forms, uploads, effects, errors, testing).docs/DESIGN-SYSTEM.md— the theming/token contract: read it when restyling — every token, the-foregroundconvention, fonts, light/dark mechanics.docs/combo-box.md— theComboBoxliving spec: read it when working with async sources, value modes, or creatable selects.docs/date-picker.md— the date/time design contract: read it when you need the partial-aware value model, ranges, or bounds explained in depth.docs/gallery.md— theGallerycarousel/lightbox living spec: read it when composing galleries, slideshows, or the lightbox.
Package entry points
import { Button, defineRoute, useRoute } from '@kode4/react-foundation';
import '@kode4/react-foundation/styles.css'; // batteries-included styles, once near the app root
// Module augmentation target for your app's route context:
declare module '@kode4/react-foundation/router/context' {
/* extend AppContext */
}The package is graph-splittable: with a tree-shaking bundler you pay only for
the components you import (per-component CSS included), while ./styles.css
remains the single batteries-included stylesheet. See docs/INSTRUCTIONS.md
§2.1–2.2.
Stability & support
This section describes the promise as it stands today, at 0.10.x. The
authoritative text is the stability policy in CHANGELOG.md,
which ships inside this package.
Versioning
The package is pre-1.0. The commitment is about how breaking changes arrive, not a promise that none will:
| Bump | May break? |
| --------------------------- | ----------------------------------------------------- |
| Patch (0.10.0→0.10.1) | No. Fixes, warnings, docs, widened dep ranges. |
| Minor (0.10.x→0.11.0) | Yes, always with a ### Breaking migration note. |
| Major | Reserved for 1.0.0, once the API is worth freezing. |
Patch upgrades are always safe to take. Minor upgrades are safe to take after
you read CHANGELOG.md. A minor that breaks something without
a migration note is a bug. Please report it.
Pinning. On 0.x, npm's caret does not cross minors: ^0.10.0 and
~0.10.0 both mean >=0.10.0 <0.11.0, so you get patches only. Moving to a
new minor is always a deliberate edit to package.json, and that is the moment to
read the changelog. If you really want minors to arrive automatically, use an
explicit range such as >=0.10.0 <1.0.0.
What counts as public API
A change to any of the following is never made in a patch. When it breaks
something, it comes with a ### Breaking note:
- Everything exported from the package root (
@kode4/react-foundation). That covers components, hooks, functions, and the exported types, including every component's…Propstype and theLabelscontract ofI18nProvider. - The rendered contract: the element and ARIA role a component renders, its keyboard behaviour, and its default look.
@kode4/react-foundation/router/context, the module you augment to typeAppContext.@kode4/react-foundation/styles.css, the single bundled stylesheet.- The theming contract: every design token in
docs/DESIGN-SYSTEM.md, thek4-*BEM class names (block,__element,--modifier), the@layer k4cascade layer, and thedata-*attributes the docs name as styling hooks.
These are not public API:
- Anything that is not exported from the package root. The package's
exportsmap is closed, so the internal modules (includinginternal/) and the file layout inside the package cannot be imported, and file names likeButton2.jsmay change in any release. - The inside of a component. A minor may restructure a component's DOM or
rewrite the declarations behind its classes. When that changes the default
look, the change is listed under
### Breaking. Token overrides survive such changes. Structural overrides written against BEM classes work, but you have to re-check them on each upgrade (docs/INSTRUCTIONS.md§2.2). - Dev-only console warnings. A patch may add new ones. They never fire in a production build.
For translations, type them as LabelsOverrides (deep-partial and deep-merged)
and not as the full Labels type. With LabelsOverrides, a key added in a later
release falls back to its English default instead of breaking your build.
Supported environments
- React 19 (
react/react-dompeer^19.0.0). React 18 is not supported. - The other peers (
react-router-dom7,zod4, TanStack Query 5, and the CodeMirror/TipTap cores the editors share) are published with the minimum versions the library is built against. The exact ranges are in this package'spackage.jsonunderpeerDependencies. Modern npm installs peers for you. Keep each one to a single copy: duplicate CodeMirror or ProseMirror cores break the editors. - A bundler. The package is ESM-only and resolves with
moduleResolution: "bundler". It is built and tested with Vite. Other tree-shaking bundlers are expected to work but are not yet tested. - Modern evergreen browsers. In practice the floor is Chrome/Edge 111,
Safari 16.4 and Firefox 128. The shipped CSS relies on cascade layers and
oklch()colours, and the JS targets the same baseline. Chromium and WebKit (including iPhone emulation) are exercised in end-to-end tests. Firefox is not yet. Phone and tablet touch support is a standing requirement for every component. - Client-side rendering. The library is a client SPA. It can be imported
and rendered under Node, but server rendering and hydration are not supported
yet. See the Rendering stance in
docs/INSTRUCTIONS.md.
Links
- Changelog —
CHANGELOG.md(ships with the package) - Website — https://react-foundation.kode4.de
- Source — https://gitlab.com/kode4/react-foundation (currently private, so the link asks you to sign in)
- Report a bug — https://gitlab.com/kode4/react-foundation/-/issues (same restriction for now)
License: MIT.
