@pantheon-systems/p1-internal-components
v0.0.3
Published
Components and Puck blocks shared between Pantheon's internal P1 sites, built on PDS
Maintainers
Keywords
Readme
@pantheon-systems/p1-internal-components
This package holds components and Puck blocks shared between Pantheon's internal
P1 sites. They are built on PDS (@pantheon-systems/pds-toolkit-react).
It is published to npm as a public package, from this internal repo (visible to the pantheon-systems org only).
Using it in a site
1. Install it:
npm install @pantheon-systems/p1-internal-components2. Install its peers if the site doesn't already have them. They are peer dependencies, so a site never ends up with two copies of any of them:
| Peer | Version | Why |
| --- | --- | --- |
| react, react-dom | 19 | |
| @pantheon-systems/pds-toolkit-react | 2 (>=2.0.0-beta.14) | every component is built on PDS |
| @puckeditor/core | 0.21 to 0.24 | the blocks are Puck ComponentConfigs |
| next | >=16 | links go through next/link |
| @pantheon-systems/p1-media | >=0.5.2 | the Image, Video and Steps blocks' media fields and rendering |
The media fields are the p1-media field type, which the site's editor registers with p1-media's
createMediaPlugin. Media is served from the site's media CDN, whose origin the blocks read from
NEXT_PUBLIC_MEDIA_BASE_URL. A site that does not set that variable passes the origin to the block
factories instead:
import { createImageBlock } from "@pantheon-systems/p1-internal-components/content-image";
components: { ...internalBlocks, ImageBlock: createImageBlock({ mediaBaseUrl: MEDIA_ORIGIN }) },createVideoBlock and createStepsBlock take the same option. With neither, a media value renders nothing
(p1-media fails closed on an origin it cannot check), while a plain URL saved before a field became a media
field still renders.
3. Register the blocks in puck.config.tsx:
import { internalBlocks, internalCategories } from "@pantheon-systems/p1-internal-components/puck";
export const config = {
categories: { ...internalCategories /* , the site's own */ },
components: { ...internalBlocks /* , the site's own */ },
};Blocks
Each block is registered under the key below, in internalBlocks. The key is what Puck saves in a page's
data, so it never changes. The keys are the ones p1-docs used before the blocks moved here.
| Key | Component (subpath) | What it is |
| --- | --- | --- |
| HeadingBlock | ContentHeading (/content-heading) | h1 to h4, edited in place; h2 and h3 get an id from their text |
| ParagraphBlock | ContentParagraph (/content-paragraph) | rich-text body copy, with a link editor |
| CodeSampleBlock | CodeSample (/code-sample) | PDS CodeBlock with a copy button |
| NoteBlock | ContentNote (/content-note) | info, warning, critical or success callout (PDS SectionMessage) |
| TableBlock | ContentTable (/content-table) | read-only table (PDS Table); cells allow a, code, strong, em |
| StepsBlock | ContentSteps (/content-steps) | numbered steps (PDS StepList), each with optional code, screenshots and a note |
| PrerequisitesBlock | ContentPrerequisites (/content-prerequisites) | "Before you start" list in a PDS Panel |
| ImageBlock | ContentImage (/content-image) | media library image, shown whole, with a caption |
| VideoBlock | ContentVideo (/content-video) | YouTube, Vimeo or Wistia (PDS VideoEmbed), or a self-hosted mp4 |
| BreadcrumbsBlock | PageHeader (/page-header) | breadcrumb trail (PDS Breadcrumb), title and lede |
| HeroBlock | PageHero (/page-hero) | full-bleed band with a backdrop, a nav slot and a content slot |
| SectionBlock | PageSection (/page-section) | centred column with a content slot, in the hero's rhythm |
| LinkCardsBlock | LinkCards (/link-cards) | a row of linked PDS Cards, plain or feature |
Every block's defaults are neutral placeholders. A site that wants its own starting copy overrides
defaultProps where it registers the block: NoteBlock: { ...noteBlock, defaultProps: { ... } }.
The helpers the blocks share are exported too, from /shared, for a site's own blocks: safeHref,
slugify, SmartLink, proseRichTextField and RichTextLinkControls (a Link control for Puck's rich-text
menus, which ship none), mediaImageField and resolveMediaImage.
Spacing
The blocks set no margin around themselves. Where a block's element has a browser default margin (a
heading, a figure), it is reset at zero specificity (:where(...)), so any rule of the site's wins
whatever order the stylesheets load in. The space between blocks belongs to the site, which sets it on
the blocks' root classes:
.content-heading (plus .content-heading--1 to --4) .content-paragraph .code-sample
.content-note .content-table .content-steps .content-prerequisites
.content-image .content-video .page-header .page-hero .page-section .link-cardsFor example: .my-article > :is(.content-paragraph, .code-sample, .content-note, .content-table) { margin-block-start: var(--pds-spacing-l); }.
Two exceptions, both inside a block rather than between blocks:
- Hero and Section stacks. What is dropped into a Hero's or a Section's slot is spaced by the stack
(
.page-hero__stack,.page-section__stack), with tighter spacing under a heading. - Inside a step. A step's code sample and note are spaced by the step, and lose any margin a site
gives
.code-sampleor.content-note.
Two custom properties set accents: --page-hero-link-accent (the underline of links in hero copy) and
--link-cards-accent (the icon disc on feature cards, PDS's highlight colour by default).
Layout
src/<name>/
<name>.tsx the component ("use client" — PDS ships no directives)
<name>.block.tsx its Puck ComponentConfig: fields, defaults, render
<name>.css plain CSS on PDS tokens (var(--pds-*)), classes prefixed with the component name
<name>.stories.tsx Storybook story
index.ts what the component's subpath exports
src/shared/ helpers the blocks share (links, rich text, media), exported as /shared
src/puck.ts every block, for a site to spread into its Puck configEach component is a subpath, for example @pantheon-systems/p1-internal-components/code-sample. A page
therefore only pulls in what it uses.
npm run build compiles src/ into dist/, one module per source file, so each component keeps its
"use client" directive and CSS import. Only dist/ is published. Relative imports in src/ carry a .js
extension (./code-sample.js) because the published ESM needs one; TypeScript and Storybook resolve them to
the source.
Developing against a site
Work on a component in this repo's Storybook. To try it in a site, install a packed copy of the package:
npm pack # in this repo: writes pantheon-systems-p1-internal-components-<version>.tgz
npm i ../p1-internal-pantheon-components/pantheon-systems-p1-internal-components-<version>.tgz # in the siteUse a packed copy, not npm link or a file: link to this folder. Turbopack does not resolve files outside
the site's root. A link would also load this repo's own development copies of React and PDS next to the
site's, and two copies of React break hooks.
Releasing
Releases publish from GitHub Actions (.github/workflows/publish.yml) through npm trusted publishing. There
is no npm token.
- On a branch, bump the version:
npm version patch --no-git-tag-version(orminor, orprerelease --preid=betafor a beta, which publishes under thenexttag instead oflatest). - Add the release to
CHANGELOG.md, and merge the PR. - Tag the merge commit on
mainand push the tag:git tag v0.0.2 && git push origin v0.0.2.
The workflow checks that the tag matches package.json, then typechecks, builds, lints the package
(publint, attw), scans it for internal details (scripts/check-leaks.sh), and publishes it.
Before a release, npm pack --dry-run lists exactly what will be published.
npm trusts the workflow by its filename. Renaming publish.yml breaks publishing until an npm org admin
updates the package's trusted publisher.
