UNPKG

@wordpress/components

Version:
50 lines (49 loc) • 1.35 kB
import clsx from "clsx"; import Notice from "./index.mjs"; import { createElement } from "react"; import { jsxs } from "react/jsx-runtime"; // packages/components/src/notice/list.tsx const noop = () => {}; /** * `NoticeList` is a component used to render a collection of notices. * *```jsx * import { Notice, NoticeList } from `@wordpress/components`; * * const MyNoticeList = () => { * const [ notices, setNotices ] = useState( [ * { * id: 'second-notice', * content: 'second notice content', * }, * { * id: 'fist-notice', * content: 'first notice content', * }, * ] ); * * const removeNotice = ( id ) => { * setNotices( notices.filter( ( notice ) => notice.id !== id ) ); * }; * * return <NoticeList notices={ notices } onRemove={ removeNotice } />; *}; *``` */ function NoticeList({ notices, onRemove = noop, className, children }) { const removeNotice = (id) => () => onRemove(id); className = clsx("components-notice-list", className); return /* @__PURE__ */ jsxs("div", { className, children: [children, [...notices].reverse().map((notice) => { const { content, ...restNotice } = notice; return /* @__PURE__ */ createElement(Notice, { ...restNotice, key: notice.id, onRemove: removeNotice(notice.id) }, notice.content); })] }); } export { NoticeList as default }; //# sourceMappingURL=list.mjs.map