Styling and icon assets
Petal Components gives consuming Phoenix applications a shared visual layer based on Tailwind CSS and reusable SVG icons. The application loads the CSS asset, chooses or remaps its color roles, and supplies the icon assets needed by its build. This page explains that visual boundary; the wider runtime model is described in Component runtime and assets, and browser behavior is described in Browser hooks.
Visual theme
Color roles
The color system gives component styles stable semantic names instead of tying them to one brand hue. primary and secondary express brand accents, info, success, warning, and danger express status, and gray supplies neutral UI chrome. Each role has a Tailwind-style ramp from 50 through 950, so the same role can serve fills, borders, text, hover states, and dark-mode states.
The default asset supplies blue primary, pink secondary, semantic status ramps, and zinc values under the gray name. These values are fallback tokens. A consuming application can map each role to its own Tailwind hue without changing component calls or markup.
References: assets/default.css• L1-16 assets/default.css• L16-100 rules.md• L93-108
Tailwind overrides
Applications define brand colors in their Tailwind theme and map the Petal roles to those values. The override must cover the ramp stops that the application expects to use. Because the shipped values use a soft default theme, an application theme remains the source of truth even when it is placed before or after the Petal CSS import.
The gray role needs special care. Petal uses Tailwind's zinc palette under the gray name, which also affects the application's own text-gray-* and bg-gray-* utilities. An application can map gray to another neutral such as slate, or import tailwind-gray.css after default.css to restore Tailwind's original gray values.
References: assets/default.css• L1-14 assets/tailwind-gray.css• L1-26 rules.md• L95-113 UPGRADE_GUIDE.md• L124-217
Component CSS
CSS asset contract
assets/default.css is the main visual asset for the library. It defines the pc- class family and the shared component rules that give server-rendered markup its layout, type, state, color, focus, and dark-mode behavior. Components add their public classes to the rendered elements, while application classes can extend or adjust those elements through the normal Phoenix and Tailwind class interface.
The consuming application's Tailwind entry point must scan the package source and import the default asset. Scanning makes utility classes used by component markup available to the generated stylesheet; importing the asset supplies the library's component layer and fallback tokens. The application can then add its own theme and Tailwind variants at the same CSS boundary.
References: assets/default.css• L102-131 assets/default.css• L713-779 README.md• L67-73 rules.md• L27-40
Class and sizing expectations
The pc- prefix separates component contracts from application-specific classes. A component's visual variants are expressed through these classes and the shared color roles, so a change to a token can retint many components without changing their APIs. The components also expose custom classes for local layout and presentation rather than requiring an application to replace the base style system.
Icons inside fixed component controls have a defined size so consumer icon styles do not change the control's geometry. Applications can size icons that they own, but should treat component-owned icon slots and action controls as part of the component's visual contract. This matters when an application also loads a Heroicons Tailwind plugin or another global rule for .hero-* elements.
References: assets/default.css• L129-179 assets/default.css• L407-452 assets/default.css• L5600-5615 assets/default.css• L5641-5672 assets/default.css• L5747-5763 lib/…/typography.ex• L12-24
Dark-mode styling
The CSS asset includes light and dark variants for shared component states. The application chooses how its page marks dark mode and must keep that choice aligned with its Tailwind variant and color-scheme controls. The color-scheme switch can use the library's default icons or accept application-provided SVG slot content, so the visual asset boundary remains separate from the browser hook that changes the scheme.
References: assets/default.css• L181-203 assets/default.css• L730-779 lib/…/color_scheme_switch.ex• L115-127 UPGRADE_GUIDE.md• L106-110
SVG icon infrastructure
Heroicons
<.icon> is the normal icon entry point for current Heroicons. Applications pass a class-style name such as hero-home, with suffixes for the solid, mini, or micro variants. When the Heroicons asset set is available during compilation, the component can render the matching SVG; when it is not available, the library warns and leaves the class-based icon container for the consuming setup to resolve.
The package does not make Heroicons a runtime JavaScript or font concern. The consuming application supplies the supported Heroicons dependency or its compatible Tailwind icon setup. The icon accepts classes and limited global attributes, which lets the application control size, color, and accessibility state through the same HTML boundary as other visual content.
References: lib/…/icon.ex• L1-21 lib/…/icon.ex• L24-40 lib/…/icon.ex• L44-107 README.md• L224-228
Brand SVGs
Brand icons are a separate inline SVG path for providers whose logos are not part of Heroicons. BrandIcon supports a fixed set of provider names and renders the glyph with currentColor by default. A colored mode uses the provider's published colors where the icon supports it, while black brands remain tied to currentColor so they remain visible across themes.
SocialButton consumes these brand SVGs and keeps them aligned with the normal button geometry. Applications remain responsible for provider trademark and usage rules. A brand icon is decorative by default; an icon used as the only label must receive an accessible name.
References: lib/…/brand_icon.ex• L1-19 lib/…/brand_icon.ex• L46-75 lib/…/social_button.ex• L9-21 lib/…/social_button.ex• L73-103
SVG accessibility
The icon systems distinguish decorative graphics from meaningful graphics. The current Heroicons wrapper exposes aria-hidden and role attributes, while the older generated SVG components can include a title. Use an accessible name when an SVG carries meaning that is not also present in nearby text; keep decorative icons hidden from assistive technology.
References: lib/…/icon.ex• L24-40 lib/…/brand_icon.ex• L50-75 lib/…/svg.ex• L1-13 lib/…/outline.ex• L15-61
Legacy Heroicons
PetalComponents.HeroiconsV1 remains a direct SVG component surface for applications that still use the older Heroicons API. It is separate from the current <.icon> class-name interface and is available through the alias added by use PetalComponents. New consuming code should keep its icon choice consistent with the current package setup instead of mixing both surfaces without a clear migration reason.
References: lib/petal_components.ex• L19-81 lib/…/outline.ex• L1-27 lib/…/solid.ex• L1-27
Consuming application integration
Tailwind pipeline
The consuming application joins its own Tailwind entry point with the package's source and CSS asset. The integration produces one stylesheet that contains the component classes, the token defaults or overrides, and the utilities used by component markup.
The setup follows this relationship:
flowchart LR
A[Application Tailwind entry point] --> B[Scan Petal source]
A --> C[Import default.css]
C --> D[Default color roles and pc classes]
E[Application theme] --> F[Role overrides]
F --> D
D --> G[Generated application stylesheet]
B --> G
G --> H[Rendered HEEx components]
For a stock neutral palette, the application adds tailwind-gray.css after default.css. For a brand palette, it maps the semantic roles in its own theme. The application should make one deliberate choice for the gray namespace because that choice affects both Petal components and application utilities.
References: README.md• L53-73 rules.md• L27-40 assets/default.css• L1-16 assets/tailwind-gray.css• L1-14
Icon dependency boundary
The application controls the icon dependency because the component package only uses the Heroicons files when they are present in the build environment. The normal consumer path is to add the supported Heroicons dependency, scan the package source, import the stylesheet, and use <.icon> with a valid Heroicons class name. Brand icons do not need a separate asset pipeline because their SVG paths are rendered by the component.
The visual path is:
flowchart LR
A[HEEx icon call] --> B{Icon kind}
B -- Heroicon --> C[Heroicons dependency and generated SVG]
B -- Brand logo --> D[Inline BrandIcon SVG]
C --> E[CSS classes and SVG attributes]
D --> E
E --> F[Application stylesheet and page markup]
References: lib/…/icon.ex• L6-21 lib/…/icon.ex• L44-106 lib/…/brand_icon.ex• L46-75 rules.md• L60-73
Asset and runtime coordination
CSS and SVG assets usually work without a browser hook. A hook is needed only when a visual control also changes browser state, such as the color-scheme switch. In that case the application loads the CSS and registers the hook bundle as separate setup steps; the CSS supplies the states and sizing while the hook changes the DOM state. See Browser hooks for the client-side contract.
References: lib/…/color_scheme_switch.ex• L119-147 assets/…/petal_components.js• L863-927 component-runtime-and-assets.md• L62-84
Change checklist
When these files or sections are changed, remember to consider these:
- When a color role or token namespace changes, check component variants, application utility names, dark-mode values, and the optional stock-gray override together.
- When the CSS import or source path changes, check both standard and umbrella application paths because the relative dependency path is different.
- When a component class or icon size changes, check global Heroicons rules and any consumer utility that may win through the Tailwind cascade.
- When an icon name or variant changes, check the Heroicons dependency boundary, the current
<.icon>API, and any legacyHeroiconsV1call sites. - When an SVG becomes meaningful content, check its accessible name and the default decorative behavior of the icon wrapper.
- When color-scheme markup changes, check the CSS dark variant, the switch's SVG slots, and the related
PetalColorSchemehook contract.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The application imports component markup without default.css. | Components render without their shared pc- rules and fallback color tokens. | Import the asset from the application's Tailwind entry point. |
| Tailwind does not scan the package source. | Utility classes used by component markup can be absent from the generated stylesheet. | Add the package @source path and exclude showcase code when appropriate. |
The application assumes gray means stock Tailwind gray. | Petal and application gray utilities use the default zinc-based role instead. | Remap the role or import tailwind-gray.css after default.css. |
| Heroicons are missing from the build. | Current icon calls cannot resolve their generated Heroicons SVG implementation. | Add the supported Heroicons dependency or use a compatible consumer icon setup. |
| A global Heroicons rule overrides a component-owned icon size. | Fixed controls can have stretched, squashed, or misaligned icons. | Keep consumer icon rules in a compatible cascade layer and preserve the component sizing contract. |
| A meaningful icon has no accessible name. | Assistive technology receives no useful label for the control or graphic. | Add text, aria-label, or an appropriate SVG role and title. |
Key files
| File | Why to read it |
|---|---|
| assets/default.css | Defines the shared pc- component styles, color-token fallbacks, dark-mode rules, and icon sizing contracts. |
| assets/tailwind-gray.css | Defines the optional replacement for the default zinc-based gray role. |
lib/petal_components/icon.ex | Defines the current Heroicons name and build boundary for <.icon>. |
lib/petal_components/brand_icon.ex | Defines the inline provider-logo SVG surface and its color and accessibility behavior. |
lib/petal_components/social_button.ex | Shows how brand SVGs join the shared button visual contract. |
lib/petal_components/color_scheme_switch.ex | Shows how CSS color states and application-provided SVG slots meet the scheme hook. |
lib/petal_components/icons/heroicons_v1/outline.ex | Shows the legacy direct-SVG Heroicons surface and title support. |
| README.md | Shows the consuming application's Tailwind and asset setup. |
| rules.md | States the supported Tailwind source, import, and color override guidance. |