@wordpress/components
Version:
UI components for WordPress.
8 lines (7 loc) • 2.44 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/animate/index.tsx"],
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * Internal dependencies\n */\n\n/**\n * @param type The animation type\n * @return Default origin\n */\nfunction getDefaultOrigin(type) {\n return type === 'appear' ? 'top' : 'left';\n}\n\n/**\n * @param options\n *\n * @return ClassName that applies the animations\n */\nexport function getAnimateClassName(options) {\n if (options.type === 'loading') {\n return 'components-animate__loading';\n }\n const {\n type,\n origin = getDefaultOrigin(type)\n } = options;\n if (type === 'appear') {\n const [yAxis, xAxis = 'center'] = origin.split(' ');\n return clsx('components-animate__appear', {\n ['is-from-' + xAxis]: xAxis !== 'center',\n ['is-from-' + yAxis]: yAxis !== 'middle'\n });\n }\n if (type === 'slide-in') {\n return clsx('components-animate__slide-in', 'is-from-' + origin);\n }\n return undefined;\n}\n\n/**\n * Simple interface to introduce animations to components.\n *\n * ```jsx\n * import { Animate, Notice } from '@wordpress/components';\n *\n * const MyAnimatedNotice = () => (\n * \t<Animate type=\"slide-in\" options={ { origin: 'top' } }>\n * \t\t{ ( { className } ) => (\n * \t\t\t<Notice className={ className } status=\"success\">\n * \t\t\t\t<p>Animation finished.</p>\n * \t\t\t</Notice>\n * \t\t) }\n * \t</Animate>\n * );\n * ```\n */\nexport function Animate({\n type,\n options = {},\n children\n}) {\n return children({\n className: getAnimateClassName({\n type,\n ...options\n })\n });\n}\nexport default Animate;"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAUjB,SAAS,iBAAiB,MAAM;AAC9B,SAAO,SAAS,WAAW,QAAQ;AACrC;AAOO,SAAS,oBAAoB,SAAS;AAC3C,MAAI,QAAQ,SAAS,WAAW;AAC9B,WAAO;AAAA,EACT;AACA,QAAM;AAAA,IACJ;AAAA,IACA,SAAS,iBAAiB,IAAI;AAAA,EAChC,IAAI;AACJ,MAAI,SAAS,UAAU;AACrB,UAAM,CAAC,OAAO,QAAQ,QAAQ,IAAI,OAAO,MAAM,GAAG;AAClD,eAAO,YAAAA,SAAK,8BAA8B;AAAA,MACxC,CAAC,aAAa,KAAK,GAAG,UAAU;AAAA,MAChC,CAAC,aAAa,KAAK,GAAG,UAAU;AAAA,IAClC,CAAC;AAAA,EACH;AACA,MAAI,SAAS,YAAY;AACvB,eAAO,YAAAA,SAAK,gCAAgC,aAAa,MAAM;AAAA,EACjE;AACA,SAAO;AACT;AAmBO,SAAS,QAAQ;AAAA,EACtB;AAAA,EACA,UAAU,CAAC;AAAA,EACX;AACF,GAAG;AACD,SAAO,SAAS;AAAA,IACd,WAAW,oBAAoB;AAAA,MAC7B;AAAA,MACA,GAAG;AAAA,IACL,CAAC;AAAA,EACH,CAAC;AACH;AACA,IAAO,kBAAQ;",
"names": ["clsx"]
}