diff options
| author | Frank <[email protected]> | 2025-08-08 13:22:54 -0400 |
|---|---|---|
| committer | Frank <[email protected]> | 2025-08-08 13:24:32 -0400 |
| commit | 183e0911b76025a1f2a82e979d9834fec2131d0e (patch) | |
| tree | 9987c1753bd64d1ce1d174ab397f1a8c681f642c /cloud/web/src/ui/dialog-string.tsx | |
| parent | c7bb19ad0712469063eab35589aa5d3602b0c5b1 (diff) | |
| download | opencode-183e0911b76025a1f2a82e979d9834fec2131d0e.tar.gz opencode-183e0911b76025a1f2a82e979d9834fec2131d0e.zip | |
wip: gateway
Diffstat (limited to 'cloud/web/src/ui/dialog-string.tsx')
| -rw-r--r-- | cloud/web/src/ui/dialog-string.tsx | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/cloud/web/src/ui/dialog-string.tsx b/cloud/web/src/ui/dialog-string.tsx new file mode 100644 index 000000000..af2174786 --- /dev/null +++ b/cloud/web/src/ui/dialog-string.tsx @@ -0,0 +1,70 @@ +import { z } from "zod" +import { onMount } from "solid-js" +import { createDialog } from "./context-dialog" +import { Button } from "./button" + +export const DialogString = createDialog({ + size: "sm", + schema: z.object({ + title: z.string(), + placeholder: z.string(), + action: z.string(), + onSubmit: z.function().args(z.string()).returns(z.void()), + }), + render: (ctx) => { + let input: HTMLInputElement + onMount(() => { + setTimeout(() => { + input.focus() + input.value = "" + }, 50) + }) + + function submit() { + const value = input.value.trim() + if (value) { + ctx.input.onSubmit(value) + ctx.control.close() + } + } + + return ( + <> + <div data-slot="header"> + <label + data-size="md" + data-slot="title" + data-component="label" + for={`dialog-string-${ctx.input.title}`} + > + {ctx.input.title} + </label> + </div> + <div data-slot="main"> + <input + data-slot="input" + data-size="lg" + data-component="input" + ref={(r) => (input = r)} + placeholder={ctx.input.placeholder} + id={`dialog-string-${ctx.input.title}`} + onKeyDown={(e) => { + if (e.key === "Enter") { + e.preventDefault() + submit() + } + }} + /> + </div> + <div data-slot="footer"> + <Button size="md" color="ghost" onClick={() => ctx.control.close()}> + Cancel + </Button> + <Button size="md" color="secondary" onClick={submit}> + {ctx.input.action} + </Button> + </div> + </> + ) + }, +}) |
