UNPKG

@wordpress/components

Version:
1 lines • 2.77 kB
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/animate/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport deprecated from '@wordpress/deprecated';\nimport type { AnimateProps, GetAnimateOptions } from './types';\n\n/**\n * @param type The animation type\n * @return Default origin\n */\nfunction getDefaultOrigin( type?: GetAnimateOptions[ 'type' ] ) {\n\treturn type === 'appear' ? 'top' : 'left';\n}\n\n/**\n * @param options\n *\n * @return ClassName that applies the animations\n */\nexport function getAnimateClassName( options: GetAnimateOptions ) {\n\tif ( options.type === 'loading' ) {\n\t\treturn 'components-animate__loading';\n\t}\n\n\tconst { type, origin = getDefaultOrigin( type ) } = options;\n\n\tif ( type === 'appear' ) {\n\t\tconst [ yAxis, xAxis = 'center' ] = origin.split( ' ' );\n\t\treturn clsx( 'components-animate__appear', {\n\t\t\t[ 'is-from-' + xAxis ]: xAxis !== 'center',\n\t\t\t[ 'is-from-' + yAxis ]: yAxis !== 'middle',\n\t\t} );\n\t}\n\n\tif ( type === 'slide-in' ) {\n\t\treturn clsx( 'components-animate__slide-in', 'is-from-' + origin );\n\t}\n\n\treturn undefined;\n}\n\n/**\n * Simple interface to introduce animations to components.\n *\n * This component is deprecated. Write your own CSS animations instead,\n * preferably using the [motion tokens](https://wordpress.github.io/gutenberg/?path=/docs/design-system-tokens-introduction--docs)\n * available in `@wordpress/theme`.\n *\n * @deprecated\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( { type, options = {}, children }: AnimateProps ) {\n\tdeprecated( 'wp.components.Animate', {\n\t\tsince: '7.2',\n\t\tversion: '7.4',\n\t} );\n\n\treturn children( {\n\t\tclassName: getAnimateClassName( {\n\t\t\ttype,\n\t\t\t...options,\n\t\t} as GetAnimateOptions ),\n\t} );\n}\n\nexport default Animate;\n"],"mappings":";;;;;;;AAQA,SAAS,iBAAkB,MAAqC;CAC/D,OAAO,SAAS,WAAW,QAAQ;AACpC;;;;;;AAOA,SAAgB,oBAAqB,SAA6B;CACjE,IAAK,QAAQ,SAAS,WACrB,OAAO;CAGR,MAAM,EAAE,MAAM,SAAS,iBAAkB,IAAK,MAAM;CAEpD,IAAK,SAAS,UAAW;EACxB,MAAM,CAAE,OAAO,QAAQ,YAAa,OAAO,MAAO,GAAI;EACtD,OAAO,KAAM,8BAA8B;IACxC,aAAa,QAAS,UAAU;IAChC,aAAa,QAAS,UAAU;EACnC,CAAE;CACH;CAEA,IAAK,SAAS,YACb,OAAO,KAAM,gCAAgC,aAAa,MAAO;AAInE;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,QAAS,EAAE,MAAM,UAAU,CAAC,GAAG,YAA2B;CACzE,WAAY,yBAAyB;EACpC,OAAO;EACP,SAAS;CACV,CAAE;CAEF,OAAO,SAAU,EAChB,WAAW,oBAAqB;EAC/B;EACA,GAAG;CACJ,CAAuB,EACxB,CAAE;AACH"}