@wordpress/notices
Version:
State management for notices.
8 lines (7 loc) • 1.74 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/components/snackbar-notices/index.tsx"],
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { SnackbarList } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as noticesStore } from '../../store';\n\n// Last three notices. Slices from the tail end of the list.\nconst MAX_VISIBLE_NOTICES = -3;\n\ntype SnackbarNoticesProps = {\n\tclassName?: string;\n\tcontext?: string;\n};\n\nexport default function SnackbarNotices( {\n\tclassName,\n\tcontext,\n}: SnackbarNoticesProps ) {\n\tconst notices = useSelect(\n\t\t( select ) => select( noticesStore ).getNotices( context ),\n\t\t[ context ]\n\t);\n\tconst { removeNotice } = useDispatch( noticesStore );\n\tconst snackbarNotices = notices\n\t\t.filter( ( { type } ) => type === 'snackbar' )\n\t\t.slice( MAX_VISIBLE_NOTICES );\n\n\treturn (\n\t\t<SnackbarList\n\t\t\tnotices={ snackbarNotices }\n\t\t\tclassName={ clsx( 'components-notices__snackbar', className ) }\n\t\t\tonRemove={ ( id ) => removeNotice( id, context ) }\n\t\t/>\n\t);\n}\n"],
"mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,oBAAoB;AAC7B,SAAS,aAAa,iBAAiB;AAKvC,SAAS,SAAS,oBAAoB;AAwBpC;AArBF,IAAM,sBAAsB;AAOb,SAAR,gBAAkC;AAAA,EACxC;AAAA,EACA;AACD,GAA0B;AACzB,QAAM,UAAU;AAAA,IACf,CAAE,WAAY,OAAQ,YAAa,EAAE,WAAY,OAAQ;AAAA,IACzD,CAAE,OAAQ;AAAA,EACX;AACA,QAAM,EAAE,aAAa,IAAI,YAAa,YAAa;AACnD,QAAM,kBAAkB,QACtB,OAAQ,CAAE,EAAE,KAAK,MAAO,SAAS,UAAW,EAC5C,MAAO,mBAAoB;AAE7B,SACC;AAAA,IAAC;AAAA;AAAA,MACA,SAAU;AAAA,MACV,WAAY,KAAM,gCAAgC,SAAU;AAAA,MAC5D,UAAW,CAAE,OAAQ,aAAc,IAAI,OAAQ;AAAA;AAAA,EAChD;AAEF;",
"names": []
}