UNPKG

@wordpress/editor

Version:
73 lines (65 loc) 1.69 kB
import { createElement } from "@wordpress/element"; /** * External dependencies */ import { invoke } from 'lodash'; /** * WordPress dependencies */ import { __ } from '@wordpress/i18n'; import { TextControl } from '@wordpress/components'; import { withSelect, withDispatch } from '@wordpress/data'; import { compose, withState } from '@wordpress/compose'; /** * Internal dependencies */ import PostTypeSupportCheck from '../post-type-support-check'; export const PageAttributesOrder = withState({ orderInput: null })(({ onUpdateOrder, order = 0, orderInput, setState }) => { const setUpdatedOrder = value => { setState({ orderInput: value }); const newOrder = Number(value); if (Number.isInteger(newOrder) && invoke(value, ['trim']) !== '') { onUpdateOrder(Number(value)); } }; const value = orderInput === null ? order : orderInput; return createElement(TextControl, { className: "editor-page-attributes__order", type: "number", label: __('Order'), value: value, onChange: setUpdatedOrder, size: 6, onBlur: () => { setState({ orderInput: null }); } }); }); function PageAttributesOrderWithChecks(props) { return createElement(PostTypeSupportCheck, { supportKeys: "page-attributes" }, createElement(PageAttributesOrder, props)); } export default compose([withSelect(select => { return { order: select('core/editor').getEditedPostAttribute('menu_order') }; }), withDispatch(dispatch => ({ onUpdateOrder(order) { dispatch('core/editor').editPost({ menu_order: order }); } }))])(PageAttributesOrderWithChecks); //# sourceMappingURL=order.js.map