forked from nirsky/figma-plugin-react-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
42 lines (35 loc) · 1.03 KB
/
App.tsx
File metadata and controls
42 lines (35 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import React, { useRef } from 'react';
import useOnPluginMessage from '../hooks/useOnPluginMessage';
import triggerPluginAction from '../util/triggerPluginAction';
import { PLUGIN_ACTIONS } from '../constants';
function App() {
const inputRef = useRef(null)
const onCreate = () => {
const text = inputRef.current.value;
triggerPluginAction({ type: PLUGIN_ACTIONS.CREATE_BUTTON, text })
};
const onCancel = () => {
triggerPluginAction({ type: PLUGIN_ACTIONS.CANCEL } )
};
// This is how we read messages sent from the plugin controller
useOnPluginMessage((pluginMessage) => {
console.log(pluginMessage);
const { type, message } = pluginMessage;
if (type === PLUGIN_ACTIONS.CREATE_BUTTON) {
console.log(`Figma Says: ${message}`);
}
});
return (
<div>
<h1>Button Creator</h1>
<p>
Title <input ref={inputRef} />
</p>
<button onClick={onCreate}>
Create
</button>
<button onClick={onCancel}>Cancel</button>
</div>
);
}
export default App;