-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Background attribute gets API for 3rd party plugins to allow other background types, e.g. patterns (tiles) #51465
Comments
Hi @porg, The tabs are hard-coded with only two colors, a solid color, and a gradient color, so for now it appears that arbitrary tabs cannot be inserted. However, it is possible to inject a new button using the /**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useState } from '@wordpress/element';
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
import {
Button,
Dropdown,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
export default function Edit( { clientId } ) {
const [ customBackground, setCustomBackground ] = useState();
const blockProps = useBlockProps();
return (
<>
<InspectorControls group="color">
<ToolsPanelItem
className="block-editor-tools-panel-color-gradient-settings__item"
hasValue={ () => !! customBackground }
label={ __( 'Custom background' ) }
onDeselect={ () => setCustomBackground( undefined ) }
resetAllFilter={ () => ( {
customBackground: undefined,
} ) }
isShownByDefault={ true }
panelId={ clientId }
>
<Dropdown
popoverProps={ { placement: 'bottom-start' } }
renderToggle={ ( { onToggle } ) => (
<Button onClick={ onToggle }>
Custom background
</Button>
) }
renderContent={ ( { onClose } ) => (
<>
<p>This is the content of the popover.</p>
<Button
onClick={ () => {
onClose();
setCustomBackground( '#ff0000' );
} }
>
Set custom background
</Button>
</>
) }
/>
</ToolsPanelItem>
</InspectorControls>
<div { ...blockProps }>Hello World</div>
</>
);
} |
|
All of these are included in the sample code provided in this comment. If a third-party plugin were to add items to the color control or display a drop-down, it would need to write code like this. The same goes for implementing a background pattern like the one you suggested. It may be difficult, but |
Dear t-hamano, thanks but this is again not an answer to my question. Again: How would the user get to the point which is shown on the screenshot? Please as a step by step description like:
X. … which opens a dropdown with the options … Because from the screenshot alone one can really not recognize from where that dropdown menu has opened, and I have also no idea which previous steps led here. Please explain these. Thanks. |
The screenshot I showed you cannot be reached by normal operation. Because unless you write code on the plugin side like I have shown and extend it explicitly, you will not see the UI as shown in the screenshot. |
That's clear to me. Let me rephrase: How would you get to it, if it would be implemented. |
We discuss a concept. Hence in order to give feedback I'd like to know how you would get there. |
Is the following answer what you expect?
|
Is there anything else I can do regarding this issue? I'm having trouble determining what you're looking for, whether you're expecting a new API to be implemented in Gutenberg, or whether you want to know how to implement it using existing APIs. |
To me, this issue feels like a question about specific implementation methods rather than a proposal for a new feature, so I'm closing it. @porg If there's anything I've missed, feel free to comment. |
Proposal
Possible plugin applications
Background pattern
Many more possibilities
The text was updated successfully, but these errors were encountered: