Statamic Rive Field is a Statamic addon that accepts an a .riv file upload, displays an animiation preview and gives configuration options for the Rive animation.
This addon does:
- Upload a .riv Rive file
- Configure settings for the Rive Model
- Display a preview of the Rive animation
- Display file information about the Rive animation
You can search for this addon in the Tools > Addons section of the Statamic control panel and click install, or run the following command from your project root:
composer require darinlarimore/statamic-rive'additional_uploadable_extensions' => [
'riv',
],Name the field handle rive_animation or whatever you like.
Use the rive_animation handle in your template. The field will have the following properties:
url- The URL of the Rive animationwidth- The width of the animationheight- The height of the animationstateMachine- The state machine of the animationanimation- The timeline name of the animationartboard- The artboard of the animationshouldDisableRiveListeners- Whether or not to disable Rive listeners
npm install @rive-app/canvasimport { Rive } from "@rive-app/canvas";
window.Rive = Rive;Using Alpine.js to initialize the Rive animation:
<div x-data x-init="() => {
const rive = new window.Rive({
src: '{{ rive_animation.url }}',
canvas: $refs.riveCanvas,
autoplay: true,
onLoad: () => {
rive.resizeDrawingSurfaceToCanvas();
},
{{ if rive_animation.stateMachine }}
stateMachines: '{{ rive_animation.stateMachine }}',
{{ /if }}
{{ if rive_animation.animation }}
animations: '{{ rive_animation.animation }}',
{{ /if }}
{{ if rive_animation.artboard }}
artboard: '{{ rive_animation.artboard }}',
{{ /if }}
shouldDisableRiveListeners: '{{ rive_animation.shouldDisableRiveListeners }}',
});
}">
<canvas x-ref="riveCanvas" width="{{rive_animation.width}}" height="{{rive_animation.height}}"></canvas>
</div>

