-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: ✏️ prepares hooks docs to release
- Loading branch information
Showing
21 changed files
with
1,035 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// https://vitejs.dev/guide/features.html#typescript-compiler-options | ||
/// <reference types="vite/client" /> |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<script src="https://miro.com/app/static/sdk/v2/miro.js"></script> | ||
<title>Miro - React hooks app example</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
|
||
<script type="module" src="/app.tsx"></script> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"use client"; | ||
|
||
import * as React from "react"; | ||
import { createRoot } from "react-dom/client"; | ||
import { createBrowserRouter, RouterProvider } from "react-router-dom"; | ||
|
||
import { MiroProvider } from "../../esm"; | ||
|
||
import { UseCurrentUser } from "./pages/UserCurrentUser"; | ||
import { Index } from "./pages/Index"; | ||
import { Miro } from "./pages/UseMiro"; | ||
import { UseInfo } from "./pages/UseInfo"; | ||
import { UseOnlineUsers } from "./pages/UseOnlineUsers"; | ||
import { UseSelectedItems } from "./pages/UseSelectedItems"; | ||
import { UseViewport } from "./pages/UseViewport"; | ||
|
||
const router = createBrowserRouter([ | ||
{ | ||
path: "/app.html", | ||
element: <Index />, | ||
}, | ||
{ | ||
path: "/miro", | ||
element: <Miro />, | ||
}, | ||
{ | ||
path: "/use-current-user", | ||
element: <UseCurrentUser />, | ||
}, | ||
{ | ||
path: "/use-info", | ||
element: <UseInfo />, | ||
}, | ||
{ | ||
path: "/use-online-users", | ||
element: <UseOnlineUsers />, | ||
}, | ||
{ | ||
path: "/use-selected-items", | ||
element: <UseSelectedItems />, | ||
}, | ||
{ | ||
path: "/use-viewport", | ||
element: <UseViewport />, | ||
}, | ||
]); | ||
|
||
const App = () => { | ||
return ( | ||
<React.StrictMode> | ||
<MiroProvider> | ||
<RouterProvider router={router} /> | ||
</MiroProvider> | ||
</React.StrictMode> | ||
); | ||
}; | ||
|
||
const container = document.getElementById("root")!; | ||
const root = createRoot(container); | ||
root.render(<App />); |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<script src="https://miro.com/app/static/sdk/v2/miro.js"></script> | ||
<title>Miro - React hooks app example</title> | ||
</head> | ||
<body> | ||
<script type="module" src="./index.ts"></script> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export async function init() { | ||
miro.board.ui.on("icon:click", async () => { | ||
await miro.board.ui.openPanel({ url: "app.html" }); | ||
}); | ||
} | ||
|
||
init(); |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use client"; | ||
|
||
import * as React from "react"; | ||
import { Link } from "react-router-dom"; | ||
|
||
export const Index: React.FC = () => { | ||
return ( | ||
<main> | ||
<ul> | ||
<li> | ||
<Link to={`/miro`}>useMiro</Link> | ||
</li> | ||
<li> | ||
<Link to={`/use-current-user`}>useCurrentUser</Link> | ||
</li> | ||
<li> | ||
<Link to={`/use-info`}>useInfo</Link> | ||
</li> | ||
<li> | ||
<Link to={`/use-online-users`}>useOnlineUsers</Link> | ||
</li> | ||
<li> | ||
<Link to={`/use-selected-items`}>useSelectedItems</Link> | ||
</li> | ||
<li> | ||
<Link to={`/use-viewport`}>useViewport</Link> | ||
</li> | ||
</ul> | ||
</main> | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"use client"; | ||
|
||
import * as React from "react"; | ||
import { useInfo } from "../../../esm"; | ||
|
||
export const UseInfo: React.FC = () => { | ||
const { status, error, result } = useInfo(); | ||
|
||
if (status === "loading") { | ||
return <p>Fetching board info...</p>; | ||
} | ||
|
||
if (error) { | ||
return <p>Something went wrong</p>; | ||
} | ||
|
||
if (status === "success") { | ||
return ( | ||
<div> | ||
<p>Current board info</p> | ||
<pre>{JSON.stringify(result, null, 2)}</pre> | ||
</div> | ||
); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"use client"; | ||
|
||
import * as React from "react"; | ||
import { useMiro } from "../../../esm"; | ||
|
||
export const Miro: React.FC = () => { | ||
const miro = useMiro(); | ||
|
||
return <pre>{JSON.stringify(miro, null, 2)}</pre>; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use client"; | ||
|
||
import * as React from "react"; | ||
import { useOnlineUsers } from "../../../esm"; | ||
|
||
export const UseOnlineUsers: React.FC = () => { | ||
const { status, result, error } = useOnlineUsers(); | ||
|
||
if (status === "loading") { | ||
return <p>Fetching online users...</p>; | ||
} | ||
|
||
if (error) { | ||
return <p>Something went wrong</p>; | ||
} | ||
|
||
if (status === "success") { | ||
return ( | ||
<div> | ||
<p>Online users</p> | ||
<ul> | ||
{result.map((user) => ( | ||
<li key={user.id}> | ||
#{user.id} - {user.name} | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use client"; | ||
|
||
import * as React from "react"; | ||
import { useSelectedItems } from "../../../esm"; | ||
|
||
export const UseSelectedItems: React.FC = () => { | ||
const { status, result, error } = useSelectedItems(); | ||
|
||
if (status === "loading") { | ||
return <p>Fetching selected items...</p>; | ||
} | ||
|
||
if (error) { | ||
return <p>Something went wrong</p>; | ||
} | ||
|
||
if (status === "success") { | ||
return ( | ||
<div> | ||
<p>Selected items:</p> | ||
<ul> | ||
{result.map((item) => ( | ||
<li key={item.id}> | ||
#{item.id} - {item.type} | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"use client"; | ||
|
||
import * as React from "react"; | ||
import { useSelectedItems, useViewport } from "../../../esm"; | ||
|
||
export const UseViewport: React.FC = () => { | ||
const { status, result, error, set, zoomTo } = useViewport(); | ||
const selected = useSelectedItems(); | ||
|
||
if (status === "loading") { | ||
return <p>Fetching viewport...</p>; | ||
} | ||
|
||
if (error) { | ||
return <p>Something went wrong</p>; | ||
} | ||
|
||
const handleSetViewport = async () => { | ||
await set({ | ||
viewport: { | ||
x: 200, | ||
y: 100, | ||
width: 1280, | ||
height: 720, | ||
}, | ||
padding: { | ||
top: 100, | ||
left: 200, | ||
bottom: 50, | ||
right: 20, | ||
}, | ||
animationDurationInMs: 1000, | ||
}); | ||
}; | ||
|
||
const handleZoomTo = async () => { | ||
if (selected.result.length < 1) { | ||
return; | ||
} | ||
|
||
await zoomTo(selected.result); | ||
}; | ||
|
||
if (status === "success") { | ||
return ( | ||
<div> | ||
<p>Selected items:</p> | ||
<ul> | ||
<li> | ||
X and Y: {result?.x} x {result?.y} | ||
</li> | ||
<li> | ||
Size (WxH): {result?.width} x {result?.height} | ||
</li> | ||
<li>Zoom level {result?.zoomLevel}</li> | ||
</ul> | ||
<button onClick={handleSetViewport}>Set viewport</button> | ||
<button disabled={selected.result.length < 1} onClick={handleZoomTo}> | ||
Zoom to selected | ||
</button> | ||
</div> | ||
); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"use client"; | ||
|
||
import * as React from "react"; | ||
import { useCurrentUser } from "../../../esm"; | ||
|
||
export const UseCurrentUser: React.FC = () => { | ||
const { status, result, error } = useCurrentUser(); | ||
|
||
if (status === "loading") { | ||
return <p>Fetching user...</p>; | ||
} | ||
|
||
if (error) { | ||
return <p>Something went wrong</p>; | ||
} | ||
|
||
if (status === "success") { | ||
return <p>The current user is "{result?.name}"</p>; | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,3 +1,43 @@ | ||
# useCurrentUser | ||
|
||
Get current [Miro user](https://developers.miro.com/docs/websdk-reference-board#getuserinfo). | ||
Get current [Miro user](https://developers.miro.com/docs/websdk-reference-board#getuserinfo). | ||
|
||
**Note**: Make sure you are running this code in a configured [Miro WebSDK app](https://developers.miro.com/docs/build-your-first-hello-world-app). | ||
|
||
## Example | ||
|
||
|
||
```tsx | ||
import * as React from "react"; | ||
import { createRoot } from "react-dom/client"; | ||
import { useCurrentUser } from "@mirohq/websdk-react-hooks"; | ||
|
||
const CurrentUser: React.FC = () => { | ||
const { status, result, error } = useCurrentUser(); | ||
|
||
if (status === "loading") { | ||
return <p>Fetching user...</p>; | ||
} | ||
|
||
if (error) { | ||
return <p>Something went wrong</p>; | ||
} | ||
|
||
if (status === "success") { | ||
return <p>The current user is "{result?.name}"</p>; | ||
} | ||
} | ||
|
||
const App = () => { | ||
return ( | ||
<MiroProvider> | ||
<CurrentUser /> | ||
</MiroProvider> | ||
) | ||
}; | ||
|
||
|
||
const container = document.getElementById("root")!; | ||
const root = createRoot(container); | ||
root.render(<App />); | ||
``` |
Oops, something went wrong.