No description
  • TypeScript 76.5%
  • CSS 23.5%
Find a file
narndtse aa192c913d
Some checks failed
/ publish-package (push) Failing after 21s
Add license
2026-05-09 20:04:58 +02:00
.forgejo/workflows Add ci workflow 2026-04-28 00:30:35 +02:00
demo Add readme 2026-04-27 23:29:09 +02:00
src Fix incorrect export 2026-04-28 00:52:43 +02:00
.gitignore Simple chat widget with 2026-04-27 21:28:46 +02:00
LICENSE Add license 2026-05-09 20:04:58 +02:00
package-lock.json Add license 2026-05-09 20:04:58 +02:00
package.json Increment version 2026-04-28 00:54:22 +02:00
README.md Add license 2026-05-09 20:04:58 +02:00
tsconfig.json Setup project 2026-04-27 17:55:56 +02:00
vite.config.ts Add ci workflow 2026-04-28 00:30:35 +02:00

ChatWidget

License

Lightweight React chat widget with streaming responses and optional Cloudflare Turnstile support.

Usage

import { ChatWidget } from "your-package-name";
import "your-package-name/styles.css";

export default function Page() {
  return (
    <ChatWidget
      apiUrl="https://your-api.com/chat"
      placeholder="Type a message..."
      sendLabel="Send"
    />
  );
}

Props

Prop Type Required Description
apiUrl string yes Endpoint that receives { query: string } and returns a streamed response
placeholder string yes Input placeholder text
sendLabel string yes Submit button label
title string no Header title
description string no Header description
initialMessages string[] no Initial assistant messages
onClose () => void no Called when close button is clicked
errorMessage string no Fallback error message
turnstileSiteKey string no Cloudflare Turnstile site key
turnstileAction string no Turnstile action name

API Requirements

The widget sends:

{
  "query": "user message"
}

Expected response:

  • text/plain stream (chunked)
  • Each chunk is appended to the assistant message

Turnstile (Optional)

If turnstileSiteKey is provided:

  • Token is fetched automatically
  • Sent via header:
x-turnstile-token: <token>

Styling

The component requires:

import "chatbot-widget/styles.css";

Styles use CSS variables for easy customization:

--primary
--background
--border
--radius
--font-sans

Development

A demo app is included for local development.

npm run dev

Notes

  • React is a peer dependency
  • Built with Vite in library mode
  • ES module output
  • Supports streaming responses