-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.tsx
36 lines (31 loc) · 1.16 KB
/
example.tsx
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
import { HTMX, HTMXComponents, serve, Fragment } from "./mod.tsx"
// http://localhost:8000/registry/@reggi/alicebob
const { component, routes, context } = new HTMXComponents('@reggi/alicebob')
const Alice = component('/alice/:name', async ({ name }: { name: string}, ctx) => {
const _name = await Promise.resolve(name)
const req = new URL(ctx.request.url)
const query = req.searchParams.get('meow')
return (
<div>
<div>This is {_name} + {ctx.data.love} {ctx.id} {query}</div>
</div>
)
})
const Bob = component('/bob', async (_p, ctx) => {
const name = await Promise.resolve('bob')
return (
<Fragment>
<HTMX.button get={Alice.getPath(ctx, { name: 'alice' }, { meow: 'meow' })}>Different</HTMX.button>
<Alice.button.get name={'kettle'} query={{meow: true}}>Alice Button</Alice.button.get>
<Alice.anchor.href name={'kettle'} useQuery>Alice Link</Alice.anchor.href>
<Alice.iframe.src name={'kettle'} query={{meow: true}} useQuery>Alice Link</Alice.iframe.src>
<div>This is {name} {ctx.id}</div>
<Alice name="alice"/>
</Fragment>
)
})
const e = context({
nestPath: '/nest',
love: 'lauriel'
})
await serve(e)