@foomo/cms-tools
v0.2.1
Published
CMS UI tools for Contentful apps, built on @foomo/ui. Every module is imported by its own subpath; there is no root entry.
Keywords
Readme
@foomo/cms-tools
CMS UI tools for Contentful apps, built on @foomo/ui.
ESM only. There is no root entry and no barrel files — import each module by its subpath:
import { SomeTool } from "@foomo/cms-tools/tools/some-tool";
import { useSomething } from "@foomo/cms-tools/hooks/use-something";Install
npm install @foomo/cms-tools @foomo/ui @contentful/app-sdk react react-dom tailwindcssStyles
The package ships precompiled CSS. Import it once, after @foomo/ui:
@import "tailwindcss";
@import "@foomo/ui/ui.css";
@import "@foomo/ui/themes/neutral.css";
@import "@foomo/cms-tools/styles.css";No Tailwind @source entry or @theme mapping is needed for this package. The stylesheet includes the cropper styles from react-image-crop.
- Prefix: every utility is prefixed
ct:(ct:flex,ct:hover:bg-muted) and every theme variable--ct-*, so nothing clashes with the host's Tailwind. Tailwind 4 only supports aprefix:form, notct-. The same approach is used by@foomo/uiwithfui:. - No preflight: the CSS does not reset any element styles.
@foomo/ui/ui.cssalready provides the reset. - Theme tokens: colors resolve straight to the
@foomo/uitokens (var(--primary),var(--border), …), so a custom theme only has to define those variables. classNameprops: a class passed to a tool from the host is unprefixed. It competes withct:utilities on specificity-equal terms, so the later stylesheet wins.
Layout
| Subpath | Source | Contents |
| --------- | ------------ | --------------------------------------------- |
| tools/* | src/tools/ | UI tools, each receiving the Contentful sdk |
| hooks/* | src/hooks/ | Shared React hooks |
| lib/* | src/lib/ | Framework-free helpers |
| contentful/* | src/contentful/ | SDK provider and complete app pages built from the tools |
| styles.css | src/styles.css | Precompiled, ct:-prefixed stylesheet |
Contentful pages read the SDK from context, so wrap the app once:
import { ContentfulSdkProvider } from "@foomo/cms-tools/contentful/sdk";
import { ImageCropPage } from "@foomo/cms-tools/contentful/image-crop-page/image-crop-page";
<ContentfulSdkProvider>
<ImageCropPage ratios={ratios} publish onImported={({ assets }) => link(assets)} />
</ContentfulSdkProvider>;A tool can be a single file (src/tools/slug-field.tsx → tools/slug-field) or a folder (src/tools/slug-field/slug-field.tsx → tools/slug-field/slug-field).
Conventions
- Import sibling modules relatively with their real extension (
./format.ts,./field.tsx);tscrewrites them to.js. - No
index.tsre-export files. Biome'snoBarrelFileandnoReExportAllrules fail the lint if one appears. @contentful/app-sdk,@foomo/uiand React are peer dependencies — never bundle them.
Playground
bun run playground serves playground/ on http://localhost:5173 as a Contentful app.
- In Contentful: create an app definition with App URL
http://localhost:5173and the Page or Entry field location, and install it. Open it from the Apps menu (page) or assign it to a field's appearance (entry field). It connects to the real SDK and lists the environment's image assets. - Standalone: opened directly in a browser, it falls back to a mock SDK with sample photos.
Scripts
bun run playground # vite dev server for playground/
bun run build # tsc + tailwind → dist/
bun run typecheck
bun run check # biome lint + format check
bun run format