|
| 1 | +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +import { html } from 'lit'; |
| 5 | +import '@nvidia-elements/core/button/define.js'; |
| 6 | +import '@nvidia-elements/core/chat-message/define.js'; |
| 7 | +import '@nvidia-elements/core/dialog/define.js'; |
| 8 | +import '@nvidia-elements/core/icon-button/define.js'; |
| 9 | +import '@nvidia-elements/core/logo/define.js'; |
| 10 | +import '@nvidia-elements/core/page/define.js'; |
| 11 | +import '@nvidia-elements/core/page-header/define.js'; |
| 12 | +import '@nvidia-elements/core/textarea/define.js'; |
| 13 | + |
| 14 | +export default { |
| 15 | + title: 'Patterns/Chat', |
| 16 | + component: 'nve-patterns' |
| 17 | +}; |
| 18 | + |
| 19 | +/** |
| 20 | + * @summary Centered page chat with a constrained message column and footer composer. Use for primary assistant experiences where the conversation is the main task and needs persistent input. |
| 21 | + * @tags pattern |
| 22 | + */ |
| 23 | +export const PageChat = { |
| 24 | + render: () => html` |
| 25 | +<nve-page> |
| 26 | + <nve-page-header slot="header"> |
| 27 | + <nve-logo slot="prefix" size="sm" color="brand-green">AI</nve-logo> |
| 28 | + <h1 slot="prefix" nve-text="heading sm">Assistant</h1> |
| 29 | + </nve-page-header> |
| 30 | + <nve-page-panel slot="subheader"> |
| 31 | + <nve-page-panel-content> |
| 32 | + <h2 nve-text="heading sm">Deployment risk review</h2> |
| 33 | + </nve-page-panel-content> |
| 34 | + </nve-page-panel> |
| 35 | + <main nve-layout="column pad:lg align:horizontal-center"> |
| 36 | + <section nve-layout="column gap:lg align:horizontal-stretch" aria-live="polite" aria-relevant="additions text" style="max-width: 520px; margin: 0 auto;"> |
| 37 | + <nve-chat-message aria-label="user message" arrow-position="top-end" style="margin-inline-start: auto; max-width: 80%;"> |
| 38 | + <nve-avatar slot="suffix" color="brand-green">NV</nve-avatar> |
| 39 | + Summarize the deployment risk for the new inference endpoint. |
| 40 | + </nve-chat-message> |
| 41 | + <nve-chat-message aria-label="assistant message" arrow-position="top-start" style="max-width: 80%;"> |
| 42 | + <nve-avatar slot="prefix" color="gray-denim">AI</nve-avatar> |
| 43 | + The highest risk is the cold-start latency on the first request after scale-out. Keep the rollout limited to the staging pool until p95 startup time stays below the service target for three consecutive runs. |
| 44 | + </nve-chat-message> |
| 45 | + <nve-chat-message aria-label="user message" arrow-position="top-end" style="margin-inline-start: auto; max-width: 80%;"> |
| 46 | + <nve-avatar slot="suffix" color="brand-green">NV</nve-avatar> |
| 47 | + What should the operator check first? |
| 48 | + </nve-chat-message> |
| 49 | + </section> |
| 50 | + </main> |
| 51 | + <form slot="footer" nve-layout="column gap:sm full pad:md" style="max-width: 520px; margin: 0 auto;"> |
| 52 | + <nve-textarea> |
| 53 | + <textarea aria-label="Message Agent" name="message" rows="3" maxlength="4000" placeholder="Ask about this deployment"></textarea> |
| 54 | + </nve-textarea> |
| 55 | + <nve-button type="button" style="margin-inline-start: auto;">Send</nve-button> |
| 56 | + </form> |
| 57 | +</nve-page> |
| 58 | + ` |
| 59 | +}; |
| 60 | + |
| 61 | +/** |
| 62 | + * @summary Right-side chat panel with persistent header, scrollable transcript, and footer composer. Use when chat supports a larger workspace without taking over the main content. |
| 63 | + * @tags pattern |
| 64 | + */ |
| 65 | +export const PanelChat = { |
| 66 | + render: () => html` |
| 67 | +<nve-page> |
| 68 | + <nve-page-header slot="header"> |
| 69 | + <nve-logo slot="prefix" size="sm" color="brand-green">AI</nve-logo> |
| 70 | + <h1 slot="prefix" nve-text="heading sm">Prompt API Chat</h1> |
| 71 | + </nve-page-header> |
| 72 | + <main nve-layout="column gap:lg pad:lg align:horizontal-stretch"> |
| 73 | + <section nve-layout="column gap:md" style="max-width: 900px;"> |
| 74 | + <h2 nve-text="heading">Model deployment</h2> |
| 75 | + <p nve-text="body"> |
| 76 | + Keep the assistant available while operators inspect logs, metrics, and deployment details in the main workspace. |
| 77 | + </p> |
| 78 | + </section> |
| 79 | + </main> |
| 80 | + <nve-page-panel id="chat-panel" slot="right" aria-labelledby="chat-title"> |
| 81 | + <nve-page-panel-header> |
| 82 | + <h2 id="chat-title" nve-text="heading sm">Assistant</h2> |
| 83 | + </nve-page-panel-header> |
| 84 | + <nve-page-panel-content> |
| 85 | + <section nve-layout="column gap:lg align:horizontal-stretch" aria-live="polite" aria-relevant="additions text" style="margin-inline-start: auto;"> |
| 86 | + <nve-chat-message aria-label="user message" arrow-position="top-end" color="brand-green" style="margin-inline-start: auto;"> |
| 87 | + How does the nve-badge work? |
| 88 | + </nve-chat-message> |
| 89 | + <nve-chat-message aria-label="assistant message" arrow-position="top-start"> |
| 90 | + The badge communicates short status, count, or label information next to related content. Use status values when the badge describes system state and color values when it needs to match a broader visual category. |
| 91 | + </nve-chat-message> |
| 92 | + </section> |
| 93 | + </nve-page-panel-content> |
| 94 | + <nve-page-panel-footer> |
| 95 | + <form nve-layout="column gap:sm full"> |
| 96 | + <nve-textarea> |
| 97 | + <textarea aria-label="Message Agent" name="message" rows="3" maxlength="4000" placeholder="Ask about NVIDIA Elements"></textarea> |
| 98 | + </nve-textarea> |
| 99 | + <nve-button type="button" style="margin-inline-start: auto;">Send</nve-button> |
| 100 | + </form> |
| 101 | + </nve-page-panel-footer> |
| 102 | + </nve-page-panel> |
| 103 | +</nve-page> |
| 104 | + ` |
| 105 | +}; |
| 106 | + |
| 107 | +/** |
| 108 | + * @summary Bottom-right anchored chat dialog with launcher button. Use for optional contextual help or assistant support that should stay available without changing the page layout. |
| 109 | + * @tags pattern |
| 110 | + */ |
| 111 | +export const PopoverChat = { |
| 112 | + render: () => html` |
| 113 | +<nve-icon-button |
| 114 | + id="chat-launcher" |
| 115 | + popovertarget="chat-popover" |
| 116 | + interaction="emphasis" |
| 117 | + icon-name="chat-bubble" |
| 118 | + size="lg" |
| 119 | + aria-label="Open assistant" |
| 120 | + style="position: fixed; inset-block-end: var(--nve-ref-space-xl); inset-inline-end: var(--nve-ref-space-xl); z-index: 100;" |
| 121 | +></nve-icon-button> |
| 122 | +<nve-dialog |
| 123 | + id="chat-popover" |
| 124 | + anchor="chat-launcher" |
| 125 | + position="top" |
| 126 | + alignment="end" |
| 127 | + size="sm" |
| 128 | + closable |
| 129 | + style="--max-width: 320px; --min-height: 340px; margin: var(--nve-ref-space-sm)" |
| 130 | +> |
| 131 | + <nve-dialog-header> |
| 132 | + <h2 nve-text="heading sm">Assistant</h2> |
| 133 | + </nve-dialog-header> |
| 134 | + <section nve-layout="column gap:md full" aria-live="polite" aria-relevant="additions text"> |
| 135 | + <nve-chat-message aria-label="assistant message" arrow-position="top-start"> |
| 136 | + I can help compare alerts, explain metrics, or draft a remediation checklist. |
| 137 | + </nve-chat-message> |
| 138 | + <nve-chat-message aria-label="user message" arrow-position="top-end" color="brand-green" style="margin-inline-start: auto;"> |
| 139 | + Why did the deployment pause? |
| 140 | + </nve-chat-message> |
| 141 | + <nve-chat-message aria-label="assistant message" arrow-position="top-start"> |
| 142 | + The canary paused because error rate exceeded the threshold for two consecutive windows. |
| 143 | + </nve-chat-message> |
| 144 | + </section> |
| 145 | + <nve-dialog-footer> |
| 146 | + <form nve-layout="column gap:sm full"> |
| 147 | + <nve-textarea> |
| 148 | + <textarea aria-label="Message Agent" name="message" rows="2" maxlength="4000" placeholder="Ask for help"></textarea> |
| 149 | + </nve-textarea> |
| 150 | + <nve-button type="button" style="margin-inline-start: auto;">Send</nve-button> |
| 151 | + </form> |
| 152 | + </nve-dialog-footer> |
| 153 | +</nve-dialog> |
| 154 | +<script type="module"> |
| 155 | + await customElements.whenDefined('nve-dialog'); |
| 156 | + const dialog = document.querySelector('#chat-popover'); |
| 157 | + const launcher = document.querySelector('#chat-launcher'); |
| 158 | + if (dialog && launcher && !dialog.matches(':popover-open')) { |
| 159 | + dialog.showPopover({ source: launcher }); |
| 160 | + } |
| 161 | +</script> |
| 162 | + ` |
| 163 | +}; |
0 commit comments