Last active
March 5, 2020 21:23
-
-
Save chrisvanpatten/f8ff23b0ec595dbe2c9edf1ba523f9d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { PluginPrePublishPanel } from '@wordpress/edit-post'; | |
import { registerPlugin } from '@wordpress/plugins'; | |
import Required from './required'; | |
const Test = () => { | |
<PluginPrePublishPanel> | |
<Required.Fill> | |
{ ( fills ) => fills.length > 0 ? fills : null ) } | |
</Required.Fill> | |
</PluginPrePublishPanel> | |
}; | |
registerPlugin( 'test-plugin-fill-panel', { render: Test } ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createSlotFill } from '@wordpress/components'; | |
const { Fill, Slot } = createSlotFill( 'OneCMSRequiredFields' ); | |
const Required = ( props ) => { | |
const { | |
children, | |
isValid, | |
} = props; | |
return ( | |
<> | |
{ ! isValid && ( | |
<Slot> | |
{ children } | |
</Slot> | |
) } | |
{ children } | |
</> | |
); | |
}; | |
Required.Fill = Fill; | |
export default Required; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { TextControl } from '@wordpress/components'; | |
import { PluginPrePublishPanel } from '@wordpress/edit-post'; | |
import { useState } from '@wordpress/element'; | |
import { registerPlugin } from '@wordpress/plugins'; | |
import Required from './required'; | |
const Test = () => { | |
const [ thing, setThing ] = useState( '' ); | |
return ( | |
<PluginDocumentSettingPanel | |
name="custom-panel" | |
title="Custom Panel" | |
className="custom-panel" | |
> | |
<Required isValid={ thing.length > 10 }> | |
<TextControl | |
onChange={ ( value ) => setThing( value ) } | |
value={ thing } | |
/> | |
</Required> | |
</PluginDocumentSettingPanel> | |
); | |
}; | |
registerPlugin( 'test-plugin-doc-panel', { render: Test } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment