Text, from the Building blocks group of the nertia component library.
npx shadcn@latest add https://ner.sh/r/block-text.jsonThe recipe carries this block's layout and variant; the install brings the component.
{
"registries": {
"@nertia": "https://ner.sh/r/{name}.json"
}
}npx shadcn@latest add @nertia/block-textnpm create nersh@latest my-site -- --site https://nertia.ai/components/building-blocks/element-block-text/site.json scaffolds a project from it.{
"slug": "element-block-text",
"mode": "builder",
"status": "draft",
"skinId": "zinc",
"composition": {
"id": "element-block-text",
"sections": [
{
"id": "block-text",
"instanceId": "stage-block-text"
}
]
},
"copy": {
"stage-block-text.text": "Body text",
"stage-block-text.footnoteMark": "",
"stage-block-text.textStyle": ""
}
}
import type { Section } from '../types';
import { Component } from './Component';
import { schema } from './schema';
import { meta } from './meta';
import { writeCopy } from './writeCopy';
export const blockText: Section = { meta, schema, Component, writeCopy };
import type { SectionProps } from '../types';
import { compositionEditPath } from '@/lib/composition/compositionEditableCopy';
import { Text } from '@/components/foundation';
import { DisplayTypeStyle } from '@/components/site/DisplayTypeStyle';
/**
* `textStyle` is a closed role set: {lead, eyebrow, stat, note, manifesto, body}. 'lead' is the
* larger opening paragraph on the site's lead type step. 'eyebrow' is the
* small tracked uppercase kicker above a hero heading (the typeshit comp:
* 12px/700/0.16em in the accent colour). 'stat' is the bold hero-figure
* treatment block-stat gives its number, for text nodes standing in as a
* pricing card's price. 'note' is the small muted line under a figure or a
* name (a pricing tier's one-line description, a caption), on the site's
* small type step. 'manifesto' is one paragraph set large in the heading face at a
* measured line length, the display end of the scale (DisplayTypeStyle), standing
* in for a section heading. Anything else stays body. The class lands after the
* size class so the role's declarations win at equal specificity.
*
* `footnoteMark` is an optional short mark printed straight after the text, with no space
* ("Domain registrar*"), pointing at a footnote elsewhere on the page. It is its own slot so the
* mark can change without touching the words; empty, it prints nothing, in the editor too. With
* a mark the text and the mark each carry their own edit marker, side by side, so typing over the
* text never takes the mark with it.
*/
export function Component({ copy, instanceId, overrides, editorMarkers }: SectionProps) {
const edit = (slotKey: string) => compositionEditPath(instanceId, slotKey);
// A text its owner emptied renders nothing on the page, so its wrapper collapses (`empty:hidden`)
// and leaves no box or gap; the editor keeps the placeholder to type into.
const footnoteMark = (copy.footnoteMark ?? '').trim();
// Its mark goes with it: a mark alone points at nothing.
if (copy.text !== undefined && !copy.text.trim() && !editorMarkers) return null;
const textStyle = (copy.textStyle ?? '').trim().toLowerCase();
const eyebrow = textStyle === 'eyebrow';
const stat = textStyle === 'stat';
const note = textStyle === 'note';
const lead = textStyle === 'lead';
const manifesto = textStyle === 'manifesto';
const roleClassName = eyebrow
? 'site-type-eyebrow'
: stat
? 'site-type-stat font-bold text-[var(--foreground)]'
: manifesto
? 'site-type-manifesto'
: undefined;
return (
<div data-section="block-text" data-font-body={overrides?.['--font-body'] ? '' : undefined}>
{manifesto ? <DisplayTypeStyle /> : null}
{footnoteMark ? (
<Text size={note ? 'sm' : lead ? 'lg' : undefined} muted={note} className={roleClassName}>
<span data-edit-path={edit('text')}>{copy.text || 'Body text'}</span>
<span data-edit-path={edit('footnoteMark')}>{footnoteMark}</span>
</Text>
) : (
<Text size={note ? 'sm' : lead ? 'lg' : undefined} muted={note} className={roleClassName} dataEditPath={edit('text')}>
{copy.text || 'Body text'}
</Text>
)}
</div>
);
}
import type { SectionCopySchemaField } from '../types';
export const schema: SectionCopySchemaField[] = [
{ key: 'text', label: 'Text', type: 'textarea', placeholder: 'Body text' },
{
key: 'footnoteMark',
label: 'Footnote mark',
type: 'text',
placeholder: '',
required: false,
maxLength: 3,
advanced: true,
helpText: 'A short mark printed straight after the text, such as * or a number, pointing at a footnote. Leave it empty for none.',
},
{
key: 'textStyle',
label: 'Style',
type: 'text',
required: false,
maxLength: 9,
advanced: true,
helpText:
'Lead is a larger opening paragraph, Eyebrow a small uppercase label in the accent color, Stat a large bold figure, Note a small muted line, and Manifesto one large paragraph set in the heading font that can stand in for a section heading. Body is the normal paragraph style.',
options: [
{ value: '', label: 'Body' },
{ value: 'lead', label: 'Lead' },
{ value: 'eyebrow', label: 'Eyebrow', budgets: { text: { maxLength: 24 } } },
{ value: 'stat', label: 'Stat', budgets: { text: { maxLength: 16 } } },
{ value: 'note', label: 'Note', budgets: { text: { maxLength: 60 } } },
{ value: 'manifesto', label: 'Manifesto', budgets: { text: { maxLength: 280 } } },
],
},
];
import type { SectionMeta } from '../types';
export const meta: SectionMeta = {
id: 'block-text',
displayName: 'Text',
family: 'component',
tags: ['component', 'atom', 'text', 'body'],
bucket: 'atom',
};
import type { BrandContext } from '@/lib/brandContext';
import type { CopyPlace } from '../types';
/** Small labels and figures never take a sentence, whatever their position. */
const NOT_A_LEDE = new Set(['eyebrow', 'stat', 'note']);
/** The first paragraph under the page's first heading is the brief's lede. */
export function writeCopy(ctx: BrandContext, place?: CopyPlace) {
const lead = place?.lead;
const isLede =
lead?.role === 'follow' &&
lead.nth === 0 &&
Boolean(place?.seeded.text) &&
!NOT_A_LEDE.has(place?.seeded.textStyle ?? '');
if (ctx.lede && isLede) return { text: ctx.lede };
return { text: 'Body text' };
}
The registry source and the @nersh/render renderer are MIT licensed.