UNPKG

@yamada-ui/react

Version:

React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion

1 lines 1.86 kB
{"version":3,"file":"factory.cjs","names":["styled","_motion"],"sources":["../../../../src/components/motion/factory.ts"],"sourcesContent":["import type { ComponentType } from \"react\"\nimport type { DOMElement, StyledOptions } from \"../../core\"\nimport type { MotionStyledComponent } from \"./index.types\"\nimport { motion as _motion } from \"motion/react\"\nimport { styled } from \"../../core\"\n\ntype Components = {\n [Y in DOMElement]: MotionStyledComponent<Y>\n}\n\ninterface Factory extends Components {\n <Y extends DOMElement = DOMElement, M extends object = {}>(\n el: Y,\n options?: StyledOptions,\n ): MotionStyledComponent<Y, M>\n}\n\nfunction factory() {\n const cache = new Map<DOMElement, ComponentType<any>>()\n\n return new Proxy(styled, {\n apply: function (\n _target,\n _thisArg,\n [el, options]: [DOMElement, StyledOptions],\n ) {\n const component = styled(el, options) as ComponentType<any>\n\n return _motion.create(component)\n },\n\n get: function (_target, el: DOMElement) {\n if (!cache.has(el)) {\n const component = styled(el) as ComponentType<any>\n\n cache.set(el, _motion.create(component))\n }\n\n return cache.get(el)\n },\n }) as Factory\n}\n\n/**\n * `motion` is a component that allows for the easy implementation of a wide variety of animations.\n *\n * @see https://yamada-ui.com/docs/components/motion\n */\nexport const motion = factory()\n"],"mappings":";;;;;;AAiBA,SAAS,UAAU;CACjB,MAAM,wBAAQ,IAAI,KAAqC;AAEvD,QAAO,IAAI,MAAMA,wBAAQ;EACvB,OAAO,SACL,SACA,UACA,CAAC,IAAI,UACL;GACA,MAAM,YAAYA,uBAAO,IAAI,QAAQ;AAErC,UAAOC,oBAAQ,OAAO,UAAU;;EAGlC,KAAK,SAAU,SAAS,IAAgB;AACtC,OAAI,CAAC,MAAM,IAAI,GAAG,EAAE;IAClB,MAAM,YAAYD,uBAAO,GAAG;AAE5B,UAAM,IAAI,IAAIC,oBAAQ,OAAO,UAAU,CAAC;;AAG1C,UAAO,MAAM,IAAI,GAAG;;EAEvB,CAAC;;;;;;;AAQJ,MAAa,SAAS,SAAS"}