Skip to content

Commit c7ecd7a

Browse files
committed
Change style of WrpIframeHost and add devtools
1 parent 5644c98 commit c7ecd7a

File tree

2 files changed

+62
-36
lines changed

2 files changed

+62
-36
lines changed

islands/WrpExampleGuest.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function useWrpExampleServiceClient() {
8282
);
8383
useEffect(() => {
8484
if (!wrpClientImpl) return;
85-
setServiceClient(createServiceClient(wrpClientImpl));
85+
setServiceClient(createServiceClient(wrpClientImpl, { devtools: true }));
8686
}, [wrpClientImpl]);
8787
return serviceClient;
8888
}

islands/WrpIframeHost.tsx

Lines changed: 61 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
/** @jsx h */
22
/** @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";
411
import { createWrpChannel } from "https://deno.land/x/wrp@v0.0.3/channel.ts";
512
import useWrpIframeSocket from "https://deno.land/x/wrp@v0.0.3/react/useWrpIframeSocket.ts";
613
import useWrpServer from "https://deno.land/x/wrp@v0.0.3/react/useWrpServer.ts";
@@ -39,53 +46,72 @@ export default function WrpIframeHost() {
3946
},
4047
],
4148
]);
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+
};
4261
return (
4362
<>
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>
68102
</div>
69103
<style
70104
dangerouslySetInnerHTML={{
71105
__html: `
72-
div {
73-
display: flex;
74-
flex-direction: column;
75-
padding: 1em;
76-
}
77-
h2 {
78-
font-size: 2em;
79-
}
80106
label > span {
81107
margin-right: 1em;
82108
}
83109
input[type=text] {
84110
border: 1px solid black;
85111
}
86112
iframe {
87-
width: 30em;
88-
height: 30em;
113+
width: 500px;
114+
height: 400px;
89115
border: 1px solid black;
90116
resize: both;
91117
}

0 commit comments

Comments
 (0)