-
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.
Move icon into its own component and user it in compact list.
- Loading branch information
1 parent
249595b
commit 709bd65
Showing
12 changed files
with
133 additions
and
102 deletions.
There are no files selected for viewing
22 changes: 17 additions & 5 deletions
22
packages/block-directory/src/components/downloadable-block-compact-list-item/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
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
24 changes: 0 additions & 24 deletions
24
packages/block-directory/src/components/downloadable-block-header/test/fixtures/index.js
This file was deleted.
Oops, something went wrong.
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; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
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,53 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { shallow } from 'enzyme'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { BlockIcon } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import DownloadableBlockIcon from '../index'; | ||
|
||
const getContainer = ( { icon, title } ) => { | ||
return shallow( <DownloadableBlockIcon icon={ icon } title={ title } /> ); | ||
}; | ||
|
||
const IMAGE_URL = 'https://ps.w.org/listicles/assets/icon-128x128.png'; | ||
const ICON_SLUG = 'default'; | ||
|
||
describe( 'Downloadable Block Icon', () => { | ||
describe( 'icon rendering', () => { | ||
test( 'should render an <img> tag', () => { | ||
const wrapper = getContainer( { | ||
icon: IMAGE_URL, | ||
title: 'Block Name', | ||
} ); | ||
expect( wrapper.find( 'img' ).prop( 'src' ) ).toEqual( IMAGE_URL ); | ||
} ); | ||
|
||
test( 'should render an <img> tag if icon URL has query string', () => { | ||
const iconURLwithQueryString = | ||
IMAGE_URL + '?rev=2011672&test=234234'; | ||
const wrapper = getContainer( { | ||
icon: iconURLwithQueryString, | ||
title: 'Block Name', | ||
} ); | ||
expect( wrapper.find( 'img' ).prop( 'src' ) ).toEqual( | ||
iconURLwithQueryString | ||
); | ||
} ); | ||
|
||
test( 'should render a <BlockIcon/> component', () => { | ||
const wrapper = getContainer( { | ||
icon: ICON_SLUG, | ||
title: 'Block Name', | ||
} ); | ||
expect( wrapper.find( BlockIcon ) ).toHaveLength( 1 ); | ||
} ); | ||
} ); | ||
} ); |
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