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

feat: add popover docs #129

Merged
merged 1 commit into from
Sep 12, 2023
Merged
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
19 changes: 19 additions & 0 deletions docs/extension/contributes/toolbar.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ Components need to be implemented by developers themselves and exported in `brow
// browser/index.ts
import * as React from 'react';
import { useEffect } from 'react';
import { commands } from 'kaitian-browser';

export const CustomPopover = props => {
useEffect(() => {
Expand All @@ -276,19 +277,37 @@ export const CustomPopover = props => {
return (
<div style={{ width: 200, height: 200, padding: 10 }}>
Hello {props.context?.name}
<button
onClick={() => {
commands.executeCommand('popup.testCommand');
}}
>
Execute Command
</button>
</div>
);
};
```

In this code, a context object can be obtained from props, and the context can be dynamically updated by calling `actionHandler API` from the plug-in Node side.

The Popover can obtain the state passed in by NodeJS from props.context, and it can also use `commands.executeCommand` to invoke the Commands registered in NodeJS.

```ts
// node/index.ts
export function activate() {
const action = await kaitian.toolbar.getToolbarActionButtonHandle(
'sample-start'
);

kaitian.commands.registerCommand('popup.testCommand', () => {
console.log('command executed');
});

action.onClick(() => {
action.showPopover();
});

setInterval(() => {
action.setContext({
// Update context value regularly
Expand Down
19 changes: 19 additions & 0 deletions docs/extension/contributes/toolbar.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export function activate() {
// browser/index.ts
import * as React from 'react';
import { useEffect } from 'react';
import { commands } from 'kaitian-browser';

export const CustomPopover = props => {
useEffect(() => {
Expand All @@ -278,19 +279,37 @@ export const CustomPopover = props => {
return (
<div style={{ width: 200, height: 200, padding: 10 }}>
Hello {props.context?.name}
<button
onClick={() => {
commands.executeCommand('popup.testCommand');
}}
>
调用 Command
</button>
</div>
);
};
```

这段代码中,可以从 props 获取一个 context 对象,context 可以通过插件 Node 端调用 `actionHandler API` 来动态更新。

Popover 可以从 props.context 中获取到 NodeJS 传入的状态,同时又可以使用 `commands.executeCommand` 来调用 NodeJS 中注册的 Commands。

```ts
// node/index.ts
export function activate() {
const action = await kaitian.toolbar.getToolbarActionButtonHandle(
'sample-start'
);

kaitian.commands.registerCommand('popup.testCommand', () => {
console.log('command executed');
});

action.onClick(() => {
action.showPopover();
});

setInterval(() => {
action.setContext({
// 定时更新 context 值
Expand Down
Loading