-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
84 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,65 +4,34 @@ title: Writing a Plugin | |
|
||
import { LiveExample } from "../../lib/liveExample.js"; | ||
|
||
In this section, we will explore different ways to write a Grid.js plugin. | ||
|
||
## Using a class | ||
|
||
Grid.js has a `BaseComponent` class which is used everywhere to ensure that all components are receiving the same set of | ||
internal properties and functions. Simply extend this class and add your own functionality to develop a new plugin. | ||
|
||
First of all, import both `BaseComponent` and `BaseProps` from `gridjs`: | ||
Grid.js Plugins are Preact Functional Components. Simply create a new functional component to render a plugin: | ||
|
||
```js | ||
import { BaseComponent, BaseProps, h } from "gridjs"; | ||
import { h } from "gridjs"; | ||
``` | ||
|
||
Then, create a new class and extend `BaseComponent`: | ||
|
||
```js | ||
class MyPlugin extends BaseComponent { | ||
render() { | ||
return h('h1', {}, 'Hello World!'); | ||
} | ||
function MyPlugin () { | ||
return h('h1', {}, 'Hello World!'); | ||
} | ||
``` | ||
|
||
<LiveExample children={ | ||
` | ||
class MyPlugin extends BaseComponent { | ||
render() { | ||
return h('h1', {}, 'Hello World!'); | ||
} | ||
} | ||
|
||
const grid = new Grid({ | ||
columns: ['Name', 'Email', 'Phone Number'], | ||
data: [ | ||
['John', '[email protected]', '(353) 01 222 3333'], | ||
['Mark', '[email protected]', '(01) 22 888 4444'], | ||
] | ||
}); | ||
|
||
grid.plugin.add({ | ||
id: 'myplugin', | ||
component: MyPlugin, | ||
position: PluginPosition.Header, | ||
}); | ||
` | ||
} /> | ||
|
||
## Using a function | ||
|
||
You can also write a simple function that returns a VNode and renders the component: | ||
:::tip | ||
You don't have to use the `h` function to render elements if your bundler is set up to understand Preact JSX renderer: | ||
|
||
```js | ||
import { h } from "gridjs"; | ||
function MyPlugin () { | ||
return <h1>Hello World!</h1>; | ||
} | ||
``` | ||
|
||
See this guide for more details https://preactjs.com/guide/v10/getting-started#setting-up-jsx | ||
::: | ||
|
||
<LiveExample children={ | ||
` | ||
function MyPlugin() { | ||
return h('h1', {}, 'Hello world!'); | ||
function MyPlugin () { | ||
return h('h1', {}, 'Hello World!'); | ||
} | ||
|
||
const grid = new Grid({ | ||
|
@@ -80,4 +49,3 @@ grid.plugin.add({ | |
}); | ||
` | ||
} /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4567540
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
gridjs – ./
gridjs-git-master-tinyapp.vercel.app
gridjs.vercel.app
gridjs.io
www.gridjs.io
gridjs-tinyapp.vercel.app