Issue #2350Opened October 23, 2019by AbdiasM14 reactions

[Question] How do I add elements/sectors to views container using a custom button in the Panel

Question

Code SnippetTEXT
I have added a custom button to the Panel as below:

        const pm = editor.Panels;        
        pm.addButton('views', {
            id: 'customButton',
            className: '',
            command: {
                run: function (editor) {
                    alert("Hello");
                },
                stop: function (editor) {

                }
            },
            attributes: { class: 'fa fa-address-card-o' },
            active: false,
        });

I would like to add custom elements in the views-container when this button is clicked. Screen shot attached. Could you please help with this?

![CustomButtonClick](https://user-images.githubusercontent.com/18558443/67381298-540e1d00-f5a9-11e9-8c79-4d3284820d32.PNG)

Answers (3)

pouyamiralayiFebruary 18, 202013 reactions

@AbdiasM @ko06 sorry for being late on this! based on #277

        const pn = editor.Panels
        let editPanel = null
        pn.addButton('views', {
            id: 'editMenu',
            attributes: {class: 'fa fa-address-card-o', title: "Edit Menu"},
            active: false,
            command: {
                run: function (editor) {
                    if(editPanel == null){
                        const editMenuDiv = document.createElement('div')
                        editMenuDiv.innerHTML = `
                        <div id="your-content">
                             Input: <input/>
                             <button>Button</button> 
                              <!-- eg. bind a click event on button and do something with GrapesJS API -->
                        </div>
                    `
                        const panels = pn.getPanel('views-container')
                        panels.set('appendContent', editMenuDiv).trigger('change:appendContent')
                        editPanel = editMenuDiv
                    }
                    editPanel.style.display = 'block'
                },
                stop: function (editor) {
                    if(editPanel != null){
                        editPanel.style.display = 'none'
                    }
                }

            }
        })

Cheers!

hc0127December 12, 20231 reactions

Hi, @pouyamiralayi . thanks for your post. I got custom view container. But I wanna use react components on that part. Is it possible? if so, Please help me.

ko06October 24, 20190 reactions

is this fixed?

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.