-
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
95e769d
commit 578c1f2
Showing
20 changed files
with
403 additions
and
22 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,60 @@ | ||
/** | ||
* 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' ] ]; | ||
|
||
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 } | ||
/> | ||
</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,78 @@ | ||
.wp-block-buttons .block-editor-block-list__block[data-type="core/button"] { | ||
display: inline-block; | ||
} | ||
|
||
|
||
.wp-block-buttons { | ||
// 1. Reset margins on immediate innerblocks container. | ||
> .block-editor-inner-blocks > .block-editor-block-list__layout { | ||
margin-left: 0; | ||
margin-right: 0; | ||
} | ||
|
||
// 2. Remove paddings on subsequent immediate children. | ||
> .block-editor-inner-blocks > .block-editor-block-list__layout > .wp-block { | ||
width: auto; | ||
padding-left: 0; | ||
padding-right: 0; | ||
} | ||
|
||
// 3. Remove margins on subsequent Edit container. | ||
> .block-editor-inner-blocks > .block-editor-block-list__layout > .wp-block > .block-editor-block-list__block-edit { | ||
margin-left: 0; | ||
margin-right: 0; | ||
} | ||
|
||
// 4. Hide the block outlines. | ||
> .block-editor-inner-blocks > .block-editor-block-list__layout > .wp-block > .block-editor-block-list__block-edit::before { | ||
content: none; | ||
} | ||
|
||
// 5. Remove vertical margins on subsequent block container. | ||
> .block-editor-inner-blocks > .block-editor-block-list__layout > .wp-block > .block-editor-block-list__block-edit > [data-block] { | ||
margin-top: 0; | ||
margin-bottom: 0; | ||
} | ||
|
||
// Hide the breadcrumb. | ||
// Hide the mover. | ||
.block-editor-block-list__breadcrumb, | ||
.block-editor-block-mover.block-editor-block-mover { // Needs specificity. | ||
display: none; | ||
} | ||
|
||
.block-editor-inserter { | ||
display: none; | ||
} | ||
|
||
.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; | ||
} | ||
} |
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,8 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { G, Path, SVG } from '@wordpress/components'; | ||
|
||
export default ( | ||
<SVG viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><Path fill="none" d="M0 0h24v24H0V0z" /><G><Path d="M19 6H5c-1.1 0-2 .9-2 2v8c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zm0 10H5V8h14v8z" /></G></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,29 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import edit from './edit'; | ||
import icon from './icon'; | ||
import metadata from './block.json'; | ||
import save from './save'; | ||
|
||
const { name } = metadata; | ||
|
||
export { metadata, name }; | ||
|
||
export const settings = { | ||
title: __( 'Buttons' ), | ||
description: __( 'Prompt visitors to take action with a group of button-style links.' ), | ||
icon, | ||
keywords: [ __( 'link' ) ], | ||
supports: { | ||
align: true, | ||
alignWide: false, | ||
}, | ||
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,12 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { InnerBlocks } from '@wordpress/block-editor'; | ||
|
||
export default function save() { | ||
return ( | ||
<div> | ||
<InnerBlocks.Content /> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.