Introducing a new way to review your PRs.

Read the announcement

petalframework / petal_components

Phoenix + Live View HEEX Components

View on GitHub

24 documents · Updated Sep 2, 2026

docs / petal-design-skill

Petal design skill

The Petal design skill is a small guidance package for building, styling, and reviewing Phoenix and LiveView interfaces with petal_components. It combines a component catalogue with composition patterns, theme rules, and a review playbook so an engineer can choose the right shared component and keep custom UI aligned with the same design system. See the parent page, Design skill tooling, for the wider snapshot and tooling context.

Package role

Design doctrine

The skill defines how Petal UI should be composed rather than adding a separate design setup step. Its main SKILL.md file routes UI work to the right reference and sets the basic rules for component use, theme use, and review work. The package applies to HEEx, LiveView, Tailwind, dark mode, brand themes, and UI audits. It does not target backend-only work.

The package is versioned with petal_components. Its front matter records the component version, and its doctrine treats the bundled references as the working source for design decisions. This makes the guidance usable from a consuming Phoenix app without requiring a new design document.

References: skills/…/SKILL.md• L1-13

Reference set

The skill separates selection, composition, visual styling, and evaluation into focused references. This lets an engineer load only the guidance needed for the current task while keeping the rules connected.

ReferenceMain question it answers
references/components.mdWhich Petal component matches the requested UI?
references/patterns.mdHow should related components share state and compose into a flow?
references/tokens.mdWhich colors, radius, type, focus, spacing, and dark-mode rules apply?
references/review.mdHow should a UI change be judged and reported for design drift?
data/schemas.jsonWhat is the current component and slot contract when an example needs exact attributes?

References: skills/…/SKILL.md• L15-32 skills/…/components.md• L1-9 skills/…/review.md• L1-17

Guidance modes

Build mode

Build mode is the default for UI changes. It starts with component selection, then adds composition and styling guidance only where needed. Custom markup must follow the token reference, while data tables, filters, forms, and the Chat family must follow the pattern reference before they are wired.

The craft floor favors a Petal function component over equivalent raw HTML. It also keeps component names separate from CSS names: HEEx uses names such as <.button>, while pc- is reserved for CSS classes and styling hooks. This keeps the UI on the library’s accessibility and theme path instead of creating a parallel control.

References: skills/…/SKILL.md• L15-32 skills/…/SKILL.md• L51-60

Theme mode

Theme mode covers brand changes, dark mode, fonts, and corner shape. It treats the application theme as a shared system: semantic color ramps provide the palette, gray acts as the neutral dial, --pc-radius controls corners, and the type variables provide optional heading, body, and mono faces.

The guidance keeps a rebrand in the consuming app’s main CSS. An app remaps complete ramps instead of changing individual components, and the same ramps drive the dark material and text contrast. This keeps a brand change broad and predictable.

References: skills/…/SKILL.md• L26-28 skills/…/tokens.md• L5-21 skills/…/tokens.md• L118-146

Review mode

Review mode evaluates a change without editing it. The reviewer first records a design judgment about hierarchy, spacing, token use, and dark-mode parity. The reviewer then checks changed UI files for known drift patterns, verifies component schemas, and reports concrete P0–P3 findings with file and line locations.

The result is a findings report, not a score or an automatic gate. The order matters because the visual judgment supplies context that pattern checks cannot provide, while schema and dark-pair checks catch defects that may compile or look acceptable in one theme.

References: skills/…/review.md• L1-29 skills/…/review.md• L174-200

Component selection

Component inventory

The component reference is the first stop when a screen needs a control or content primitive. It lists public function components by family and shows the rough API shape through attribute and slot counts. The inventory covers common controls, forms, overlays, data views, navigation, content, effects, and the separately namespaced Chat family.

The inventory is for choosing a component, not for guessing its full API. It also records important required attributes and slots, which helps an engineer reject an incomplete choice before writing the template.

References: skills/…/components.md• L1-9 skills/…/components.md• L42-89 skills/…/components.md• L219-359

Schema resolution

After selection, the skill resolves the component’s exact attributes and slots through a three-step ladder: the Petal MCP server, the bundled schema snapshot, or the component source in the dependency. This separates the product decision, “which component fits,” from the contract decision, “which options are valid.”

The versioned snapshot is the local fallback when MCP is not connected. The skill tells the engineer to report that condition once, continue with the snapshot, and avoid blocking the task. This protects UI work from stale training data without making the external service a hard dependency.

References: skills/…/SKILL.md• L34-49 skills/…/review.md• L135-157

Component naming

The package makes naming part of component selection because a wrong name can produce code that does not compile or that selects the wrong contract. Core components are imported through use PetalComponents, while the Chat family is intentionally namespaced as PetalComponents.Chat to avoid generic-name conflicts.

The same rule explains several high-value choices: combo_box is the searchable select, the sidebar is a family of named parts rather than one <.sidebar>, and new dropdown work uses side and align rather than older placement names. These distinctions keep copied examples aligned with the public API.

References: lib/petal_components.ex• L1-17 lib/petal_components.ex• L19-102 skills/…/patterns.md• L119-127

Composition patterns

Shared query state

The patterns reference treats query state as the link between browsing surfaces. A single PetalComponents.DataTable.State can drive both a filter bar and a data table, so a change from either surface updates the same sort, filter, search, page, and page-size view.

This pattern keeps the UI and query layer interchangeable. A list engine can serve local data, and a later database query can consume the same state without changing the page composition. Link mode puts that state in the URL, while event mode sends the same operation vocabulary to a LiveView or LiveComponent.

The relationship is summarized below.

flowchart LR
    User[User action] --> Surface[Filter bar or data table]
    Surface --> State[Shared table state]
    State --> Engine[Query engine]
    Engine --> Rows[Rows and updated state]
    Rows --> Surface
    State --> URL[URL in link mode]

References: skills/…/patterns.md• L5-27 skills/…/patterns.md• L29-63

State boundaries

The guidance keeps query state separate from UI state. Sorting, filtering, searching, paging, and page size belong to the shared table state. Selection, column visibility, and column order belong to UI events and must be handled separately.

This boundary prevents a table’s display preferences from leaking into shareable query URLs. It also calls out a silent failure: the table state handler ignores UI operations by design, so a page that enables selection or column controls must provide the matching UI-state handling.

References: skills/…/patterns.md• L65-83

Form and chat composition

For forms, the pattern reference starts with the field layer. A field combines the label, control, help text, and error state for the common case, while standalone input primitives support custom layouts. For chat, the conversation surface, message content, composer, and message satellites form a named composition rather than a set of unrelated controls.

The package uses these patterns to preserve behavior across surfaces. Form bindings remain compatible with Phoenix forms, and Chat content can add sources, attachments, tool traces, actions, errors, or follow-up suggestions without rebuilding the message shell.

References: skills/…/patterns.md• L85-105

Token system

Semantic ramps

The token reference defines seven semantic color ramps: primary, secondary, info, success, warning, danger, and gray. Components and custom markup use ramp names and stops instead of literal palette families, so an app can change its neutral or brand hue in one theme layer.

The gray ramp is a semantic neutral dial. It may use zinc by default or be remapped to another neutral family by the app. This keeps component chrome consistent when the product changes its neutral tone.

References: skills/…/tokens.md• L5-29

Shared visual knobs

The skill uses a small set of shared rules for visual consistency. --pc-radius controls component-adjacent corners, the type variables control optional text faces, and the focus recipe provides a common visible keyboard ring. Multi-line surfaces use a radius clamp so a pill value does not become an awkward ellipse as content grows.

The rules also define a dark ghost material based on alpha versions of gray-400. Light surfaces, dark translucent chrome, text emphasis, borders, and focus states therefore follow a small grammar instead of a new color decision in every component.

References: skills/…/tokens.md• L31-58 skills/…/tokens.md• L60-106

Custom markup

Custom markup is allowed when no shipped component fits, but it must read the same tokens as Petal components. The reference covers paired light and dark colors, neutral surfaces with semantic accents, shared radius, focus rings, elevation, motion, and tap-target growth.

This makes custom UI a compatible extension of the library rather than a competing style system. The guidance also treats Tailwind v4 as a prerequisite because the @theme ramps and related token behavior depend on it.

References: skills/…/SKILL.md• L60-105 skills/…/tokens.md• L108-165

Review evaluation

Drift checks

The review playbook turns design judgment into a repeatable set of checks. It looks for literal neutral palettes, forced CSS overrides, hand-rolled overlays, incorrect component prefixes, old dropdown spellings, broken animation properties, raw controls where components exist, missing dark pairs, invalid component attributes, and other known drift signals.

Each result is classified as missing-token, one-off value, conceptual mismatch, or local defect. Severity ranges from P0 for a broken or unusable surface to P3 for polish, with a support-impact tie-break for issues that users would report.

References: skills/…/review.md• L31-133 skills/…/review.md• L174-197

Review output

The expected review output starts with the written judgment, then groups findings by severity, and ends with counts. Each finding names the severity, file and line, drift class, defect, and proposed fix. The reviewer does not change files unless the requester asks for fixes.

This format keeps the evaluation useful to both the author and the maintainer. It explains why a change drifts from the system and gives a direct repair path without hiding the original design judgment behind an automated result.

References: skills/…/review.md• L19-29 skills/…/review.md• L174-200

Snapshot lifecycle

Generated references

The schema snapshot and component inventory are generated from compiled component metadata. The generator also collects curated, compile-checked showcase examples and attaches each example to the component it actually renders. The result gives the skill both a compact selection list and a local contract source for exact component use.

The generator excludes showcase modules from the public component catalogue and keeps special handling for the namespaced Chat family. This preserves the distinction between examples used to teach a component and components that an application can call directly.

References: lib/…/petal.gen.skill_snapshot.ex• L1-24 lib/…/petal.gen.skill_snapshot.ex• L64-84 lib/…/petal.gen.skill_snapshot.ex• L153-183 lib/…/petal.gen.skill_snapshot.ex• L214-227

Release consistency

At release time, one generator run refreshes the schema snapshot, component inventory, and version marker in SKILL.md. JSON keys and component order are deterministic, so a generated diff shows schema changes instead of toolchain order changes.

The snapshot tests protect both directions of the contract. They check that the package version appears in every marker, that stored attributes and slots match live modules, that new live components are not omitted, that Chat examples stay namespaced, and that every reference named by SKILL.md exists.

References: lib/…/petal.gen.skill_snapshot.ex• L263-301 lib/…/petal.gen.skill_snapshot.ex• L350-368 test/…/skill_snapshot_test.exs• L4-28 test/…/skill_snapshot_test.exs• L28-115 test/…/skill_snapshot_test.exs• L117-179

Change checklist

When these files or sections are changed, remember to consider these:

  • Update SKILL.md routing when a new work mode or reference file changes how engineers should choose guidance.
  • Regenerate data/schemas.json and references/components.md when public component attributes, slots, required flags, or component names change.
  • Keep the petal_components_version marker, schema version, and inventory version aligned with the package release.
  • Keep Chat examples and inventory entries namespaced when Chat component names or import behavior changes.
  • Recheck the review playbook when a new design-drift class or token rule becomes part of the design contract.
  • Preserve the shared token vocabulary when changing brand or dark-mode rules; a partial ramp remap can create mismatched states.

Important failure modes

TriggerConsequenceGuard
A component is chosen from memory instead of the inventory and schema ladderThe template can use an unknown attribute or an old enum valueResolve the schema through MCP, the bundled snapshot, or source before adding non-default attributes
A public component changes without snapshot regenerationThe skill recommends a stale contract or omits a new componentRun mix petal.gen.skill_snapshot; snapshot tests compare the stored and live component shapes
A custom surface uses a literal neutral palette or lacks a dark pairThe surface ignores the app’s neutral dial or becomes unreadable in dark modeUse semantic ramps and the paired dark rules from references/tokens.md
A Chat example is copied as a bare dot-callThe consuming module fails because Chat is not part of use PetalComponentsAlias PetalComponents.Chat and use namespaced calls
A review reports only grep resultsA visual hierarchy or spacing defect can pass the mechanical checksWrite the design judgment before the drift checks
A table uses separate state for filters and dataChanges from one surface do not update the other surfacePass one DataTable.State to both components

Key files

FileWhy to read it
skills/…/SKILL.mdDefines the package purpose, modes, schema ladder, craft floor, and staleness rule
skills/…/components.mdProvides the generated component inventory used for initial component selection
skills/…/patterns.mdExplains shared state and composition for tables, filters, forms, overlays, and Chat
skills/…/tokens.mdDefines semantic color, radius, type, dark-mode, focus, spacing, and theme rules
skills/…/review.mdDefines the judgment, drift checks, severity model, and review report format
skills/…/schemas.jsonSupplies the versioned local component contract used when MCP is unavailable
lib/mix/tasks/petal.gen.skill_snapshot.exShows how the schema and inventory are generated and versioned
test/petal/skill_snapshot_test.exsShows the release checks that keep the skill references aligned with live components
lib/petal_components.exShows the public import boundary and the explicit namespace boundary for Chat