| 1 |
import { __ } from '@wordpress/i18n'; |
| 2 |
import { registerBlockType } from '@wordpress/blocks'; |
| 3 |
import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; |
| 4 |
import { CheckboxControl, PanelBody, RangeControl, SelectControl, TextControl } from '@wordpress/components'; |
| 5 |
import ServerSideRender from '@wordpress/server-side-render'; |
| 6 |
|
| 7 |
registerBlockType( 'friends/friend-posts', { |
| 8 |
apiVersion: 2, |
| 9 |
edit: function( { attributes, setAttributes } ) { |
| 10 |
const blockProps = useBlockProps(); |
| 11 |
return ( |
| 12 |
<> |
| 13 |
<InspectorControls> |
| 14 |
<PanelBody> |
| 15 |
<CheckboxControl |
| 16 |
label={ __( 'Display Author name', 'friends' ) } |
| 17 |
checked={ attributes.author_name } |
| 18 |
onChange={ author_name => setAttributes( { author_name } ) } |
| 19 |
/> |
| 20 |
<CheckboxControl |
| 21 |
label={ __( 'Display Author avatar', 'friends' ) } |
| 22 |
checked={ attributes.author_avatar } |
| 23 |
onChange={ author_avatar => setAttributes( { author_avatar } ) } |
| 24 |
/> |
| 25 |
<CheckboxControl |
| 26 |
label={ __( 'Show Author inline', 'friends' ) } |
| 27 |
checked={ attributes.author_inline } |
| 28 |
onChange={ author_inline => setAttributes( { author_inline } ) } |
| 29 |
/> |
| 30 |
<CheckboxControl |
| 31 |
label={ __( 'Show Date', 'friends' ) } |
| 32 |
checked={ attributes.show_date } |
| 33 |
onChange={ show_date => setAttributes( { show_date } ) } |
| 34 |
/> |
| 35 |
<RangeControl |
| 36 |
label={ __( 'Number of posts', 'friends' ) } |
| 37 |
value={ attributes.count } |
| 38 |
onChange={ count => setAttributes( { count } ) } |
| 39 |
min={ 1 } |
| 40 |
max={ 100 } |
| 41 |
/> |
| 42 |
<TextControl |
| 43 |
label={ __( 'Exclude these users', 'friends' ) } |
| 44 |
placeholder={ __( 'space and/or comma separated', 'friends' ) } |
| 45 |
value={ attributes.exclude_users } |
| 46 |
onChange={ exclude_users => setAttributes( { exclude_users } ) } |
| 47 |
/> |
| 48 |
<TextControl |
| 49 |
label={ __( 'Only these users', 'friends' ) } |
| 50 |
placeholder={ __( 'space and/or comma separated', 'friends' ) } |
| 51 |
value={ attributes.only_users } |
| 52 |
onChange={ only_users => setAttributes( { only_users } ) } |
| 53 |
/> |
| 54 |
<CheckboxControl |
| 55 |
label={ __( 'Link to local page', 'friends' ) } |
| 56 |
checked={ attributes.internal_link } |
| 57 |
onChange={ internal_link => setAttributes( { internal_link } ) } |
| 58 |
/> |
| 59 |
</PanelBody> |
| 60 |
</InspectorControls> |
| 61 |
<div {...blockProps}> |
| 62 |
<ServerSideRender |
| 63 |
block="friends/friend-posts" |
| 64 |
attributes={ attributes } |
| 65 |
/> |
| 66 |
</div> |
| 67 |
</> |
| 68 |
); |
| 69 |
}, |
| 70 |
|
| 71 |
save() { |
| 72 |
return null; |
| 73 |
}, |
| 74 |
} ); |
| 75 |
|