Layouts
Layouts are reusable view structures with named slots — insertion points where content is projected via React portals. They are created with makeLayout and consumed via ScreenWithLayout in module screen definitions.
Source: frontend/shared/murray/src/utilities/Layout.tsx
Creating a layout
import { makeLayout, type LayoutDefinition, type LayoutUtilities } from "murray/utilities";
const myLayoutDef: LayoutDefinition<{ children: React.ReactNode; titleKey: string }> = {
Component: ({ children, titleKey, Slot }) => (
<div>
<header>
<h1>{titleKey}</h1>
<Slot name="actions" />
</header>
<main>{children}</main>
</div>
),
slots: ["actions"],
};
export const MyLayout = makeLayout("MyLayout", myLayoutDef);
makeLayout(displayName, definition) returns a Layout component with a static SlotContent property for content injection.
LayoutDefinition properties
| Property | Type | Required | Description |
|---|---|---|---|
Component | ComponentType<LayoutDefinition.Properties & LayoutUtilities> | Yes | — |
slots | string[] | No | — |
LayoutUtilities
| Property | Type | Required | Description |
|---|---|---|---|
Slot | ({ name }: { name: string }) => ReactNode | Yes | — |
Using a layout in a screen
Screens reference layouts via ScreenWithLayout:
const myFeature: Module<MyScreens> = {
name: "my-feature",
screens: {
myPage: {
path: "my-page",
screen: {
layout: MyLayout,
props: {
children: <MyPage />,
titleKey: "My Page",
},
},
when: "logged-in",
},
},
};
ScreenWithLayout properties
| Property | Type | Required | Description |
|---|---|---|---|
layout | unknown<Properties> | Yes | — |
props | Properties | Yes | — |
Slots
Slots let child content project into named placeholders defined by the layout, using React portals.
- Declare slot names in
LayoutDefinition.slots - Place
<Slot name="..." />in the layout component where content should appear - Inject content from children using
Layout.SlotContent
// Inside a page rendered within MyLayout
const MyPage = () => (
<div>
<MyLayout.SlotContent name="actions">
<Button>Create</Button>
</MyLayout.SlotContent>
<p>Page content here</p>
</div>
);
If a slot doesn't exist or SlotContent is used outside a layout context, it silently renders nothing.
Real-world example
CustomerDashboardPageLayout (frontend/shared/global-customer-dashboard/shared-layout/CustomerDashboardPageLayout.tsx) is a production layout with actions and description slots, tabs, search, and filters.
Naming convention
Components created with makeLayout own an entire page and are consumed via ScreenWithLayout. To distinguish them from plain React layout components (reusable sections within a page), follow this convention:
| Type | Suffix | Created with | Example |
|---|---|---|---|
| Page-level | PageLayout | makeLayout() | CustomerDashboardPageLayout |
| Section-level | Layout or descriptive name | Plain React component | TwoColumnLayout |
Rules:
- The
PageLayoutsuffix is reserved formakeLayout-based layouts consumed viaScreenWithLayout. - Plain React layout components (sections, wrappers, grids) must not use the
PageLayoutsuffix.