Skip to content

Astro Kit ​

Copy-in Astro components for Contentrain sites, the shadcn model. A site receives the component source and owns it from then on, so nothing here is a runtime dependency of the site. The package ships:

  • the components;
  • a machine-readable catalog;
  • mapping tables from page-builder elements to components;
  • a small API that copies components into a project.
bash
pnpm add -D @contentrain/astro-kit

Current version: 0.50.4.

The components are made for the Astro starter (templates/astro-starter). They read its design tokens and pass its gates: astro check with the strictest preset, knip, a single stylesheet and zero JavaScript by default.

Components ​

All 35 components, by role. The JavaScript column is the js field of each component's catalog entry.

idWhat it isJavaScript
header, footerSite chrome: brand, navigation and an optional action; link columns, social links, copyrightnone
navNavigation with submenus to any depth, a drawer or dropdown on narrow screensnone
announcementA one-line notice above the header that the visitor can closenone
consentCookie consent bar; consent is denied until the visitor acceptsvanilla
language-switcherLinks to the same page in the site's other languagesnone
search-boxA search field that sends the visitor to the site's search pagenone
social-linksLinks to the site's profiles on other networksnone
heroPage opener: heading, text, actions, imagenone
splitAn image beside a block of text and buttonsnone
card-grid, feature-listA grid of cards; a list of short featuresnone
stepsAn ordered sequence of stepsnone
statsA row of figures with a short label each; can count up once in viewvanilla
logo-cloudClient or partner logosnone
pricingPrice plans side by side, one featurednone
teamPortrait, name, role and short bio for each personnone
testimonialQuotes with who said themnone
post-list, post-cardA list of posts as cards; one post in a listnone
cta, bandCall-to-action band; the styled fallback sectionnone
faqQuestions as <details>, optional FAQPage JSON-LDnone
contact-detailsEmail, phone, address, hours and a map link, without a formnone
contact-formA Studio form with contact detailsStudio runtime
newsletterA sign-up posting straight to the list providernone
dialogA modal popup the visitor opens from a buttonvanilla
galleryAn image grid or masonry with a lightboxvanilla
sliderCarousel on a scroll-snap rowEmbla
tabsTabbed panels, readable as headed sections without JavaScriptZag.js
embedVideo, map or player loaded on clickvanilla
behaviorA source widget no component carries, kept as the site's markup and wired by one small modulevanilla
proseA rich-text body rendered as the editor wrote it; the fallback for unmapped elementsnone
pagination, breadcrumbWordPress-style /page/N/ links; ancestors with optional JSON-LDnone

The full list, with each component's props, variants, slots, dependencies and accessibility notes, is in the package's catalog.json.

Each component lives in components/<id>/:

  • <Name>.astro: the component. Its props are typed and its variants use tailwind-variants.
  • meta.json: its catalog entry. Props are Contentrain FieldDefs, and sources names the builder elements the component replaces.
  • fixtures.json: the visual-regression cases.

API ​

ts
import { copyComponents, KIT_COMPONENTS_DIR, loadCatalog, loadMapping, planCopy, rulesFor } from '@contentrain/astro-kit'

const catalog = await loadCatalog()
const plan = planCopy(catalog, ['header', 'card-grid']) // adds nav, the shared files and the npm packages needed
await copyComponents(plan, KIT_COMPONENTS_DIR, '/path/to/site') // → src/components/kit/<id>/…

const gutenberg = await loadMapping('gutenberg')
rulesFor(gutenberg, 'core/cover') // the rule that turns a cover block into a hero

validateCatalog, componentsForSource, validateMapping and unmappedSources check the catalog and the mapping tables against each other.

Mapping tables ​

The tables are mapping/<builder>.json, one each for gutenberg, elementor, divi and classic.

  • They map builder elements to components. Each prop takes its value from a small, closed set of source expressions.
  • They are versioned.
  • An element no rule covers stays rich text (fallback: "prose").
  • When several rules match an element, the outermost match owns its subtree.

Tokens and measured style ​

Components use colour roles and widths, never raw values. A site defines these tokens in @theme, as the starter already does:

  • colours: --color-surface, --color-ink, --color-accent, --color-accent-text, …
  • widths: --container-page, …
  • shapes: --radius-card, …

A migration can also hand a section the style it measured on the source page (measured: MeasuredStyle from @contentrain/types): frame width, padding, background, item columns per breakpoint, gap, tone, radius and minimum height. Every value is validated before it reaches a style attribute.

See the package README for the complete token list and the development scripts.