On this Page
MotionPreset
MotionPreset is the reusable keyframe contract used by the motion preset collection. It describes the initial, entered, and exited states for a motion element; it is a TypeScript interface, not a rendered component.
Usage
Svelte
<script lang="ts">
import { Motion, type MotionPreset } from 'fractalsvelte/motion';
const notice: MotionPreset = {
initial: { opacity: 0, y: 8 },
animate: { opacity: 1, y: 0 },
exit: { opacity: 0, y: 4 }
};
</script>
<Motion
initial={notice.initial}
animate={notice.animate}
exit={notice.exit}
>
Saved successfully
</Motion>
The built-in presets collection provides fade, fadeUp, scale, menu, and toast values that already satisfy this interface.
API
TypeScript
interface MotionPreset {
initial: DOMKeyframesDefinition;
animate: DOMKeyframesDefinition;
exit: DOMKeyframesDefinition;
}
| Field | Type | Description |
|---|---|---|
initial | DOMKeyframesDefinition | Keyframes applied before the element enters. |
animate | DOMKeyframesDefinition | Keyframes for the entered or steady state. |
exit | DOMKeyframesDefinition | Keyframes applied while the element leaves. |
DOMKeyframesDefinition accepts animatable property values such as { opacity: 0, y: 12 }. Use compatible property names and values supported by the underlying Motion animation engine.
Related APIs
- Use
presetsfor the package’s ready-madeMotionPresetvalues. - Use
Motionto apply a preset’sinitial,animate, andexitkeyframes. - Use
MotionTransitionto describe the timing or spring configuration separately from the keyframes.
