writing-ui-components
Skill721 starsChanged 59 days agoMITView on GitHub
Structure and abstraction rules for PostHog UI code — any React component or frontend file under `frontend/src/` or `products/*/frontend/`. Use ALWAYS before creating, moving, splitting, or restructuring a component or frontend file, extracting a shared/generic component, promoting a component to `lib/`, renaming a frontend symbol or feature, or reviewing a diff that does any of these. Covers file and folder organization (one component per file, one home per symbol, no re-export shims or barrels), when duplication becomes a component and when a generic is premature, rename sweeps and the frozen-strings contract (event names, properties, flag keys, `data-attr` values are API), UI resolution states (loading, empty, and error are three different screens), and visual discipline (design tokens, on-brand custom components with no AI slop, real interactive elements, reduced motion, Storybook). Component choice (Lemon vs quill) lives in `frontend/src/AGENTS.md` Rule 1; state management in `/writing-kea-logics`.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- PostHog/posthogword for word, first seen Oct 4, 2026
Other versions1 project uses a version of this.
Word for word · 1
- PostHog/posthog★ 40k100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository119 other files it gives its agents.
- AGENTS.mdAGENTS.md
- common/AGENTS.mdAGENTS.md
- proto/AGENTS.mdAGENTS.md
- rust/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- common/CLAUDE.mdCLAUDE.md
- proto/CLAUDE.mdCLAUDE.md
- rust/CLAUDE.mdCLAUDE.md
- .cursor/rules/django-python.mdcCursor rule
- .cursor/rules/react-typescript.mdcCursor rule
- .cursor/rules/rust.mdcCursor rule
- adding-activity-loggingSkill
- adding-api-scopesSkill
- adding-inbound-webhooksSkill
- adding-inbox-sourcesSkill
- adding-ingestion-warningsSkill
- adding-mcp-store-serversSkill
- adding-personhog-rpcSkill
- adding-product-alertingSkill
- adding-project-secret-api-key-authSkill
- adopting-generated-api-typesSkill
- analyzing-experiment-precompute-canarySkill
- analyzing-experiment-query-performanceSkill
- analyzing-insights-across-teamsSkill
- announcing-behavior-changesSkill
- auditing-llm-gateway-paritySkill
- auditing-warehouse-source-coverageSkill
- authenticating-to-clickhouseSkill
- authoring-ci-workflowsSkill
- autoresolving-pr-conflictsSkill
- building-product-empty-statesSkill
- clickhouse-migrationsSkill
- debugging-ci-failuresSkill
- debugging-local-replaySkill
- debugging-local-task-agent-runsSkill
- debugging-mcp-analyticsSkill
- debugging-signals-pipelineSkill
- debugging-table-access-deniedSkill
- depot-ciSkill
- depot-container-buildsSkill
- depot-github-runnersSkill
- developing-subscriptionsSkill
- django-migrationsSkill
- django-startup-timeSkill
- documenting-warehouse-sourcesSkill
- editing-agents-mdSkill
- establishing-code-ownershipSkill
- extending-hobby-smoke-testsSkill
- extending-personhog-test-harnessSkill
- finding-llm-gateway-migration-candidatesSkill
- fixing-flaky-testsSkill
- gating-production-deploysSkill
- gating-sensitive-actionsSkill
- generating-clickhouse-query-performance-reportsSkill
- hogliSkill
- implementing-mcp-toolsSkill
- implementing-mcp-ui-appsSkill
- implementing-warehouse-sourcesSkill
- improving-drf-endpointsSkill
- improving-mcp-toolsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 4 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 80
When they conflict, the priority order is conventions > compliant precedent > invention.
- Distinctive: line 92
One concern per file: When a file accumulates a second concern, split it: pure decision functions come out of logics and components into a …
- Very specific: line 101
Every symbol has exactly one home: No re-export shims creating a second import path, no export * from, no new barrel files.
- Very specific: line 122
The generic owns scaffolding, not variants: If the second call site needs a boolean prop to switch off half the generic's behavior …
- Distinctive: line 137
One vocabulary per concept: When a feature is renamed, sweep the code symbols completely — components, logics, files, folders, props, test …
- Distinctive: line 195
Custom components stay on brand: When the design system genuinely lacks what you need, build the new component from the system's primitives …
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Writing UI components
How UI code is structured: which file a component lives in, when duplication becomes a shared
component, what a rename must sweep, and what every component renders before its data resolves.
Applies to everything under frontend/src/ and products/*/frontend/.
Each section leads with its gate question. If you can answer the gate honestly, the details below it usually follow on their own.
Use this skill when
- Creating a new component, scene, view, hook, or frontend module
- Splitting or restructuring an existing component file, or moving one between folders
- Extracting a repeated shape into a shared/generic component, or promoting one toward
lib/ - Renaming a frontend symbol, file, or feature vocabulary
- Adding loading/empty/error handling to a view
- Reviewing a PR that does any of the above
Companion rules (do not duplicate)
This skill owns structure. These own their own territory — link to them, don't restate them:
- frontend/src/AGENTS.md — Rule 1: reuse before you create (the Lemon/quill lookup table) and Rule 2 (generated API types). Both apply before anything here.
- writing-kea-logics — business logic lives in a logic, not in React; state container choice. using-kea-disposables for anything that needs cleanup.
- writing-user-facing-copy — every visible string.
- writing-code-comments — every comment, including the pinned-string comments below.
- building-product-empty-states — scene-level
first-run empty states (the
ProductEmptyStategate). - scene-menu-bar — scene action surfaces.
- setting-feature-flags-in-storybook — stories for flag-gated components.
Survey precedent before you build
Gate: which existing scene or component are you modeling this on — and does that model itself follow these rules?
Brand consistency comes from imitation, not invention. Before building any new UI, read how
2–3 comparable scenes or components are implemented — component choice, density, layout, file
structure, logic wiring, data-attr naming — and name the precedent you're following. A new
surface that matches its compliant neighbors is on-brand by construction.
But filter precedent through the conventions. The codebase carries legacy that predates
these rules — clickable divs, hand-rolled tables, new-style-banned LemonMenus, whole-scene
ProductIntroduction panels where the scene gate belongs, re-export shims, slop styling. An existing violation is
history, not license: this skill and frontend/src/AGENTS.md outrank precedent. When the
nearest example violates the rules, follow the rules — and if the violation is cheap to fix,
convert it while you're there (references/anti-patterns.md).
Telling good precedent from bad:
- Prefer reference implementations named in skills — e.g. MCP analytics for
empty states, the migrated scenes listed in
scene-menu-bar — and recently-touched code (
git log) over untouched corners. - Prefer current primitives: quill menus/comboboxes over
LemonMenu/Radix menus, theProductEmptyStategate over a whole-sceneProductIntroduction, generated*Apitypes over handwritten ones. - When they conflict, the priority order is conventions > compliant precedent > invention. Inventing a new pattern when a compliant precedent exists is itself a reuse violation.
Code organization
Gate: can a reader find this code by name, from the folder tree alone?
- One component per file. A file exports the component its name promises — nothing else. A
private sub-piece may stay only when it is unexported, has a single consumer in the same file,
is small (a few lines of markup, not a second real component), and is inseparable from the
parent (mode-variants of the same export). The moment it's exported, it moves to its own file.
Named exports only, never
default(handbook rule). - One concern per file. When a file accumulates a second concern, split it: pure decision functions come out of logics and components into a sibling module and get tested directly (see writing-tests — extract, don't escalate); a dialog opened by a button is not part of the button. Copy stays inline where reviewers see it in rendering context — extract only long-form copy blocks or copy shared across components.
- Folders mirror the feature. A flow is a shell plus a
steps/folder; reusable pieces incomponents/; shared helpers inutils.ts(or the layer's existinghelpers.ts). The tree should read like a table of contents. Files are named after their main export (DashboardMenu.tsx,dashboardLogic.ts); noindex.ts,styles.css, or other generic names. - Every symbol has exactly one home. No re-export shims creating a second import path, no
export * from, no new barrel files. When you extract or move a module, point every consumer at the new home in the same PR and delete the old path — imports are mechanical; sweep them. The only tolerated shim is inside a multi-PR migration that crosses team ownership boundaries, marked// TODO(<issue>): delete after <migration>and removed in the final PR of the series.
The abstraction ladder
Gate: does the call site read as content, not markup?
That's the litmus for a good extraction: callers pass data and slots; the generic owns the scaffolding. Climb the ladder one rung at a time:
- Reuse before you create — frontend/src/AGENTS.md Rule 1. The design system is the brand: Lemon/quill components carry PostHog's tokens, density, and interaction patterns, so building from them is what keeps a scene looking like PostHog. Hand-rolling markup that an existing component already is counts as duplication and a branding leak.
- Duplicate before you abstract. Extract a shared component when the same shape appears three times, or twice within one feature with a third clearly coming. Below that threshold, duplication is cheaper than the wrong abstraction.
- The generic owns scaffolding, not variants. If the second call site needs a boolean prop
to switch off half the generic's behavior (
hideIcon,noBorder,variant="other"), it is not the same shape — inline the call sites again or split into two components. - Keep new generics feature-local. They live next to the feature that uses them until a
second feature needs them; promotion is one
git mvaway. The path is: feature folder →frontend/src/lib/components/(app-shared) → lemon-ui / quill (design system — needs design review). Products never import from each other: a second consumer in another product forces promotion to a shared layer, not a cross-product import. - Don't abstract single-consumer, state-coordinated components. A wrapper with one caller is indirection, not reuse — delete the layer.
Naming and vocabulary
Gate: does the name promise exactly what the thing does — and does it promise it everywhere?
- One vocabulary per concept. When a feature is renamed, sweep the code symbols completely —
components, logics, files, folders, props, test names.
git grepthe old name before calling the rename done; a codename surviving alongside the real name costs every future reader a translation step. - Names don't over-promise. A hook named for "any wizard run" must not answer only for
self-driving; a
use<X>that only works under one scene is named for that scene. If the scope is narrower than the name, rename one of them. Wire strings are frozen. The rename sweep stops at anything the outside world can see:
Frozen string Who depends on it Event names ( posthog.capture('…'))dashboards, insights, cohorts, alerts Event/person property names and values the same, plus breakdowns and filters Feature flag keys rollout state lives server-side; a renamed key is a new flag data-attrvaluesautocapture-built dashboards, Playwright selectors, QA tooling localStorage/sessionStoragekeysusers' persisted state silently resets URL paths and search params bookmarks, docs links, urlToActionhandlersPin them where they're defined with a comment stating the constraint, e.g.
// pinned: analytics event name — renaming breaks dashboards. If a wire string genuinely must change, that's a migration (emit both, backfill, deprecate), not a rename.
Resolution states
Gate: what does this component render before its data has answered?
Loading, empty, and error are three different screens. "Empty" is a verdict about resolved data; rendering it from unresolved data shows every user a flash of the wrong screen — or worse, acts on it.
// don't — the empty state renders during the first fetch
{
items.length === 0 ? <EmptyState /> : <ItemsList items={items} />
}
// do — unresolved data is its own branch, checked first
{
itemsLoading ? <Spinner /> : items.length === 0 ? <EmptyState /> : <ItemsList items={items} />
}- Branch in resolution order: loading → error → empty → content.
- Model "not yet known" explicitly in the logic —
null(a loader's natural default) or an explicit'unknown', neverfalse/[]doubling as "nobody asked yet". See state-decision.md for the logic side. - Scene-level first-run ("product not set up") belongs to the ProductEmptyState gate, not bespoke branching.
- Any submit that fires a network request disables the trigger and shows a loading state while
in flight (root
CLAUDE.mdrule) — reset in both success and error paths.
Visual discipline
- Design tokens, not hardcoded values. Colors come from tokens (
--color-*, product accents infrontend/src/styles/base.scss) — a hardcoded hex is invisible to dark mode. Spacing comes from the Tailwind scale; an arbitrary value (w-[347px]) needs a comment explaining the constraint, or it should be a scale value. - Custom components stay on brand. When the design system genuinely lacks what you need, build the new component from the system's primitives and tokens (colors, spacing, radii, typography) and match the density and tone of the surrounding scene — PostHog's product UI is dense, flat, and utilitarian. Do not fill the gap with the generic AI-generated look ("AI slop"): purple/blue gradients and neon glows, gradient text, glassmorphism and blurred orbs, oversized radii and decorative shadows, icon-tile-above-heading card grids, pill badges floating over headings, and motion that isn't tied to a state change. The test: every styling choice is traceable to a token or an existing PostHog pattern — if it isn't, it's a tell. Full catalog: references/anti-patterns.md.
- Tailwind utilities over inline styles; components over repeated class strings. A class string copy-pasted across three files is a component in disguise. SCSS is the fallback for what Tailwind can't express, namespaced BEM-style under the component's class (handbook rule).
- Interactive elements are real elements. A real
<button>/<a>— which is whatLemonButtonand quill triggers render — neveronClickon a<div>or a Card. Real elements give keyboard focus, Enter/Space activation, and autocapture for free. If the design-system component isn't semantically right, extend it; don't drop to a clickable div. Don't remove focus outlines; give motion amotion-reduce:variant. data-attron meaningful interactions. New buttons and key interactive elements get a kebab-casedata-attr(match the surrounding scene's pattern) — it's how autocapture dashboards and Playwright find them. Once shipped it's frozen (see the table above).- New presentational components ship with a story (handbook rule). Each committed story
shows a state that no other story shows. A story adds a light and a dark visual review
baseline, and every later change to that surface must re-approve both. A quarantined story's
diff does not gate the PR, so check for it and approve it by identifier
(triaging-visual-review-runs).
A story written only
to look at a change or to take a PR screenshot is scratch: keep it out of the commit.
Flag-gated components use the
featureFlagsstory parameter (setting-feature-flags-in-storybook).
Anti-patterns
references/anti-patterns.md is the convert-on-sight catalog — before/after for the rules above. Read it when reviewing UI diffs.
Before you open the PR
- New UI is modeled on named, compliant precedent — violating neighbors were not copied
- Every new file exports what its name promises — one component each, named exports
- No new re-export shims or barrels; moved symbols' consumers all updated, old paths deleted
- New generics: call sites read as content; no variant booleans; feature-local unless a second feature exists today
- Loading, empty, and error all reachable and distinct; empty never renders from unresolved data
- No hardcoded colors; arbitrary Tailwind values justified or replaced
- Renames swept (
git grepthe old name returns nothing); wire strings untouched and pinned - New presentational component has a story; every committed story shows a distinct state, and no scratch story is committed
- Typecheck/lint cadence per frontend/src/AGENTS.md —
full check once at the end,
pnpm --filter=@posthog/frontend fixbefore finishing
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

