| 1 |
import { __ } from '@wordpress/i18n'; |
| 2 |
import { registerBlockType } from '@wordpress/blocks'; |
| 3 |
import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; |
| 4 |
import { CheckboxControl, PanelBody, SelectControl, TextControl } from '@wordpress/components'; |
| 5 |
import ServerSideRender from '@wordpress/server-side-render'; |
| 6 |
|
| 7 |
registerBlockType( 'friends/friends-list', { |
| 8 |
apiVersion: 2, |
| 9 |
edit: function( { attributes, setAttributes } ) { |
| 10 |
const blockProps = useBlockProps(); |
| 11 |
return ( |
| 12 |
<> |
| 13 |
<InspectorControls> |
| 14 |
<PanelBody> |
| 15 |
<CheckboxControl |
| 16 |
label={ __( 'Display Users inline', 'friends' ) } |
| 17 |
checked={ attributes.users_inline } |
| 18 |
onChange={ users_inline => setAttributes( { users_inline } ) } |
| 19 |
/> |
| 20 |
<SelectControl |
| 21 |
label={ __( 'User Types', 'friends' ) } |
| 22 |
onChange={ user_types => setAttributes( { user_types } ) } |
| 23 |
value={ attributes.user_types } |
| 24 |
options={ [ |
| 25 |
{ |
| 26 |
label: __( 'Friends', 'friends' ), |
| 27 |
value: 'friends', |
| 28 |
}, |
| 29 |
{ |
| 30 |
label: __( 'Friend requests', 'friends' ), |
| 31 |
value: 'friend_requests', |
| 32 |
}, |
| 33 |
{ |
| 34 |
label: __( 'Subscriptions', 'friends' ), |
| 35 |
value: 'subscriptions', |
| 36 |
}, |
| 37 |
{ |
| 38 |
label: __( 'Friends + Subscriptions', 'friends' ), |
| 39 |
value: 'friends_subscriptions', |
| 40 |
}, |
| 41 |
] } |
| 42 |
/> |
| 43 |
</PanelBody> |
| 44 |
</InspectorControls> |
| 45 |
<div {...blockProps}> |
| 46 |
<ServerSideRender |
| 47 |
block="friends/friends-list" |
| 48 |
attributes={ attributes } |
| 49 |
/> |
| 50 |
</div> |
| 51 |
</> |
| 52 |
); |
| 53 |
}, |
| 54 |
|
| 55 |
save() { |
| 56 |
return null; |
| 57 |
}, |
| 58 |
} ); |
| 59 |
|