init
This commit is contained in:
commit
fe636432d0
154 files changed
+30381
No files matched your search
+217
@@ -0,0 +1,217 @@
|
||||
.wrap {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.panel {
|
||||
border-radius: var(--radius-lg);
|
||||
background: linear-gradient(
|
||||
180deg,
|
||||
rgba(255, 255, 255, 0.07),
|
||||
rgba(255, 255, 255, 0.03)
|
||||
);
|
||||
border: 1px solid color-mix(in oklab, white, transparent 88%);
|
||||
box-shadow: var(--shadow-md);
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.title {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
letter-spacing: 0.02em;
|
||||
color: color-mix(in oklab, var(--muted), white 18%);
|
||||
}
|
||||
|
||||
.disclosure {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.badge {
|
||||
font-size: 12px;
|
||||
color: color-mix(in oklab, var(--accent), white 18%);
|
||||
background: rgba(110, 231, 255, 0.12);
|
||||
border: 1px solid rgba(110, 231, 255, 0.28);
|
||||
padding: 6px 10px;
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.hint {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.promptRow {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.input {
|
||||
flex: 1;
|
||||
border-radius: 12px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
background: rgba(0, 0, 0, 0.12);
|
||||
color: var(--ink);
|
||||
padding: 10px 12px;
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
.input::placeholder {
|
||||
color: color-mix(in oklab, var(--muted), transparent 10%);
|
||||
}
|
||||
|
||||
.btn {
|
||||
border-radius: 999px;
|
||||
border: 1px solid color-mix(in oklab, white, transparent 85%);
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
color: var(--ink);
|
||||
padding: 10px 12px;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
transition: transform var(--dur-2) var(--ease-out), background var(--dur-2) var(--ease-out),
|
||||
border-color var(--dur-2) var(--ease-out);
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
transform: translateY(-1px);
|
||||
background: rgba(255, 255, 255, 0.07);
|
||||
border-color: color-mix(in oklab, var(--accent), white 35%);
|
||||
}
|
||||
|
||||
.btnPrimary {
|
||||
border-color: color-mix(in oklab, var(--accent), white 40%);
|
||||
background: linear-gradient(
|
||||
180deg,
|
||||
rgba(110, 231, 255, 0.2),
|
||||
rgba(255, 255, 255, 0.06)
|
||||
);
|
||||
}
|
||||
|
||||
.output {
|
||||
margin-top: 12px;
|
||||
border-radius: var(--radius-md);
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.typing {
|
||||
display: inline-flex;
|
||||
gap: 6px;
|
||||
align-items: center;
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 999px;
|
||||
background: color-mix(in oklab, var(--accent), white 15%);
|
||||
opacity: 0.6;
|
||||
animation: pulse 900ms var(--ease-out) infinite;
|
||||
}
|
||||
|
||||
.dot:nth-child(2) {
|
||||
animation-delay: 120ms;
|
||||
}
|
||||
|
||||
.dot:nth-child(3) {
|
||||
animation-delay: 240ms;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%,
|
||||
100% {
|
||||
transform: translateY(0);
|
||||
opacity: 0.45;
|
||||
}
|
||||
50% {
|
||||
transform: translateY(-1px);
|
||||
opacity: 0.9;
|
||||
}
|
||||
}
|
||||
|
||||
.text {
|
||||
margin: 0;
|
||||
color: color-mix(in oklab, var(--ink), white 2%);
|
||||
font-size: 13px;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.citations {
|
||||
margin-top: 10px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 7px 10px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.chipNumber {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border-radius: 999px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(110, 231, 255, 0.14);
|
||||
border: 1px solid rgba(110, 231, 255, 0.26);
|
||||
color: color-mix(in oklab, var(--accent), white 20%);
|
||||
font-weight: 650;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.controls {
|
||||
margin-top: 12px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.controlRow {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.whyRow {
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.status {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.statusStrong {
|
||||
color: color-mix(in oklab, var(--success), white 18%);
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.dot {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo, useState } from "react";
|
||||
import styles from "./AssistantRail.module.css";
|
||||
|
||||
type Suggestion = {
|
||||
id: string;
|
||||
text: string;
|
||||
citations: Array<{ title: string; href: string }>;
|
||||
};
|
||||
|
||||
const seededSuggestions: Suggestion[] = [
|
||||
{
|
||||
id: "cta",
|
||||
text: "Reduce competing CTAs: keep one primary action, demote the rest to secondary to sharpen hierarchy.",
|
||||
citations: [
|
||||
{ title: "Design System: CTA hierarchy", href: "#" },
|
||||
{ title: "UX principle: one primary per view", href: "#" },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "motion",
|
||||
text: "Use motion only as feedback (hover, state changes, subtle reveal). Respect reduced-motion automatically.",
|
||||
citations: [
|
||||
{ title: "Motion guidelines", href: "#" },
|
||||
{ title: "Reduced motion support", href: "#" },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export function AssistantRail() {
|
||||
const [prompt, setPrompt] = useState("Summarize how to improve this page’s hierarchy.");
|
||||
const [isGenerating, setIsGenerating] = useState(false);
|
||||
const [active, setActive] = useState<Suggestion | null>(seededSuggestions[0]);
|
||||
const [appliedIds, setAppliedIds] = useState<string[]>([]);
|
||||
const [lastAppliedId, setLastAppliedId] = useState<string | null>(null);
|
||||
const [showWhy, setShowWhy] = useState(false);
|
||||
|
||||
const appliedSet = useMemo(() => new Set(appliedIds), [appliedIds]);
|
||||
|
||||
function run() {
|
||||
setIsGenerating(true);
|
||||
window.setTimeout(() => {
|
||||
const promptLower = prompt.toLowerCase();
|
||||
const keywordMatch =
|
||||
promptLower.includes("motion") || promptLower.includes("animation")
|
||||
? "motion"
|
||||
: promptLower.includes("cta") || promptLower.includes("button")
|
||||
? "cta"
|
||||
: null;
|
||||
|
||||
const next =
|
||||
(keywordMatch ? seededSuggestions.find((s) => s.id === keywordMatch) : null) ??
|
||||
(() => {
|
||||
const currentIndex = seededSuggestions.findIndex((s) => s.id === (active?.id ?? seededSuggestions[0].id));
|
||||
const nextIndex = (currentIndex + 1) % seededSuggestions.length;
|
||||
return seededSuggestions[nextIndex];
|
||||
})();
|
||||
setActive(next);
|
||||
setShowWhy(false);
|
||||
setIsGenerating(false);
|
||||
}, 700);
|
||||
}
|
||||
|
||||
function apply() {
|
||||
if (!active || appliedSet.has(active.id)) return;
|
||||
setAppliedIds((prev) => [...prev, active.id]);
|
||||
setLastAppliedId(active.id);
|
||||
}
|
||||
|
||||
function undo() {
|
||||
if (!lastAppliedId) return;
|
||||
setAppliedIds((prev) => prev.filter((id) => id !== lastAppliedId));
|
||||
setLastAppliedId(null);
|
||||
}
|
||||
|
||||
function resetApplied() {
|
||||
if (!appliedIds.length) return;
|
||||
const ok = window.confirm("Clear applied items? This is just a demo of confirmation UI.");
|
||||
if (!ok) return;
|
||||
setAppliedIds([]);
|
||||
setLastAppliedId(null);
|
||||
}
|
||||
|
||||
return (
|
||||
<section className={styles.panel} aria-label="AI Assistant">
|
||||
<div className={styles.header}>
|
||||
<h2 className={styles.title}>Assistant Rail</h2>
|
||||
<div className={styles.disclosure}>
|
||||
<span className={styles.badge} title="This content is generated by AI. Review before applying.">
|
||||
AI-generated
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p className={styles.hint}>
|
||||
Human-in-control: you can apply or undo changes. This is a starter UI pattern, not a full chatbot.
|
||||
</p>
|
||||
|
||||
<div className={styles.promptRow}>
|
||||
<input
|
||||
className={styles.input}
|
||||
value={prompt}
|
||||
onChange={(e) => setPrompt(e.target.value)}
|
||||
placeholder="Ask for a UI change…"
|
||||
aria-label="Prompt"
|
||||
/>
|
||||
<button className={`${styles.btn} ${styles.btnPrimary}`} type="button" onClick={run}>
|
||||
Ask
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className={styles.output} aria-live="polite">
|
||||
{isGenerating ? (
|
||||
<div className={styles.typing} aria-label="Generating">
|
||||
<span>Thinking</span>
|
||||
<span className={styles.dot} />
|
||||
<span className={styles.dot} />
|
||||
<span className={styles.dot} />
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<p className={styles.text}>{active?.text}</p>
|
||||
<div className={styles.citations} aria-label="Citations">
|
||||
{(active?.citations ?? []).map((c, idx) => (
|
||||
<span key={c.title} className={styles.chip} title={c.title}>
|
||||
<span className={styles.chipNumber}>{idx + 1}</span>
|
||||
<a href={c.href}>{c.title}</a>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
<div className={styles.whyRow}>
|
||||
<button className={styles.btn} type="button" onClick={() => setShowWhy((v) => !v)}>
|
||||
Why this?
|
||||
</button>
|
||||
</div>
|
||||
{showWhy ? (
|
||||
<p className={styles.hint}>
|
||||
This suggestion targets high-leverage UX: clearer hierarchy reduces cognitive load and makes the
|
||||
primary action obvious. It also reduces regret by keeping changes easy to apply/undo.
|
||||
</p>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className={styles.controls}>
|
||||
<div className={styles.controlRow}>
|
||||
<button className={styles.btn} type="button" onClick={apply} disabled={!active || appliedSet.has(active.id)}>
|
||||
Apply
|
||||
</button>
|
||||
<button className={styles.btn} type="button" onClick={undo} disabled={!lastAppliedId}>
|
||||
Undo
|
||||
</button>
|
||||
<button className={styles.btn} type="button" onClick={resetApplied} disabled={!appliedIds.length}>
|
||||
Reset
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className={styles.status} aria-live="polite">
|
||||
Applied:{" "}
|
||||
<span className={appliedIds.length ? styles.statusStrong : undefined}>{appliedIds.length}</span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user