UNPKG

framer-motion

Version:

A simple and powerful JavaScript animation library

1 lines 2.19 kB
{"version":3,"file":"index.mjs","sources":["../../../../src/components/MotionConfig/index.tsx"],"sourcesContent":["\"use client\"\n\nimport * as React from \"react\"\nimport { useContext, useMemo } from \"react\"\nimport { MotionConfigContext } from \"../../context/MotionConfigContext\"\nimport {\n loadExternalIsValidProp,\n IsValidProp,\n} from \"../../render/dom/utils/filter-props\"\nimport { useConstant } from \"../../utils/use-constant\"\n\nexport interface MotionConfigProps extends Partial<MotionConfigContext> {\n children?: React.ReactNode\n isValidProp?: IsValidProp\n}\n\n/**\n * `MotionConfig` is used to set configuration options for all children `motion` components.\n *\n * ```jsx\n * import { motion, MotionConfig } from \"framer-motion\"\n *\n * export function App() {\n * return (\n * <MotionConfig transition={{ type: \"spring\" }}>\n * <motion.div animate={{ x: 100 }} />\n * </MotionConfig>\n * )\n * }\n * ```\n *\n * @public\n */\nexport function MotionConfig({\n children,\n isValidProp,\n ...config\n}: MotionConfigProps) {\n isValidProp && loadExternalIsValidProp(isValidProp)\n\n /**\n * Inherit props from any parent MotionConfig components\n */\n config = { ...useContext(MotionConfigContext), ...config }\n\n /**\n * Don't allow isStatic to change between renders as it affects how many hooks\n * motion components fire.\n */\n config.isStatic = useConstant(() => config.isStatic)\n\n /**\n * Creating a new config context object will re-render every `motion` component\n * every time it renders. So we only want to create a new one sparingly.\n */\n const context = useMemo(\n () => config,\n [\n JSON.stringify(config.transition),\n config.transformPagePoint,\n config.reducedMotion,\n ]\n )\n\n return (\n <MotionConfigContext.Provider value={context as MotionConfigContext}>\n {children}\n </MotionConfigContext.Provider>\n )\n}\n"],"names":[],"mappings":";;;;;;;AAgBA;;;;;;;;;;;;;;;;AAgBG;AACG;AAKF;AAEA;;AAEG;;AAGH;;;AAGG;AACH;AAEA;;;AAGG;;AAIK;AACA;AACA;AACH;AAGL;AAKJ;;"}