UNPKG

@wordpress/block-library

Version:
1 lines • 2.13 kB
{"version":3,"file":"order-control.cjs","names":["__","SelectControl"],"sources":["../../../../src/query/edit/inspector-controls/order-control.jsx"],"sourcesContent":["import { SelectControl } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\n\nconst defaultOrderByOptions = [\n\t{\n\t\tlabel: __( 'Newest to oldest' ),\n\t\tvalue: 'date/desc',\n\t},\n\t{\n\t\tlabel: __( 'Oldest to newest' ),\n\t\tvalue: 'date/asc',\n\t},\n\t{\n\t\t/* translators: Label for ordering posts by title in ascending order. */\n\t\tlabel: __( 'A → Z' ),\n\t\tvalue: 'title/asc',\n\t},\n\t{\n\t\t/* translators: Label for ordering posts by title in descending order. */\n\t\tlabel: __( 'Z → A' ),\n\t\tvalue: 'title/desc',\n\t},\n];\n\nfunction OrderControl( {\n\torder,\n\torderBy,\n\torderByOptions = defaultOrderByOptions,\n\tonChange,\n} ) {\n\treturn (\n\t\t<SelectControl\n\t\t\tlabel={ __( 'Order by' ) }\n\t\t\tvalue={\n\t\t\t\torderByOptions.find(\n\t\t\t\t\t( item ) => item.value === `${ orderBy }/${ order }`\n\t\t\t\t) ??\n\t\t\t\torderByOptions[ 0 ] ??\n\t\t\t\tnull\n\t\t\t}\n\t\t\titems={ orderByOptions }\n\t\t\tonValueChange={ ( item ) => {\n\t\t\t\tif ( ! item || item.value === `${ orderBy }/${ order }` ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst [ newOrderBy, newOrder ] = item.value.split( '/' );\n\t\t\t\tonChange( { order: newOrder, orderBy: newOrderBy } );\n\t\t\t} }\n\t\t/>\n\t);\n}\n\nexport default OrderControl;\n"],"mappings":";;;;;;;;;AAGA,MAAM,wBAAwB;CAC7B;EACC,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,kBAAmB;EAC9B,OAAO;CACR;CACA;EACC,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,kBAAmB;EAC9B,OAAO;CACR;CACA;EAEC,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,OAAQ;EACnB,OAAO;CACR;CACA;EAEC,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,OAAQ;EACnB,OAAO;CACR;AACD;AAEA,SAAS,aAAc,EACtB,OACA,SACA,iBAAiB,uBACjB,YACG;CACH,OACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,cAAAA,eAAD;EACC,QAAA,GAAQD,gBAAAA,GAAAA,CAAI,UAAW;EACvB,OACC,eAAe,MACZ,SAAU,KAAK,UAAU,GAAI,QAAS,GAAI,OAC7C,KACA,eAAgB,MAChB;EAED,OAAQ;EACR,gBAAkB,SAAU;GAC3B,IAAK,CAAE,QAAQ,KAAK,UAAU,GAAI,QAAS,GAAI,SAC9C;GAED,MAAM,CAAE,YAAY,YAAa,KAAK,MAAM,MAAO,GAAI;GACvD,SAAU;IAAE,OAAO;IAAU,SAAS;GAAW,CAAE;EACpD;CACA,CAAA;AAEH"}