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

Editor Panels #224

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const deprecationsSidebar = require('./sidebars/deprecations');
const dynamicTagsSidebar = require('./sidebars/dynamic-tags');
const editorSidebar = require('./sidebars/editor');
const editorControlsSidebar = require('./sidebars/editor-controls');
const editorPanelsSidebar = require('./sidebars/editor-panels');
const finderSidebar = require('./sidebars/finder');
const formActionsSidebar = require('./sidebars/form-actions');
const formFieldsSidebar = require('./sidebars/form-fields');
Expand Down Expand Up @@ -201,6 +202,7 @@ module.exports = {
'/dynamic-tags/': dynamicTagsSidebar,
'/editor/': editorSidebar,
'/editor-controls/': editorControlsSidebar,
'/editor-panels/': editorPanelsSidebar,
'/getting-started/': gettingStartedSidebar,
'/hello-elementor-theme/': helloElementorTheme,
'/finder/': finderSidebar,
Expand Down
39 changes: 39 additions & 0 deletions src/.vuepress/sidebars/editor-panels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = [
{
title: 'Editor Panels',
collapsable: false,
sidebarDepth: -1,
children: [
['', 'Introduction'],
]
},
{
title: 'Managing Panels',
collapsable: false,
sidebarDepth: -1,
children: [
'add-new-panel',
]
},
{
title: 'Creating Panels',
collapsable: false,
sidebarDepth: -1,
children: [
'panel-structure',
'panel-actions',
'panel-status',
'panel-create',
'panel-register',
]
},
{
title: 'Examples',
collapsable: false,
sidebarDepth: -1,
children: [
'simple-example',
'advanced-example',
]
},
];
30 changes: 30 additions & 0 deletions src/editor-panels/add-new-panel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Add New Panel

<Badge type="tip" vertical="top" text="Elementor Core" /> <Badge type="warning" vertical="top" text="Intermediate" />

Elementor offers many built-in editor panels out of the box, but it also allows external developers to register new editor panels.

## Hooks

To add new editor panels we need to enqueue the JS files that handle the panels registration process. The `elementor/editor/v2/scripts/enqueue` action hook enqueues the scripts that handle the Elementor Editor components. Please note that `elementor-packages-editor-panels` is a dependency script for panel components.

## Panels Script

To enqueue the script that adds new editor panels use the following code:

```php
function enqueue_new_editor_panels() {

wp_enqueue_script(
'my-plugin',
plugins_url( 'assets/js/my-plugin-editor-panel.js', __FILE__ ),
[ 'elementor-packages-editor-panels' ],
null,
true
);

}
add_action( 'elementor/editor/v2/scripts/enqueue', 'enqueue_new_editor_panels' );
```

For more information about the [panel structure](./panel-structure.md), read about the widget class structure.
57 changes: 57 additions & 0 deletions src/editor-panels/advanced-example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Advanced Example

<Badge type="tip" vertical="top" text="Elementor Core" /> <Badge type="warning" vertical="top" text="Intermediate" />

[intro] (No webpack)

## Folder Structure

The addon will have the following folder structure:

```
elementor-editor-panels/
|
├─ assets/
| └─ js/
| ├─ components/
| | ├─ my-panel-1.jsx
| | └─ my-panel-2.jsx
| |
| ├─ index.js
| ├─ init.js
| └─ panels.js
|
└─ elementor-editor-panels.php
```

## Plugin Files

**elementor-editor-panels.php**

```php
```

**assets/js/index.js**

```js
```

**assets/js/init.js**

```js
```

**assets/js/panels.js**

```js
```

**assets/js/components/my-panel-1.jsx**

```jsx
```

**assets/js/components/my-panel-2.jsx**

```jsx
```
26 changes: 26 additions & 0 deletions src/editor-panels/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Elementor Editor Panels

<Badge type="tip" vertical="top" text="Elementor Core" /> <Badge type="warning" vertical="top" text="Intermediate" />

The editor panels are part of the [Elementor Editor](./../editor/). The panel is an interface that allows the user to change certain settings. The editor panels are extendable and 3rd party developers can create new custom panels in the editor.

## Managing Panels

External developers can enqueue scripts that register new editor panels:

* [Add New Panel](./add-new-panel/)

## Creating Panels

* [Panel Structure](./panel-structure/)
* [Panel Actions](./panel-actions/)
* [Panel Status](./panel-status/)
* [Panel Create](./panel-create/)
* [Panel Register](./panel-register/)

## Code Examples

Check out how easy it is to create Elementor editor panels:

* [Simple Example](./simple-example/)
* [Advanced Example](./advanced-example/)
36 changes: 36 additions & 0 deletions src/editor-panels/panel-actions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Panel Actions

<Badge type="tip" vertical="top" text="Elementor Core" /> <Badge type="warning" vertical="top" text="Intermediate" />

When registering a new panel, you get a React hook for panel-related actions:

**panel.js**

```js
import { createPanel, registerPanel } from '@elementor/editor-panels';
import MyPanel from './components/my-panel';

export const { usePanelActions } = createPanel( {
id: 'my-panel',
component: MyPanel,
} );
```

**components/my-app.jsx**

```jsx
import { usePanelActions } from '../panel';

export default function MyApp() {
const { open, close } = usePanelActions();

return (
<>
<button onClick={ open }>Open Panel</button>
<button onClick={ close }>Close Panel</button>
</>
);
}
```

The above buttons will open and close the specific panel that we created in `panel.js`.
3 changes: 3 additions & 0 deletions src/editor-panels/panel-create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Panel Create

<Badge type="tip" vertical="top" text="Elementor Core" /> <Badge type="warning" vertical="top" text="Intermediate" />
3 changes: 3 additions & 0 deletions src/editor-panels/panel-register.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Panel Register

<Badge type="tip" vertical="top" text="Elementor Core" /> <Badge type="warning" vertical="top" text="Intermediate" />
39 changes: 39 additions & 0 deletions src/editor-panels/panel-status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Panel Status

<Badge type="tip" vertical="top" text="Elementor Core" /> <Badge type="warning" vertical="top" text="Intermediate" />

When registering a new panel, you get a React hook for the panel status:

**panel.js**

```js
import { createPanel, registerPanel } from '@elementor/editor-panels';
import MyPanel from './components/my-panel';

export const { usePanelStatus } = createPanel( {
id: 'my-panel',
component: MyPanel,
} );
```

**components/my-app.jsx**

```jsx
import { usePanelStatus } from '../panel';

export default function MyApp() {
const { isOpen, isBlocked } = usePanelStatus();

return (
<>
<p>Panel is { isOpen ? 'open' : 'closed' }</p>
<p>Panel is { isBlocked ? 'blocked' : 'not blocked' }</p>
</>
);
}
```

This hook will return the following values:

- `isOpen` - `true` if the panel is open, `false` otherwise.
- `isBlocked` - `true` if the panel can be interacted with, `false` otherwise.
64 changes: 64 additions & 0 deletions src/editor-panels/panel-structure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Panel Structure

<Badge type="tip" vertical="top" text="Elementor Core" /> <Badge type="warning" vertical="top" text="Intermediate" />

Elementor Editor panels are built with components. You can import these panel components from the `@elementor/editor-panels` at build time or use the `window.elementor-v2.editor-panels` global object at run time.

## Panel Components

Elementor uses the folowing panel components:

- `<Panel>` - wrapper component for editor panels.
- `<PanelHeader>` - wrapper component for editor panel header.
- `<PanelHeaderTitle>` - wrapper component for the panel header text.
- `<PanelBody>` - wrapper component for the pael content.

::: tip Note
You don't _have_ to use Elementor's components, but we _highly_ recommend using them in order to keep consistency across all the Editor panels and have better UX for the users.
:::

## Usage

### Build Time

```jsx
import { Panel, PanelHeader, PanelHeaderTitle, PanelBody } from '@elementor/editor-panels';

export default function MyPanel() {
return (
<Panel>
<PanelHeader>
<PanelHeaderTitle>
{/* Panel title */}
</PanelHeaderTitle>
</PanelHeader>

<PanelBody>
{/* Panel content */}
</PanelBody>
</Panel>
);
}
```

### Run Time

```jsx
const { Panel, PanelHeader, PanelHeaderTitle, PanelBody } = window.elementor-v2.editorPanels;

export default function MyPanel() {
return (
<Panel>
<PanelHeader>
<PanelHeaderTitle>
{/* Panel title */}
</PanelHeaderTitle>
</PanelHeader>

<PanelBody>
{/* Panel content */}
</PanelBody>
</Panel>
);
}
```
Loading