UNPKG

@wordpress/components

Version:
100 lines (99 loc) • 2.19 kB
import clsx from "clsx"; import { useReducedMotion } from "@wordpress/compose"; import { useRef } from "@wordpress/element"; import Snackbar from "./index.mjs"; import { __unstableAnimatePresence, __unstableMotion } from "../animation/index.mjs"; import { jsx, jsxs } from "react/jsx-runtime"; // packages/components/src/snackbar/list.tsx const SNACKBAR_VARIANTS = { init: { height: 0, opacity: 0 }, open: { height: "auto", opacity: 1, transition: { height: { type: "tween", duration: .3, ease: [ 0, 0, .2, 1 ] }, opacity: { type: "tween", duration: .25, delay: .05, ease: [ 0, 0, .2, 1 ] } } }, exit: { opacity: 0, transition: { type: "tween", duration: .1, ease: [ 0, 0, .2, 1 ] } } }; /** * Renders a list of notices. * * ```jsx * const MySnackbarListNotice = () => ( * <SnackbarList * notices={ notices } * onRemove={ removeNotice } * /> * ); * ``` */ function SnackbarList({ notices, className, children, onRemove }) { const listRef = useRef(null); const isReducedMotion = useReducedMotion(); className = clsx("components-snackbar-list", className); const removeNotice = (notice) => () => onRemove?.(notice.id); return /* @__PURE__ */ jsxs("div", { className, tabIndex: -1, ref: listRef, "data-testid": "snackbar-list", children: [children, /* @__PURE__ */ jsx(__unstableAnimatePresence, { children: notices.map((notice) => { const { content, ...restNotice } = notice; return /* @__PURE__ */ jsx(__unstableMotion.div, { layout: isReducedMotion ? false : "position", style: { width: "100%" }, initial: "init", animate: "open", exit: "exit", variants: isReducedMotion ? void 0 : SNACKBAR_VARIANTS, children: /* @__PURE__ */ jsx("div", { className: "components-snackbar-list__notice-container", children: /* @__PURE__ */ jsx(Snackbar, { ...restNotice, onRemove: removeNotice(notice), listRef, children: notice.content }) }) }, notice.id); }) })] }); } export { SnackbarList, SnackbarList as default }; //# sourceMappingURL=list.mjs.map