stackable-components
v1.8.2
Published
Reusable React components for Contentstack projects
Readme
Stackable Components
Ready-made React section components for Contentstack projects — heroes, banners, grids, pricing tables, FAQs, footers and more. Drop them onto a page, feed them entry data, and they render.
Installation
npm install stackable-componentsInstall the peer dependencies too, if your project doesn't already have them:
npm install react react-dom @heroicons/react react-iconsQuick start
import { HeroBanner, ProductCard } from 'stackable-components';
import 'stackable-components/dist/styles.css'; // required
export default function MyPage() {
return (
<>
<HeroBanner
heading="Welcome to Our Site"
subheading="Discover amazing products"
cta_button={{ text: 'Get Started', link: '/products' }}
/>
<ProductCard
product_name="Amazing Product"
description="This product will change your life"
price={99.99}
/>
</>
);
}You don't need Tailwind. dist/styles.css is a self-contained build that carries every utility the components use. If your project already runs Tailwind, importing it alongside is fine.
Every prop is optional and has a sensible default, so a component renders something reasonable before any content reaches it.
Runtime renderer
A site doesn't have to import components one by one. StackablesEntry renders any
entry straight from its content type's schema, so one route can serve every page of
a Stackables-published stack:
import { StackablesEntry, parseSiteConfig, pageConfigFor, referencePaths } from 'stackable-components';
// entry: the fetched entry (references resolved — see referencePaths(schema))
// schema: the entry's content type schema, with global field schemas included
// config: the `stackables_site_config` entry Stackables publishes into the stack
<StackablesEntry entry={entry} schema={contentType.schema} config={config} page={pageConfigFor(config, contentType.uid)} />A global_field field renders as one component, a reference field as one per
referenced entry, a group as a run of sibling sections and a blocks field as one
component per block, in schema order. Asset objects are flattened to their URLs.
Which component a content type / global field uid maps to comes from the site
config's components map (falling back to the uid in PascalCase); per-section widths
and the page's container cap come from its pages entry. StackablesChrome renders
the site header / footer the same way from the config's header / footer, and
readTypography + themeFromTypography turn a composed Typography component into a
ThemeProvider theme.
A site can supply its own components: components (by library name) replaces a
library component wherever it appears; componentsByUid (by content type / global
field uid) renders every field pointing at that uid — including uids the library has no
component for — and, given the entry's own contentType, can take a whole page type
over. renderUnknown is called for anything nothing renders.
Custom pages (1.2.1)
A page type made directly in Contentstack — one Stackables never designed, so the site config says nothing about it — routes and renders too:
buildRoutes(config, contentTypes)gives every content type with URLs a route after the site config's pages, from its URL Prefix joined to its URL Pattern (contentTypeUrlPattern: prefix/newpage/+ pattern/:title→/newpage/:title;{title}is accepted as a placeholder too). Such routes havecustom: trueandpage: null. Where one shares a URL shape with a designed page, the designed page is tried first.StackablesEntryrenders a custom page's component fields as usual, and its plain fields — text, rich text (HTML or JSON), Markdown, files, links, numbers, dates, booleans — as a document: consecutive plain fields share one section in the container, styled by the.sk-plainrules instyles.css. A custom page with no component fields also gets its title as an<h1>. This isrenderPlainFields, which defaults to on exactly when nopageis given; a page designed in Stackables renders precisely as before.
Markdown fields are parsed by the library itself (renderer/markdown.tsx, no
dependency) straight to React elements — CommonMark's everyday set plus GitHub's
tables, task lists, strikethrough and bare links; raw HTML in the text is shown
as text, never interpreted. A boolean shows with its label ("Gift wrapping:
Yes" / "No"; .sk-plain__boolean), and nothing when the entry never set it.
A multi-entry reference field made in Contentstack (field_metadata.ref_multiple,
with multiple left false) renders every entry it holds, not only the first —
isMultipleReference(field) is the test, exported alongside the others.
Field overrides — StackablesEntry's fields prop replaces the rendering of any
plain field, the kinds the library never renders (custom, json, taxonomy)
included:
<StackablesEntry
fields={{
uids: { care_notes: CareCard, "details.size_chart": SizeChart, internal_notes: null },
customFields: { blt0123456789abcdef: StarRating }, // by custom field extension uid
types: { markdown: ArticleMarkdown, boolean: YesNoBadge },
}}
/* … */
/>Checked most specific first: uids[path], uids[uid], customFields[extension uid],
types[kind]; null hides a field; uids.title replaces a custom page's title
heading. types apply where plain fields render (a custom page); uids and
customFields on every page. An override receives { field, value, kind, path,
entry, parent, editTag, children }, children being the library's own rendering.
Kinds: text, multiline, markdown, html, json_rte, number, date, file,
link, boolean, select, custom, json, taxonomy (fieldKind(field) tells
which). A select shows its choice's label; custom fields, plain JSON and taxonomies
render only through an override.
PlainField, isPlainField and hasComponentFields are exported for a site that
takes a custom page over but wants its text rendered the same way. Add .sk-plain
to an element for the typography alone; the automatic sections also carry
.sk-plain--section for their padding.
Every content component is reachable by name through the registry
(getComponent('HeroBanner')) — withSectionWidth registers each export under the
display name it is given, which is why that name must match the catalog's
react_component.
Server code (a Next.js generateMetadata, say) should import the pure helpers from
stackable-components/runtime instead — same functions, no components in the bundle,
so it loads inside a React Server Component where the main entry cannot.
Available Components
Typography
- Typography: Themed text primitive for headings/body copy
Hero Banners
- HeroBanner: Full-width gradient hero with CTA button
- SplitHeroBanner: Split layout hero with content and image placeholder
- HeroBannerClassic: Classic hero with heading lines, avatars, and footer stats
- SpotlightHero: Hero with a spotlighted CTA list
Banners
- Banner / BannerLight: Full-width promo banners (dark/light)
- BannerCallout: Inline callout banner
- PromoBanner: Rotating multi-slide promo banner
- CommunityBanner: Banner with avatar stack and CTA
- CountdownBanner: Banner with a countdown timer
- CookieConsentBanner: Cookie consent bar
Carousels & Sliders
- ImageVideoCarousel: Interactive image/video carousel with navigation
- CircleImageCarousel: Circular image carousel
- VerticalProductCarousel: Vertical scrolling product carousel
- GalleryCarousel: Gallery-style slide carousel
- ProductSlider: Product slide carousel with CTA
Product Components
- ProductCard / ProductCardRegular / ProductCardLarge: Product display cards
- ProductBanner: Banner-style product highlight
- FeaturedProduct: One product shown big, with options and Add to Cart
- ProductListing: Grid layout for multiple products (PLP)
- ProductDetails: Product detail page layout (PDP)
Cards
- ResourceCard: Resource/article card list
- ProfileCard: Profile card with stats
- FlipCard: Card with a flip animation
- CardAccordion: Expandable accordion card
Grids
- BentoGrid: Bento-style mixed grid layout
- IndexSection: Indexed list/grid section
- HexTileGrid: Hexagonal tile grid
- CategoryGrid: Category tile grid
- FlipCardGrid: Grid of flip cards
- ImageGrid / ImageGridDynamic: Static and dynamic image grids
Testimonials & Reviews
- Testimonial: Testimonial quote block
- RatingSummary: Aggregate rating summary
- CardStack: Stacked testimonial cards
- Reviews: Review list section
Logo Marquee
- LogoMarquee: Scrolling logo strip (or a still row/grid)
FAQ
- FAQ: Standard FAQ accordion
- FaqCategorized: FAQ grouped by category
Empty State
- NotFoundPage: Pre-built 404 page: illustration, message, buttons and suggested links
Pricing
- Pricing: Pricing tier comparison
- PricingSpreadCard: Single spread pricing card
Statistics
- StatCounterRow: Row of animated stat counters
Forms
- ContactForm: Customizable contact form
- ContactFormSplit: Split-layout contact form
- NewsletterSignup: Newsletter signup form
Navigation
- NavigationBar: Responsive navigation with mobile menu
- ExtendedNavigation: Multi-level navigation menu
- BreadcrumbNavigation: Breadcrumb trail
- Sidebar: Sidebar navigation
Footers
- FooterSimple: Minimal single-row footer
- FooterMultiColumn: Multi-column footer with links
CTAs
- TextCTA: Text-led call-to-action section
- JustifiedTextCTA: Justified-text call-to-action section
Buttons
- PrimaryButton: Primary action button
- ToggleSwitch: On/off toggle control
Article Pages
- ArticleDetails: Article detail page layout
- ArticleListing: Article listing page layout
Tabs
- Tabs: Tabbed content section
Section Introduction
- SectionIntroduction: Section heading/intro block
- SectionIntroductionTwoColumn: Two-column section intro
Video
- VideoSection: Heading block with a video that plays in place — a video file or a YouTube, Vimeo or Loom link
Feature Benefits
- FeatureBenefitWithImage: Benefit section with supporting image
- StandardBenefit: Configurable standard benefits section
Feature Showcase
- StickyScrollFeature: Sticky scroll-driven feature showcase
Timeline
- VerticalTimeline / TimelineHorizontal: Timeline layouts (Vertical can alternate cards either side of a center line)
- TimelineYearBlocks: Year-grouped timeline blocks
Feature Comparison
- FeatureComparisonTable: Tabular feature comparison
- FeatureComparisonVs: Head-to-head comparison
- FeatureComparisonCards: Card-based comparison
Team
- TeamBanner: Team member showcase banner
Social
- SocialPostEmbed: Embedded social post
- SocialLinks: Social media link list
Process
- ProcessStep: Step-by-step process section
Awards
- AwardsSection: Awards/recognition showcase
Auth
- AuthSplitScreen: Split-screen auth (sign in/up) layout
Page width
Components sit inside a page container that the page owns, not the component. Each section picks one of three modes via container_width:
| mode | section box | content inside |
|---|---|---|
| inherit (default) | stops at the container | stops at the container |
| full_background | full page width — the background bleeds edge to edge | stops at the container |
| full | full page width | full page width |
Set the container once for the page with PageLayout:
import { PageLayout, HeroBanner, FAQ, StatCounterRow } from 'stackable-components';
<PageLayout maxWidth={1280}>
<HeroBanner container_width="full" {...heroProps} />
<FAQ container_width="full_background" {...faqProps} />
<StatCounterRow container_width="inherit" {...statsProps} />
</PageLayout>Or skip PageLayout and pass container_cap per component:
<FAQ container_width="full_background" container_cap={1280} {...props} />container_cap accepts a number (px), a CSS length ('80rem'), or 'full' for no cap. The container width is always a ceiling — it can pull content in, never push it out, so a 1280px container never overflows a 390px phone. Default is 1280px.
Spacing between sections
PageLayout also spaces its sections apart (since 1.6.2), from what each one actually paints:
- two sections that run a colour, gradient, image or video of their own from one page edge to the other (a band — usually
full_background/full) touch; - everything else is kept at least
--stackables-section-gapapart (defaultclamp(2rem, 5vw, 4rem)). A boxed surface — aninheritsection with a background — counts from its edge; a section with nothing painted at its edge counts from its first and last content, so a component's own padding is part of the gap rather than added on top of it.
The page's top and bottom count as bands (that is where the site header and footer sit), and so does a section whose root is a <header>, <nav> or <footer>. It is applied as each section's inline margin-top, measured before first paint and again when the page resizes or its sections change. Turn it off with <PageLayout autoMargin={false}> (a Stackables project: Settings → Appearance → Auto margin, which ships as the site config's autoMargin), or for a whole site with --stackables-section-gap: 0px.
Add this to your global stylesheet so no section can ever widen the page:
html, body { max-width: 100%; overflow-x: hidden; }Theming
Brand colours, fonts and button styling come from CSS variables. Set them with ThemeProvider:
import { ThemeProvider } from 'stackable-components';
<ThemeProvider theme={{ primary: '#e11d48', containerWidth: '1280px', fontFamily: 'Inter, sans-serif' }}>
{children}
</ThemeProvider>Or set the variables yourself in CSS — --stackables-primary, --stackables-container-width, --stackables-font-family, and the --stackables-btn-* family.
Style hooks — global overrides
Every component marks its common parts with stable, unstyled class names, so a site can restyle one kind of thing everywhere from its own stylesheet — every button, every section heading, every card — without forking a component. The library puts no CSS on these classes (the project typography settings aside, see below); they exist to be targeted.
| class | marks |
|---|---|
| sk-<component> | the component's root, its export name in kebab case: sk-faq, sk-hero-banner, sk-pricing-spread-card (not on Typography, whose name is taken by the ThemeProvider's sk-typography scope) |
| sk-header · sk-footer | the root of a site header (nav bar) · site footer component, alongside its own sk-<component> |
| sk-eyebrow | the small label above a section heading ("PHARMACY SERVICES") |
| sk-heading | a section's main heading |
| sk-subheading | a secondary heading or subtitle in the section header |
| sk-text | body copy — a section's description or intro paragraph |
| sk-btn | anything drawn as a button (filled, outlined or ghost), <a> or <button> |
| sk-btn--primary · sk-btn--secondary | with sk-btn: the main call to action · the alternative one (outline / ghost / second button) |
| sk-link | a text link in content — "Learn more →", "View all", a link inside copy |
| sk-nav-link | a header or footer menu link (dropdown links included) |
| sk-logo | the brand logo / wordmark, image or link |
| sk-card | one repeated item: a card, tile, plan, testimonial, team member, step, FAQ item |
| sk-card__title · sk-card__text | that item's title · its body text |
| sk-media | a content image or video (not icons) |
| sk-badge | a small tag, pill or label on content ("New", "Save 20%") |
| sk-form · sk-input · sk-label | a form · its inputs, selects and textareas · their labels |
| sk-list · sk-list-item | structural, not a style hook: the wrappers the runtime renderer (and a generated static page) puts around a page-level repeatable field and each of its items, carrying the Live Preview list tags; unstyled, and PageLayout's auto spacing looks through them |
Put overrides in the site's global stylesheet, outside any @layer: the components' Tailwind utilities live in @layer utilities, and unlayered CSS beats layered CSS whatever the specificity, so no !important is needed.
.sk-btn { border-radius: 0; letter-spacing: 0.08em; }
.sk-btn--primary { box-shadow: 0 6px 20px rgb(0 0 0 / 0.15); }
.sk-heading { font-family: "Playfair Display", serif; }
.sk-card { border-radius: 1.25rem; }
.sk-faq .sk-card__title { font-weight: 700; } /* scoped to one component */Two limits. A colour an editor picks in Contentstack (a background colour, a button colour field) is applied as an inline style, which beats any stylesheet — override those with !important, or change the field. And the project typography settings (ThemeProvider typography) already target .sk-btn and .sk-link for their button and link fonts. The body text transform (typography.body.transform) applies to body text only — p, list items that hold no other role, dd/dt, blockquote, figcaption, table cells, sk-text, sk-card__text (TYPOGRAPHY_BODY_SELECTOR) — never to the wrapper, so it doesn't inherit into headings, buttons, eyebrows, badges, labels or menu links: inside body text those keep their own setting (heading / button transform), else none. A link inside a sentence follows the sentence.
Contentstack Live Preview
Every component accepts a $ prop carrying Contentstack's edit tags, so entries stay click-to-edit in Live Preview and Visual Builder. Run addEditableTags(entry, contentTypeUid, true, locale) from @contentstack/utils on the entry and spread it onto the component — the renderer (StackablesEntry / StackablesChrome) does this for you on runtime sites:
<FAQ heading={entry.heading} faqs={entry.faqs} $={entry.$} />The tags follow the shape addEditableTags produces: an object's $ holds one tag per direct field ($.heading, $.faqs) plus one per list item by index ($.faqs__0), and every nested object carries its own $ (faqs[i].$.question, cta_button.$.text, link.$.title). Components read them that way: {...$?.heading}, {...item.$?.question}, {...group?.$?.field}, {...$?.['tags__' + i]} for a list of plain strings, and {...linkTags(link)?.title} for a link's title. The EditTags type (and its doc comment) in types.ts is the contract; the $ of an item or group is typed on that item's interface. A hand-written component that reads $?.items?.[i]?.title gets no tag — that path does not exist.
Repeatable fields also carry list tags, which is what lets the Visual Builder add, move and delete items: the element containing the items gets {...$?.items} and each item's root gets {...$?.['items__' + i]} (original index). Components do this on their own list markup. For a page's own repeatable fields (modular blocks, repeatable groups, components and references) StackablesEntry emits <div class="sk-list"> / <div class="sk-list-item"> wrappers with those tags; an empty modular blocks field in the preview renders as an empty box with the builder's visual-builder__empty-block-parent class (VB_EMPTY_BLOCK_PARENT_CLASS), so the first block can be added. Only modular blocks get that class.
Contentstack Studio
Every component can be placed on Contentstack Studio sections and templates. stackable-components/studio (its own entry, so a site without Studio never loads the Studio SDK — @contentstack/studio-react is an optional peer) registers them with Studio from a manifest: the component's content model uid (Studio's type), its export name, and its Contentstack field schema, which becomes the component's Studio props (studioPropsFromSchema — text → string, select → choice (a numeric dropdown too: Studio's only dropdown type, string options — the registration hands the component the number back, '10' → 10; Studio SDK 2.0.1 rejects a CMS number bound to a choice prop and falls back to the static/default value, so bind numeric dropdowns to a text field or set them statically), file → imageurl (a bound asset arrives as its URL; the registration hands the component { url }), link → { title, href }, group → object, repeatable → array, sk_* platform fields left out):
import 'stackable-components'; // loads every component into the registry
import { registerStackablesComponents, studioManifestFromSite } from 'stackable-components/studio';
// From a Stackables site config's component map + the stack's global fields (a runtime site)…
registerStackablesComponents(studioManifestFromSite(config.components, globalFields));
// …or from a list written at build time:
registerStackablesComponents([{ id: 'faq', importAs: 'FAQ', name: 'FAQ', category: 'Content', schema }]);Call it after studioSdk.init and before <StudioCanvas /> / <StudioComponent /> mount; Studio skips a type that is already registered, so calling it again is harmless. Components are registered with wrap: false: withSectionWidth takes Studio's studioAttributes and className onto a root element, and folds Studio's $heading-style edit-tag props into the $ object components already read, so no component needs Studio-specific code.
A site's own component — passed as components (by the library export name it replaces) or componentsByUid (by content model uid), the overrides a runtime site keeps in src/components/overrides.js — gets the same treatment without being wrapped in withSectionWidth: registerStackablesComponents registers it inside a host element (withStudioHost) that takes studioAttributes, className and the text style groups, so it is selectable on the canvas and styled by the Design tab while it renders only its content props (Studio's $field props and container_width / container_cap reach it as before). The host is a plain block div — not display: contents, which would leave the Section group's spacing, background and border nothing to land on — and outside Studio it adds no element at all. Not wrapped: library components, anything wrapped in withSectionWidth, and a component marked as taking those props itself — the opt-out for one that spreads studioAttributes and className on its own root:
import { markStudioHost } from 'stackable-components'; // also exported by stackable-components/studio
function PromoStrip({ studioAttributes, className, heading }) {
return <section {...studioAttributes} className={className}>{heading}</section>;
}
export default markStudioHost(PromoStrip); // or PromoStrip.stackablesStudioHost = trueA thin pass-through like (props) => <HeroBanner {...props} /> needs no mark: the host takes Studio's props, and HeroBanner, receiving none, renders without a second wrapper.
The Design tab works the same way, with nothing per component. registerStackablesComponents also registers the site's design tokens and design classes (pass design: { theme, typography } — what ThemeProvider renders with — so the panel's colour and font pickers offer the site's own values), and gives every component five style groups: Section (className on the wrapper's root element: spacing, background, border, visibility, and the design classes — sk-surface-ink / -primary / -soft, sk-headings-body-font / -accent-font, sk-text-heading-font, sk-headings-uppercase / -tight, sk-text-center, all in styles.css and working through the theme variables), and Headings, Body text, Buttons, Links (typography; the wrapper reads the rules Studio compiled for each group back out of the document and re-targets them at the section's style hooks — sk-heading/sk-card__title, sk-text/sk-card__text/sk-subheading/sk-eyebrow, sk-btn, sk-link/sk-nav-link — with the plain tags as fallback, and the Section group's object-fit reaches the section's media — components/Layout/studioStyles.ts). Keep the hooks on new components: they are what the Design tab styles. Static sites vendor src/studio/design.ts with the rest.
The palette is grouped by project: <project> · Atoms (Heading, Text, Eyebrow, Button, Link, Image, Video, Icon, Badge, Divider, Spacer, Stat, Price, Rich Text — src/studio/atoms.tsx), <project> · Layout (Container, Stack, Grid, Columns, Card, Center, Overlay, Sticky Bar — slot containers, src/studio/layouts.tsx) and <project> · Components (the project's own catalog components). Atoms and layouts ship with the library and register with every site (registerStackablesComponents(manifest, { palette: projectName }); atoms: false leaves them out); they are plain elements styled by the site's theme and hooks, take Studio's attributes on their own root (no section wrapper, so a heading in a Stack is just a heading), and only Container takes part in the page-width contract and auto spacing. Thumbnails are inline SVGs (src/studio/thumbnails.ts). Every layout control that is about layout — Grid columns, Stack direction/gap/alignment, Columns split, Container and Card padding, Center width, Overlay height, the Spacer's height — is a Studio design prop: a choice keyed by the CSS property it sets (gridTemplateColumns, gap, flexDirection, paddingBlock…) with design: true, which the editor sets per breakpoint through the canvas device switcher (4 columns on desktop, 2 on tablet, 1 on phones). Studio hands the component one generated class per prop, media queries inside, and the layout puts it on its root; :where(.sk-studio-*) rules in styles.css are the look before anything is set (Grid and Columns auto-fit, so they collapse on phones on their own). A component of your own gets the same per-device control by registering such a prop and applying the class it receives.
Compatibility
A deployed stack keeps the content types it was exported with, while a generated site installs the newest 1.x of this library on every build. So the library reads every shape a stack can still hold, and never drops an export in a minor: a superseded contract or renderer export stays, marked LEGACY in its header, until the next major. The full rule and the per-change checklist live in the Stackables repo's .claude/skills/stackables-schema-change skill (deployment-app half: its stackables-lib-upgrade skill). A schema change that cannot be read both ways is a major bump, and the deployment app's generator floors move with it.
| Since | Change | Still read / exported for older stacks and tools | Removed in |
|---|---|---|---|
| 1.8.0 | A link is a page reference — reference_to: ['page'] in the catalog, resolved to the project's page types on export by withReferenceTargets (contract/references.ts), read with pageHref / hasPage / pageTitle | pageHref also reads the old Link { title, href }, { title, url } and a bare string; resolveLinkRefs (renderer/links.ts, run by StackablesEntry and StackablesChrome) still folds a pre-1.8.0 stack's sk_<link>_ref into its link; contract/links.ts (withLinkRefFields, withPlacementLinkRefs, linkRefUid…) stays exported for the deployment app | 2.0 |
| 1.8.2 | StackablesEntry renders nothing for a BLANK section (isBlankSection: every content field empty) that sits inside a group — before, only a top-level blank section was skipped and a blank group member rendered as an empty shell. Needed so a Personalize entry variant can take a section in a group off for its visitors | Behaviour only: no export, prop or entry shape changed; a section with any content renders exactly as before, and Live Preview / Visual Builder still show a blank one so it can be filled in | — |
| 1.8.0 | A site config page may list urls — exact addresses of its entries its urlPattern doesn't cover (the first entry of a page that became /promos/:title keeps /promos); buildRoutes adds an all-static route for each | Additive and optional: a config without urls builds exactly the routes it did before; no export renamed or removed | — |
TypeScript
Full type definitions ship with the package:
import type { HeroBannerProps, SectionWidth, StackablesTheme } from 'stackable-components';Each component exports its own props interface (FaqProps, PricingProps, …), and every component additionally accepts container_width and container_cap.
License
MIT — a Contentstack Solutions project.
