|
1 | 1 | /** @jsx h */
|
2 | 2 | /** @jsxFrag Fragment */
|
3 |
| -import { Fragment, h, useMemo, useState } from "../client_deps.ts"; |
| 3 | +import { |
| 4 | + Fragment, |
| 5 | + h, |
| 6 | + tw, |
| 7 | + useEffect, |
| 8 | + useMemo, |
| 9 | + useState, |
| 10 | +} from "../client_deps.ts"; |
4 | 11 | import { createWrpChannel } from "https://deno.land/x/wrp@v0.0.3/channel.ts";
|
5 | 12 | import useWrpIframeSocket from "https://deno.land/x/wrp@v0.0.3/react/useWrpIframeSocket.ts";
|
6 | 13 | import useWrpServer from "https://deno.land/x/wrp@v0.0.3/react/useWrpServer.ts";
|
@@ -39,53 +46,72 @@ export default function WrpIframeHost() {
|
39 | 46 | },
|
40 | 47 | ],
|
41 | 48 | ]);
|
| 49 | + useEffect(() => { |
| 50 | + // @ts-ignore |
| 51 | + // hooking code for getting event from iframe's devtools |
| 52 | + window["@pbkit/devtools"] = window.frames[0]["@pbkit/devtools"]; |
| 53 | + }, []); |
| 54 | + const styles = { |
| 55 | + main: tw`flex flex-col items-center gap-4 p-4 text-center`, |
| 56 | + button: (color: string) => |
| 57 | + tw`w-full bg-${color}-400 hover:bg-${color}-500 text-white font-bold py-2 px-4 rounded`, |
| 58 | + label: (color: string) => |
| 59 | + tw`flex items-center rounded bg-${color}-100 p-4 gap-4`, |
| 60 | + }; |
42 | 61 | return (
|
43 | 62 | <>
|
44 |
| - <div> |
45 |
| - <h2>host inputs</h2> |
46 |
| - <label> |
47 |
| - <span>slider</span> |
48 |
| - <input |
49 |
| - type="range" |
50 |
| - value={sliderValue} |
51 |
| - min="0" |
52 |
| - max="100" |
53 |
| - onInput={(e) => setSliderValue(+(e.target as any).value)} |
54 |
| - /> |
55 |
| - </label> |
56 |
| - <label> |
57 |
| - <span>text</span> |
58 |
| - <input |
59 |
| - type="text" |
60 |
| - value={text} |
61 |
| - onInput={(e) => setText((e.target as any).value)} |
62 |
| - /> |
63 |
| - </label> |
64 |
| - </div> |
65 |
| - <div> |
66 |
| - <h2>iframe</h2> |
67 |
| - <iframe ref={iframeRef} src="/wrp-example-guest" /> |
| 63 | + <div class={styles.main}> |
| 64 | + <h1 class={tw`text-2xl font-bold`}>WrpExampleServer (Host)</h1> |
| 65 | + <p> |
| 66 | + You can use pbkit{" "} |
| 67 | + <a |
| 68 | + class={tw`text-blue-500 font-bold`} |
| 69 | + href="https://chrome.google.com/webstore/detail/pbkit-devtools/fjacmiijeihblfhobghceofniolonhca" |
| 70 | + target="_blank" |
| 71 | + > |
| 72 | + chrome devtools |
| 73 | + </a>{" "} |
| 74 | + here! |
| 75 | + </p> |
| 76 | + <div class={tw`flex flex-col gap-4`}> |
| 77 | + <label class={styles.label("blue")}> |
| 78 | + <b>SliderValue</b> |
| 79 | + <input |
| 80 | + type="range" |
| 81 | + class={tw`w-full`} |
| 82 | + value={sliderValue} |
| 83 | + min="0" |
| 84 | + max="100" |
| 85 | + onInput={(e) => setSliderValue(+(e.target as any).value)} |
| 86 | + /> |
| 87 | + </label> |
| 88 | + <label class={styles.label("green")}> |
| 89 | + <b>TextValue</b> |
| 90 | + <input |
| 91 | + type="text" |
| 92 | + class={tw`p-1`} |
| 93 | + value={text} |
| 94 | + onInput={(e) => setText((e.target as any).value)} |
| 95 | + /> |
| 96 | + </label> |
| 97 | + </div> |
| 98 | + <div> |
| 99 | + <h2 class={tw`text-2xl font-bold my-4`}>iframe</h2> |
| 100 | + <iframe ref={iframeRef} src="/wrp-example-guest" /> |
| 101 | + </div> |
68 | 102 | </div>
|
69 | 103 | <style
|
70 | 104 | dangerouslySetInnerHTML={{
|
71 | 105 | __html: `
|
72 |
| - div { |
73 |
| - display: flex; |
74 |
| - flex-direction: column; |
75 |
| - padding: 1em; |
76 |
| - } |
77 |
| - h2 { |
78 |
| - font-size: 2em; |
79 |
| - } |
80 | 106 | label > span {
|
81 | 107 | margin-right: 1em;
|
82 | 108 | }
|
83 | 109 | input[type=text] {
|
84 | 110 | border: 1px solid black;
|
85 | 111 | }
|
86 | 112 | iframe {
|
87 |
| - width: 30em; |
88 |
| - height: 30em; |
| 113 | + width: 500px; |
| 114 | + height: 400px; |
89 | 115 | border: 1px solid black;
|
90 | 116 | resize: both;
|
91 | 117 | }
|
|
0 commit comments