-
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
1eca362
commit 50429bf
Showing
19 changed files
with
402 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
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,58 @@ | ||
/** | ||
* 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 }; | ||
|
||
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 } | ||
/> | ||
</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,80 @@ | ||
.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; | ||
} | ||
|
||
.block-editor-block-list__layout { | ||
display: flex; | ||
align-items: center; | ||
flex-wrap: wrap; | ||
} | ||
|
||
&[data-align="center"] .block-editor-block-list__layout { | ||
justify-content: center; | ||
} | ||
|
||
&[data-align="right"] .block-editor-block-list__layout { | ||
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> | ||
); | ||
} |
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,7 @@ | ||
.wp-block-buttons .wp-block-button { | ||
display: inline-block; | ||
margin: $grid-size-small; | ||
} | ||
.wp-block-buttons.aligncenter { | ||
text-align: center; | ||
} |
Oops, something went wrong.