-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/award-desc-block' into develop
- Loading branch information
Showing
7 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "hrswp/er-award-description", | ||
"title": "ER Award Description", | ||
"category": "text", | ||
"description": "The ER award description.", | ||
"keywords": [ "text" ], | ||
"textdomain": "default", | ||
"attributes": { | ||
"align": { | ||
"type": "string" | ||
}, | ||
"content": { | ||
"type": "string", | ||
"source": "html", | ||
"selector": "p", | ||
"default": "" | ||
}, | ||
"placeholder": { | ||
"type": "string" | ||
}, | ||
"direction": { | ||
"type": "string", | ||
"enum": [ "ltr", "rtl" ] | ||
} | ||
}, | ||
"supports": { | ||
"className": false | ||
}, | ||
"editorScript": "hrswp-employee-recognition" | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, _x, isRTL } from '@wordpress/i18n'; | ||
import { ToolbarDropdownMenu } from '@wordpress/components'; | ||
import { | ||
AlignmentControl, | ||
BlockControls, | ||
RichText, | ||
useBlockProps, | ||
} from '@wordpress/block-editor'; | ||
import { formatLtr } from '@wordpress/icons'; | ||
|
||
function erAwardRTLControl( { direction, setDirection } ) { | ||
return ( | ||
isRTL() && ( | ||
<ToolbarDropdownMenu | ||
controls={ [ | ||
{ | ||
icon: formatLtr, | ||
title: _x( 'Left to right', 'editor button' ), | ||
isActive: direction === 'ltr', | ||
onClick() { | ||
setDirection( | ||
direction === 'ltr' ? undefined : 'ltr' | ||
); | ||
}, | ||
}, | ||
] } | ||
/> | ||
) | ||
); | ||
} | ||
|
||
function erAwardDescriptionEdit( { | ||
attributes, | ||
mergeBlocks, | ||
onReplace, | ||
onRemove, | ||
setAttributes, | ||
} ) { | ||
const { align, content, direction, placeholder } = attributes; | ||
const blockProps = useBlockProps( { | ||
className: classnames( { | ||
[ `has-text-align-${ align }` ]: align, | ||
} ), | ||
style: { direction }, | ||
} ); | ||
|
||
return ( | ||
<> | ||
<BlockControls group="block"> | ||
<AlignmentControl | ||
value={ align } | ||
onChange={ ( newAlign ) => | ||
setAttributes( { align: newAlign } ) | ||
} | ||
/> | ||
<erAwardRTLControl | ||
direction={ direction } | ||
setDirection={ ( newDirection ) => | ||
setAttributes( { direction: newDirection } ) | ||
} | ||
/> | ||
</BlockControls> | ||
<RichText | ||
identifier="content" | ||
tagName="p" | ||
{ ...blockProps } | ||
value={ content } | ||
onChange={ ( newContent ) => | ||
setAttributes( { content: newContent } ) | ||
} | ||
onMerge={ mergeBlocks } | ||
onReplace={ onReplace } | ||
onRemove={ onRemove } | ||
aria-label={ | ||
content | ||
? __( 'ER Award Description' ) | ||
: __( 'Describe the award.' ) | ||
} | ||
data-empty={ content ? false : true } | ||
placeholder={ placeholder || __( 'Describe the award.' ) } | ||
__unstableEmbedURLOnPaste | ||
__unstableAllowPrefixTransformations | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
export default erAwardDescriptionEdit; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { paragraph as icon } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import edit from './edit'; | ||
import metadata from './block.json'; | ||
import save from './save'; | ||
|
||
const { name } = metadata; | ||
|
||
export { metadata, name }; | ||
|
||
export const settings = { | ||
icon, | ||
edit, | ||
save, | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { RichText, useBlockProps } from '@wordpress/block-editor'; | ||
|
||
export default function save( { attributes } ) { | ||
const { align, content, direction } = attributes; | ||
const className = classnames( { | ||
[ `has-text-align-${ align }` ]: align, | ||
} ); | ||
|
||
return ( | ||
<p { ...useBlockProps.save( { className, dir: direction } ) }> | ||
<RichText.Content value={ content } /> | ||
</p> | ||
); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import * as erAwardDescription from './er-award-description'; | ||
|
||
const erAwardBlocks = [ erAwardDescription ]; | ||
|
||
const registerBlock = ( block ) => { | ||
if ( ! block ) { | ||
return; | ||
} | ||
const { metadata, settings, name } = block; | ||
registerBlockType( name, { | ||
...metadata, | ||
...settings, | ||
} ); | ||
}; | ||
|
||
export const registerBlocks = () => { | ||
erAwardBlocks.forEach( registerBlock ); | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { registerBlocks } from './blocks'; | ||
import './editor.css'; | ||
import './style.css'; | ||
|
||
registerBlocks(); |