UNPKG

@ingridsandev/chatbot-widget

Version:

A framework-agnostic chatbot widget using Web Components

466 lines (401 loc) 9.57 kB
/* Base chatbot widget styles */ .chatbot-widget { --chatbot-primary-color: #007bff; --chatbot-secondary-color: #6c757d; --chatbot-background-color: #ffffff; --chatbot-text-color: #333333; --chatbot-border-color: #dee2e6; --chatbot-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); --chatbot-border-radius: 8px; --chatbot-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; --chatbot-font-size: 14px; --chatbot-line-height: 1.5; position: fixed; z-index: 9999; font-family: var(--chatbot-font-family); font-size: var(--chatbot-font-size); line-height: var(--chatbot-line-height); } .chatbot-widget.position-bottom-right { bottom: 20px; right: 20px; } .chatbot-widget.position-bottom-left { bottom: 20px; left: 20px; } .chatbot-widget.position-top-right { top: 20px; right: 20px; } .chatbot-widget.position-top-left { top: 20px; left: 20px; } /* Trigger button */ .chatbot-trigger { width: 60px; height: 60px; border-radius: 50%; background: var(--chatbot-primary-color); border: none; color: white; font-size: 24px; cursor: pointer; box-shadow: var(--chatbot-shadow); transition: all 0.3s ease; display: flex; align-items: center; justify-content: center; } .chatbot-trigger:hover { transform: scale(1.05); box-shadow: 0 4px 15px rgba(0, 123, 255, 0.3); } .chatbot-trigger.open { background: var(--chatbot-secondary-color); } /* Chat container */ .chatbot-container { position: absolute; bottom: 70px; right: 0; width: 350px; height: 500px; background: var(--chatbot-background-color); border-radius: var(--chatbot-border-radius); box-shadow: var(--chatbot-shadow); display: none; flex-direction: column; overflow: hidden; border: 1px solid var(--chatbot-border-color); } .chatbot-container.open { display: flex; animation: slideUp 0.3s ease-out; } @keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } } /* Header */ .chatbot-header { padding: 16px; background: var(--chatbot-primary-color); color: white; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--chatbot-border-color); } .chatbot-title { font-weight: 600; margin: 0; font-size: 16px; } .chatbot-close { background: none; border: none; color: white; font-size: 18px; cursor: pointer; padding: 4px; border-radius: 4px; transition: background-color 0.2s; } .chatbot-close:hover { background: rgba(255, 255, 255, 0.1); } /* Agent selector */ .chatbot-agent-selector { padding: 12px 16px; border-bottom: 1px solid var(--chatbot-border-color); background: #f8f9fa; } .chatbot-agent-select { width: 100%; padding: 8px 12px; border: 1px solid var(--chatbot-border-color); border-radius: 4px; background: white; font-size: var(--chatbot-font-size); cursor: pointer; } .chatbot-agent-select:focus { outline: none; border-color: var(--chatbot-primary-color); box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25); } /* Messages area */ .chatbot-messages { flex: 1; padding: 16px; overflow-y: auto; background: var(--chatbot-background-color); } .chatbot-message { margin-bottom: 16px; display: flex; align-items: flex-start; gap: 8px; animation: fadeIn 0.3s ease-out; } @keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } } .chatbot-message.user { flex-direction: row-reverse; } .chatbot-message-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--chatbot-primary-color); color: white; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; } .chatbot-message.user .chatbot-message-avatar { background: var(--chatbot-secondary-color); } .chatbot-message-content { max-width: 80%; padding: 12px 16px; border-radius: 18px; background: #f1f3f4; color: var(--chatbot-text-color); word-wrap: break-word; } .chatbot-message.user .chatbot-message-content { background: var(--chatbot-primary-color); color: white; } .chatbot-message-time { font-size: 11px; color: var(--chatbot-secondary-color); margin-top: 4px; text-align: center; } /* Input area */ .chatbot-input-area { padding: 16px; border-top: 1px solid var(--chatbot-border-color); background: var(--chatbot-background-color); } .chatbot-input-container { display: flex; gap: 8px; align-items: flex-end; } .chatbot-input { flex: 1; padding: 12px 16px; border: 1px solid var(--chatbot-border-color); border-radius: 20px; resize: none; min-height: 20px; max-height: 100px; font-family: inherit; font-size: var(--chatbot-font-size); line-height: var(--chatbot-line-height); } .chatbot-input:focus { outline: none; border-color: var(--chatbot-primary-color); box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25); } .chatbot-input::placeholder { color: var(--chatbot-secondary-color); } .chatbot-send-button { width: 40px; height: 40px; border-radius: 50%; background: var(--chatbot-primary-color); border: none; color: white; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 16px; transition: background-color 0.2s; flex-shrink: 0; } .chatbot-send-button:hover:not(:disabled) { background: #0056b3; } .chatbot-send-button:disabled { background: var(--chatbot-secondary-color); cursor: not-allowed; } /* Typing indicator */ .chatbot-typing { display: none; padding: 12px 16px; color: var(--chatbot-secondary-color); font-style: italic; font-size: 13px; } .chatbot-typing.show { display: block; } .chatbot-typing::after { content: ''; animation: typing 1.5s infinite; } @keyframes typing { 0%, 60%, 100% { content: ''; } 20% { content: '.'; } 40% { content: '..'; } 80% { content: '...'; } } /* Scrollbar styling */ .chatbot-messages::-webkit-scrollbar { width: 6px; } .chatbot-messages::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 3px; } .chatbot-messages::-webkit-scrollbar-thumb { background: var(--chatbot-secondary-color); border-radius: 3px; } .chatbot-messages::-webkit-scrollbar-thumb:hover { background: #495057; } /* Mobile responsive */ @media (max-width: 480px) { .chatbot-container { width: calc(100vw - 40px); height: calc(100vh - 140px); max-width: 350px; max-height: 500px; } .chatbot-widget.position-bottom-right, .chatbot-widget.position-bottom-left { left: 20px; right: 20px; } .chatbot-container { right: 0; left: 0; } } /* Theme variations for chatbot widget */ /* Light theme (default) */ .chatbot-widget.theme-light { --chatbot-primary-color: #007bff; --chatbot-secondary-color: #6c757d; --chatbot-background-color: #ffffff; --chatbot-text-color: #333333; --chatbot-border-color: #dee2e6; --chatbot-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); } /* Dark theme */ .chatbot-widget.theme-dark { --chatbot-primary-color: #0d6efd; --chatbot-secondary-color: #6c757d; --chatbot-background-color: #1a1a1a; --chatbot-text-color: #ffffff; --chatbot-border-color: #333333; --chatbot-shadow: 0 2px 10px rgba(0, 0, 0, 0.3); } .chatbot-widget.theme-dark .chatbot-agent-selector { background: #2d2d2d; } .chatbot-widget.theme-dark .chatbot-message-content { background: #2d2d2d; color: #ffffff; } .chatbot-widget.theme-dark .chatbot-message.user .chatbot-message-content { background: var(--chatbot-primary-color); color: white; } .chatbot-widget.theme-dark .chatbot-input { background: #343a40; color: var(--chatbot-text-color); border-color: var(--chatbot-border-color); } .chatbot-widget.theme-dark .chatbot-input::placeholder { color: var(--chatbot-secondary-color); } .chatbot-widget.theme-dark .chatbot-agent-select { background: #1a1a1a; color: #ffffff; border-color: #333333; } .chatbot-widget.theme-dark .chatbot-messages::-webkit-scrollbar-track { background: #343a40; } /* Purple Theme */ .chatbot-widget.theme-purple { --chatbot-primary-color: #6f42c1; --chatbot-secondary-color: #6c757d; --chatbot-background-color: #ffffff; --chatbot-text-color: #333333; --chatbot-border-color: #dee2e6; --chatbot-shadow: 0 2px 10px rgba(111, 66, 193, 0.1); } /* Auto theme - respects system preference */ @media (prefers-color-scheme: dark) { .chatbot-widget.theme-auto { --chatbot-primary-color: #0d6efd; --chatbot-secondary-color: #6c757d; --chatbot-background-color: #1a1a1a; --chatbot-text-color: #ffffff; --chatbot-border-color: #333333; --chatbot-shadow: 0 2px 10px rgba(0, 0, 0, 0.3); } .chatbot-widget.theme-auto .chatbot-message-content { background: #2d2d2d; color: #ffffff; } .chatbot-widget.theme-auto .chatbot-agent-selector { background: #2d2d2d; border-color: #333333; } .chatbot-widget.theme-auto .chatbot-agent-select { background: #1a1a1a; color: #ffffff; border-color: #333333; } .chatbot-widget.theme-auto .chatbot-messages::-webkit-scrollbar-track { background: #343a40; } } @media (prefers-color-scheme: light) { .chatbot-widget.theme-auto { --chatbot-primary-color: #007bff; --chatbot-secondary-color: #6c757d; --chatbot-background-color: #ffffff; --chatbot-text-color: #333333; --chatbot-border-color: #dee2e6; --chatbot-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); } }