Canvas paint and className
A painted shape is not a DOM element or a React Native view. Hozo can
translate a static className into drawing props at build time, but it
does not run a CSS cascade over the scene. This is separate from styling
the outer Canvas view.
Start with a static class list
Section titled “Start with a static class list”import { Canvas } from '@hozo/canvas'export function PaintSwatch() { return ( <Canvas width={80} height={56} decorative> <Canvas.Rect x={8} y={8} width={64} height={40} className="bg-blue-500/50 border-2 border-blue-700" /> </Canvas> )}For this rectangle, the compiler maps the background to fill and the
border to stroke and strokeWidth. The colours come from your project
theme and are emitted for each backend. The example keeps the rectangle’s
required width and height explicit, separate from the paint.
Common portable starting points are fill-*, stroke-*, stroke widths,
and opacity-*. Shape-specific utilities are not interchangeable:
rounded-* supplies a radius on Canvas.RoundedRect, and text classes
such as text-sm and font-semibold belong on Canvas.Text.
Coordinates such as x and y are still scene coordinates.
Pass changing values as props
Section titled “Pass changing values as props”Use React state or data to compute paint props, rather than constructing a class string at runtime. This works even when the module is not compiled.
import { Canvas } from '@hozo/canvas'export function StatusSwatch({ selected }: { selected: boolean }) { return ( <Canvas width={80} height={56} decorative> <Canvas.RoundedRect x={8} y={8} width={64} height={40} radius={6} fill={selected ? '#2563eb' : '#cbd5e1'} stroke="#334155" strokeWidth={2} /> </Canvas> )}When a class does nothing
Section titled “When a class does nothing”CANVAS_CLASS_NOT_LOWERED means the compiler could not translate part or
all of a shape’s class list. A supported literal in the same list can still
be lowered. Do not depend on the leftover class to draw anything.
- Replace generated class strings with explicit values such as
fill,stroke, oropacity. - Do not assume CSS selectors like
hover:apply to a painted shape. Drive interaction through the scene’s event handlers and update the paint prop. - Use explicit scene units when a class requires unresolved layout, such as a percentage width. The parent view’s layout is not the shape’s geometry.
Return to 2D Canvas for geometry, interaction, and accessibility.