@wordpress/edit-post
Version:
Edit Post module for WordPress.
48 lines (46 loc) • 1.67 kB
JavaScript
import { createElement, Fragment } from "@wordpress/element";
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { Button } from '@wordpress/components';
import { withSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import BaseOption from './base';
export function CustomFieldsConfirmation({
willEnable
}) {
const [isReloading, setIsReloading] = useState(false);
return createElement(Fragment, null, createElement("p", {
className: "edit-post-preferences-modal__custom-fields-confirmation-message"
}, __('A page reload is required for this change. Make sure your content is saved before reloading.')), createElement(Button, {
className: "edit-post-preferences-modal__custom-fields-confirmation-button",
isSecondary: true,
isBusy: isReloading,
disabled: isReloading,
onClick: () => {
setIsReloading(true);
document.getElementById('toggle-custom-fields-form').submit();
}
}, willEnable ? __('Enable & Reload') : __('Disable & Reload')));
}
export function EnableCustomFieldsOption({
label,
areCustomFieldsEnabled
}) {
const [isChecked, setIsChecked] = useState(areCustomFieldsEnabled);
return createElement(BaseOption, {
label: label,
isChecked: isChecked,
onChange: setIsChecked
}, isChecked !== areCustomFieldsEnabled && createElement(CustomFieldsConfirmation, {
willEnable: isChecked
}));
}
export default withSelect(select => ({
areCustomFieldsEnabled: !!select('core/editor').getEditorSettings().enableCustomFields
}))(EnableCustomFieldsOption);
//# sourceMappingURL=enable-custom-fields.js.map