npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sagegreytechnologies-nkiru-ai-chat-widget-webcomponent

v2.4.0

Published

Native Web Component chat widget with complete CSS isolation using Shadow DOM

Readme

🤖 AI Chat Widget - Web Component

A modern, customizable AI chat widget as a native Web Component with complete CSS isolation using Shadow DOM. Works with any framework or vanilla HTML - React, Vue.js, Angular, and more!

npm version TypeScript Web Components

✨ Features

  • 🎨 Fully Customizable - Colors, positioning, messages, and styling
  • 🔒 Complete CSS Isolation - Uses Shadow DOM for true style encapsulation
  • 🚀 Zero Dependencies - Pure vanilla JavaScript Web Component
  • 🌐 Universal Compatibility - Works with any framework or vanilla HTML
  • 📱 Responsive Design - Works perfectly on desktop and mobile
  • 🔄 Session Management - Automatic session restoration and persistence
  • 📈 Escalation Support - Seamless handoff to human agents
  • 📊 Chat History - Built-in conversation history with grouping
  • 🎯 Smart Categorization - Ticket categories for better organization
  • Lightweight - Optimized bundle size for fast loading
  • 🛡️ Framework Agnostic - Works with React, Vue.js, Angular, and vanilla HTML

📦 Installation

Option 1: CDN (Recommended for quick setup)

<script src="https://unpkg.com/[email protected]/chat-widget.min.js"></script>

Option 2: NPM Install

npm install sagegreytechnologies-nkiru-ai-chat-widget-webcomponent

Option 3: Yarn

yarn add sagegreytechnologies-nkiru-ai-chat-widget-webcomponent

🚀 Quick Start

Vanilla HTML/JavaScript

<!DOCTYPE html>
<html>
<head>
    <title>Your Website</title>
</head>
<body>
    <!-- Your website content -->
    
    <!-- AI Chat Widget -->
    <chat-widget
        api-url="https://your-api.com"          <!-- REQUIRED -->
        third-party-api-key="your-api-key"     <!-- REQUIRED -->
        company-name="Your Company"             <!-- REQUIRED -->
        primary-color="#3b82f6"                 <!-- Optional -->
        title="Chat Support"                    <!-- Optional -->
        subtitle="We're here to help"          <!-- Optional -->
        welcome-message="Hello! How can I help you today?"  <!-- Optional -->
        placeholder="Type your message..."     <!-- Optional -->
    ></chat-widget>

    <!-- Load the Web Component -->
    <script src="https://unpkg.com/[email protected]/chat-widget.min.js"></script>
</body>
</html>

⚠️ Important: The api-url, third-party-api-key, and company-name attributes are required. If any of these are missing, the widget will display a configuration error instead of the chat interface.

🔧 Framework Integration

React Integration

Method 1: useEffect + DOM Manipulation (Recommended)

import { useEffect, useRef } from 'react';
import 'sagegreytechnologies-nkiru-ai-chat-widget-webcomponent/chat-widget.js';

function App() {
  const widgetContainerRef = useRef<HTMLDivElement>(null);

  useEffect(() => {
    if (widgetContainerRef.current) {
      // Create the web component element
      const widget = document.createElement('chat-widget');
      
      // Set attributes
      widget.setAttribute('api-url', 'https://your-api.com');
      widget.setAttribute('third-party-api-key', 'your-api-key');
      widget.setAttribute('company-name', 'Your Company');
      widget.setAttribute('primary-color', '#3b82f6');
      widget.setAttribute('position', 'bottom-right');
      widget.setAttribute('title', 'Support Chat');
      widget.setAttribute('subtitle', "We're here to help");
      widget.setAttribute('welcome-message', 'Hello! How can I help you today?');
      widget.setAttribute('placeholder', 'Type your message...');
      
      // Append to container
      widgetContainerRef.current.appendChild(widget);
      
      // Cleanup function
      return () => {
        if (widgetContainerRef.current && widget.parentNode) {
          widgetContainerRef.current.removeChild(widget);
        }
      };
    }
  }, []);

  return (
    <div className="App">
      <h1>My React App</h1>
      {/* Your app content */}
      
      {/* Widget container */}
      <div ref={widgetContainerRef}></div>
    </div>
  );
}

export default App;

Method 2: React.createElement (Alternative)

import React from 'react';
import 'sagegreytechnologies-nkiru-ai-chat-widget-webcomponent/chat-widget.js';

function App() {
  return (
    <div className="App">
      <h1>My React App</h1>
      {/* Your app content */}
      
      {/* AI Chat Widget using React.createElement */}
      {React.createElement('chat-widget', {
        'api-url': 'https://your-api.com',
        'third-party-api-key': 'your-api-key',
        'company-name': 'Your Company',
        'primary-color': '#3b82f6',
        'position': 'bottom-right',
        'title': 'Support Chat',
        'subtitle': "We're here to help",
        'welcome-message': 'Hello! How can I help you today?',
        'placeholder': 'Type your message...'
      })}
    </div>
  );
}

export default App;

Method 3: Direct JSX (TypeScript Declaration Required)

// First, add this to your global.d.ts or component file:
declare global {
  namespace JSX {
    interface IntrinsicElements {
      'chat-widget': any;
    }
  }
}

import 'sagegreytechnologies-nkiru-ai-chat-widget-webcomponent/chat-widget.js';

function App() {
  return (
    <div className="App">
      <h1>My React App</h1>
      
      <chat-widget
        api-url="https://your-api.com"
        third-party-api-key="your-api-key"
        company-name="Your Company"
        primary-color="#3b82f6"
        position="bottom-right"
        title="Support Chat"
        subtitle="We're here to help"
        welcome-message="Hello! How can I help you today?"
        placeholder="Type your message..."
      />
    </div>
  );
}

export default App;

Vue.js Integration

Vue 3 Composition API

<template>
  <div>
    <h1>My Vue App</h1>
    <!-- Your app content -->
    
    <!-- AI Chat Widget -->
    <chat-widget
      api-url="https://your-api.com"
      third-party-api-key="your-api-key"
      company-name="Your Company"
      primary-color="#3b82f6"
      position="bottom-right"
      title="Support Chat"
      subtitle="We're here to help"
      welcome-message="Hello! How can I help you today?"
      placeholder="Type your message..."
    />
  </div>
</template>

<script setup>
import { onMounted } from 'vue';

onMounted(() => {
  // Import the web component
  import('sagegreytechnologies-nkiru-ai-chat-widget-webcomponent/chat-widget.js');
});
</script>

Vue 2 Options API

<template>
  <div>
    <h1>My Vue App</h1>
    
    <chat-widget
      api-url="https://your-api.com"
      third-party-api-key="your-api-key"
      company-name="Your Company"
      primary-color="#3b82f6"
      position="bottom-right"
      title="Support Chat"
      subtitle="We're here to help"
      welcome-message="Hello! How can I help you today?"
      placeholder="Type your message..."
    />
  </div>
</template>

<script>
export default {
  name: 'App',
  mounted() {
    // Import the web component
    import('sagegreytechnologies-nkiru-ai-chat-widget-webcomponent/chat-widget.js');
  }
}
</script>

Angular Integration

Step 1: Enable Custom Elements

// app.module.ts
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule],
  providers: [],
  bootstrap: [AppComponent],
  schemas: [CUSTOM_ELEMENTS_SCHEMA] // Add this line
})
export class AppModule { }

Step 2: Import in Component

// app.component.ts
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  title = 'my-angular-app';

  ngOnInit() {
    // Import the web component
    import('sagegreytechnologies-nkiru-ai-chat-widget-webcomponent/chat-widget.js');
  }
}

Step 3: Use in Template

<!-- app.component.html -->
<h1>My Angular App</h1>
<!-- Your app content -->

<!-- AI Chat Widget -->
<chat-widget
  api-url="https://your-api.com"
  third-party-api-key="your-api-key"
  company-name="Your Company"
  primary-color="#3b82f6"
  position="bottom-right"
  title="Support Chat"
  subtitle="We're here to help"
  welcome-message="Hello! How can I help you today?"
  placeholder="Type your message...">
</chat-widget>

Svelte Integration

<script>
  import { onMount } from 'svelte';
  
  onMount(async () => {
    // Import the web component
    await import('sagegreytechnologies-nkiru-ai-chat-widget-webcomponent/chat-widget.js');
  });
</script>

<h1>My Svelte App</h1>

<chat-widget
  api-url="https://your-api.com"
  third-party-api-key="your-api-key"
  company-name="Your Company"
  primary-color="#3b82f6"
  position="bottom-right"
  title="Support Chat"
  subtitle="We're here to help"
  welcome-message="Hello! How can I help you today?"
  placeholder="Type your message..."
/>

📋 Configuration Attributes

⚠️ Required Attributes

The following attributes are required for the widget to function properly. If any of these are missing, the widget will display a configuration error:

| Attribute | Type | Description | |-----------|------|-------------| | api-url | string | REQUIRED - Your chat API endpoint | | third-party-api-key | string | REQUIRED - Your API authentication key | | company-name | string | REQUIRED - Your company name |

🎨 Optional Attributes

These attributes are optional and have default values:

| Attribute | Type | Default | Description | |-----------|------|---------|-------------| | primary-color | string | #3b82f6 | Widget color theme | | position | string | bottom-right | Widget position (bottom-right, bottom-left, top-right, top-left) | | title | string | Chat Support | Widget header title | | subtitle | string | We're here to help | Widget header subtitle | | welcome-message | string | Hello! How can I help you today? | Initial bot message | | placeholder | string | Type your message... | Input field placeholder | | user-email | string | "" | Pre-fill user email | | user-name | string | "" | Pre-fill user name |

🔍 Validation & Error Handling

The widget includes built-in validation that checks for required attributes when the component is initialized:

  • Missing Required Props: If any required attribute is missing, the widget will:
    • Display a configuration error message instead of the chat interface
    • Log detailed error information to the browser console
    • Show which specific attributes are missing

Example Error Display:

Configuration Error
API URL is required
API Key is required

Console Error Example:

ChatWidget: Missing required props: API URL, API Key

✅ Minimum Working Example

<chat-widget
  api-url="https://your-api.com"
  third-party-api-key="your-api-key"
  company-name="Your Company"
></chat-widget>

🎨 CSS Isolation & Shadow DOM

This Web Component uses Shadow DOM to provide complete CSS isolation:

  • No CSS conflicts: Widget styles won't affect your site
  • No external interference: Your site styles won't break the widget
  • Consistent appearance: Widget looks the same across all sites
  • Framework agnostic: Works with any CSS framework (Bootstrap, Tailwind, etc.)
  • No CSS imports needed: All styles are encapsulated within the component

Benefits over Traditional Components:

  • 🔒 True Encapsulation: Styles are completely isolated
  • 🚀 No Build Step Required: Works directly in any environment
  • 🎯 Better Performance: Isolated rendering and styling
  • 🛡️ Future Proof: Based on web standards

🔄 Advanced Features

Session Management

  • Automatic Session Restoration - Conversations resume where they left off
  • Local Storage Integration - User preferences and history saved locally
  • Cross-tab Synchronization - Sessions work across multiple browser tabs

Escalation Support

  • Automatic Detection - AI determines when escalation is needed
  • Manual Escalation - Users can request human assistance
  • Agent Handoff - Smooth transition from bot to human agent
  • Status Indicators - Clear visual feedback during escalation

Chat History

  • Grouped by Date - Conversations organized by day

  • Searchable - Easy to find previous conversations

  • Persistent - History maintained across sessions

📱 Browser Support

  • ✅ Chrome 53+ (Full support)
  • ✅ Firefox 63+ (Full support)
  • ✅ Safari 10.1+ (Full support)
  • ✅ Edge 79+ (Full support)
  • ✅ Mobile browsers (iOS Safari, Chrome Mobile)

🐛 Troubleshooting

Widget not appearing

  • Check that the script is loaded correctly
  • Verify API URL and credentials
  • Check browser console for errors
  • Ensure the web component is imported before use

React TypeScript Issues

// Add this to your global.d.ts or component file:
declare global {
  namespace JSX {
    interface IntrinsicElements {
      'chat-widget': any;
    }
  }
}

Vue.js Issues

// In vue.config.js
module.exports = {
  chainWebpack: config => {
    config.module
      .rule('vue')
      .use('vue-loader')
      .tap(options => {
        options.compilerOptions = {
          ...options.compilerOptions,
          isCustomElement: tag => tag === 'chat-widget'
        }
        return options
      })
  }
}

Angular Issues

Make sure to add CUSTOM_ELEMENTS_SCHEMA to your module:

import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';

@NgModule({
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})

🔄 Migration from React Widget

If you're upgrading from the React-based widget:

  1. Remove React dependencies: No need for React-specific imports
  2. Update attribute names: camelCase → kebab-case (e.g., primaryColorprimary-color)
  3. Remove CSS imports: Shadow DOM handles all styling
  4. Update integration method: Use one of the framework integration methods above
  5. Enjoy improved CSS isolation: No more style conflicts!

🎯 Best Practices

Performance

  • Lazy Loading: Import the widget only when needed
  • CDN Usage: Use CDN for faster loading
  • Minimal Configuration: Only set attributes you need to customize

Security

  • API Key Protection: Never expose API keys in client-side code
  • Input Validation: Always validate user inputs on the backend
  • Rate Limiting: Implement rate limiting on your API endpoints

User Experience

  • Clear Messaging: Use descriptive welcome messages
  • Responsive Design: Test on various screen sizes
  • Accessibility: Ensure keyboard navigation works properly

📄 License

MIT License - see LICENSE file for details.

🤝 Support


Made with ❤️ by Sagegrey Technologies