-
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.
Block Directory: Add list of installed blocks to pre-publish sidebar (#…
…22752) * Block Directory: Pull block icon into a separate component * Add a list of installed blocks to the pre-publish sidebar * Update package-lock * Rename panel * Fix style import * Fix lint issue Co-authored-by: dufresnesteven <[email protected]>
- Loading branch information
1 parent
ee2905e
commit 6e38764
Showing
18 changed files
with
252 additions
and
70 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
38 changes: 38 additions & 0 deletions
38
packages/block-directory/src/components/compact-list/index.js
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,38 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import DownloadableBlockIcon from '../downloadable-block-icon'; | ||
|
||
export default function CompactList( { items } ) { | ||
if ( ! items.length ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<ul className="block-directory-compact-list"> | ||
{ items.map( ( { icon, id, title, author } ) => ( | ||
<li key={ id } className="block-directory-compact-list__item"> | ||
<DownloadableBlockIcon icon={ icon } title={ title } /> | ||
|
||
<div className="block-directory-compact-list__item-details"> | ||
<div className="block-directory-compact-list__item-title"> | ||
{ title } | ||
</div> | ||
<div className="block-directory-compact-list__item-author"> | ||
{ sprintf( | ||
/* translators: %s: Name of the block author. */ | ||
__( 'By %s' ), | ||
author | ||
) } | ||
</div> | ||
</div> | ||
</li> | ||
) ) } | ||
</ul> | ||
); | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/block-directory/src/components/compact-list/style.scss
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,28 @@ | ||
.block-directory-compact-list { | ||
margin: 0; | ||
list-style: none; | ||
} | ||
|
||
.block-directory-compact-list__item { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
margin-bottom: $grid-unit-20; | ||
|
||
&:last-child { | ||
margin-bottom: 0; | ||
} | ||
} | ||
|
||
.block-directory-compact-list__item-details { | ||
margin-left: $grid-unit-10; | ||
} | ||
|
||
.block-directory-compact-list__item-title { | ||
font-weight: 500; | ||
} | ||
|
||
.block-directory-compact-list__item-author { | ||
color: $dark-gray-500; | ||
font-size: 11px; | ||
} |
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
26 changes: 26 additions & 0 deletions
26
packages/block-directory/src/components/downloadable-block-icon/index.js
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 { __, sprintf } from '@wordpress/i18n'; | ||
import { BlockIcon } from '@wordpress/block-editor'; | ||
|
||
function DownloadableBlockIcon( { icon, title } ) { | ||
return ( | ||
<div className="block-directory-downloadable-block-icon"> | ||
{ icon.match( /\.(jpeg|jpg|gif|png)(?:\?.*)?$/ ) !== null ? ( | ||
<img | ||
src={ icon } | ||
alt={ sprintf( | ||
// translators: %s: Name of the plugin e.g: "Akismet". | ||
__( '%s block icon' ), | ||
title | ||
) } | ||
/> | ||
) : ( | ||
<BlockIcon icon={ icon } showColors /> | ||
) } | ||
</div> | ||
); | ||
} | ||
|
||
export default DownloadableBlockIcon; |
11 changes: 11 additions & 0 deletions
11
packages/block-directory/src/components/downloadable-block-icon/style.scss
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 @@ | ||
.block-directory-downloadable-block-icon { | ||
width: $button-size; | ||
height: $button-size; | ||
|
||
.block-editor-block-icon { | ||
width: $button-size; | ||
height: $button-size; | ||
font-size: $button-size; | ||
background-color: $light-gray-300; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...s/block-directory/src/components/downloadable-block-icon/test/__snapshots__/index.js.snap
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,34 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Downloadable Block Icon icon rendering should render a <BlockIcon /> component 1`] = ` | ||
<div | ||
className="block-directory-downloadable-block-icon" | ||
> | ||
<BlockIcon | ||
icon="default" | ||
showColors={true} | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`Downloadable Block Icon icon rendering should render an <img> tag 1`] = ` | ||
<div | ||
className="block-directory-downloadable-block-icon" | ||
> | ||
<img | ||
alt="Block Name block icon" | ||
src="https://ps.w.org/listicles/assets/icon-128x128.png" | ||
/> | ||
</div> | ||
`; | ||
exports[`Downloadable Block Icon icon rendering should render an <img> tag if icon URL has query string 1`] = ` | ||
<div | ||
className="block-directory-downloadable-block-icon" | ||
> | ||
<img | ||
alt="Block Name block icon" | ||
src="https://ps.w.org/listicles/assets/icon-128x128.png?rev=2011672&test=234234" | ||
/> | ||
</div> | ||
`; |
41 changes: 41 additions & 0 deletions
41
packages/block-directory/src/components/downloadable-block-icon/test/index.js
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,41 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { shallow } from 'enzyme'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import DownloadableBlockIcon from '../index'; | ||
|
||
const IMAGE_URL = 'https://ps.w.org/listicles/assets/icon-128x128.png'; | ||
|
||
describe( 'Downloadable Block Icon', () => { | ||
describe( 'icon rendering', () => { | ||
test( 'should render an <img> tag', () => { | ||
const wrapper = shallow( | ||
<DownloadableBlockIcon icon={ IMAGE_URL } title="Block Name" /> | ||
); | ||
expect( wrapper ).toMatchSnapshot(); | ||
} ); | ||
|
||
test( 'should render an <img> tag if icon URL has query string', () => { | ||
const wrapper = shallow( | ||
<DownloadableBlockIcon | ||
icon={ IMAGE_URL + '?rev=2011672&test=234234' } | ||
title="Block Name" | ||
/> | ||
); | ||
|
||
expect( wrapper ).toMatchSnapshot(); | ||
} ); | ||
|
||
test( 'should render a <BlockIcon /> component', () => { | ||
const wrapper = shallow( | ||
<DownloadableBlockIcon icon="default" title="Block Name" /> | ||
); | ||
|
||
expect( wrapper ).toMatchSnapshot(); | ||
} ); | ||
} ); | ||
} ); |
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
46 changes: 46 additions & 0 deletions
46
packages/block-directory/src/plugins/installed-blocks-pre-publish-panel/index.js
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,46 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { _n, sprintf } from '@wordpress/i18n'; | ||
import { PluginPrePublishPanel } from '@wordpress/edit-post'; | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import CompactList from '../../components/compact-list'; | ||
|
||
export default function InstalledBlocksPrePublishPanel() { | ||
const newBlockTypes = useSelect( ( select ) => | ||
select( 'core/block-directory' ).getInstalledBlockTypes() | ||
); | ||
|
||
if ( ! newBlockTypes.length ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<PluginPrePublishPanel | ||
icon="block-default" | ||
title={ sprintf( | ||
// translators: %d: number of blocks (number). | ||
_n( | ||
'Added: %d block', | ||
'Added: %d blocks', | ||
newBlockTypes.length | ||
), | ||
newBlockTypes.length | ||
) } | ||
initialOpen={ true } | ||
> | ||
<p className="installed-blocks-pre-publish-panel__copy"> | ||
{ _n( | ||
'The following block has been added to your site.', | ||
'The following blocks have been added to your site.', | ||
newBlockTypes.length | ||
) } | ||
</p> | ||
<CompactList items={ newBlockTypes } /> | ||
</PluginPrePublishPanel> | ||
); | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/block-directory/src/plugins/installed-blocks-pre-publish-panel/style.scss
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,3 @@ | ||
.installed-blocks-pre-publish-panel__copy { | ||
margin-top: 0; | ||
} |
Oops, something went wrong.