@nas/chatbot-widget (1.0.1)
Installation
@nas:registry=npm install @nas/chatbot-widget@1.0.1"@nas/chatbot-widget": "1.0.1"About this package
ChatWidget
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/plainstream (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
Dependencies
Development dependencies
| ID | Version |
|---|---|
| @types/node | ^25.6.0 |
| @types/react | ^19.2.14 |
| @types/react-dom | ^19.2.3 |
| @vitejs/plugin-react | ^6.0.1 |
| react | ^19.2.5 |
| react-dom | ^19.2.5 |
| typescript | ^5.9.3 |
| vite | ^8.0.10 |
| vite-plugin-dts | ^4.5.4 |
Peer dependencies
| ID | Version |
|---|---|
| react | >=18 |
| react-dom | >=18 |
Details
Assets (1)
Versions (2)
View all
chatbot-widget-1.0.1.tgz
4 KiB