How to use petal_components in HEEx
mainOnce use PetalComponents is added to your web module, components are available as plain HEEx tags with a leading dot.
Naming Conventions
- HEEx Tags: Use
<.component_name>(e.g.,<.button>,<.modal>,<.table>). Do not use apc_prefix in the tag name. - Modules: The underlying modules are namespaced under
PetalComponents.*(e.g.,PetalComponents.Button). - CSS Overrides: Use the
pc-prefix for manual styling overrides (e.g.,pc-button,pc-modal). This is the only place thepc-prefix should be used.
Form Input Patterns
There are two ways to handle inputs:
- Bundled Field: Use
<.field type="..." />when you want the label, input, error message, and help text bundled together (ideal for standard forms). - Standalone Primitives: Use
<.text_input>,<.select>,<.checkbox>, etc., when you need to compose a custom layout.
Component Discovery
If you are unsure of the attributes or slots available, use the petal_components MCP server if available:
list_components: Returns all components with summaries.get_component <name>: Returns the full schema (attrs, slots, defaults) and a usage example.