-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1316c9
commit 90c1f46
Showing
21 changed files
with
456 additions
and
21 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
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 { | ||
createContext, | ||
} from '@wordpress/element'; | ||
|
||
const ButtonEditSettings = createContext( { | ||
urlInPopover: false, | ||
} ); | ||
export { ButtonEditSettings }; |
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,5 @@ | ||
{ | ||
"name": "core/buttons", | ||
"category": "layout", | ||
"attributes": {} | ||
} |
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,70 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { IconButton } from '@wordpress/components'; | ||
import { InnerBlocks } from '@wordpress/block-editor'; | ||
import { createBlock } from '@wordpress/blocks'; | ||
import { useCallback } from '@wordpress/element'; | ||
import { useDispatch } from '@wordpress/data'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { name as buttonBlockName } from '../button/'; | ||
import { ButtonEditSettings } from '../button/edit-settings'; | ||
|
||
const ALLOWED_BLOCKS = [ buttonBlockName ]; | ||
const BUTTON_BLOCK_SETTINGS = { urlInPopover: true }; | ||
const BUTTONS_TEMPLATE = [ [ 'core/button' ] ]; | ||
const UI_PARTS = { | ||
hasSelectedUI: false, | ||
hasFocusedUI: false, | ||
hasHoveredUI: false, | ||
hasBreadcrumbs: false, | ||
hasMovers: false, | ||
hasSpacing: false, | ||
hasSideInserter: false, | ||
}; | ||
|
||
function useInsertButton( clientId ) { | ||
const { insertBlock } = useDispatch( 'core/block-editor' ); | ||
const insertButton = useCallback( | ||
() => { | ||
const buttonBlock = createBlock( buttonBlockName ); | ||
insertBlock( buttonBlock, undefined, clientId ); | ||
}, | ||
[ insertBlock, clientId ] | ||
); | ||
return useCallback( | ||
() => { | ||
return ( | ||
<IconButton | ||
icon="insert" | ||
label={ __( 'Add button' ) } | ||
labelPosition="bottom" | ||
onClick={ insertButton } | ||
/> | ||
); | ||
}, | ||
[ insertButton ] | ||
); | ||
} | ||
|
||
function ButtonsEdit( { clientId, className } ) { | ||
const renderAppender = useInsertButton( clientId ); | ||
return ( | ||
<div className={ className }> | ||
<ButtonEditSettings.Provider value={ BUTTON_BLOCK_SETTINGS }> | ||
<InnerBlocks | ||
allowedBlocks={ ALLOWED_BLOCKS } | ||
renderAppender={ renderAppender } | ||
template={ BUTTONS_TEMPLATE } | ||
__experimentalUIParts={ UI_PARTS } | ||
/> | ||
</ButtonEditSettings.Provider> | ||
</div> | ||
); | ||
} | ||
|
||
export default ButtonsEdit; |
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,37 @@ | ||
.wp-block-buttons .wp-block.block-editor-block-list__block[data-type="core/button"] { | ||
display: inline-block; | ||
width: auto; | ||
} | ||
|
||
.wp-block-buttons { | ||
.block-editor-block-list__block[data-type="core/button"] .block-editor-block-alignment-toolbar { | ||
display: none; | ||
} | ||
|
||
.wp-block-button .wp-block-button__link { | ||
margin-top: 0; | ||
} | ||
} | ||
|
||
.block-editor-block-list__block[data-type="core/buttons"] { | ||
div[data-type="core/button"] div[data-block] { | ||
display: block; | ||
} | ||
|
||
&[data-align="center"] .block-editor-block-list__layout { | ||
display: flex; | ||
align-items: center; | ||
flex-wrap: wrap; | ||
justify-content: center; | ||
} | ||
|
||
&[data-align="right"] .block-editor-block-list__layout { | ||
display: flex; | ||
justify-content: flex-end; | ||
} | ||
|
||
.block-list-appender { | ||
display: inline-block !important; | ||
margin: 0; | ||
} | ||
} |
Oops, something went wrong.