-
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
ccb3ed6
commit 1a6636e
Showing
15 changed files
with
308 additions
and
105 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
59 changes: 59 additions & 0 deletions
59
packages/block-editor/src/components/block-patterns-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,59 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useMemo } from '@wordpress/element'; | ||
import { parse } from '@wordpress/blocks'; | ||
import { ENTER, SPACE } from '@wordpress/keycodes'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BlockPreview from '../block-preview'; | ||
|
||
function BlockPattern( { pattern, onClick } ) { | ||
const { content, viewportWidth } = pattern; | ||
const blocks = useMemo( () => parse( content ), [ content ] ); | ||
|
||
return ( | ||
<div | ||
className="block-editor-block-patterns-list__item" | ||
role="button" | ||
onClick={ () => onClick( pattern, blocks ) } | ||
onKeyDown={ ( event ) => { | ||
if ( ENTER === event.keyCode || SPACE === event.keyCode ) { | ||
onClick( pattern, blocks ); | ||
} | ||
} } | ||
tabIndex={ 0 } | ||
aria-label={ pattern.title } | ||
> | ||
<BlockPreview blocks={ blocks } viewportWidth={ viewportWidth } /> | ||
<div className="block-editor-block-patterns-list__item-title"> | ||
{ pattern.title } | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
function BlockPatternPlaceholder() { | ||
return ( | ||
<div className="block-editor-block-patterns-list__item is-placeholder" /> | ||
); | ||
} | ||
|
||
function BlockPatternList( { blockPatterns, shownPatterns, onClickPattern } ) { | ||
return blockPatterns.map( ( pattern ) => { | ||
const isShown = shownPatterns.includes( pattern ); | ||
return isShown ? ( | ||
<BlockPattern | ||
key={ pattern.name } | ||
pattern={ pattern } | ||
onClick={ onClickPattern } | ||
/> | ||
) : ( | ||
<BlockPatternPlaceholder key={ pattern.name } /> | ||
); | ||
} ); | ||
} | ||
|
||
export default BlockPatternList; |
29 changes: 29 additions & 0 deletions
29
packages/block-editor/src/components/block-patterns-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,29 @@ | ||
.block-editor-block-patterns-list__item { | ||
border-radius: $radius-block-ui; | ||
cursor: pointer; | ||
margin-top: $grid-unit-20; | ||
transition: all 0.05s ease-in-out; | ||
position: relative; | ||
border: $border-width solid transparent; | ||
|
||
&:hover { | ||
border: $border-width solid $theme-color; | ||
} | ||
|
||
&:focus { | ||
box-shadow: inset 0 0 0 1px $white, 0 0 0 $border-width-focus $theme-color; | ||
|
||
// Windows High Contrast mode will show this outline, but not the box-shadow. | ||
outline: 2px solid transparent; | ||
} | ||
|
||
&.is-placeholder { | ||
min-height: 100px; | ||
} | ||
} | ||
|
||
.block-editor-block-patterns-list__item-title { | ||
padding: $grid-unit-05; | ||
font-size: 12px; | ||
text-align: center; | ||
} |
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
File renamed without changes.
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
Oops, something went wrong.