What are you trying to do?
I’m trying to add smooth animations to my Plasmic components when they change variants or when their layout changes. I’m using Framer Motion for this, which requires a specific setup to work properly:
- Framer Motion needs a
LayoutGroup
component at the parent level to coordinate animations between children - Any component that should animate needs to be wrapped in a
motion.div
with thelayout
prop - For animations to work smoothly, both the parent and all children that participate in the animation need to be motion components
For example, in regular React, it would look like this:
<LayoutGroup>
<motion.div layout>
<motion.div layout>Child 1</motion.div>
<motion.div layout>Child 2</motion.div>
</motion.div>
</LayoutGroup>
The challenge is implementing this structure in Plasmic while preserving all component styles and behaviors.
What have you tried so far?
- Created a MotionBehavior component:
const MotionBehavior: React.FC<MotionBehaviorProps> = ({ children }) => {
return (
<motion.div
{...children.props}
layout
>
{children.props.children}
</motion.div>
);
};
Problem: This only wraps the parent in motion.div, but Framer Motion needs all children to be motion components too. When I tried to recursively wrap children, the components lost their Plasmic styles and behaviors.
- Tried using root element override through the API explorer:
<PlasmicComponent
component="Plasmic components"
componentProps={{
root: {
as: motion.div,
props: {
layout: true
}
}
}}
/>
Problem: I can’t import motion from “framer-motion” in this file even through its running on my server/project, additionally i couldn’t find how to override the antd components only the plasmic components and my custom components.
The main issues I’m facing:
- How to properly structure the LayoutGroup and motion.div hierarchy in Plasmic
- How to make sure all components that need to animate are wrapped in motion.div
- How to preserve Plasmic styles and behaviors while adding motion capabilities
- How to handle this globally so all components can animate when changing variants
Questions:
- Is there a recommended way to implement Framer Motion animations in Plasmic?
- How can we add motion capabilities to components without breaking their styles?
- Is there a way to globally enhance components with motion features?
Any help would be greatly appreciated as I’m stuck trying to make these two great tools (Plasmic and Framer Motion) work together!
Relevant links:
- Framer Motion layout animations: Layout animations | Motion for React (prev Framer Motion)
- Plasmic documentation we’ve reviewed:
- Component Behaviors: Custom behaviors (attachments) | Learn Plasmic
- Component Overrides: Overriding props on elements | Learn Plasmic
- Global Contexts: Global Contexts | Learn Plasmic
- Code Components Reference: Code components API reference | Learn Plasmic
- Component Registration: Registering your code components | Learn Plasmic
- Writing Code Components: Writing code components for use with Plasmic | Learn Plasmic
- Component Substitution: https://docs.plasmic.app/learn/component-substitution/
- Data Provider: Querying data with code components | Learn Plasmic
- Codegen Components: Codegen Guide: Components | Learn Plasmic
- Editor Actions: https://docs.plasmic.app/learn/editor-actions-code-components/
- Element Actions: Element actions for code components | Learn Plasmic
We’ve extensively reviewed these docs trying to find the best approach to implement motion animations while preserving Plasmic’s component system, but haven’t found a clear solution that satisfies both Framer Motion’s requirements and Plasmic’s component structure.