-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
Issue: Framer Motion TypeScript Definitions Should Allow Custom CSS Variables in style Property
Description
The current TypeScript definitions for Framer Motion do not allow for the use of custom CSS variables in the style property of initial and animate objects. This limitation causes TypeScript errors when using custom CSS variables in these properties. The error message received is: "Object literal may only specify known properties, and ''--x'' does not exist in type 'string[] | AnimationControls | TargetAndTransition'."
Proposed Fix
Modify the TypeScript definitions to allow for custom CSS variables in the style property by using a custom type definition for the style property.
Steps to Reproduce
- Use custom CSS variables in the
styleproperty ofinitialoranimateobjects in a Framer Motion component. - Run TypeScript checks or linting with ESLint.
- Observe TypeScript errors related to the use of custom CSS variables.
Example
import { motion, MotionProps } from 'framer-motion'
type CustomStyle = {
'--x': string;
};
type CustomMotionProps = MotionProps & {
initial: {
style: CustomStyle;
scale: number;
};
animate: {
style: CustomStyle;
};
};
const initialProps: CustomMotionProps = {
initial: {
style: {
'--x': '100%',
},
scale: 1,
},
animate: {
style: {
'--x': '-100%',
},
},
};
// Use `initialProps` in a Framer Motion componentMetadata
Metadata
Assignees
Labels
No labels