-
Notifications
You must be signed in to change notification settings - Fork 51
Add ability to show inline media controls for the Image component
#172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0e644f8
Added inline controls logic
ncoetzer f66c4db
Added a multi-image example block
ncoetzer 579a84a
Fix optional default
ncoetzer 050e31a
Add example when not optional
ncoetzer 7b1dceb
Merge branch 'develop' into feature/image-inline-controls-option
fabiankaegy 3bff3cd
Merge branch 'develop' into feature/image-inline-controls-option
fabiankaegy 30022d2
Merge branch 'develop' into feature/image-inline-controls-option
fabiankaegy b35bc4d
Merge branch 'develop' into feature/image-inline-controls-option
ncoetzer 3bbdf17
Remove custom inline controls icons
ncoetzer 8dc3dcd
Updated inline controls design/display
ncoetzer f256f00
Corrected the focalpoint object in multi-image example block.json
ncoetzer b172c19
Added linebreaks for attributes/props to multi-image example edit file
ncoetzer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,20 @@ | ||
| const Replace = () => ( | ||
| <svg id="replace" xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"> | ||
| <path d="M59,22H48V5a5.006,5.006,0,0,0-5-5H5A5.006,5.006,0,0,0,0,5V37a5.006,5.006,0,0,0,5,5H16V59a5.006,5.006,0,0,0,5,5H59a5.006,5.006,0,0,0,5-5V27A5.006,5.006,0,0,0,59,22ZM5,40a3,3,0,0,1-3-3V5A3,3,0,0,1,5,2H43a3,3,0,0,1,3,3V22H21a5.006,5.006,0,0,0-5,5V40ZM62,59a3,3,0,0,1-3,3H21a3,3,0,0,1-3-3V27a3,3,0,0,1,3-3H59a3,3,0,0,1,3,3Z" /> | ||
| <path d="M52,10h4a1,1,0,0,1,1,1v3.586l-.293-.293a1,1,0,0,0-1.414,1.414l2,2a1,1,0,0,0,1.416,0l2-2a1,1,0,0,0-1.414-1.414L59,14.586V11a3,3,0,0,0-3-3H52a1,1,0,0,0,0,2Z" /> | ||
| <path d="M12,54H8a1,1,0,0,1-1-1V49.414l.293.293a1,1,0,0,0,1.414-1.414l-2-2a.99.99,0,0,0-.326-.217,1,1,0,0,0-1.09.217l-2,2a1,1,0,0,0,1.414,1.414L5,49.414V53a3,3,0,0,0,3,3h4a1,1,0,0,0,0-2Z" /> | ||
| <path d="M48.3,36.345a5,5,0,0,0-9.062,0L38.279,38.4a4.99,4.99,0,0,0-7.984,1.313L22.32,55.659A3,3,0,0,0,25,60H54.625a3,3,0,0,0,2.719-4.269ZM25,58a1,1,0,0,1-.894-1.448L32.083,40.6a3,3,0,0,1,5.366,0l8.7,17.4Zm30.468-.463a.984.984,0,0,1-.844.463H48.385L39.567,40.364l1.481-3.174a3,3,0,0,1,5.438,0l9.047,19.387a.984.984,0,0,1-.063.96Z" /> | ||
| <path d="M32.767,34a4,4,0,1,0-4-4A4,4,0,0,0,32.767,34Zm0-6a2,2,0,1,1-2,2A2,2,0,0,1,32.767,28Z" /> | ||
| </svg> | ||
| ); | ||
|
|
||
| const Remove = () => ( | ||
| <svg xmlns="http://www.w3.org/2000/svg" width="44" height="44" viewBox="0 0 44 44"> | ||
| <path | ||
| d="M175.976,132.887a1.524,1.524,0,0,0-2.154,0l-19.39,19.382-19.39-19.382A1.523,1.523,0,0,0,132.849,135l.038.038,19.39,19.382L132.887,173.8A1.523,1.523,0,1,0,135,175.994l.037-.037,19.39-19.382,19.39,19.382a1.523,1.523,0,0,0,2.154-2.153l-19.39-19.382,19.39-19.382A1.522,1.522,0,0,0,175.976,132.887Z" | ||
| transform="translate(-132.422 -132.422)" | ||
| /> | ||
| </svg> | ||
| ); | ||
|
|
||
| export { Replace, Remove }; |
This file contains hidden or 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 hidden or 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 hidden or 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,82 @@ | ||
| import styled from '@emotion/styled'; | ||
|
|
||
| export const InlineControlsStyleWrapper = styled('div')` | ||
| line-height: 0; | ||
| position: relative; | ||
|
|
||
| &:hover, | ||
| &:focus, | ||
| &:focus-visible, | ||
| &:focus-within { | ||
| & .inline-controls { | ||
| opacity: 1; | ||
| pointer-events: all; | ||
| } | ||
| } | ||
|
|
||
| & .inline-controls { | ||
| position: absolute; | ||
| top: 0; | ||
| left: 0; | ||
| display: flex; | ||
| flex-direction: row; | ||
| gap: 5px; | ||
| width: 100%; | ||
| height: 100%; | ||
| justify-content: center; | ||
| align-items: center; | ||
| opacity: 0; | ||
| pointer-events: none; | ||
| transition: opacity 250ms ease-out; | ||
|
|
||
| &::after { | ||
| content: ''; | ||
| position: absolute; | ||
| top: 0; | ||
| left: 0; | ||
| width: 100%; | ||
| height: 100%; | ||
| background-color: rgba(0, 0, 0, 0.5); | ||
| z-index: 0; | ||
| } | ||
|
|
||
| & > * { | ||
| z-index: 1; | ||
| } | ||
|
|
||
| & .components-button { | ||
| --button-text: #fff; | ||
| --button-background: var(--wp-admin-theme-color); | ||
| white-space: nowrap; | ||
| background: var(--button-background); | ||
| color: var(--button-text); | ||
| text-decoration: none; | ||
| text-shadow: none; | ||
| outline: 1px solid transparent; | ||
| width: 60px; | ||
| height: 60px; | ||
| border-radius: 50%; | ||
| padding: 12px; | ||
| border: 1px solid var(--button-background); | ||
|
|
||
| & svg { | ||
| width: 100%; | ||
| height: 100%; | ||
| } | ||
|
|
||
| &:focus:not(.disabled) { | ||
| outline: var(--wp-admin-theme-color); | ||
| } | ||
|
|
||
| &:hover:not(.disabled), | ||
| &:active:not(.disabled) { | ||
| --button-text: #fff; | ||
| --button-background: var(--wp-admin-theme-color-darker-10); | ||
| } | ||
|
|
||
| &.remove-button { | ||
| padding: 18px; | ||
| } | ||
| } | ||
| } | ||
| `; |
This file contains hidden or 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,44 @@ | ||
| { | ||
| "name": "example/multiple-image-example", | ||
| "apiVersion": 2, | ||
| "title": "Multiple Image Example", | ||
| "description": "Multiple images block to show the Image with inline controls in usage", | ||
| "icon": "smiley", | ||
| "category": "common", | ||
| "example": {}, | ||
| "supports": { | ||
| "html": false | ||
| }, | ||
| "attributes": { | ||
| "image1": { | ||
| "type": "number" | ||
| }, | ||
| "image2": { | ||
| "type": "number" | ||
| }, | ||
| "image3": { | ||
| "type": "number" | ||
| }, | ||
| "focalPoint1": { | ||
| "type": "object", | ||
| "default": { | ||
| "x": 0.5, | ||
| "y": 0.5 | ||
| } | ||
| }, | ||
| "focalPoint2": { | ||
| "type": "object", | ||
| "default": { | ||
| "x": 0.5, | ||
| "y": 0.5 | ||
| } | ||
| }, | ||
| "focalPoint3": { | ||
| "type": "object", | ||
| "default": { | ||
| "x": 0.5, | ||
| "y": 0.5 | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,25 @@ | ||
| import { __ } from '@wordpress/i18n'; | ||
| import { useBlockProps } from '@wordpress/block-editor'; | ||
|
|
||
| import { Image } from '@10up/block-components'; | ||
|
|
||
| export function BlockEdit(props) { | ||
| const { | ||
| attributes, | ||
| setAttributes | ||
| } = props; | ||
|
|
||
| const { image1, image2, image3, focalPoint1, focalPoint2, focalPoint3 } = attributes; | ||
| const blockProps = useBlockProps(); | ||
|
|
||
| return ( | ||
| <div {...blockProps}> | ||
|
|
||
| <Image id={image1} size="large" onSelect={(image) => setAttributes({image1: image.id })} className="example-image" focalPoint={focalPoint1} onChangeFocalPoint={(value) => setAttributes({focalPoint1: value})} hasInlineControls={true} onRemove={() => setAttributes({image1: null})} isOptional={false} /> | ||
|
|
||
| <Image id={image2} size="large" onSelect={(image) => setAttributes({image2: image.id })} className="example-image" focalPoint={focalPoint2} onChangeFocalPoint={(value) => setAttributes({focalPoint2: value})} hasInlineControls={true} onRemove={() => setAttributes({image2: null})} /> | ||
|
|
||
| <Image id={image3} size="large" onSelect={(image) => setAttributes({image3: image.id })} className="example-image" focalPoint={focalPoint3} onChangeFocalPoint={(value) => setAttributes({focalPoint3: value})} hasInlineControls={true} onRemove={() => setAttributes({image3: null})} /> | ||
| </div> | ||
| ) | ||
| } | ||
This file contains hidden or 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,10 @@ | ||
| import { registerBlockType } from '@wordpress/blocks'; | ||
| import { __ } from '@wordpress/i18n'; | ||
|
|
||
| import { BlockEdit } from './edit'; | ||
| import metadata from './block.json'; | ||
|
|
||
| registerBlockType( metadata, { | ||
| edit: BlockEdit, | ||
| save: () => null | ||
| } ); |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.