nixaut-codelabs's picture
Promote version 112f534 to main
baa51d8 verified
raw
history blame
19.8 kB
class CustomSidebar extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
}
connectedCallback() {
this.shadowRoot.innerHTML = `
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');
* { font-family: 'Inter', sans-serif; }
.sidebar {
width: 260px;
background: #09090b;
border-right: 1px solid #18181b;
padding: 16px;
overflow-y: auto;
height: 100vh;
position: fixed;
left: 0;
top: 0;
z-index: 1000;
display: flex;
flex-direction: column;
box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
}
.new-chat-btn {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
width: 100%;
padding: 12px;
background: #18181b;
border: 1px solid #27272a;
border-radius: 12px;
color: #ffffff;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
margin-bottom: 8px;
}
.new-chat-btn:hover {
background: #27272a;
border-color: #3f3f46;
}
.sidebar-btn {
display: flex;
align-items: center;
gap: 12px;
width: 100%;
padding: 12px;
background: #18181b;
border: 1px solid #27272a;
border-radius: 12px;
color: #71717a;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
text-align: left;
}
.sidebar-btn:hover {
background: #27272a;
color: #fafafa;
border-color: #3f3f46;
}
.sidebar-btn svg {
width: 20px;
height: 20px;
flex-shrink: 0;
}
.history-section {
flex: 1;
overflow-y: auto;
}
.history-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.history-title {
font-size: 12px;
font-weight: 600;
color: #52525b;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.history-actions {
display: flex;
gap: 8px;
}
.history-action-btn {
width: 24px;
height: 24px;
display: flex;
align-items: center;
justify-content: center;
background: transparent;
border: none;
color: #52525b;
cursor: pointer;
transition: color 0.2s ease;
}
.history-action-btn:hover {
color: #ffffff;
}
.history-action-btn svg {
width: 14px;
height: 14px;
}
.history-group {
margin-bottom: 20px;
}
.chat-item {
display: flex;
align-items: center;
gap: 12px;
width: 100%;
padding: 10px 12px;
background: #18181b;
border: 1px solid #27272a;
border-radius: 10px;
margin-bottom: 8px;
cursor: pointer;
transition: all 0.2s ease;
text-align: left;
}
.chat-item:hover {
background: #27272a;
border-color: #3f3f46;
}
.chat-item.active {
background: #27272a;
border-color: #52525b;
}
.chat-item svg {
width: 18px;
height: 18px;
color: #71717a;
flex-shrink: 0;
}
.chat-item:hover svg,
.chat-item.active svg {
color: #fafafa;
}
.chat-info {
flex: 1;
overflow: hidden;
}
.chat-title {
font-size: 13px;
font-weight: 500;
color: #ffffff;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-bottom: 2px;
}
.chat-meta {
font-size: 11px;
color: #71717a;
display: flex;
align-items: center;
gap: 8px;
}
.chat-time,
.chat-model {
display: flex;
align-items: center;
gap: 4px;
}
.model-dot {
width: 6px;
height: 6px;
border-radius: 50%;
display: inline-block;
}
.user-section {
margin-top: auto;
padding-top: 16px;
border-top: 1px solid #18181b;
}
.user-button {
display: flex;
align-items: center;
gap: 12px;
width: 100%;
padding: 12px;
background: #18181b;
border: 1px solid #27272a;
border-radius: 12px;
cursor: pointer;
transition: all 0.2s ease;
text-align: left;
}
.user-button:hover {
background: #27272a;
border-color: #3f3f46;
}
.user-avatar {
width: 32px;
height: 32px;
border-radius: 50%;
background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: 600;
font-size: 14px;
flex-shrink: 0;
}
.user-info {
flex: 1;
}
.user-name {
font-size: 13px;
font-weight: 500;
color: #ffffff;
margin-bottom: 2px;
}
.user-plan {
font-size: 11px;
color: #a1a1aa;
}
.user-status {
display: flex;
align-items: center;
gap: 4px;
}
.status-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: #10b981;
}
.sidebar::-webkit-scrollbar {
width: 4px;
}
.sidebar::-webkit-scrollbar-track {
background: transparent;
}
.sidebar::-webkit-scrollbar-thumb {
background: #525252;
border-radius: 2px;
}
.sidebar::-webkit-scrollbar-thumb:hover {
background: #71717a;
}
</style>
<nav class="sidebar" role="navigation" aria-label="Main navigation">
<div class="sidebar-buttons">
<button onclick="startNewChat()" class="new-chat-btn" aria-label="Start a new chat">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M12 5v14m-7-7h14"/>
</svg>
<span>New Chat</span>
</button>
<button onclick="window.location.href='/media'" class="sidebar-btn" aria-label="Go to media library">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"/>
<circle cx="8.5" cy="8.5" r="1.5"/>
<path d="M21 15l-5-5L5 21"/>
</svg>
<span>Media Library</span>
</button>
</div>
<div class="history-section" role="region" aria-label="Chat history">
<div class="history-header">
<span class="history-title">Chat History</span>
<div class="history-actions">
<button class="history-action-btn" title="Search chat history" aria-label="Search">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="11" cy="11" r="8"/>
<path d="m21 21-4.35-4.35"/>
</svg>
</button>
<button class="history-action-btn" title="Clear chat history" aria-label="Clear">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M3 6h18M8 6V4a2 2 0 012-2h4a2 2 0 012 2v2m3 0v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6h14zM10 11v6M14 11v6"/>
</svg>
</button>
</div>
</div>
<div class="history-group">
<button onclick="loadChatHistory(1)" class="chat-item" data-id="1">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"/>
</svg>
<div class="chat-info">
<div class="chat-title">Website Redesign</div>
<div class="chat-meta">
<span class="chat-time">2:30 PM</span>
<span class="chat-model">
<span class="model-dot" style="background: #ffffff;"></span>
Max
</span>
</div>
</div>
</button>
<button onclick="loadChatHistory(2)" class="chat-item" data-id="2">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"/>
</svg>
<div class="chat-info">
<div class="chat-title">JavaScript Performance Tips</div>
<div class="chat-meta">
<span class="chat-time">1:15 PM</span>
<span class="chat-model">
<span class="model-dot" style="background: #a1a1aa;"></span>
Turbo
</span>
</div>
</div>
</button>
<button onclick="loadChatHistory(3)" class="chat-item active" data-id="3">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"/>
</svg>
<div class="chat-info">
<div class="chat-title">React Architecture</div>
<div class="chat-meta">
<span class="chat-time">11:45 AM</span>
<span class="chat-model">
<span class="model-dot" style="background: #71717a;"></span>
Lite
</span>
</div>
</div>
</button>
</div>
<div class="history-group">
<div class="history-title">Yesterday</div>
<button onclick="loadChatHistory(4)" class="chat-item" data-id="4">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"/>
</svg>
<div class="chat-info">
<div class="chat-title">Data Analysis Project</div>
<div class="chat-meta">
<span class="chat-time">6:20 PM</span>
<span class="chat-model">
<span class="model-dot" style="background: #d4d4d8;"></span>
Deep Research
</span>
</div>
</div>
</button>
<button onclick="loadChatHistory(5)" class="chat-item" data-id="5">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"/>
</svg>
<div class="chat-info">
<div class="chat-title">Cloud Architecture Design</div>
<div class="chat-meta">
<span class="chat-time">4:10 PM</span>
<span class="chat-model">
<span class="model-dot" style="background: #ffffff;"></span>
Max
</span>
</div>
</div>
</button>
</div>
<div class="history-group">
<div class="history-title">Older</div>
<button onclick="loadChatHistory(6)" class="chat-item" data-id="6">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"/>
</svg>
<div class="chat-info">
<div class="chat-title">Database Optimization</div>
<div class="chat-meta">
<span class="chat-time">3 days ago</span>
<span class="chat-model">
<span class="model-dot" style="background: #a1a1aa;"></span>
Turbo
</span>
</div>
</div>
</button>
<button onclick="loadChatHistory(7)" class="chat-item" data-id="7">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"/>
</svg>
<div class="chat-info">
<div class="chat-title">Security Best Practices</div>
<div class="chat-meta">
<span class="chat-time">5 days ago</span>
<span class="chat-model">
<span class="model-dot" style="background: #ffffff;"></span>
Max
</span>
</div>
</div>
</button>
</div>
</div>
<div class="user-section">
<button onclick="openAccount()" class="user-button">
<div class="user-avatar">U</div>
<div class="user-info">
<div class="user-name">User Account</div>
<div class="user-plan">Pro Plan</div>
</div>
<div class="user-status">
<div class="status-dot"></div>
</div>
</button>
</div>
</nav>
`;
this.setupMobileMenu();
}
}
customElements.define('custom-sidebar', CustomSidebar);
// Sidebar functions
function startNewChat() {
clearChat();
}
function loadChatHistory(chatId) {
console.log('Loading chat history for:', chatId);
document.querySelectorAll('.chat-item').forEach(item => {
item.classList.remove('active');
});
const clickedChat = document.querySelector(`.chat-item[data-id="${chatId}"]`);
if (clickedChat) {
clickedChat.classList.add('active');
}
}
function openAccount() {
console.log('Opening account settings...');
}