/ng-prism:write-pluginfrom ng-prism
Guides writing ng-prism plugins with build-time hooks (onComponentScanned, onServiceScanned, onPipeScanned, onPageScanned, onManifestReady), panels, canvas overlays, custom controls, header widgets, sidebar decorations, and npm packaging.
Ships in ng-prism. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A plugin is a factory function that returns an NgPrismPlugin, registered in ng-prism.config.ts
(plugins: [notesPlugin()]). That file runs twice: in Node inside the builder, where the hooks run, and in the
browser, where the styleguide picks up panels, controls, widgets and decorations. Whatever a plugin imports at the top
level has to load on both sides.
Read version in node_modules/@ng-prism/core/package.json. Where this skill and the installed package disagree, the
package is right:
node_modules/@ng-prism/core/dist/plugin/plugin.types.d.ts.https://ng-prism.github.io/ng-prism/, served as raw Markdown you can fetch directly, e.g.
https://ng-prism.github.io/ng-prism/plugins/writing-plugins.md. The pages for this skill are listed at the end.import type { NgPrismPlugin } from '@ng-prism/core/plugin';
export function notesPlugin(): NgPrismPlugin {
return {
name: 'notes',
onComponentScanned(component) {
const variants = component.showcaseConfig.variants ?? [];
component.showcaseConfig.meta = { ...component.showcaseConfig.meta, notes: { variants: variants.length } };
return component;
}
};
}
onComponentScanned(component) runs once per component, onServiceScanned(service) once per service and onPipeScanned(pipe) once per
pipe (see below), onPageScanned(page) once per page from the config's pages (not the component pages registered in main.ts),
onManifestReady(manifest) once at the end.async is fine.@Showcase({ meta }) arrives as component.showcaseConfig.meta, a variant's as
component.showcaseConfig.variants[i].meta.component.api (ComponentApi, since 22.7.0) is experimental until 23.0.0 and may change in a 22.x minor, so
read it knowing that and keep your own data in showcaseConfig.meta, as below. It holds the type of each
input and the payload of each output (ApiTypeRef: text and links to cards), the change event of each model(), the
documented methods and the types they reach. The scan only reads it when a plugin in the config sets
componentApi: true on its plugin object (also experimental; in the Node entry, like the hooks): a plugin that reads
api, in a hook or a panel, sets it. jsDocPlugin() does, but don't rely on another plugin. It is also absent when
the scan cannot read it, on a component a hook builds from scratch and in the manifest of an older core, so check for
it. inputs, outputs and the other fields of ScannedComponent are stable.component.composition (ComponentComposition, since 22.7.0) holds what the scan read from a showcase's
template and host: { template }: variantCases (per variant, an index into cases or -1) and cases, each with
the markup as written, template, and unbound, the inputs of the subject the case does not bind. imports lists
the classes the wrapper imports besides the subject ({ name, from }), which a usage example names too. The markup
has COMPOSITION_SUBJECT_SLOT (from @ng-prism/core/plugin) at the end of the subject's start tag: a plugin that
shows the markup of a variant replaces it with the attributes it wants there, as the usage example of jsDocPlugin()
does.
It is read before the hooks run, so a hook that edits template or host afterwards changes nothing that renders,
and it is absent when no variant has one and on a component a hook builds from scratch.@Showcase({ partOf: '<selector of the parent>' }) is
a part of that component or directive and has no page of its own. onComponentScanned runs on it like on any
component, so it has inputs, outputs and, with componentApi, api. When partOf resolved,
component.parentClassName names the parent: a hook that works per page (builds, measures or photographs each
component) returns early for a component that has it. onManifestReady gets the parts nested: they are not in
manifest.components but in parts of their parent (ScannedComponent.parts, sorted by title), the same shape as
RuntimeComponent.parts. So a plugin that walks manifest.components sees parents only and reads c.parts ?? [] to
include parts, and a filter that drops a parent drops its parts too. The scan decides which parent a part belongs to:
a hook that rewrites the parent, its selector or class name included, keeps its parts on it.component.showcaseConfig.meta[<your key>], as the official plugins do. Data for the
whole library goes into manifest.meta, read in the browser with inject(PRISM_MANIFEST).meta.manifest.meta alike. Strings, numbers, booleans, arrays and plain objects arrive
as written, and a Date as a Date (since 22.8.0; before, it became {} in showcase meta and an ISO string in
manifest.meta). A function becomes undefined, and a Map, Set or other class instance becomes a plain object
of its own enumerable fields ({} for the built-ins).const { readFile } = await import('node:fs/promises')), never at the top
of the file: the same file is bundled for the browser.@Showcase and @Injectable or @Service
is a service: it is in manifest.services, never in manifest.components, and onComponentScanned never sees it.
onServiceScanned(service: ScannedService) works like the component hook (mutate or return, async is fine, plugins
chain). className, filePath, importPath, showcaseConfig, provision ('auto' | 'manual') and meta are
stable; service.api (ServiceApi: members, setup, types) is experimental until 23.0.0 and may change in a 22.x
minor, so read it knowing that and keep your own data in service.meta. Services only reach the manifest, and the
hook only runs, when some plugin has a view panel (placement: 'view') with appliesTo including 'service';
otherwise the build only counts them, without reading them, and logs a hint once per run
(ng-prism: <n> service(s) with @Showcase found, but no plugin shows services; …). navigationDecorations are not
called for services.@Showcase and @Pipe is a pipe: it is in
manifest.pipes, never in manifest.components or manifest.services, and neither onComponentScanned nor
onServiceScanned sees it. onPipeScanned(pipe: ScannedPipe) works like the service hook. className, filePath,
importPath, showcaseConfig, pipeName, pure (absent when it can't be read) and meta are stable;
pipe.api (PipeApi: transform signatures, setup, types) is experimental until 23.0.0, so keep your own
data in pipe.meta. Pipes reach the manifest, and the hook runs, only when some plugin has a view panel
(placement: 'view') with appliesTo including 'pipe', decided apart from services; otherwise the build only
counts them and logs a hint (ng-prism: <n> pipe(s) with @Showcase found, but no plugin shows pipes; …).
navigationDecorations are not called for pipes.ng-prism: plugin "<name>" failed in <hook> for …; during serve, a failed
rescan keeps the previous manifest.| Field | Definition | The component receives |
|---|---|---|
panels | { id, label, loadComponent, icon?, placement?: 'addon' | 'view', appliesTo?, listsParts?, isVisible?, badge?, keepAlive?, providers?, loadOverlayComponent? } | input activeComponent: RuntimeComponent | null, activeService: RuntimeService | null for a view panel that applies to services, activePipe: RuntimePipe | null for one that applies to pipes, activePart: string | null for a panel with listsParts |
| overlay | loadOverlayComponent on a panel, drawn over the canvas while that panel is active | input rendererService: PrismRendererService |
controls | { matchType: (input: InputMeta) => boolean, component } | inputs inputMeta and rendererService |
headerWidgets | { id, loadComponent, placement?: 'start' | 'end', order? } | nothing |
navigationDecorations | { id, icon, order?, badge: (c) => { variant: 'warn' | 'danger', label } | null } | (no component) |
Components are standalone. Load panels, overlays and header widgets lazily:
loadComponent: () => import('./notes-panel.component').then((m) => m.NotesPanelComponent). An eager component
pulls its imports into the file that also runs in Node. Controls only have component.
RuntimeComponent.meta is the whole scanned component, so the user's showcase meta is
activeComponent()?.meta.showcaseConfig.meta, and a panel reads the API at activeComponent()?.meta.api
(experimental, undefined for a component without one, and only in the manifest when a plugin sets
componentApi: true, so set it on yours).
RuntimeComponent.parts (since 22.7.0, experimental until 23.0.0) is RuntimePart[], one { meta: ScannedComponent }
per part of the component, sorted by title, with no type: the variants of the component render a part, never the
part itself. It is missing for a component without parts.
Panels for services and pipes. appliesTo: ('component' | 'service' | 'pipe')[] (since 22.7.0) says where a
panel appears, default ['component']. A service or pipe page has no canvas and offers only the panels that apply
to it, as view tabs: such a panel needs placement: 'view', since there is no addon area. An addon panel shows on
component pages only, and only when it applies to 'component'. The panel component declares
readonly activeService = input<RuntimeService | null>(null) and/or
readonly activePipe = input<RuntimePipe | null>(null) (and activeComponent if it applies to components); it is
only given the inputs of the targets it names. isVisible and badge are called for components only. Declare
placement and appliesTo in the plugin's Node entry too, not only in index.browser.ts: the build reads them from
there to decide whether any plugin shows services or pipes. The panel reads the API at activeService()?.meta.api
or activePipe()?.meta.api.
A panel that lists parts. listsParts: true on a view panel for 'component' (since 22.7.0, experimental until
23.0.0) says it shows the parts of the component (RuntimeComponent.parts). It declares
readonly activePart = input<string | null>(null), the key of the part to show (its class name, ~2, ~3, … appended
for a later part of the same class name; partKeys(parts) from @ng-prism/core/plugin lists them), and scrolls to
its block; only a panel with listsParts is given the input. activePart follows the part URL parameter and a
part's popover in the component head, which links to the first visible panel with listsParts; it goes back to
null when the component or the view changes. The link of the part already shown sets it to null for one render
and then to the part again, so scrolling whenever the input changes is enough.
The selected variant and its inputs: inject PrismRendererService from @ng-prism/core (activeVariantIndex(),
inputValues(), renderedElement(), subjectElement(), selectVariant(), updateInput()).
renderedElement() is the root of everything the canvas renders: for a variant with a template or a host: { template }
(a composition, since 22.7.0) that is the whole composition, frame and other parts included, so measuring, auditing
or capturing the picture reads it. subjectElement() (since 22.7.0, Element | null) is the showcased component or
directive inside it, the element the generated wrapper marks with data-prism-subject, and the root itself outside
a composition: read it when you mean that element, for its role, label or attributes.
PrismNavigationService.activeComponent is the selection. PRISM_MANIFEST, PRISM_CONFIG and ICON_NAMES (the valid icon values) come from
@ng-prism/core/plugin.
isVisible, badge and a decoration's badge run during change detection: keep them pure and cheap, and decide
verdicts in onComponentScanned.
A panel's badge returns { kind?: 'count' | 'issues', text, tone?: 'primary' | 'warn' | 'danger', label? } or
null (since 22.7). issues is a number of open findings, a filled pill in tone (default danger), hidden at
'0'; count is a plain muted figure. label is what a screen reader hears after the tab label. variant is
deprecated (removed in 23.0.0) and still mapped: warn/danger → issues, default → count, ok → nothing.
Grade a figure with statusFor(value, { ok, warn, direction? }) or thresholdFromTarget(target) from
@ng-prism/core/plugin (warn down to 75 % of the target, danger below), and worstTone() for several. The header
badge, the sidebar and the built-in panels grade the same way, so a plugin that does too never disagrees with them.
Show a Date (an input default, a payload, a value) with formatDateValue(date) from @ng-prism/core/plugin
(since 22.8.0): the local day, plus the time when there is one, as the Events panel and the API page show it. An
input's default as code writes it, its Dates included, comes from formatDefaultValue(value) (since 22.8.0), and
the checkerboard of transparent from checkerboardStyle() (since 22.8.0).
Panel ids are not deduplicated: prefix yours and avoid the built-in overview, controls, events and a11y.
Decoration ids are deduplicated: built-ins first (only a11y), then plugins in registration order. The first
definition of an id wins, later ones are dropped silently. The orders 10, 20 and 30 belong to a11y, visual regression
and coverage.
The first control whose matchType matches wins, in registration order. A control that keeps text of its own while
someone types drops it when rendererService().variantApplied() changes (since 22.8.0): Reset and another variant
can hand back the value it shows.
InputMeta.type is 'string' | 'number' | 'boolean' | 'union' | 'date' | 'array' | 'object' | 'unknown'. 'date'
(since 22.8.0) is a Date input, also with null or undefined, which up to 22.7.x was 'object': a control that
matches 'object' no longer gets it. For a 'date', emptyValue ('null' | 'undefined') is what an emptied control
writes, and it is missing when the input allows neither.
wrapComponent and a panel's position are in the typings, but nothing has ever read them; they are deprecated
(removed in 23.0.0). Don't use them. Where a panel appears is placement.
Since 22.7 the built-in panels share one anatomy, and the same primitives are exported from @ng-prism/core:
prism-panel-toolbar (slots [toolbarStart], [toolbarEnd]), prism-tabs (items, [(active)], size),
prism-segmented, prism-metric-card (label, value, unit, tone, statusLabel, fraction, threshold,
title), prism-list-row (selected, interactive; slots [rowBadge], [rowTitle], [rowDescription],
[rowMeta]), prism-badge (tone, variant, size, label, value), button[prismButton],
button[prismIconButton], plus toneForStatus(status) for a badge tone. Use them instead of styling your own, and
follow the rules the built-ins follow:
prism-tabs size="sm") or actions; no meta text in it, put counts,
timestamps and thresholds in tooltips.title); findings as list rows, a selected
row tinted, never a coloured left border.--prism-primary; the brand gradient is not for data.--prism-bg-surface, embeds too. Actions right in the toolbar, prismButton sm, secondary before
primary.--prism-* tokens, so the panel works in both themes; plugins/panel-design.md has a full
example. A style that has to differ per theme keys on the attribute data-prism-theme (dark or light, since
22.8.0) on <html>, for example :host-context(html[data-prism-theme='light']). data-theme is
deprecated (removed in 23.0.0); a core older than 22.8.0 sets only that one.container-type: inline-size on its root), not with media queries on the viewport.PrismMetricBadgeComponent draws it.The official plugins with build-time hooks split into a Node entry with everything and a browser entry with the runtime contributions only:
{
"type": "module",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/index.d.ts",
"browser": "./dist/index.browser.js",
"import": "./dist/index.js",
"default": "./dist/index.js"
}
},
"peerDependencies": { "@angular/core": ">=20.0.0", "@ng-prism/core": "^22.7.0-0" }
}
index.ts exports the factory with hooks and contributions; index.browser.ts exports a factory of the same name
without the hooks. Both export the same names, since they share one index.d.ts.@ng-prism/core are peerDependencies, never bundled. Start the @ng-prism/core range at the release
whose APIs the plugin uses: statusFor, the UI primitives and PanelBadge.kind exist from 22.7.0, so a plugin that
follows this skill needs ^22.7.0-0, and ^22.8.0-0 once it uses formatDateValue, formatDefaultValue, checkerboardStyle,
InputMeta's 'date' or data-prism-theme.ng add: a schematic that calls addPluginToConfig(tree, path, { importName, importFrom, call }) from
@ng-prism/core/schematics/utils, with path pointing at ng-prism.config.ts.A plugin doesn't have to be a package. Import its file from ng-prism.config.ts with the .ts extension
(import { notesPlugin } from './prism/notes-plugin.ts';) and add "rewriteRelativeImportExtensions": true to the
compilerOptions of the styleguide app's tsconfig.app.json, so the browser build accepts that path. In the builder,
Node loads the file as it is, which needs Node 22.18 or newer; without "type": "module" in the root package.json it
prints a harmless MODULE_TYPELESS_PACKAGE_JSON warning. That file and whatever it imports statically may only
use TypeScript Node can strip: import type for types, no enum, no decorators, no constructor parameter properties.
Write its own relative imports with .ts as well; Node adds no extension. Keep components behind loadComponent,
which only the browser runs. That rules out controls: a control's component is eager, so its decorator would have
to run in Node. Restart ng run <lib>:prism after changing a hook: Node caches the imported plugin module, so a rescan
doesn't reload it.
ScannedComponent, ScannedService or ScannedPipe.ng run <lib>:prism), check the hook's effect in the log and open the panel; the showcase
skill's screenshot script with --shell shows the UI.plugins/writing-plugins.md, plugins/panel-design.md, architecture/plugin-hooks.md, api/ng-prism-plugin.md,
api/plugin-ui.md, api/services.md,
api/types.md (ScannedComponent, ComponentApi, ComponentComposition, ScannedService, ServiceApi, ScannedPipe, PipeApi),
guide/services-and-pipes.mdWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
ng-prism, plugin-development, angular-styleguide, build-hooks
3 skills in this plugin
/setupUse when setting up or configuring ng-prism (@ng-prism/core) in an Angular CLI or Nx workspace - ng add, ng-prism.config.ts, the prism and prism-build targets and their options, adding an official plugin (jsdoc, box-model, figma, perf, coverage, visual-regression), theming the styleguide, publishing a library without its @Showcase decorators, or upgrading ng-prism. Not for writing showcases (skill showcase) or plugins (skill write-plugin), and not for developing ng-prism itself./showcaseUse when writing or changing an @Showcase decorator in an Angular library that uses @ng-prism/core (variants, inputs, content projection, compiled templates with host templates and imports for components that work together such as a form field with its input, components that only exist as a part of another (`partOf`), directive hosts, states and pseudo states, canvas background and layout, status, component pages, services with @Injectable or @Service and pipes with @Pipe, with their setup), when a build prints a "⚠ ng-prism:" warning, when a component, service or pipe is missing from the ng-prism styleguide or an input has no effect there, or when a showcase should be checked in the running styleguide with a screenshot. Also when someone asks for a "story" in a project that uses ng-prism instead of Storybook. Not for developing ng-prism itself.npx claudepluginhub ng-prism/ng-prism --plugin ng-prismOther plugins' skills for the same job