Logo

dev-resources.site

for different kinds of informations.

Update Content for a Custom Block Toolbar Button (Full Site Editing)

Published at
1/1/2023
Categories
wordpress
gutenberg
fullsiteediting
blocktheme
Author
sneeitdotcom
Author
12 person written this
sneeitdotcom
open
Update Content for a Custom Block Toolbar Button (Full Site Editing)

Hello,

I am trying to create a custom button on the Block Toolbar of the Full Site Editor. This button could insert custom content to paragraphs, button text, or headings. But I don’t know how to finish my code. Here is the code:

import { registerFormatType } from '@wordpress/rich-text';
import { BlockControls } from '@wordpress/block-editor';
import { ToolbarGroup, ToolbarButton, Button } from '@wordpress/components';

/*
https://developer.wordpress.org/block-editor/reference-guides/components/modal/
*/
import { Modal } from '@wordpress/components';
import { useState } from '@wordpress/element';

const MyCustomButtonIcon = ( props ) => {    

    const [ isOpen, setOpen ] = useState( false );
    const openModal = () => setOpen( true );
    const closeModal = () => setOpen( false );



    return (
        <BlockControls>
            <ToolbarGroup>
                <ToolbarButton
                    icon="buddicons-activity"
                    title="Custom Icon"
                    onClick={ openModal }                    
                />
                { isOpen && (
                <Modal title="Search an Icon" onRequestClose={ closeModal }>
                    <Button onClick={'**What should I put here to update the content?**'}>
                        Insert a thing
                    </Button>

                </Modal>
            ) }
            </ToolbarGroup>
        </BlockControls>
    );
};

registerFormatType( 'my-custom-format/my-sample-output', {
    title: 'Custom Icon',
    tagName: 'i',
    className: null,    
    attributes: {
        className: 'class'        
    },
    edit: MyCustomButtonIcon,
} );
Enter fullscreen mode Exit fullscreen mode

Hope you could help me on this. What is the function that I need to use to update the content of the block?

Thank you very much.

gutenberg Article's
30 articles in total
Favicon
WordPress Data Views: Basic setup
Favicon
A Beginner’s Guide to Global State Management in WordPress Gutenberg
Favicon
Comparing the Drupal and WordPress Implementations of Gutenberg themes, blocks, and more!
Favicon
WordPress Interactivity API: Detailed Explanation
Favicon
2 easy ways disable Gutenberg editor in WordPress
Favicon
WooCommerce Checkout Blocks
Favicon
MaxiBlocks
Favicon
How to create Gutenberg blocks using Advanced Custom Fields in WordPress
Favicon
Gutenberg vs Elementor
Favicon
How and Why to Build Custom Gutenberg Blocks in WordPress
Favicon
How to register custom Gutenberg Block Category
Favicon
Creating Gutenberg Blocks with Advanced Custom Fields (ACF) and LazyBlocks: A Comparative Guide
Favicon
Gutenberg Block to retrieve GitHub public repositories (and enhance a portfolio)
Favicon
Update Content for a Custom Block Toolbar Button (Full Site Editing)
Favicon
How to Create a Product Page - P5 - Using Meta Box and Gutenberg
Favicon
Introducing Theme Redone - the modern WordPress Starter Theme
Favicon
Embed privacy: Free 2-click-privacy plugin for YouTube and Twitter
Favicon
Gutenberg 13.0 och förbättringar i Wordpress 6.0
Favicon
How to Display Images from Cloneable Fields - P1 - with Gutenberg
Favicon
Gutenberg cheatsheet – Block's `supports` property
Favicon
Gutenberg – Block Deprecation
Favicon
Why Gutenberg is killing Wordpress
Favicon
How Symfony Station was built: an adventurous exploration of layout solutions
Favicon
Full Site Editing - P5: What Are Block Patterns in Gutenberg? How to Create Them?
Favicon
Review Quadrat - A WordPress Block Theme
Favicon
The Future of WordPress Themes in 5.8 and Beyond.
Favicon
Full Site Editing (FSE) - All You Need To Know - P1 - Overview
Favicon
Gutenberg vs. Page Builders - What is Better & Faster? In-depth Comparison
Favicon
Gutenberg Full Width Editor with Blocks Border Plugin
Favicon
Create a Custom Gutenberg Block Plugin with Underpin

Featured ones: