@designa8/vibedesign-v6 1.20.19 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/fonts/plusjakartasans/PlusJakartaSans-Italic[wght].ttf +0 -0
- package/dist/fonts/plusjakartasans/PlusJakartaSans[wght].ttf +0 -0
- package/dist/index.cjs +12027 -4942
- package/dist/index.js +12089 -5004
- package/dist/styles.css +1393 -97
- package/package.json +116 -1
- package/src/atoms/AgentQuestionCard/AgentQuestionCard.tsx +567 -0
- package/src/atoms/AgentQuestionCard/index.ts +6 -0
- package/src/atoms/AgentQuestionCard/preview.tsx +199 -0
- package/src/atoms/AppLayout/AppLayout.tsx +85 -22
- package/src/atoms/AppLayout/preview.tsx +4 -0
- package/src/atoms/AppSidebar/AppSidebar.tsx +222 -137
- package/src/atoms/AppSidebar/preview.tsx +61 -8
- package/src/atoms/AppSidebarMobile/AppSidebarMobile.tsx +241 -169
- package/src/atoms/AppSidebarMobile/preview.tsx +59 -89
- package/src/atoms/AuthLogin/AuthLogin.tsx +86 -49
- package/src/atoms/AuthLogin/preview.tsx +16 -0
- package/src/atoms/AuthSignUp/AuthSignUp.tsx +206 -126
- package/src/atoms/AuthSignUp/preview.tsx +10 -0
- package/src/atoms/BillingToggle/BillingToggle.tsx +2 -2
- package/src/atoms/BottomSheet/BottomSheet.tsx +199 -0
- package/src/atoms/BottomSheet/index.ts +2 -0
- package/src/atoms/BottomSheet/preview.tsx +50 -0
- package/src/atoms/Button/Button.tsx +19 -3
- package/src/atoms/Button/preview.tsx +2 -1
- package/src/atoms/ChatHistorySidebar/ChatHistorySidebar.tsx +160 -84
- package/src/atoms/ChatHistorySidebar/preview.tsx +81 -42
- package/src/atoms/ChatScreen/ChatScreen.tsx +298 -33
- package/src/atoms/ChatScreen/preview.tsx +54 -90
- package/src/atoms/Chip/Chip.tsx +81 -33
- package/src/atoms/Chip/preview.tsx +39 -21
- package/src/atoms/CodeEditor/CodeEditor.tsx +10 -4
- package/src/atoms/ComponentActionsSheet/ComponentActionsSheet.tsx +165 -0
- package/src/atoms/ComponentActionsSheet/index.ts +7 -0
- package/src/atoms/ComponentActionsSheet/preview.tsx +67 -0
- package/src/atoms/ComponentCard/ComponentCard.tsx +17 -35
- package/src/atoms/ComponentCard/preview.tsx +9 -9
- package/src/atoms/DesignSystemLoader/DesignSystemLoader.tsx +153 -0
- package/src/atoms/DesignSystemLoader/index.ts +2 -0
- package/src/atoms/DesignSystemLoader/preview.tsx +19 -0
- package/src/atoms/DesignSystemShowcase/DesignSystemShowcase.tsx +410 -0
- package/src/atoms/DesignSystemShowcase/index.ts +6 -0
- package/src/atoms/DesignSystemShowcase/preview.tsx +22 -0
- package/src/atoms/DesignTokensPanel/DesignTokensPanel.data.ts +254 -0
- package/src/atoms/DesignTokensPanel/DesignTokensPanel.tsx +946 -0
- package/src/atoms/DesignTokensPanel/index.ts +9 -0
- package/src/atoms/DesignTokensPanel/preview.tsx +39 -0
- package/src/atoms/ExpandableMessage/ExpandableMessage.tsx +239 -0
- package/src/atoms/ExpandableMessage/fix-link-note.txt +3 -0
- package/src/atoms/ExpandableMessage/index.ts +2 -0
- package/src/atoms/ExpandableMessage/markdown.tsx +310 -0
- package/src/atoms/ExpandableMessage/preview.tsx +83 -0
- package/src/atoms/FilterTabBar/FilterTabBar.tsx +2 -2
- package/src/atoms/FontCombobox/FontCombobox.tsx +655 -0
- package/src/atoms/FontCombobox/index.ts +6 -0
- package/src/atoms/FontCombobox/preview.tsx +111 -0
- package/src/atoms/HomePageTemplate/HomePageTemplate.tsx +894 -96
- package/src/atoms/HomePageTemplate/preview.tsx +4 -0
- package/src/atoms/Icon/Icon.tsx +17 -11
- package/src/atoms/Icon/icons.data.ts +34 -0
- package/src/atoms/Input/Input.tsx +37 -21
- package/src/atoms/LandingHero/LandingHero.tsx +545 -0
- package/src/atoms/LandingHero/index.ts +6 -0
- package/src/atoms/LandingHero/preview.tsx +88 -0
- package/src/atoms/MarketingFooter/MarketingFooter.tsx +215 -0
- package/src/atoms/MarketingFooter/index.ts +7 -0
- package/src/atoms/MarketingFooter/preview.tsx +28 -0
- package/src/atoms/MarketingNavbar/MarketingNavbar.tsx +451 -0
- package/src/atoms/MarketingNavbar/index.ts +7 -0
- package/src/atoms/MarketingNavbar/preview.tsx +109 -0
- package/src/atoms/MobileActionsDrawer/MobileActionsDrawer.tsx +548 -0
- package/src/atoms/MobileActionsDrawer/index.ts +9 -0
- package/src/atoms/MobileActionsDrawer/preview.tsx +109 -0
- package/src/atoms/Modal/Modal.tsx +77 -28
- package/src/atoms/PreviewDock/PreviewDock.tsx +119 -0
- package/src/atoms/PreviewDock/index.ts +2 -0
- package/src/atoms/PreviewDock/preview.tsx +30 -0
- package/src/atoms/PreviewToolbar/PreviewToolbar.tsx +47 -30
- package/src/atoms/PricingCard/PricingCard.tsx +15 -4
- package/src/atoms/PricingPageTemplate/PricingPageTemplate.tsx +109 -89
- package/src/atoms/ProjectSettingsModal/ProjectSettingsModal.tsx +314 -0
- package/src/atoms/ProjectSettingsModal/index.ts +2 -0
- package/src/atoms/ProjectSettingsModal/preview.tsx +130 -0
- package/src/atoms/ProjectSettingsModal/switch.snippet.txt +8 -0
- package/src/atoms/PromptInputBar/PromptInputBar.tsx +750 -302
- package/src/atoms/PromptInputBar/preview.tsx +64 -64
- package/src/atoms/SettingsPageTemplate/SettingsPageTemplate.tsx +272 -0
- package/src/atoms/SettingsPageTemplate/index.ts +2 -0
- package/src/atoms/SettingsPageTemplate/preview.tsx +29 -0
- package/src/atoms/SidebarUpgradeBanner/SidebarUpgradeBanner.tsx +178 -0
- package/src/atoms/SidebarUpgradeBanner/index.ts +2 -0
- package/src/atoms/SidebarUpgradeBanner/preview.tsx +47 -0
- package/src/atoms/SkeletonChip/SkeletonChip.tsx +198 -0
- package/src/atoms/SkeletonChip/index.ts +2 -0
- package/src/atoms/SkeletonChip/preview.tsx +44 -0
- package/src/atoms/TemplateHeader/TemplateHeader.tsx +129 -0
- package/src/atoms/TemplateHeader/index.ts +2 -0
- package/src/atoms/TemplateHeader/preview.tsx +39 -0
- package/src/atoms/TemplateHero/TemplateHero.tsx +286 -0
- package/src/atoms/TemplateHero/index.ts +2 -0
- package/src/atoms/TemplateHero/preview.tsx +32 -0
- package/src/atoms/TemplateSummary/TemplateSummary.tsx +85 -0
- package/src/atoms/TemplateSummary/index.ts +2 -0
- package/src/atoms/TemplateSummary/preview.tsx +10 -0
- package/src/atoms/Toast/Toast.tsx +178 -0
- package/src/atoms/Toast/index.ts +2 -0
- package/src/atoms/Toast/preview.tsx +100 -0
- package/src/atoms/TopNavbar/TopNavbar.tsx +145 -67
- package/src/atoms/TopNavbar/preview.tsx +13 -7
- package/src/atoms/TopupModal/TopupModal.tsx +94 -0
- package/src/atoms/TopupModal/index.ts +2 -0
- package/src/atoms/TopupModal/preview.tsx +22 -0
- package/src/atoms/UpgradeCard/UpgradeCard.tsx +124 -43
- package/src/atoms/UpgradeCard/index.ts +1 -1
- package/src/atoms/UpgradeCard/preview.tsx +7 -14
- package/src/atoms/UpgradeModal/UpgradeModal.tsx +192 -0
- package/src/atoms/UpgradeModal/index.ts +2 -0
- package/src/atoms/UpgradeModal/preview.tsx +41 -0
- package/src/index.ts +23 -0
- package/src/tokens.css +45 -7
- package/dist/fonts/inter/Inter-Italic[opsz,wght].ttf +0 -0
- package/dist/fonts/inter/Inter[opsz,wght].ttf +0 -0
|
@@ -3,6 +3,7 @@ import { PromptInputBar, PromptMode, PromptInputBarModel } from "../PromptInputB
|
|
|
3
3
|
import { Button } from "../Button";
|
|
4
4
|
import { Icon } from "../Icon";
|
|
5
5
|
import { Modal } from "../Modal";
|
|
6
|
+
import { ExpandableMessage } from "../ExpandableMessage";
|
|
6
7
|
|
|
7
8
|
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
8
9
|
|
|
@@ -55,9 +56,20 @@ export interface ChatMessage {
|
|
|
55
56
|
content: string;
|
|
56
57
|
/** Initials shown in the user avatar — falls back to "U" */
|
|
57
58
|
userInitials?: string;
|
|
58
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* Relative time shown under a sender bubble, e.g. "12:04" or "Just now".
|
|
61
|
+
* Only rendered when provided — never fabricated.
|
|
62
|
+
*/
|
|
63
|
+
sentAt?: string;
|
|
64
|
+
/** Sender message failed to send — error fill + "Not sent" / "Retry" row */
|
|
65
|
+
failed?: boolean;
|
|
66
|
+
/** Called when the sender taps "Retry" on a failed message */
|
|
67
|
+
onRetry?: (message: ChatMessage) => void;
|
|
68
|
+
/** Called after the sender copies this message's text */
|
|
69
|
+
onCopy?: (content: string) => void;
|
|
70
|
+
/** AI is still generating — shows a "Thinking" row with a pulsing dot under the message body */
|
|
59
71
|
inFlight?: boolean;
|
|
60
|
-
/** Label for the current tool being invoked, e.g. "Writing atom" */
|
|
72
|
+
/** Label for the current tool being invoked, e.g. "Writing atom" (no longer rendered while inFlight) */
|
|
61
73
|
currentToolLabel?: string;
|
|
62
74
|
/** Optional timeline of agent tool-call steps — renders a collapsible TimelineBlock */
|
|
63
75
|
timeline?: TimelineItem[];
|
|
@@ -596,7 +608,7 @@ const SuggestedImageWidget: React.FC<{ suggestedImage: ChatMessageSuggestedImage
|
|
|
596
608
|
);
|
|
597
609
|
};
|
|
598
610
|
|
|
599
|
-
// ───
|
|
611
|
+
// ─── Avatars ──────────────────────────────────────────────────────────────────
|
|
600
612
|
|
|
601
613
|
/** AI avatar — small primary circle with "AI" text */
|
|
602
614
|
const AIAvatar: React.FC = () => (
|
|
@@ -618,20 +630,125 @@ const UserAvatar: React.FC<{ initials?: string }> = ({ initials = "U" }) => (
|
|
|
618
630
|
</span>
|
|
619
631
|
);
|
|
620
632
|
|
|
621
|
-
|
|
633
|
+
// ─── Sender row: copy affordance ──────────────────────────────────────────────
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Quiet icon-only copy button that sits ABOVE the sender bubble, outside the
|
|
637
|
+
* tinted fill. Hidden until the row is hovered or focused, so it never
|
|
638
|
+
* competes with the message. Confirms with a success-coloured check glyph and
|
|
639
|
+
* announces the change through a polite live region.
|
|
640
|
+
*/
|
|
641
|
+
const CopyMessageButton: React.FC<{ text: string; onCopy?: (content: string) => void }> = ({
|
|
642
|
+
text,
|
|
643
|
+
onCopy,
|
|
644
|
+
}) => {
|
|
645
|
+
const [copied, setCopied] = React.useState(false);
|
|
646
|
+
const timeoutRef = React.useRef<number | null>(null);
|
|
647
|
+
|
|
648
|
+
React.useEffect(
|
|
649
|
+
() => () => {
|
|
650
|
+
if (timeoutRef.current !== null) {
|
|
651
|
+
window.clearTimeout(timeoutRef.current);
|
|
652
|
+
}
|
|
653
|
+
},
|
|
654
|
+
[],
|
|
655
|
+
);
|
|
656
|
+
|
|
657
|
+
const handleCopy = () => {
|
|
658
|
+
try {
|
|
659
|
+
void navigator?.clipboard?.writeText(text);
|
|
660
|
+
} catch {
|
|
661
|
+
// Clipboard access can be blocked — the affordance still confirms.
|
|
662
|
+
}
|
|
663
|
+
onCopy?.(text);
|
|
664
|
+
setCopied(true);
|
|
665
|
+
if (timeoutRef.current !== null) {
|
|
666
|
+
window.clearTimeout(timeoutRef.current);
|
|
667
|
+
}
|
|
668
|
+
timeoutRef.current = window.setTimeout(() => setCopied(false), 1500);
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
return (
|
|
672
|
+
<div className="flex items-center justify-end mb-xs">
|
|
673
|
+
<button
|
|
674
|
+
type="button"
|
|
675
|
+
onClick={handleCopy}
|
|
676
|
+
aria-label={copied ? "Message copied" : "Copy message"}
|
|
677
|
+
data-copied={copied ? "true" : "false"}
|
|
678
|
+
className="inline-flex items-center justify-center rounded-xs p-xxs text-muted-soft opacity-0 cursor-pointer transition duration-150 ease-out hover:text-ink active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue group-hover:opacity-100 group-focus-within:opacity-100 focus-visible:opacity-100 data-[copied=true]:opacity-100"
|
|
679
|
+
>
|
|
680
|
+
<Icon
|
|
681
|
+
name={copied ? "check-checkmark" : "copy-clipboard"}
|
|
682
|
+
size={14}
|
|
683
|
+
className={copied ? "text-semantic-success" : undefined}
|
|
684
|
+
/>
|
|
685
|
+
</button>
|
|
686
|
+
<span role="status" aria-live="polite" className="sr-only">
|
|
687
|
+
{copied ? "Message copied to clipboard" : ""}
|
|
688
|
+
</span>
|
|
689
|
+
</div>
|
|
690
|
+
);
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
// ─── Thinking indicator ───────────────────────────────────────────────────────
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* In-flight indicator shown under the message body while the AI message is
|
|
697
|
+
* still generating: one row holding a small primary dot that pulses slowly
|
|
698
|
+
* (about 1.2s) followed by the word "Thinking" in solid muted text. The dot is
|
|
699
|
+
* decorative and the row carries the accessible name, so assistive tech hears
|
|
700
|
+
* "Thinking" once. Under prefers-reduced-motion the dot stays solid.
|
|
701
|
+
*/
|
|
702
|
+
const THINKING_DOT_CSS = `
|
|
703
|
+
@keyframes chat-thinking-pulse {
|
|
704
|
+
0%, 100% { opacity: 1; }
|
|
705
|
+
50% { opacity: 0.25; }
|
|
706
|
+
}
|
|
707
|
+
.chat-thinking-dot {
|
|
708
|
+
animation: chat-thinking-pulse 1.2s ease-in-out infinite;
|
|
709
|
+
}
|
|
710
|
+
@media (prefers-reduced-motion: reduce) {
|
|
711
|
+
.chat-thinking-dot {
|
|
712
|
+
animation: none;
|
|
713
|
+
opacity: 1;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
`;
|
|
717
|
+
|
|
718
|
+
const ThinkingIndicator: React.FC = () => (
|
|
719
|
+
<>
|
|
720
|
+
<style>{THINKING_DOT_CSS}</style>
|
|
721
|
+
<div
|
|
722
|
+
role="status"
|
|
723
|
+
aria-live="polite"
|
|
724
|
+
aria-label="Thinking"
|
|
725
|
+
className="mt-sm flex items-center gap-xs"
|
|
726
|
+
>
|
|
727
|
+
<span
|
|
728
|
+
aria-hidden="true"
|
|
729
|
+
className="chat-thinking-dot size-2 flex-shrink-0 rounded-full bg-primary"
|
|
730
|
+
/>
|
|
731
|
+
<span aria-hidden="true" className="text-body-sm text-muted">
|
|
732
|
+
Thinking
|
|
733
|
+
</span>
|
|
734
|
+
</div>
|
|
735
|
+
</>
|
|
736
|
+
);
|
|
737
|
+
|
|
738
|
+
// ─── AI message ───────────────────────────────────────────────────────────────
|
|
739
|
+
|
|
740
|
+
/** AI message — plain prose column (no bubble) so long answers stay readable */
|
|
622
741
|
const AiMessage: React.FC<{ message: ChatMessage }> = ({ message }) => (
|
|
623
742
|
<div className="flex items-start gap-md w-full">
|
|
624
743
|
<AIAvatar />
|
|
625
744
|
<div className="flex-1 min-w-0">
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
)}
|
|
634
|
-
<p className="text-body-sm text-body leading-relaxed">{message.content}</p>
|
|
745
|
+
<ExpandableMessage
|
|
746
|
+
variant="flush"
|
|
747
|
+
maxLines={6}
|
|
748
|
+
content={message.content}
|
|
749
|
+
className="text-body-sm text-body"
|
|
750
|
+
/>
|
|
751
|
+
{message.inFlight && <ThinkingIndicator />}
|
|
635
752
|
{message.images && message.images.length > 0 && (
|
|
636
753
|
<MessageImageGallery images={message.images} align="start" />
|
|
637
754
|
)}
|
|
@@ -645,35 +762,90 @@ const AiMessage: React.FC<{ message: ChatMessage }> = ({ message }) => (
|
|
|
645
762
|
<AgentConversationMark mark={message.agentMark} align="start" />
|
|
646
763
|
)}
|
|
647
764
|
{message.postContent && (
|
|
648
|
-
<
|
|
765
|
+
<ExpandableMessage
|
|
766
|
+
variant="flush"
|
|
767
|
+
maxLines={6}
|
|
768
|
+
content={message.postContent}
|
|
769
|
+
className="text-body-sm text-body mt-md"
|
|
770
|
+
/>
|
|
649
771
|
)}
|
|
650
772
|
</div>
|
|
651
773
|
</div>
|
|
652
774
|
);
|
|
653
775
|
|
|
654
|
-
|
|
655
|
-
|
|
776
|
+
// ─── Sender message ───────────────────────────────────────────────────────────
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* Sender message — right-aligned tinted bubble. The text runs through
|
|
780
|
+
* ExpandableMessage (flush, 6 lines) so long prompts collapse with a
|
|
781
|
+
* Show more control inside the same surface: one tinted rectangle, no nested
|
|
782
|
+
* card. A copy affordance floats above the bubble, a quiet timestamp below it,
|
|
783
|
+
* and a failed send swaps the fill to the error tint with a "Not sent" row.
|
|
784
|
+
* Image-only messages render no bubble at all.
|
|
785
|
+
*/
|
|
656
786
|
const UserMessage: React.FC<{ message: ChatMessage }> = ({ message }) => {
|
|
657
787
|
const hasText = message.content.trim().length > 0;
|
|
658
788
|
const hasImages = !!message.images && message.images.length > 0;
|
|
789
|
+
const failed = !!message.failed;
|
|
790
|
+
|
|
791
|
+
// Avatar aligns to the bubble, not to the timestamp line below it.
|
|
792
|
+
const hasMetaLine = hasText && (failed || !!message.sentAt);
|
|
659
793
|
|
|
660
794
|
return (
|
|
661
|
-
<div className="flex items-
|
|
662
|
-
<div className="flex max-w-[80%] flex-col items-end">
|
|
795
|
+
<div className="flex items-end gap-sm w-full justify-end">
|
|
796
|
+
<div className="group flex min-w-0 max-w-[80%] flex-col items-end">
|
|
663
797
|
{hasText && (
|
|
664
|
-
|
|
665
|
-
<
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
798
|
+
<>
|
|
799
|
+
<CopyMessageButton text={message.content} onCopy={message.onCopy} />
|
|
800
|
+
|
|
801
|
+
<div
|
|
802
|
+
className={[
|
|
803
|
+
"max-w-full rounded-xl px-lg py-md",
|
|
804
|
+
failed ? "bg-semantic-error-soft" : "bg-primary-soft",
|
|
805
|
+
"transition-colors duration-150 ease-out",
|
|
806
|
+
].join(" ")}
|
|
807
|
+
>
|
|
808
|
+
<ExpandableMessage
|
|
809
|
+
variant="flush"
|
|
810
|
+
maxLines={6}
|
|
811
|
+
content={message.content}
|
|
812
|
+
className="text-body-sm text-ink"
|
|
813
|
+
toggleClassName="text-primary-text hover:text-primary-active"
|
|
814
|
+
/>
|
|
815
|
+
{message.agentMark && (
|
|
816
|
+
<AgentConversationMark mark={message.agentMark} align="end" />
|
|
817
|
+
)}
|
|
818
|
+
</div>
|
|
819
|
+
</>
|
|
670
820
|
)}
|
|
821
|
+
|
|
671
822
|
{!hasText && message.agentMark && (
|
|
672
823
|
<AgentConversationMark mark={message.agentMark} align="end" />
|
|
673
824
|
)}
|
|
825
|
+
|
|
826
|
+
{hasText && failed && (
|
|
827
|
+
<div className="mt-xs flex items-center gap-sm justify-end">
|
|
828
|
+
<span className="text-caption text-semantic-error">Not sent</span>
|
|
829
|
+
<button
|
|
830
|
+
type="button"
|
|
831
|
+
onClick={() => message.onRetry?.(message)}
|
|
832
|
+
className="rounded-xs text-caption text-primary-text underline underline-offset-2 cursor-pointer transition duration-150 ease-out hover:text-primary-active active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue"
|
|
833
|
+
>
|
|
834
|
+
Retry
|
|
835
|
+
</button>
|
|
836
|
+
</div>
|
|
837
|
+
)}
|
|
838
|
+
|
|
839
|
+
{hasText && !failed && message.sentAt && (
|
|
840
|
+
<span className="mt-xs text-caption text-muted-soft">{message.sentAt}</span>
|
|
841
|
+
)}
|
|
842
|
+
|
|
674
843
|
{hasImages && <MessageImageGallery images={message.images!} align="end" />}
|
|
675
844
|
</div>
|
|
676
|
-
|
|
845
|
+
|
|
846
|
+
<div className={hasMetaLine ? "mb-lg" : undefined}>
|
|
847
|
+
<UserAvatar initials={message.userInitials ?? "U"} />
|
|
848
|
+
</div>
|
|
677
849
|
</div>
|
|
678
850
|
);
|
|
679
851
|
};
|
|
@@ -684,6 +856,14 @@ const DEFAULT_EMPTY_TITLE = "Start the conversation";
|
|
|
684
856
|
const DEFAULT_EMPTY_DESCRIPTION =
|
|
685
857
|
"Ask about atoms, tokens, components, or anything in your design system.";
|
|
686
858
|
|
|
859
|
+
/** Distance from the bottom (px) still treated as "reading the latest turn". */
|
|
860
|
+
const NEAR_BOTTOM_THRESHOLD = 80;
|
|
861
|
+
|
|
862
|
+
/** True while the reader is within NEAR_BOTTOM_THRESHOLD of the thread's end. */
|
|
863
|
+
const isNearBottom = (element: HTMLDivElement) =>
|
|
864
|
+
element.scrollHeight - element.scrollTop - element.clientHeight <=
|
|
865
|
+
NEAR_BOTTOM_THRESHOLD;
|
|
866
|
+
|
|
687
867
|
export const ChatScreen = React.forwardRef<HTMLDivElement, ChatScreenProps>(
|
|
688
868
|
(
|
|
689
869
|
{
|
|
@@ -740,6 +920,16 @@ export const ChatScreen = React.forwardRef<HTMLDivElement, ChatScreenProps>(
|
|
|
740
920
|
);
|
|
741
921
|
const threadRef = React.useRef<HTMLDivElement>(null);
|
|
742
922
|
const lastMessageCountRef = React.useRef(messages.length);
|
|
923
|
+
// Whether the reader is currently pinned to the bottom of the thread.
|
|
924
|
+
// Flipped by real user scrolling only — the component's own scrolls never
|
|
925
|
+
// touch it, so a streaming update can never yank the view back down.
|
|
926
|
+
const pinnedToBottomRef = React.useRef(true);
|
|
927
|
+
// Set while we scroll the thread programmatically, so the scroll event the
|
|
928
|
+
// browser fires for that scroll does not count as a user scroll.
|
|
929
|
+
const programmaticScrollRef = React.useRef(false);
|
|
930
|
+
const hasMountedScrollRef = React.useRef(false);
|
|
931
|
+
// Detaches the scroll listener from whichever thread node is mounted.
|
|
932
|
+
const detachScrollRef = React.useRef<(() => void) | null>(null);
|
|
743
933
|
|
|
744
934
|
React.useEffect(() => {
|
|
745
935
|
if (initialMessages !== undefined) {
|
|
@@ -747,21 +937,93 @@ export const ChatScreen = React.forwardRef<HTMLDivElement, ChatScreenProps>(
|
|
|
747
937
|
}
|
|
748
938
|
}, [initialMessages]);
|
|
749
939
|
|
|
940
|
+
const scrollToBottom = (element: HTMLDivElement) => {
|
|
941
|
+
programmaticScrollRef.current = true;
|
|
942
|
+
element.scrollTop = element.scrollHeight;
|
|
943
|
+
if (typeof window !== "undefined" && typeof window.requestAnimationFrame === "function") {
|
|
944
|
+
window.requestAnimationFrame(() => {
|
|
945
|
+
programmaticScrollRef.current = false;
|
|
946
|
+
});
|
|
947
|
+
} else {
|
|
948
|
+
programmaticScrollRef.current = false;
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
// Track whether the reader has scrolled away from the bottom. This is the
|
|
953
|
+
// ONLY place pinnedToBottomRef is cleared: a programmatic scroll is
|
|
954
|
+
// ignored, so only a genuine user scroll can unpin the thread.
|
|
955
|
+
//
|
|
956
|
+
// This is a CALLBACK REF, not an effect with empty deps: the scrolling
|
|
957
|
+
// thread only exists once the thread branch renders, so an effect that ran
|
|
958
|
+
// on mount would attach nothing while the empty state (or `children`) was
|
|
959
|
+
// in the tree and never re-bind when messages replaced it — leaving the
|
|
960
|
+
// thread permanently pinned so streaming updates kept forcing the view to
|
|
961
|
+
// the bottom. A callback ref runs every time the node mounts, including
|
|
962
|
+
// after the empty state swaps out for real messages.
|
|
963
|
+
const setThreadNode = React.useCallback((node: HTMLDivElement | null) => {
|
|
964
|
+
if (detachScrollRef.current) {
|
|
965
|
+
detachScrollRef.current();
|
|
966
|
+
detachScrollRef.current = null;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
threadRef.current = node;
|
|
970
|
+
if (!node) return;
|
|
971
|
+
|
|
972
|
+
const handleScroll = () => {
|
|
973
|
+
if (programmaticScrollRef.current) return;
|
|
974
|
+
pinnedToBottomRef.current = isNearBottom(node);
|
|
975
|
+
};
|
|
976
|
+
|
|
977
|
+
node.addEventListener("scroll", handleScroll, { passive: true });
|
|
978
|
+
detachScrollRef.current = () =>
|
|
979
|
+
node.removeEventListener("scroll", handleScroll);
|
|
980
|
+
}, []);
|
|
981
|
+
|
|
982
|
+
// Release the listener if the component unmounts while a thread is mounted.
|
|
983
|
+
React.useEffect(() => {
|
|
984
|
+
return () => {
|
|
985
|
+
if (detachScrollRef.current) {
|
|
986
|
+
detachScrollRef.current();
|
|
987
|
+
detachScrollRef.current = null;
|
|
988
|
+
}
|
|
989
|
+
};
|
|
990
|
+
}, []);
|
|
991
|
+
|
|
750
992
|
React.useLayoutEffect(() => {
|
|
751
993
|
const thread = threadRef.current;
|
|
752
994
|
if (!thread) return;
|
|
753
995
|
|
|
754
996
|
const previousCount = lastMessageCountRef.current;
|
|
755
997
|
const currentCount = messages.length;
|
|
756
|
-
|
|
998
|
+
lastMessageCountRef.current = currentCount;
|
|
757
999
|
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
thread
|
|
1000
|
+
// First paint: jump to the newest message.
|
|
1001
|
+
if (!hasMountedScrollRef.current) {
|
|
1002
|
+
hasMountedScrollRef.current = true;
|
|
1003
|
+
scrollToBottom(thread);
|
|
1004
|
+
return;
|
|
762
1005
|
}
|
|
763
1006
|
|
|
764
|
-
|
|
1007
|
+
// A newly appended sender message always pins the thread back to the
|
|
1008
|
+
// bottom, even if the reader had scrolled up while reading.
|
|
1009
|
+
const newestMessage = messages[messages.length - 1];
|
|
1010
|
+
const appendedUserMessage = currentCount > previousCount && newestMessage?.role === "user";
|
|
1011
|
+
if (appendedUserMessage) {
|
|
1012
|
+
pinnedToBottomRef.current = true;
|
|
1013
|
+
scrollToBottom(thread);
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
// Streaming updates (existing message count) follow along whenever the
|
|
1018
|
+
// reader is pinned. The distance-to-bottom check is deliberately NOT
|
|
1019
|
+
// consulted here: by the time this effect runs the message has already
|
|
1020
|
+
// grown, so the measured gap can exceed NEAR_BOTTOM_THRESHOLD even
|
|
1021
|
+
// though the reader never scrolled — which would unpin the thread after
|
|
1022
|
+
// the first large delta and make it stop following. Pinned state is
|
|
1023
|
+
// cleared only by a real user scroll event.
|
|
1024
|
+
if (pinnedToBottomRef.current) {
|
|
1025
|
+
scrollToBottom(thread);
|
|
1026
|
+
}
|
|
765
1027
|
}, [messages]);
|
|
766
1028
|
|
|
767
1029
|
const handleSend = (value: string) => {
|
|
@@ -797,7 +1059,7 @@ export const ChatScreen = React.forwardRef<HTMLDivElement, ChatScreenProps>(
|
|
|
797
1059
|
{children}
|
|
798
1060
|
</div>
|
|
799
1061
|
) : showEmptyState ? (
|
|
800
|
-
<div className="flex-1 flex items-center justify-center overflow-y-auto px-lg py-xl">
|
|
1062
|
+
<div className="flex-1 flex items-center justify-center overflow-y-auto overscroll-contain px-lg py-xl">
|
|
801
1063
|
{emptyState !== undefined ? (
|
|
802
1064
|
emptyState
|
|
803
1065
|
) : (
|
|
@@ -805,7 +1067,10 @@ export const ChatScreen = React.forwardRef<HTMLDivElement, ChatScreenProps>(
|
|
|
805
1067
|
)}
|
|
806
1068
|
</div>
|
|
807
1069
|
) : (
|
|
808
|
-
<div
|
|
1070
|
+
<div
|
|
1071
|
+
ref={setThreadNode}
|
|
1072
|
+
className="flex-1 overflow-y-auto overscroll-contain px-lg py-xl"
|
|
1073
|
+
>
|
|
809
1074
|
<div className="w-full max-w-2xl mx-auto flex flex-col gap-xl">
|
|
810
1075
|
{messages.map((msg) =>
|
|
811
1076
|
msg.role === "user" ? (
|
|
@@ -7,169 +7,133 @@ const DEMO_MODELS: PromptInputBarModel[] = [
|
|
|
7
7
|
{ id: "pro", name: "Pro", tier: "Pro", description: "Deeper reasoning for complex components" },
|
|
8
8
|
];
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const LONG_AI_MESSAGE = `Got it — here's the plan for the onboarding wizard end to end.
|
|
11
|
+
I'll build a WizardShell organism that owns step state and renders a progress indicator across the top.
|
|
12
|
+
Step 1 will use the existing Input atom with debounced async validation against the workspace-name check.
|
|
13
|
+
Step 2 will use a Textarea with a parser that splits on commas and newlines, then renders each parsed email as a removable Chip with per-row error state.
|
|
14
|
+
Step 3 will use a responsive card grid, each card composed from the existing card atoms so we don't duplicate the hover and selection styling.
|
|
15
|
+
Step 4 reads the accumulated state back and renders label/value rows with an Edit action per section that jumps to that step.
|
|
16
|
+
For resuming after a closed tab, the wizard state persists on every step change and rehydrates on mount.`;
|
|
17
|
+
|
|
18
|
+
const LONG_USER_MESSAGE = `Here's the full context on what I need for the onboarding flow.
|
|
19
|
+
We want a multi-step wizard that collects the workspace name, invites teammates, and lets the user pick a starter template.
|
|
20
|
+
Step one should validate the workspace name is unique before allowing next.
|
|
21
|
+
Step two should support pasting a comma-separated list of emails and show inline validation per row.
|
|
22
|
+
Step three should show a grid of starter templates with a live preview thumbnail for each.
|
|
23
|
+
On the last step, show a summary of every choice made so far with an edit link back to that step.`;
|
|
24
|
+
|
|
25
|
+
const mainConversation: ChatMessage[] = [
|
|
11
26
|
{
|
|
12
27
|
id: "1",
|
|
28
|
+
role: "ai",
|
|
29
|
+
content: LONG_AI_MESSAGE,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: "2",
|
|
13
33
|
role: "user",
|
|
14
|
-
content: "
|
|
34
|
+
content: "Short follow-up — can you also add a skip link on step 2?",
|
|
15
35
|
userInitials: "ME",
|
|
16
|
-
|
|
36
|
+
sentAt: "12:04",
|
|
17
37
|
},
|
|
18
38
|
{
|
|
19
|
-
id: "
|
|
39
|
+
id: "3",
|
|
20
40
|
role: "ai",
|
|
21
41
|
content: "I can help you create a new atom. What type of atom would you like to create?",
|
|
22
42
|
},
|
|
23
43
|
{
|
|
24
|
-
id: "
|
|
44
|
+
id: "4",
|
|
25
45
|
role: "user",
|
|
26
46
|
content: "Actually, let me switch to typography first to check our text styles.",
|
|
27
47
|
userInitials: "ME",
|
|
28
|
-
|
|
48
|
+
sentAt: "12:06",
|
|
29
49
|
},
|
|
30
50
|
{
|
|
31
|
-
id: "
|
|
51
|
+
id: "5",
|
|
32
52
|
role: "ai",
|
|
33
53
|
content: "I'll build the Button atom now. Tracking progress below:",
|
|
34
54
|
timeline: [
|
|
35
55
|
{ id: "t1", kind: "thinking", label: "Planning component API and variants", status: "done" },
|
|
36
56
|
{ id: "t2", kind: "read", label: "Reading design tokens", detail: "colors, spacing, rounded", status: "done" },
|
|
37
57
|
{ id: "t3", kind: "write", label: "Writing Button.tsx", status: "done" },
|
|
38
|
-
{ id: "t4", kind: "
|
|
39
|
-
{ id: "t5", kind: "verify", label: "Verifying atom passes linter", status: "running" },
|
|
40
|
-
],
|
|
41
|
-
inFlight: true,
|
|
42
|
-
currentToolLabel: "Verifying…",
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
id: "5",
|
|
46
|
-
role: "ai",
|
|
47
|
-
content: "And here's an error state in the timeline.",
|
|
48
|
-
timeline: [
|
|
49
|
-
{ id: "t10", kind: "thinking", label: "Planning layout structure", status: "done" },
|
|
50
|
-
{ id: "t11", kind: "read", label: "Reading reference atom", status: "done" },
|
|
51
|
-
{ id: "t12", kind: "write", label: "Writing component file", status: "error" },
|
|
58
|
+
{ id: "t4", kind: "verify", label: "Verifying atom passes linter", status: "running" },
|
|
52
59
|
],
|
|
53
60
|
},
|
|
54
|
-
];
|
|
55
|
-
|
|
56
|
-
const messagesWithImages: ChatMessage[] = [
|
|
57
61
|
{
|
|
58
|
-
id: "
|
|
62
|
+
id: "6",
|
|
59
63
|
role: "user",
|
|
60
64
|
content: "Here's the hero shot for the landing page, can you match this look?",
|
|
61
65
|
userInitials: "ME",
|
|
62
|
-
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
id: "2",
|
|
66
|
-
role: "ai",
|
|
67
|
-
content: "Got it — matching the crop and spacing from that reference now.",
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
id: "3",
|
|
71
|
-
role: "user",
|
|
72
|
-
content: "",
|
|
73
|
-
userInitials: "ME",
|
|
66
|
+
sentAt: "12:08",
|
|
74
67
|
images: [
|
|
68
|
+
{ src: "https://picsum.photos/seed/hero1/800/500", alt: "Landing page hero reference" },
|
|
75
69
|
{ src: "https://picsum.photos/seed/mosaic1/600/600", alt: "Screenshot 1" },
|
|
76
70
|
{ src: "https://picsum.photos/seed/mosaic2/600/600", alt: "Screenshot 2" },
|
|
77
71
|
{ src: "https://picsum.photos/seed/mosaic3/600/400", alt: "Screenshot 3" },
|
|
78
|
-
{ src: "https://picsum.photos/seed/mosaic4/600/400", alt: "Screenshot 4" },
|
|
79
|
-
],
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
id: "4",
|
|
83
|
-
role: "ai",
|
|
84
|
-
content: "Here are a few more style directions to compare side by side.",
|
|
85
|
-
images: [
|
|
86
|
-
{ src: "https://picsum.photos/seed/style1/600/600", alt: "Style 1" },
|
|
87
|
-
{ src: "https://picsum.photos/seed/style2/600/600", alt: "Style 2" },
|
|
88
|
-
{ src: "https://picsum.photos/seed/style3/600/400", alt: "Style 3" },
|
|
89
|
-
{ src: "https://picsum.photos/seed/style4/600/400", alt: "Style 4" },
|
|
90
|
-
{ src: "https://picsum.photos/seed/style5/600/400", alt: "Style 5" },
|
|
91
|
-
{ src: "https://picsum.photos/seed/style6/600/400", alt: "Style 6" },
|
|
92
72
|
],
|
|
93
73
|
},
|
|
94
74
|
];
|
|
95
75
|
|
|
96
|
-
const
|
|
76
|
+
const statesConversation: ChatMessage[] = [
|
|
97
77
|
{
|
|
98
78
|
id: "1",
|
|
99
79
|
role: "user",
|
|
100
|
-
content:
|
|
80
|
+
content: LONG_USER_MESSAGE,
|
|
101
81
|
userInitials: "ME",
|
|
82
|
+
sentAt: "12:12",
|
|
102
83
|
},
|
|
103
84
|
{
|
|
104
85
|
id: "2",
|
|
105
86
|
role: "ai",
|
|
106
|
-
content: "
|
|
107
|
-
suggestedImage: {
|
|
108
|
-
src: "https://picsum.photos/seed/mockup1/900/600",
|
|
109
|
-
alt: "Pricing page mockup",
|
|
110
|
-
ctaLabel: "Create this design",
|
|
111
|
-
onCta: () => console.log("create single design"),
|
|
112
|
-
},
|
|
87
|
+
content: "Understood — I'll start with the wizard shell and come back with the step-by-step plan.",
|
|
113
88
|
},
|
|
114
89
|
{
|
|
115
90
|
id: "3",
|
|
116
91
|
role: "user",
|
|
117
|
-
content: "Can
|
|
92
|
+
content: "Can you suggest a design for our new pricing page?",
|
|
118
93
|
userInitials: "ME",
|
|
94
|
+
failed: true,
|
|
95
|
+
onRetry: (message) => console.log("retry message", message.id),
|
|
119
96
|
},
|
|
120
97
|
{
|
|
121
98
|
id: "4",
|
|
122
|
-
role: "
|
|
123
|
-
content: "
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
alt: "
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
{ id: "opt-c", src: "https://picsum.photos/seed/optC/900/700", label: "Option C — Split view" },
|
|
132
|
-
],
|
|
133
|
-
onSelectOption: (id) => console.log("selected design option", id),
|
|
134
|
-
},
|
|
99
|
+
role: "user",
|
|
100
|
+
content: "",
|
|
101
|
+
userInitials: "ME",
|
|
102
|
+
images: [
|
|
103
|
+
{ src: "https://picsum.photos/seed/style1/600/600", alt: "Style 1" },
|
|
104
|
+
{ src: "https://picsum.photos/seed/style2/600/600", alt: "Style 2" },
|
|
105
|
+
{ src: "https://picsum.photos/seed/style3/600/400", alt: "Style 3" },
|
|
106
|
+
{ src: "https://picsum.photos/seed/style4/600/400", alt: "Style 4" },
|
|
107
|
+
],
|
|
135
108
|
},
|
|
136
109
|
];
|
|
137
110
|
|
|
138
111
|
export default function Preview() {
|
|
139
112
|
const [suggestDesigns1, setSuggestDesigns1] = React.useState(false);
|
|
140
|
-
const [suggestDesigns2, setSuggestDesigns2] = React.useState(
|
|
141
|
-
const [suggestDesigns3, setSuggestDesigns3] = React.useState(true);
|
|
113
|
+
const [suggestDesigns2, setSuggestDesigns2] = React.useState(true);
|
|
142
114
|
|
|
143
115
|
return (
|
|
144
116
|
<div className="w-full max-w-3xl mx-auto space-y-xl">
|
|
145
|
-
<div style={{ height:
|
|
117
|
+
<div style={{ height: 720 }}>
|
|
146
118
|
<ChatScreen
|
|
147
|
-
messages={
|
|
119
|
+
messages={mainConversation}
|
|
148
120
|
placeholder="Ask anything…"
|
|
149
121
|
models={DEMO_MODELS}
|
|
150
122
|
selectedModelId="fast"
|
|
151
123
|
suggestDesigns={suggestDesigns1}
|
|
152
124
|
onSuggestDesignsChange={setSuggestDesigns1}
|
|
125
|
+
onSend={(value) => console.log("send", value)}
|
|
153
126
|
/>
|
|
154
127
|
</div>
|
|
155
|
-
<div style={{ height:
|
|
128
|
+
<div style={{ height: 720 }}>
|
|
156
129
|
<ChatScreen
|
|
157
|
-
messages={
|
|
130
|
+
messages={statesConversation}
|
|
158
131
|
placeholder="Ask anything…"
|
|
159
132
|
models={DEMO_MODELS}
|
|
160
133
|
selectedModelId="pro"
|
|
161
134
|
suggestDesigns={suggestDesigns2}
|
|
162
135
|
onSuggestDesignsChange={setSuggestDesigns2}
|
|
163
|
-
|
|
164
|
-
</div>
|
|
165
|
-
<div style={{ height: 640 }}>
|
|
166
|
-
<ChatScreen
|
|
167
|
-
messages={messagesWithSuggestions}
|
|
168
|
-
placeholder="Ask anything…"
|
|
169
|
-
models={DEMO_MODELS}
|
|
170
|
-
selectedModelId="fast"
|
|
171
|
-
suggestDesigns={suggestDesigns3}
|
|
172
|
-
onSuggestDesignsChange={setSuggestDesigns3}
|
|
136
|
+
onSend={(value) => console.log("send", value)}
|
|
173
137
|
/>
|
|
174
138
|
</div>
|
|
175
139
|
</div>
|