@wordpress/components
Version:
UI components for WordPress.
1 lines • 2.15 kB
Source Map (JSON)
{"version":3,"file":"list.mjs","names":[],"sources":["../../src/notice/list.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport Notice from '.';\nimport type { WordPressComponentProps } from '../context';\nimport type { NoticeListProps } from './types';\n\nconst noop = () => {};\n\n/**\n * `NoticeList` is a component used to render a collection of notices.\n *\n *```jsx\n * import { Notice, NoticeList } from `@wordpress/components`;\n *\n * const MyNoticeList = () => {\n *\tconst [ notices, setNotices ] = useState( [\n *\t\t{\n *\t\t\tid: 'second-notice',\n *\t\t\tcontent: 'second notice content',\n *\t\t},\n *\t\t{\n *\t\t\tid: 'fist-notice',\n *\t\t\tcontent: 'first notice content',\n *\t\t},\n *\t] );\n *\n *\tconst removeNotice = ( id ) => {\n *\t\tsetNotices( notices.filter( ( notice ) => notice.id !== id ) );\n *\t};\n *\n *\treturn <NoticeList notices={ notices } onRemove={ removeNotice } />;\n *};\n *```\n */\nfunction NoticeList( {\n\tnotices,\n\tonRemove = noop,\n\tclassName,\n\tchildren,\n}: WordPressComponentProps< NoticeListProps, 'div', false > ) {\n\tconst removeNotice =\n\t\t( id: NoticeListProps[ 'notices' ][ number ][ 'id' ] ) => () =>\n\t\t\tonRemove( id );\n\n\tclassName = clsx( 'components-notice-list', className );\n\n\treturn (\n\t\t<div className={ className }>\n\t\t\t{ children }\n\t\t\t{ [ ...notices ].reverse().map( ( notice ) => {\n\t\t\t\tconst { content, ...restNotice } = notice;\n\t\t\t\treturn (\n\t\t\t\t\t<Notice\n\t\t\t\t\t\t{ ...restNotice }\n\t\t\t\t\t\tkey={ notice.id }\n\t\t\t\t\t\tonRemove={ removeNotice( notice.id ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ notice.content }\n\t\t\t\t\t</Notice>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</div>\n\t);\n}\n\nexport default NoticeList;\n"],"mappings":";;;;;AAKA,MAAM,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BpB,SAAS,WAAY,EACpB,SACA,WAAW,MACX,WACA,YAC6D;CAC7D,MAAM,gBACH,aACD,SAAU,EAAG;CAEf,YAAY,KAAM,0BAA0B,SAAU;CAEtD,OACC,qBAAC,OAAD;EAAiB;EAAjB,UAAA,CACG,UACA,CAAE,GAAG,OAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAO,WAAY;GAC7C,MAAM,EAAE,SAAS,GAAG,eAAe;GACnC,OACC,8BAAC,QAAD;IACC,GAAK;IACL,KAAM,OAAO;IACb,UAAW,aAAc,OAAO,EAAG;GAG5B,GADL,OAAO,OACF;EAEV,CAAE,CACE;;AAEP"}