@wordpress/components
Version:
UI components for WordPress.
93 lines (92 loc) • 3.06 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
// \0rolldown/runtime.js
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: ((k) => from[k]).bind(null, key),
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
let clsx = require("clsx");
clsx = __toESM(clsx);
let _wordpress_deprecated = require("@wordpress/deprecated");
_wordpress_deprecated = __toESM(_wordpress_deprecated);
// packages/components/src/animate/index.tsx
/**
* @param type The animation type
* @return Default origin
*/
function getDefaultOrigin(type) {
return type === "appear" ? "top" : "left";
}
/**
* @param options
*
* @return ClassName that applies the animations
*/
function getAnimateClassName(options) {
if (options.type === "loading") return "components-animate__loading";
const { type, origin = getDefaultOrigin(type) } = options;
if (type === "appear") {
const [yAxis, xAxis = "center"] = origin.split(" ");
return (0, clsx.default)("components-animate__appear", {
["is-from-" + xAxis]: xAxis !== "center",
["is-from-" + yAxis]: yAxis !== "middle"
});
}
if (type === "slide-in") return (0, clsx.default)("components-animate__slide-in", "is-from-" + origin);
}
/**
* Simple interface to introduce animations to components.
*
* This component is deprecated. Write your own CSS animations instead,
* preferably using the [motion tokens](https://wordpress.github.io/gutenberg/?path=/docs/design-system-tokens-introduction--docs)
* available in `@wordpress/theme`.
*
* @deprecated
*
* ```jsx
* import { Animate, Notice } from '@wordpress/components';
*
* const MyAnimatedNotice = () => (
* <Animate type="slide-in" options={ { origin: 'top' } }>
* { ( { className } ) => (
* <Notice className={ className } status="success">
* <p>Animation finished.</p>
* </Notice>
* ) }
* </Animate>
* );
* ```
*/
function Animate({ type, options = {}, children }) {
(0, _wordpress_deprecated.default)("wp.components.Animate", {
since: "7.2",
version: "7.4"
});
return children({ className: getAnimateClassName({
type,
...options
}) });
}
exports.Animate = Animate;
exports.default = Animate;
exports.getAnimateClassName = getAnimateClassName;
//# sourceMappingURL=index.cjs.map