✦Morph

Sections and rules

A surface is a page (or part of one) your users can reshape. A section is one part of it: a card, a chart, a table, a toolbar. Users move, resize, hide and restyle sections; what's inside a section is always yours.

import { MorphSurface, Section } from "@usemorph/react";

export default function Dashboard() {
  return (
    <MorphSurface id="dashboard">
      <Grid container spacing={3}>
        <Grid size={{ lg: 8 }}>
          <Section name="Revenue"><RevenueChart /></Section>
        </Grid>
        <Grid size={{ lg: 4 }}>
          <Section name="Latest orders" keep><LatestOrders /></Section>
        </Grid>
      </Grid>
    </MorphSurface>
  );
}

Until a user customizes the page, <MorphSurface> renders your page exactly as written. It also does that if Morph can't be reached.

<MorphSurface>#

Prop
id Required. A plain string, unique in your app, e.g. "dashboard". Lowercase letters, digits, - and _.
data Optional. Data that new views may read. See Data and actions.
actions Optional. Your actions that pages may put on buttons. See Data and actions.
shell Marks your app's frame (sidebar or top bar) around every page. init tags it for you. A change to it shows on every page.
chat Include this area in the Morph box (default true).
fallback What to show while the user's page loads (default: nothing).
onError Called when loading, saving or the AI fails, e.g. to log it.

<MorphProvider> must be above it, usually in your root layout. It holds the one Morph box for everything on screen: a request can change the page, the frame, or both, and Undo takes back the whole change.

The app's frame and app-wide look#

Besides each page's content, npm init usemorph@latest tags your app's frame, the sidebar or top bar from the layout around your signed-in pages, as a <MorphSurface id="app-shell" shell>. Navigation gets keep, so users can restyle it but never lose it. It never wraps the page content: pages stay their own areas.

Users can also change the app-wide look: "bigger text everywhere", "more compact", "a warmer accent". That's saved per user as theme CSS that may only set your CSS variables (--primary, --radius…) and font settings, on the selectors where you define them. It can't select elements, so it can't hide, move or cover anything. If your colours aren't CSS variables, only font size and spacing can change app-wide.

<Section>#

Prop
name Required. What users and the AI call this part, e.g. "Revenue trend".
id A stable id. Defaults to the name in snake_case (revenue_trend). Set it if you might rename the section later.
description A sentence for the AI if the name isn't enough, e.g. "Monthly revenue, this year vs last."
styling Class names inside the section that pages may restyle, e.g. ".bar (each bar), .bar.current".
keep A rule: this part must stay on the page. See below.

name, id, description, styling and keep must be written as plain values (strings, true, { … }), because usemorph sync reads them from your code.

Rules with keep#

<Section name="Create invoice" keep>…</Section>                         // always shown and clickable
<Section name="Navigation" keep={{ topmost: true }}>…</Section>         // and above every other section
<Section name="Checkout" keep={{ aboveFold: true, minWidth: 120 }}>…</Section>
Option Means
keep / keep={true} Must be on the page, at a real size, not hidden, and nothing on top of it
aboveFold: true Visible without scrolling (top edge within the first 700px; change it with foldPx in morph.config.ts)
topmost: true The highest section on the page
minWidth, minHeight At least this many pixels

Rules are checked on screen, in the user's browser, before a page is saved. A page that breaks one is repaired or not saved.

Your layout stays your layout#

Layout components around your sections whose props are plain values, like MUI's <Grid size={{ lg: 4 }}>, a <Stack spacing={3}> or a <div className="grid">, are part of your page's layout. Morph's AI gets to use the real ones, so a customized page keeps your responsive layout and look. A component given live values (a variable, a function) isn't treated as layout; if it isn't inside a section, sync tells you.

How init picks sections#

By default, Morph's AI plans it (you're asked first): it reads each page and the components it renders, and picks the element holding the page's main content and the meaningful parts inside it. It only chooses; init applies the choices itself, and a verifier checks that the edits only add tags and that sync accepts them. Public, marketing and sign-in pages are left alone, and sign-in URLs are never tagged whatever the AI says.

With --no-ai, init uses fixed rules instead, so the same code always gets the same tags:

The tags are ordinary code: rename them, merge them, add keep. That's the intended way to fine-tune.

Server and client components#

<MorphSurface>, <Section> and <MorphProvider> are client components, and work inside both server and client components. Put them wherever your page's content is rendered:

Adding or changing sections later#