Skip to content
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

Closed
porg opened this issue Jun 13, 2023 · 10 comments
Labels
[Feature] Plugins API Extending the Gutenberg project with plugins via the Plugins API [Type] Question Questions about the design or development of the editor.

Comments

@porg
Copy link

porg commented Jun 13, 2023

Proposal

WordPress background attribute API for 3rd party plugins

Possible plugin applications

Background pattern

Pattern Generator by Doodad

  • A tile generator like https://doodad.dev/pattern-generator/ could be run as a plugin right from within Gutenberg without the need to save intermediary PNGs/SVGs.
  • You can play around with the controls of the plugin and see the outcome immediately on the canvas of your Site Editor / Block Editor.

Many more possibilities

  • Color palette generators
  • Integration of centrally managed color palettes (cross websites) of design system
  • Dynamic content rendered by JS or WebGL
  • ... (=whatever else the imagination of plugin developers come up with)
@porg porg changed the title Background attribute gets API for 3rd party plugins to allow other backgrounds types like patterns (tiles) Background attribute gets API for 3rd party plugins to allow other backgrounds types, e.g. patterns (tiles) Jun 13, 2023
@porg porg changed the title Background attribute gets API for 3rd party plugins to allow other backgrounds types, e.g. patterns (tiles) Background attribute gets API for 3rd party plugins to allow other background types, e.g. patterns (tiles) Jun 23, 2023
@Thelmachido Thelmachido added [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Feature] Plugins API Extending the Gutenberg project with plugins via the Plugins API [Feature] Block API API that allows to express the block paradigm. [Type] Enhancement A suggestion for improvement. [Type] Feature New feature to highlight in changelogs. labels Jun 26, 2023
@t-hamano
Copy link
Contributor

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 ToolsPanelItem component. You are free to decide what you want to display and how you want it to be processed when the button is pressed. Here is a sample code. Does this approach help?

/**
 * 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>
		</>
	);
}

tools-panel-item

@porg
Copy link
Author

porg commented Jul 17, 2023

@t-hamano

  1. I'm no developer, cannot judge the sample code.
  2. As a UX designer I can judge the interaction and integration though:
  • I cannot give feedback to your proposal as I do not get the whole picture yet: Could you please write up the steps how the user would get to the point which is shown on the screenshot? Where from was the open dropdown menu triggered? How did you create the "Custom background" in the first place? Please as a short video recording or a description of the single steps. Thanks.

@t-hamano
Copy link
Contributor

t-hamano commented Aug 7, 2023

Could you please write up the steps how the user would get to the point which is shown on the screenshot? Where from was the open dropdown menu triggered?

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 [Reference Guides](https://developer.wordpress.org/block-editor/reference-guides/) would be helpful.

@porg
Copy link
Author

porg commented Aug 8, 2023

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:

  1. Select a block.
  2. Open the Inspector.
  3. Go to …

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.

@t-hamano
Copy link
Contributor

t-hamano commented Aug 8, 2023

Again: How would the user get to the point which is shown on the screenshot? Please as a step by step description like:

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.

@porg
Copy link
Author

porg commented Aug 8, 2023

That's clear to me.

Let me rephrase: How would you get to it, if it would be implemented.

@porg
Copy link
Author

porg commented Aug 8, 2023

We discuss a concept. Hence in order to give feedback I'd like to know how you would get there.

@t-hamano
Copy link
Contributor

t-hamano commented Aug 8, 2023

Let me rephrase: How would you get to it, if it would be implemented.

Is the following answer what you expect?

  • Create a custom block with the Edit component as indicated in this comment. Or hook a core block and inject InspectorControls.
  • Insert that block.
  • Click on the "Custom background" item shown in the block sidebar.

@t-hamano
Copy link
Contributor

t-hamano commented Oct 2, 2023

@porg

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.

@t-hamano
Copy link
Contributor

t-hamano commented May 2, 2024

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.

@t-hamano t-hamano closed this as not planned Won't fix, can't repro, duplicate, stale May 2, 2024
@t-hamano t-hamano added [Type] Question Questions about the design or development of the editor. and removed [Type] Enhancement A suggestion for improvement. [Feature] Block API API that allows to express the block paradigm. [Type] Feature New feature to highlight in changelogs. [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi labels May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Plugins API Extending the Gutenberg project with plugins via the Plugins API [Type] Question Questions about the design or development of the editor.
Projects
None yet
Development

No branches or pull requests

3 participants