-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a SiteDescription block similar to SiteTitle
- Loading branch information
Showing
8 changed files
with
145 additions
and
1 deletion.
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
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,39 @@ | ||
{ | ||
"name": "core/site-description", | ||
"category": "layout", | ||
"supports": { | ||
"align": [ "wide", "full" ], | ||
"html": false, | ||
"multiple": false, | ||
"reusable": false | ||
}, | ||
"attributes": { | ||
"align": { | ||
"type": "string", | ||
"default": "wide" | ||
}, | ||
"textAlign": { | ||
"type": "string", | ||
"default": "center" | ||
}, | ||
"textColor": { | ||
"type": "string" | ||
}, | ||
"customTextColor": { | ||
"type": "string" | ||
}, | ||
"backgroundColor": { | ||
"type": "string" | ||
}, | ||
"customBackgroundColor": { | ||
"type": "string" | ||
}, | ||
"fontSize": { | ||
"type": "string", | ||
"default": "small" | ||
}, | ||
"customFontSize": { | ||
"type": "number" | ||
} | ||
} | ||
} |
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,65 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
useEntityProp, | ||
__experimentalUseEntitySaving, | ||
} from '@wordpress/core-data'; | ||
import { Button } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { PlainText } from '@wordpress/block-editor'; | ||
import { compose } from '@wordpress/compose'; | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
import { ENTER } from '@wordpress/keycodes'; | ||
|
||
function SiteDescriptionEdit( { insertDefaultBlock } ) { | ||
const [ description, setDescription ] = useEntityProp( 'root', 'site', 'description' ); | ||
const [ isDirty, isSaving, save ] = __experimentalUseEntitySaving( | ||
'root', | ||
'site', | ||
'description' | ||
); | ||
|
||
const preventNewlines = ( event ) => { | ||
if ( event.keyCode === ENTER ) { | ||
event.preventDefault(); | ||
insertDefaultBlock(); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Button | ||
isPrimary | ||
className="wp-block-site-description__save-button" | ||
disabled={ ! isDirty || ! description } | ||
isBusy={ isSaving } | ||
onClick={ save } | ||
> | ||
{ __( 'Update' ) } | ||
</Button> | ||
<PlainText | ||
placeholder={ __( 'Site Description' ) } | ||
value={ description } | ||
onChange={ setDescription } | ||
isStylable | ||
onKeyDown={ preventNewlines } | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
export default compose( [ | ||
withSelect( ( select, { clientId } ) => { | ||
const { getBlockIndex, getBlockRootClientId } = select( 'core/block-editor' ); | ||
const rootClientId = getBlockRootClientId( clientId ); | ||
return { | ||
blockIndex: getBlockIndex( clientId, rootClientId ), | ||
rootClientId, | ||
}; | ||
} ), | ||
withDispatch( ( dispatch, { blockIndex, rootClientId } ) => ( { | ||
insertDefaultBlock: () => | ||
dispatch( 'core/block-editor' ).insertDefaultBlock( undefined, rootClientId, blockIndex + 1 ), | ||
} ) ), | ||
] )( SiteDescriptionEdit ); |
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,6 @@ | ||
.wp-block-site-description__save-button { | ||
position: absolute; | ||
right: 0; | ||
top: 0; | ||
z-index: z-index(".wp-block-site-description__save-button"); | ||
} |
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,11 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { SVG, Path } from '@wordpress/components'; | ||
|
||
export default ( | ||
<SVG xmlns="http://www.w3.org/2000/svg" width="24" height="24"> | ||
<Path fill="none" d="M0 0h24v24H0z" /> | ||
<Path d="M4 9h16v2H4V9zm0 4h10v2H4v-2z" /> | ||
</SVG> | ||
); |
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,20 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import metadata from './block.json'; | ||
import icon from './icon'; | ||
import edit from './edit'; | ||
|
||
const { name } = metadata; | ||
export { metadata, name }; | ||
|
||
export const settings = { | ||
title: __( 'Site Description' ), | ||
icon, | ||
edit, | ||
}; |