Skip to content

Commit

Permalink
Applied format:js for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
douglas-johnson committed Oct 23, 2023
1 parent bfe1d86 commit 87ef140
Show file tree
Hide file tree
Showing 19 changed files with 568 additions and 459 deletions.
6 changes: 2 additions & 4 deletions src/blocks/block-coauthor-avatar/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@
}
}
},
"usesContext": [
"co-authors-plus/author"
],
"usesContext": [ "co-authors-plus/author" ],
"attributes": {
"size" : {
"size": {
"type": "number",
"default": 24
},
Expand Down
224 changes: 121 additions & 103 deletions src/blocks/block-coauthor-avatar/edit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { __ } from '@wordpress/i18n';
import { useBlockProps, InspectorControls, __experimentalUseBorderProps as useBorderProps, store as blockEditorStore } from '@wordpress/block-editor';
import { SelectControl, PanelBody, ToggleControl, TextControl } from '@wordpress/components';
import {
useBlockProps,
InspectorControls,
__experimentalUseBorderProps as useBorderProps,
store as blockEditorStore,
} from '@wordpress/block-editor';
import {
SelectControl,
PanelBody,
ToggleControl,
TextControl,
} from '@wordpress/components';
import { useSelect } from '@wordpress/data';

import PlaceholderImage from '../components/placeholder-image';
Expand All @@ -14,135 +24,143 @@ import PlaceholderImage from '../components/placeholder-image';
* @return {WPElement} Element to render.
*/
export default function Edit( { context, attributes, setAttributes } ) {

const { isLink, rel, size, verticalAlign } = attributes;
const authorPlaceholder = useSelect( select => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(), []);
const author = context['co-authors-plus/author'] || authorPlaceholder;
const authorPlaceholder = useSelect(
( select ) => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(),
[]
);
const author = context[ 'co-authors-plus/author' ] || authorPlaceholder;
const { avatar_urls } = author;

if ( ! avatar_urls || 0 === avatar_urls.length ) {
return null;
}

const sizes = Object.keys( avatar_urls ).map( (size) => {
const sizes = Object.keys( avatar_urls ).map( ( size ) => {
return {
value: size,
label: `${ size } x ${ size }`
label: `${ size } x ${ size }`,
};
});
} );

const borderProps = useBorderProps( attributes );

const src = avatar_urls[size] ?? '';
const src = avatar_urls[ size ] ?? '';

return (
<>
<figure { ...useBlockProps() }>
{
'' === src ?
(
<figure { ...useBlockProps() }>
{ '' === src ? (
<PlaceholderImage
className={borderProps.className}
dimensions={{width: size, height: size}}
className={ borderProps.className }
dimensions={ { width: size, height: size } }
style={ {
height: size,
width: size,
minWidth: 'auto',
minHeight: 'auto',
padding: 0,
verticalAlign,
...borderProps.style
verticalAlign,
...borderProps.style,
} }
/>
) : (
<img
style={{...borderProps.style, verticalAlign}}
width={size}
height={size}
src={`${avatar_urls[size]}`}
/>
)
}
</figure>
<InspectorControls>
<PanelBody title={ __( 'Avatar Settings', 'co-authors-plus' ) }>
<SelectControl
label={ __( 'Avatar size', 'co-authors-plus' ) }
value={ size }
options={ sizes }
onChange={ ( nextSize ) => {
setAttributes( {
size: Number( nextSize )
} );
} }
/>
<ToggleControl
label={ __( 'Make avatar a link to author archive.', 'co-authors-plus' ) }
onChange={ () => setAttributes( { isLink: ! isLink } ) }
checked={ isLink }
/>
{ isLink && (
<TextControl
__nextHasNoMarginBottom
label={ __( 'Link rel', 'co-authors-plus' ) }
value={ rel }
onChange={ ( newRel ) =>
setAttributes( { rel: newRel } )
}
style={ { ...borderProps.style, verticalAlign } }
width={ size }
height={ size }
src={ `${ avatar_urls[ size ] }` }
/>
) }
</PanelBody>
<PanelBody initialOpen={false} title={ __( 'Co-authors Layout', 'co-authors-plus' ) }>
<SelectControl
label={ __( 'Vertical align', 'co-authors-plus' ) }
value={ verticalAlign }
options={ [
{
value: '',
label: __( 'Default', 'co-authors-plus' )
},
{
value: 'baseline',
label: __( 'Baseline', 'co-authors-plus' )
},
{
value: 'bottom',
label: __( 'Bottom', 'co-authors-plus' )
},
{
value: 'middle',
label: __( 'Middle', 'co-authors-plus' )
},
{
value: 'sub',
label: __( 'Sub', 'co-authors-plus' )
},
{
value: 'super',
label: __( 'Super', 'co-authors-plus' )
},
{
value: 'text-bottom',
label: __( 'Text Bottom', 'co-authors-plus' )
},
{
value: 'text-top',
label: __( 'Text Top', 'co-authors-plus' )
},
{
value: 'top',
label: __( 'Top', 'co-authors-plus' )
},
] }
onChange={ ( value ) => {
setAttributes( {
verticalAlign: '' === value ? undefined : value
} );
} }
help={ __( 'Vertical alignment defaults to bottom in the block layout and middle in the inline layout.', 'co-authors-plus' )}
/>
</PanelBody>
</InspectorControls>
</figure>
<InspectorControls>
<PanelBody title={ __( 'Avatar Settings', 'co-authors-plus' ) }>
<SelectControl
label={ __( 'Avatar size', 'co-authors-plus' ) }
value={ size }
options={ sizes }
onChange={ ( nextSize ) => {
setAttributes( {
size: Number( nextSize ),
} );
} }
/>
<ToggleControl
label={ __(
'Make avatar a link to author archive.',
'co-authors-plus'
) }
onChange={ () => setAttributes( { isLink: ! isLink } ) }
checked={ isLink }
/>
{ isLink && (
<TextControl
__nextHasNoMarginBottom
label={ __( 'Link rel', 'co-authors-plus' ) }
value={ rel }
onChange={ ( newRel ) =>
setAttributes( { rel: newRel } )
}
/>
) }
</PanelBody>
<PanelBody
initialOpen={ false }
title={ __( 'Co-authors Layout', 'co-authors-plus' ) }
>
<SelectControl
label={ __( 'Vertical align', 'co-authors-plus' ) }
value={ verticalAlign }
options={ [
{
value: '',
label: __( 'Default', 'co-authors-plus' ),
},
{
value: 'baseline',
label: __( 'Baseline', 'co-authors-plus' ),
},
{
value: 'bottom',
label: __( 'Bottom', 'co-authors-plus' ),
},
{
value: 'middle',
label: __( 'Middle', 'co-authors-plus' ),
},
{
value: 'sub',
label: __( 'Sub', 'co-authors-plus' ),
},
{
value: 'super',
label: __( 'Super', 'co-authors-plus' ),
},
{
value: 'text-bottom',
label: __( 'Text Bottom', 'co-authors-plus' ),
},
{
value: 'text-top',
label: __( 'Text Top', 'co-authors-plus' ),
},
{
value: 'top',
label: __( 'Top', 'co-authors-plus' ),
},
] }
onChange={ ( value ) => {
setAttributes( {
verticalAlign: '' === value ? undefined : value,
} );
} }
help={ __(
'Vertical alignment defaults to bottom in the block layout and middle in the inline layout.',
'co-authors-plus'
) }
/>
</PanelBody>
</InspectorControls>
</>
);
}
2 changes: 1 addition & 1 deletion src/blocks/block-coauthor-avatar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ registerBlockType( metadata.name, {
* @see ./edit.js
*/
edit: Edit,
icon
icon,
} );
10 changes: 2 additions & 8 deletions src/blocks/block-coauthor-description/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
"title": "Co-Author Biography",
"category": "theme",
"description": "Displays a co-author's biographical description.",
"keywords": [
"description",
"bio",
"biography"
],
"keywords": [ "description", "bio", "biography" ],
"supports": {
"html": false,
"color": {
Expand Down Expand Up @@ -39,9 +35,7 @@
}
}
},
"usesContext": [
"co-authors-plus/author"
],
"usesContext": [ "co-authors-plus/author" ],
"attributes": {
"textAlign": {
"type": "string"
Expand Down
29 changes: 17 additions & 12 deletions src/blocks/block-coauthor-description/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
*
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops
*/
import { useBlockProps, AlignmentControl, BlockControls, store as blockEditorStore } from '@wordpress/block-editor';
import {
useBlockProps,
AlignmentControl,
BlockControls,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import classnames from 'classnames';
Expand All @@ -19,10 +24,12 @@ import './editor.css';
* @return {WPElement} Element to render.
*/
export default function Edit( { context, attributes, setAttributes } ) {

const { textAlign } = attributes;
const authorPlaceholder = useSelect( select => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(), []);
const author = context['co-authors-plus/author'] || authorPlaceholder;
const authorPlaceholder = useSelect(
( select ) => select( 'co-authors-plus/blocks' ).getAuthorPlaceholder(),
[]
);
const author = context[ 'co-authors-plus/author' ] || authorPlaceholder;
const { description } = author;

return (
Expand All @@ -36,14 +43,12 @@ export default function Edit( { context, attributes, setAttributes } ) {
/>
</BlockControls>
<div
{
...useBlockProps({
className: classnames({
[`has-text-align-${ textAlign }`]: textAlign,
'is-layout-flow': true
})
})
}
{ ...useBlockProps( {
className: classnames( {
[ `has-text-align-${ textAlign }` ]: textAlign,
'is-layout-flow': true,
} ),
} ) }
dangerouslySetInnerHTML={ { __html: description.rendered } }
/>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/block-coauthor-description/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ registerBlockType( metadata.name, {
* @see ./edit.js
*/
edit: Edit,
icon
icon,
} );
4 changes: 1 addition & 3 deletions src/blocks/block-coauthor-image/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
}
}
},
"usesContext": [
"co-authors-plus/author"
],
"usesContext": [ "co-authors-plus/author" ],
"attributes": {
"isLink": {
"type": "boolean",
Expand Down
Loading

0 comments on commit 87ef140

Please sign in to comment.