init
This commit is contained in:
commit
fe636432d0
154 files changed
+30381
No files matched your search
+8
@@ -0,0 +1,8 @@
|
||||
# Next.js App Router Starter
|
||||
|
||||
Copy these files into an existing Next.js App Router project to bootstrap a strongly-themed, token-driven page.
|
||||
|
||||
- Files assume `app/` routing (not `pages/`).
|
||||
- Uses CSS variables + CSS Modules (no external styling dependencies).
|
||||
- Designed to be rethemed by editing `app/globals.css` tokens.
|
||||
- Includes an “Assistant Rail” component demonstrating AI-native UX patterns (AI disclosure, citations, and human-in-control apply/undo).
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
:root {
|
||||
--bg: #0b0d12;
|
||||
--surface: rgba(255, 255, 255, 0.06);
|
||||
--surface-2: rgba(255, 255, 255, 0.1);
|
||||
--ink: rgba(255, 255, 255, 0.92);
|
||||
--muted: rgba(255, 255, 255, 0.68);
|
||||
--accent: #6ee7ff;
|
||||
--danger: #ff5a7a;
|
||||
--warning: #ffcc66;
|
||||
--success: #55f2b1;
|
||||
--info: #6ea8ff;
|
||||
|
||||
--radius-sm: 10px;
|
||||
--radius-md: 16px;
|
||||
--radius-lg: 22px;
|
||||
|
||||
--shadow-sm: 0 10px 30px rgba(0, 0, 0, 0.28);
|
||||
--shadow-md: 0 22px 70px rgba(0, 0, 0, 0.4);
|
||||
|
||||
--container: 1120px;
|
||||
--gutter: clamp(16px, 3vw, 28px);
|
||||
--grid-gap: clamp(14px, 2vw, 22px);
|
||||
|
||||
--ease-out: cubic-bezier(0.16, 1, 0.3, 1);
|
||||
--dur-1: 140ms;
|
||||
--dur-2: 240ms;
|
||||
--dur-3: 420ms;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: radial-gradient(1200px 900px at 18% -10%, rgba(110, 231, 255, 0.18), transparent 55%),
|
||||
radial-gradient(900px 700px at 78% 10%, rgba(255, 115, 224, 0.14), transparent 60%),
|
||||
var(--bg);
|
||||
color: var(--ink);
|
||||
font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial,
|
||||
"Apple Color Emoji", "Segoe UI Emoji";
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
:focus-visible {
|
||||
outline: 2px solid color-mix(in oklab, var(--accent), white 10%);
|
||||
outline-offset: 3px;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
animation-duration: 0.01ms !important;
|
||||
animation-iteration-count: 1 !important;
|
||||
transition-duration: 0.01ms !important;
|
||||
scroll-behavior: auto !important;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import type { Metadata } from "next";
|
||||
import "./globals.css";
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Frontend Design Starter",
|
||||
description: "Token-driven Next.js starter page for rapid retheming.",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{ children: ReactNode }>) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body>{children}</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
+244
@@ -0,0 +1,244 @@
|
||||
.page {
|
||||
min-height: 100dvh;
|
||||
}
|
||||
|
||||
.skip {
|
||||
position: absolute;
|
||||
left: -999px;
|
||||
top: 12px;
|
||||
padding: 10px 12px;
|
||||
border-radius: 999px;
|
||||
background: var(--surface-2);
|
||||
}
|
||||
|
||||
.skip:focus {
|
||||
left: 12px;
|
||||
}
|
||||
|
||||
.topbar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 10;
|
||||
backdrop-filter: blur(18px);
|
||||
background: color-mix(in oklab, var(--bg), transparent 35%);
|
||||
border-bottom: 1px solid color-mix(in oklab, white, transparent 90%);
|
||||
}
|
||||
|
||||
.topbarInner {
|
||||
max-width: var(--container);
|
||||
margin: 0 auto;
|
||||
padding: 14px var(--gutter);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 18px;
|
||||
}
|
||||
|
||||
.brand {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
font-weight: 650;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
.mark {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: 10px;
|
||||
background: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.45), transparent 60%),
|
||||
linear-gradient(135deg, rgba(110, 231, 255, 0.85), rgba(255, 115, 224, 0.62));
|
||||
box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
|
||||
}
|
||||
|
||||
.nav {
|
||||
display: flex;
|
||||
gap: 14px;
|
||||
color: var(--muted);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.nav a {
|
||||
padding: 8px 10px;
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.nav a:hover {
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
.hero {
|
||||
max-width: var(--container);
|
||||
margin: 0 auto;
|
||||
padding: 54px var(--gutter) 28px;
|
||||
display: grid;
|
||||
grid-template-columns: 1.15fr 0.85fr;
|
||||
gap: clamp(18px, 3vw, 36px);
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.headline {
|
||||
margin: 0;
|
||||
font-size: clamp(34px, 4vw, 56px);
|
||||
line-height: 1.03;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.lede {
|
||||
margin: 14px 0 0;
|
||||
color: var(--muted);
|
||||
font-size: clamp(16px, 1.4vw, 18px);
|
||||
max-width: 58ch;
|
||||
}
|
||||
|
||||
.ctaRow {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 11px 14px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid color-mix(in oklab, white, transparent 85%);
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
box-shadow: var(--shadow-sm);
|
||||
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.22),
|
||||
rgba(255, 255, 255, 0.06)
|
||||
);
|
||||
}
|
||||
|
||||
.panel {
|
||||
border-radius: var(--radius-lg);
|
||||
background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.03));
|
||||
border: 1px solid color-mix(in oklab, white, transparent 88%);
|
||||
box-shadow: var(--shadow-md);
|
||||
padding: 18px;
|
||||
}
|
||||
|
||||
.rail {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.panelHeader {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.panelTitle {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
letter-spacing: 0.02em;
|
||||
color: color-mix(in oklab, var(--muted), white 18%);
|
||||
}
|
||||
|
||||
.badge {
|
||||
font-size: 12px;
|
||||
color: color-mix(in oklab, var(--accent), white 20%);
|
||||
background: rgba(110, 231, 255, 0.12);
|
||||
border: 1px solid rgba(110, 231, 255, 0.28);
|
||||
padding: 6px 10px;
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.list {
|
||||
margin: 14px 0 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.item {
|
||||
border-radius: var(--radius-md);
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
border: 1px solid rgba(255, 255, 255, 0.06);
|
||||
padding: 12px 12px;
|
||||
}
|
||||
|
||||
.itemTitle {
|
||||
font-weight: 620;
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.itemBody {
|
||||
margin: 6px 0 0;
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.content {
|
||||
max-width: var(--container);
|
||||
margin: 0 auto;
|
||||
padding: 28px var(--gutter) 64px;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(12, 1fr);
|
||||
gap: var(--grid-gap);
|
||||
}
|
||||
|
||||
.card {
|
||||
grid-column: span 4;
|
||||
border-radius: var(--radius-lg);
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
border: 1px solid rgba(255, 255, 255, 0.07);
|
||||
padding: 18px;
|
||||
transition: transform var(--dur-2) var(--ease-out), border-color var(--dur-2) var(--ease-out);
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
transform: translateY(-2px);
|
||||
border-color: color-mix(in oklab, var(--accent), white 35%);
|
||||
}
|
||||
|
||||
.card h2 {
|
||||
margin: 0 0 8px;
|
||||
font-size: 16px;
|
||||
letter-spacing: 0.01em;
|
||||
}
|
||||
|
||||
.card p {
|
||||
margin: 0;
|
||||
color: var(--muted);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.hero {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.card {
|
||||
grid-column: span 6;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 560px) {
|
||||
.card {
|
||||
grid-column: span 12;
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
import styles from "./page.module.css";
|
||||
import { AssistantRail } from "../components/AssistantRail";
|
||||
|
||||
const quickWins = [
|
||||
{
|
||||
title: "Token-first styling",
|
||||
body: "Retheme fast by editing CSS variables in globals.css (palette, radii, shadows, motion).",
|
||||
},
|
||||
{
|
||||
title: "One signature move",
|
||||
body: "Commit to a single memorable gesture (light sweep, stripe, grain, or brutal border logic).",
|
||||
},
|
||||
{
|
||||
title: "Accessible by default",
|
||||
body: "Semantic structure, visible focus, and reduced-motion support are built in.",
|
||||
},
|
||||
];
|
||||
|
||||
export default function Page() {
|
||||
return (
|
||||
<div className={styles.page}>
|
||||
<a className={styles.skip} href="#content">
|
||||
Skip to content
|
||||
</a>
|
||||
|
||||
<header className={styles.topbar}>
|
||||
<div className={styles.topbarInner}>
|
||||
<a className={styles.brand} href="#">
|
||||
<span aria-hidden className={styles.mark} />
|
||||
Frontend Design
|
||||
</a>
|
||||
<nav className={styles.nav} aria-label="Primary">
|
||||
<a href="#principles">Principles</a>
|
||||
<a href="#cards">Patterns</a>
|
||||
<a href="#cta">CTA</a>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main id="content">
|
||||
<section className={styles.hero} aria-labelledby="headline">
|
||||
<div>
|
||||
<h1 id="headline" className={styles.headline}>
|
||||
A token-driven page that looks intentional on day one.
|
||||
</h1>
|
||||
<p className={styles.lede}>
|
||||
Build structure first, then motion, then polish. Keep the UI memorable with one
|
||||
signature move—not ten random decorations.
|
||||
</p>
|
||||
<div className={styles.ctaRow} id="cta">
|
||||
<a className={`${styles.btn} ${styles.btnPrimary}`} href="#">
|
||||
Start a redesign <span aria-hidden>→</span>
|
||||
</a>
|
||||
<a className={styles.btn} href="#cards">
|
||||
See patterns
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<aside className={styles.panel} aria-label="Quick Wins" id="principles">
|
||||
<div className={styles.panelHeader}>
|
||||
<h2 className={styles.panelTitle}>Quick Wins</h2>
|
||||
<span className={styles.badge}>Next.js App Router</span>
|
||||
</div>
|
||||
<ul className={styles.list}>
|
||||
{quickWins.map((item) => (
|
||||
<li key={item.title} className={styles.item}>
|
||||
<p className={styles.itemTitle}>{item.title}</p>
|
||||
<p className={styles.itemBody}>{item.body}</p>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</aside>
|
||||
|
||||
<div className={styles.rail}>
|
||||
<AssistantRail />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className={styles.content} aria-labelledby="cards" id="cards">
|
||||
<div className={styles.grid}>
|
||||
<article className={styles.card}>
|
||||
<h2>Hierarchy</h2>
|
||||
<p>Make the primary action obvious, then design the supporting rails.</p>
|
||||
</article>
|
||||
<article className={styles.card}>
|
||||
<h2>Texture</h2>
|
||||
<p>Use subtle grain/mesh/stripe logic to avoid flat UI without clutter.</p>
|
||||
</article>
|
||||
<article className={styles.card}>
|
||||
<h2>Motion</h2>
|
||||
<p>Orchestrate a few meaningful reveals and micro-interactions—guarded by settings.</p>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+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