Components
Canvas
Canvas exposes the browser's drawing surface with a SwiftUI-style dedicated component wrapper.
Example
Requires React 18.2+ or 19 and shared styles. See setup.
Default
Loading preview…
Code
'use client';
import type { ComponentProps } from 'react';
import { Canvas } from '@swiftuijs/ui';
export default function Example() {
const args: ComponentProps<typeof Canvas> = {
'aria-label': 'Example canvas',
height: 180,
width: 320,
};
return ((<Canvas {...args} draw={(context) => {
context.fillStyle = '#007AFF';
context.fillRect(16, 16, 288, 148);
}}/>));
}Status: adapted
Usage and limitations
- Rendering is delegated to the supplied
drawcallback. - The current implementation targets a 2D context.
API reference
| Prop | Type | Required | Description |
|---|---|---|---|
draw | (context: globalThis.CanvasRenderingContext2D) => void | No | Drawing callback invoked with a 2d rendering context when available. |
Inherits additional props from Omit<IBaseElementComponent<'canvas'>, 'children'>.