@designa8/vibedesign-v6 1.20.20 → 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/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
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { DesignTokensPanel } from "./DesignTokensPanel";
|
|
3
|
+
|
|
4
|
+
export default function Preview() {
|
|
5
|
+
const [log, setLog] = React.useState("Edit a color or font, then press Save.");
|
|
6
|
+
|
|
7
|
+
return (
|
|
8
|
+
<div className="w-full max-w-3xl mx-auto p-lg space-y-base">
|
|
9
|
+
<div className="flex overflow-hidden rounded-xl border border-hairline bg-surface-soft">
|
|
10
|
+
<div className="hidden min-w-0 flex-1 flex-col gap-base p-lg sm:flex">
|
|
11
|
+
<div>
|
|
12
|
+
<p className="text-heading-sm text-ink">Components</p>
|
|
13
|
+
<p className="text-caption text-muted">Pixel-perfect products with a consistent design system.</p>
|
|
14
|
+
</div>
|
|
15
|
+
<div className="grid grid-cols-2 gap-md">
|
|
16
|
+
{["Button", "Input", "Checkbox", "Dropdown"].map((name) => (
|
|
17
|
+
<div key={name} className="flex h-28 items-end rounded-lg border border-hairline-soft bg-surface p-md">
|
|
18
|
+
<span className="text-body-sm text-body">{name}</span>
|
|
19
|
+
</div>
|
|
20
|
+
))}
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
<div className="h-[680px] w-full sm:w-[380px] sm:shrink-0">
|
|
24
|
+
<DesignTokensPanel
|
|
25
|
+
onSave={(draft) =>
|
|
26
|
+
setLog(`Saved — body font ${draft.bodyFont}${draft.headingFont ? `, heading font ${draft.headingFont}` : ""}.`)
|
|
27
|
+
}
|
|
28
|
+
onDiscard={() => setLog("Changes discarded.")}
|
|
29
|
+
onCollapse={() => setLog("Collapse requested.")}
|
|
30
|
+
onColorChange={(theme, id, hex) => setLog(`${theme} · ${id} → ${hex}`)}
|
|
31
|
+
/>
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
34
|
+
<p aria-live="polite" className="text-caption text-muted">
|
|
35
|
+
{log}
|
|
36
|
+
</p>
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Button } from "../Button";
|
|
3
|
+
import { Icon } from "../Icon";
|
|
4
|
+
|
|
5
|
+
export interface ExpandableMessageProps
|
|
6
|
+
extends Omit<React.HTMLAttributes<HTMLDivElement>, "children"> {
|
|
7
|
+
/** The full message text. Split on newlines into chunks; a chunk that overflows `maxLines` is clamped until expanded. */
|
|
8
|
+
content: string;
|
|
9
|
+
/** Number of lines a single chunk may show while collapsed. Default: 4. */
|
|
10
|
+
maxLines?: number;
|
|
11
|
+
/** Controlled expanded state. Omit to let the component manage its own state. */
|
|
12
|
+
expanded?: boolean;
|
|
13
|
+
/** Initial expanded state when uncontrolled. Default: false. */
|
|
14
|
+
defaultExpanded?: boolean;
|
|
15
|
+
/** Called whenever the expanded state changes (controlled or uncontrolled). */
|
|
16
|
+
onExpandedChange?: (expanded: boolean) => void;
|
|
17
|
+
/** Disables the Show more / Show less toggle without hiding it. */
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* "card" (default) renders the surface card with padding/shadow and a
|
|
21
|
+
* bottom gradient fade while collapsed. "flush" strips all of that —
|
|
22
|
+
* no background, no padding, no shadow, no gradient overlay — leaving
|
|
23
|
+
* only the clamped text and the Show more / Show less control, for
|
|
24
|
+
* composing inside another surface (e.g. a chat message bubble).
|
|
25
|
+
*/
|
|
26
|
+
variant?: "card" | "flush";
|
|
27
|
+
/**
|
|
28
|
+
* Replaces the Show more / Show less colour treatment (hover and active
|
|
29
|
+
* states included). Use it when the toggle sits on a tinted fill where the
|
|
30
|
+
* default `text-primary` would not clear contrast — e.g.
|
|
31
|
+
* `toggleClassName="text-primary-text hover:text-primary-active"`.
|
|
32
|
+
*/
|
|
33
|
+
toggleClassName?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const clampStyle = (lines: number): React.CSSProperties => ({
|
|
37
|
+
display: "-webkit-box",
|
|
38
|
+
WebkitLineClamp: lines,
|
|
39
|
+
WebkitBoxOrient: "vertical",
|
|
40
|
+
overflow: "hidden",
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const CHUNK_TEXT_CLASS =
|
|
44
|
+
"whitespace-pre-wrap text-body-md text-body leading-relaxed";
|
|
45
|
+
|
|
46
|
+
interface MessageChunkProps {
|
|
47
|
+
index: number;
|
|
48
|
+
text: string;
|
|
49
|
+
maxLines: number;
|
|
50
|
+
/** True only when THIS chunk's own rendered height exceeds `maxLines` and the message is collapsed. */
|
|
51
|
+
clamp: boolean;
|
|
52
|
+
/** True when the card variant should paint its bottom fade over the clamp. */
|
|
53
|
+
showFade: boolean;
|
|
54
|
+
onOverflowChange: (index: number, overflowing: boolean) => void;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* One newline-delimited chunk of the message. Each chunk measures itself in
|
|
59
|
+
* isolation so a stack of short lines never triggers the toggle — only a
|
|
60
|
+
* chunk whose own content is taller than `maxLines` does.
|
|
61
|
+
*/
|
|
62
|
+
const MessageChunk = ({
|
|
63
|
+
index,
|
|
64
|
+
text,
|
|
65
|
+
maxLines,
|
|
66
|
+
clamp,
|
|
67
|
+
showFade,
|
|
68
|
+
onOverflowChange,
|
|
69
|
+
}: MessageChunkProps) => {
|
|
70
|
+
const measureRef = React.useRef<HTMLParagraphElement>(null);
|
|
71
|
+
|
|
72
|
+
React.useLayoutEffect(() => {
|
|
73
|
+
const el = measureRef.current;
|
|
74
|
+
if (!el) return;
|
|
75
|
+
|
|
76
|
+
const update = () => {
|
|
77
|
+
onOverflowChange(index, el.scrollHeight - el.clientHeight > 1);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
update();
|
|
81
|
+
|
|
82
|
+
const ro = new ResizeObserver(update);
|
|
83
|
+
ro.observe(el);
|
|
84
|
+
return () => ro.disconnect();
|
|
85
|
+
}, [index, text, maxLines, onOverflowChange]);
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div className="relative">
|
|
89
|
+
<p
|
|
90
|
+
className={CHUNK_TEXT_CLASS}
|
|
91
|
+
style={clamp ? clampStyle(maxLines) : undefined}
|
|
92
|
+
data-clamped={clamp ? "true" : "false"}
|
|
93
|
+
>
|
|
94
|
+
{text}
|
|
95
|
+
</p>
|
|
96
|
+
|
|
97
|
+
{showFade && (
|
|
98
|
+
<div
|
|
99
|
+
aria-hidden="true"
|
|
100
|
+
className="pointer-events-none absolute inset-x-0 bottom-0 h-xl"
|
|
101
|
+
style={{
|
|
102
|
+
background:
|
|
103
|
+
"linear-gradient(to bottom, transparent, var(--color-surface))",
|
|
104
|
+
}}
|
|
105
|
+
/>
|
|
106
|
+
)}
|
|
107
|
+
|
|
108
|
+
{/* Invisible measurer — same width/typography, always clamped to maxLines */}
|
|
109
|
+
<p
|
|
110
|
+
ref={measureRef}
|
|
111
|
+
aria-hidden="true"
|
|
112
|
+
className={`invisible absolute inset-x-0 top-0 -z-10 ${CHUNK_TEXT_CLASS}`}
|
|
113
|
+
style={clampStyle(maxLines)}
|
|
114
|
+
>
|
|
115
|
+
{text}
|
|
116
|
+
</p>
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const ExpandableMessage = React.forwardRef<HTMLDivElement, ExpandableMessageProps>(
|
|
122
|
+
(
|
|
123
|
+
{
|
|
124
|
+
content,
|
|
125
|
+
maxLines = 4,
|
|
126
|
+
expanded: expandedProp,
|
|
127
|
+
defaultExpanded = false,
|
|
128
|
+
onExpandedChange,
|
|
129
|
+
disabled = false,
|
|
130
|
+
variant = "card",
|
|
131
|
+
toggleClassName,
|
|
132
|
+
className,
|
|
133
|
+
...rest
|
|
134
|
+
},
|
|
135
|
+
ref,
|
|
136
|
+
) => {
|
|
137
|
+
const reactId = React.useId();
|
|
138
|
+
const textId = `expandable-message-text-${reactId}`;
|
|
139
|
+
const isFlush = variant === "flush";
|
|
140
|
+
|
|
141
|
+
const isControlled = expandedProp !== undefined;
|
|
142
|
+
const [internalExpanded, setInternalExpanded] = React.useState(defaultExpanded);
|
|
143
|
+
const expanded = isControlled ? expandedProp : internalExpanded;
|
|
144
|
+
|
|
145
|
+
const setExpanded = (next: boolean) => {
|
|
146
|
+
if (!isControlled) setInternalExpanded(next);
|
|
147
|
+
onExpandedChange?.(next);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// Split on newlines, drop empty lines — blank lines are not preserved.
|
|
151
|
+
const chunks = React.useMemo(
|
|
152
|
+
() =>
|
|
153
|
+
content
|
|
154
|
+
.split(/\r?\n/)
|
|
155
|
+
.filter((line) => line.trim().length > 0),
|
|
156
|
+
[content],
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
// Per-chunk overflow flags, reported by each chunk's own measurer.
|
|
160
|
+
const [overflowing, setOverflowing] = React.useState<boolean[]>([]);
|
|
161
|
+
|
|
162
|
+
const handleOverflowChange = React.useCallback(
|
|
163
|
+
(index: number, isOverflowing: boolean) => {
|
|
164
|
+
setOverflowing((prev) => {
|
|
165
|
+
if (prev[index] === isOverflowing) return prev;
|
|
166
|
+
const next = prev.slice();
|
|
167
|
+
next[index] = isOverflowing;
|
|
168
|
+
return next;
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
[],
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
// Toggle appears only when at least one single chunk overflows on its own.
|
|
175
|
+
const canExpand = chunks.some((_, index) => overflowing[index] === true);
|
|
176
|
+
|
|
177
|
+
const toggleTone =
|
|
178
|
+
toggleClassName ??
|
|
179
|
+
"text-primary hover:text-primary-hover active:text-primary-active";
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<div
|
|
183
|
+
ref={ref}
|
|
184
|
+
className={[
|
|
185
|
+
"w-full",
|
|
186
|
+
isFlush ? "" : "rounded-lg bg-surface p-lg shadow-sm",
|
|
187
|
+
className,
|
|
188
|
+
]
|
|
189
|
+
.filter(Boolean)
|
|
190
|
+
.join(" ")}
|
|
191
|
+
{...rest}
|
|
192
|
+
>
|
|
193
|
+
<div id={textId} className="flex flex-col gap-xs">
|
|
194
|
+
{chunks.map((chunk, index) => {
|
|
195
|
+
const isOverflowing = overflowing[index] === true;
|
|
196
|
+
const clamp = !expanded && isOverflowing;
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<MessageChunk
|
|
200
|
+
key={index}
|
|
201
|
+
index={index}
|
|
202
|
+
text={chunk}
|
|
203
|
+
maxLines={maxLines}
|
|
204
|
+
clamp={clamp}
|
|
205
|
+
showFade={!isFlush && clamp}
|
|
206
|
+
onOverflowChange={handleOverflowChange}
|
|
207
|
+
/>
|
|
208
|
+
);
|
|
209
|
+
})}
|
|
210
|
+
</div>
|
|
211
|
+
|
|
212
|
+
{canExpand && (
|
|
213
|
+
<div className="mt-sm">
|
|
214
|
+
<Button
|
|
215
|
+
type="button"
|
|
216
|
+
variant="bare"
|
|
217
|
+
size="auto"
|
|
218
|
+
disabled={disabled}
|
|
219
|
+
onClick={() => setExpanded(!expanded)}
|
|
220
|
+
aria-expanded={expanded}
|
|
221
|
+
aria-controls={textId}
|
|
222
|
+
className={`!inline-flex !items-center !gap-xxs rounded-xs text-body-sm font-weight-heading-sm ${toggleTone} hover:underline disabled:!opacity-[var(--opacity-disabled)] disabled:pointer-events-none`}
|
|
223
|
+
>
|
|
224
|
+
{expanded ? "Show less" : "Show more"}
|
|
225
|
+
<Icon
|
|
226
|
+
name="chevron-down"
|
|
227
|
+
size={16}
|
|
228
|
+
className="transition-transform duration-150"
|
|
229
|
+
style={{ transform: expanded ? "rotate(180deg)" : "rotate(0deg)" }}
|
|
230
|
+
/>
|
|
231
|
+
</Button>
|
|
232
|
+
</div>
|
|
233
|
+
)}
|
|
234
|
+
</div>
|
|
235
|
+
);
|
|
236
|
+
},
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
ExpandableMessage.displayName = "ExpandableMessage";
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Minimal, dependency-free markdown renderer for ExpandableMessage.
|
|
5
|
+
* Supports: headings, paragraphs, bold, italic, inline code, fenced code
|
|
6
|
+
* blocks, unordered/ordered lists, links, blockquotes, and GFM tables.
|
|
7
|
+
* Plain prose with no markdown syntax renders as normal paragraphs, with
|
|
8
|
+
* blank lines becoming paragraph breaks.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
type Block =
|
|
12
|
+
| { type: "heading"; level: number; text: string }
|
|
13
|
+
| { type: "code"; code: string }
|
|
14
|
+
| { type: "blockquote"; text: string }
|
|
15
|
+
| { type: "ul"; items: string[] }
|
|
16
|
+
| { type: "ol"; items: string[] }
|
|
17
|
+
| { type: "table"; header: string[]; rows: string[][] }
|
|
18
|
+
| { type: "paragraph"; text: string };
|
|
19
|
+
|
|
20
|
+
function isTableSeparator(line: string): boolean {
|
|
21
|
+
let l = line.trim();
|
|
22
|
+
if (!l.includes("-")) return false;
|
|
23
|
+
if (l.startsWith("|")) l = l.slice(1);
|
|
24
|
+
if (l.endsWith("|")) l = l.slice(0, -1);
|
|
25
|
+
const cells = l.split("|");
|
|
26
|
+
if (cells.length === 0) return false;
|
|
27
|
+
return cells.every((c) => /^\s*:?-{1,}:?\s*$/.test(c));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function splitTableRow(line: string): string[] {
|
|
31
|
+
let l = line.trim();
|
|
32
|
+
if (l.startsWith("|")) l = l.slice(1);
|
|
33
|
+
if (l.endsWith("|")) l = l.slice(0, -1);
|
|
34
|
+
return l.split("|").map((c) => c.trim());
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function parseBlocks(content: string): Block[] {
|
|
38
|
+
const lines = content.replace(/\r\n/g, "\n").split("\n");
|
|
39
|
+
const blocks: Block[] = [];
|
|
40
|
+
let i = 0;
|
|
41
|
+
|
|
42
|
+
while (i < lines.length) {
|
|
43
|
+
const line = lines[i];
|
|
44
|
+
|
|
45
|
+
if (line.trim() === "") {
|
|
46
|
+
i++;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (/^\s*```/.test(line)) {
|
|
51
|
+
i++;
|
|
52
|
+
const codeLines: string[] = [];
|
|
53
|
+
while (i < lines.length && !/^\s*```/.test(lines[i])) {
|
|
54
|
+
codeLines.push(lines[i]);
|
|
55
|
+
i++;
|
|
56
|
+
}
|
|
57
|
+
i++;
|
|
58
|
+
blocks.push({ type: "code", code: codeLines.join("\n") });
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const headingMatch = /^(#{1,6})\s+(.+?)\s*#*\s*$/.exec(line);
|
|
63
|
+
if (headingMatch) {
|
|
64
|
+
blocks.push({ type: "heading", level: headingMatch[1].length, text: headingMatch[2] });
|
|
65
|
+
i++;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (/^>\s?/.test(line)) {
|
|
70
|
+
const quoteLines: string[] = [];
|
|
71
|
+
while (i < lines.length && /^>\s?/.test(lines[i])) {
|
|
72
|
+
quoteLines.push(lines[i].replace(/^>\s?/, ""));
|
|
73
|
+
i++;
|
|
74
|
+
}
|
|
75
|
+
blocks.push({ type: "blockquote", text: quoteLines.join("\n") });
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (line.includes("|") && i + 1 < lines.length && isTableSeparator(lines[i + 1])) {
|
|
80
|
+
const header = splitTableRow(line);
|
|
81
|
+
i += 2;
|
|
82
|
+
const rows: string[][] = [];
|
|
83
|
+
while (i < lines.length && lines[i].trim() !== "" && lines[i].includes("|")) {
|
|
84
|
+
rows.push(splitTableRow(lines[i]));
|
|
85
|
+
i++;
|
|
86
|
+
}
|
|
87
|
+
blocks.push({ type: "table", header, rows });
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (/^\s*[-*+]\s+/.test(line)) {
|
|
92
|
+
const items: string[] = [];
|
|
93
|
+
while (i < lines.length && /^\s*[-*+]\s+/.test(lines[i])) {
|
|
94
|
+
items.push(lines[i].replace(/^\s*[-*+]\s+/, ""));
|
|
95
|
+
i++;
|
|
96
|
+
}
|
|
97
|
+
blocks.push({ type: "ul", items });
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (/^\s*\d+[.)]\s+/.test(line)) {
|
|
102
|
+
const items: string[] = [];
|
|
103
|
+
while (i < lines.length && /^\s*\d+[.)]\s+/.test(lines[i])) {
|
|
104
|
+
items.push(lines[i].replace(/^\s*\d+[.)]\s+/, ""));
|
|
105
|
+
i++;
|
|
106
|
+
}
|
|
107
|
+
blocks.push({ type: "ol", items });
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const paraLines: string[] = [];
|
|
112
|
+
while (
|
|
113
|
+
i < lines.length &&
|
|
114
|
+
lines[i].trim() !== "" &&
|
|
115
|
+
!/^\s*```/.test(lines[i]) &&
|
|
116
|
+
!/^#{1,6}\s+/.test(lines[i]) &&
|
|
117
|
+
!/^>\s?/.test(lines[i]) &&
|
|
118
|
+
!/^\s*[-*+]\s+/.test(lines[i]) &&
|
|
119
|
+
!/^\s*\d+[.)]\s+/.test(lines[i])
|
|
120
|
+
) {
|
|
121
|
+
paraLines.push(lines[i]);
|
|
122
|
+
i++;
|
|
123
|
+
}
|
|
124
|
+
blocks.push({ type: "paragraph", text: paraLines.join("\n") });
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return blocks;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const inlineWrap = "break-words [overflow-wrap:anywhere]";
|
|
131
|
+
|
|
132
|
+
const linkClasses = `inline-block cursor-pointer text-primary underline transition duration-150 ease-out hover:text-primary-hover active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue ${inlineWrap}`;
|
|
133
|
+
|
|
134
|
+
function parseInline(text: string, counter: { n: number }): React.ReactNode[] {
|
|
135
|
+
const nodes: React.ReactNode[] = [];
|
|
136
|
+
const regex =
|
|
137
|
+
/`([^`]+)`|\*\*([^*]+?)\*\*|__([^_]+?)__|\*([^*]+?)\*|_([^_]+?)_|\[([^\]]+)\]\(([^)\s]+)\)/g;
|
|
138
|
+
let lastIndex = 0;
|
|
139
|
+
let match: RegExpExecArray | null;
|
|
140
|
+
|
|
141
|
+
const pushText = (str: string) => {
|
|
142
|
+
if (!str) return;
|
|
143
|
+
const parts = str.split("\n");
|
|
144
|
+
parts.forEach((part, idx) => {
|
|
145
|
+
if (idx > 0) nodes.push(<br key={`br-${counter.n++}`} />);
|
|
146
|
+
if (part) nodes.push(<React.Fragment key={`t-${counter.n++}`}>{part}</React.Fragment>);
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
while ((match = regex.exec(text))) {
|
|
151
|
+
if (match.index > lastIndex) pushText(text.slice(lastIndex, match.index));
|
|
152
|
+
|
|
153
|
+
if (match[1] !== undefined) {
|
|
154
|
+
nodes.push(
|
|
155
|
+
<code
|
|
156
|
+
key={`c-${counter.n++}`}
|
|
157
|
+
className={`rounded-sm bg-surface-strong px-xxs py-0 text-body-sm text-body ${inlineWrap}`}
|
|
158
|
+
>
|
|
159
|
+
{match[1]}
|
|
160
|
+
</code>,
|
|
161
|
+
);
|
|
162
|
+
} else if (match[2] !== undefined || match[3] !== undefined) {
|
|
163
|
+
nodes.push(
|
|
164
|
+
<strong key={`b-${counter.n++}`} className="font-weight-heading-sm">
|
|
165
|
+
{parseInline(match[2] ?? match[3] ?? "", counter)}
|
|
166
|
+
</strong>,
|
|
167
|
+
);
|
|
168
|
+
} else if (match[4] !== undefined || match[5] !== undefined) {
|
|
169
|
+
nodes.push(
|
|
170
|
+
<em key={`i-${counter.n++}`}>{parseInline(match[4] ?? match[5] ?? "", counter)}</em>,
|
|
171
|
+
);
|
|
172
|
+
} else if (match[6] !== undefined) {
|
|
173
|
+
nodes.push(
|
|
174
|
+
<a
|
|
175
|
+
key={`a-${counter.n++}`}
|
|
176
|
+
href={match[7]}
|
|
177
|
+
target="_blank"
|
|
178
|
+
rel="noreferrer"
|
|
179
|
+
className={linkClasses}
|
|
180
|
+
>
|
|
181
|
+
{parseInline(match[6], counter)}
|
|
182
|
+
</a>,
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
lastIndex = regex.lastIndex;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
pushText(text.slice(lastIndex));
|
|
190
|
+
return nodes;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function renderBlocks(blocks: Block[], counter: { n: number }): React.ReactNode[] {
|
|
194
|
+
return blocks.map((block) => {
|
|
195
|
+
const key = `blk-${counter.n++}`;
|
|
196
|
+
|
|
197
|
+
switch (block.type) {
|
|
198
|
+
case "heading": {
|
|
199
|
+
const level = block.level;
|
|
200
|
+
const Tag = `h${level}` as keyof JSX.IntrinsicElements;
|
|
201
|
+
const sizeClass =
|
|
202
|
+
level === 1
|
|
203
|
+
? "text-heading-md"
|
|
204
|
+
: level === 2
|
|
205
|
+
? "text-heading-sm"
|
|
206
|
+
: "text-body-lg font-weight-heading-sm";
|
|
207
|
+
return (
|
|
208
|
+
<Tag key={key} className={`min-w-0 max-w-full text-ink ${sizeClass} ${inlineWrap}`}>
|
|
209
|
+
{parseInline(block.text, counter)}
|
|
210
|
+
</Tag>
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
case "code":
|
|
214
|
+
return (
|
|
215
|
+
<pre
|
|
216
|
+
key={key}
|
|
217
|
+
className={`min-w-0 w-full max-w-full whitespace-pre-wrap rounded-sm bg-surface-strong p-sm text-body-sm text-body ${inlineWrap}`}
|
|
218
|
+
>
|
|
219
|
+
<code className={`whitespace-pre-wrap ${inlineWrap}`}>{block.code}</code>
|
|
220
|
+
</pre>
|
|
221
|
+
);
|
|
222
|
+
case "blockquote":
|
|
223
|
+
return (
|
|
224
|
+
<blockquote
|
|
225
|
+
key={key}
|
|
226
|
+
className={`min-w-0 max-w-full border-l-2 border-hairline-strong pl-md italic text-body-md text-muted ${inlineWrap}`}
|
|
227
|
+
>
|
|
228
|
+
{block.text.split("\n").map((line, idx) => (
|
|
229
|
+
<React.Fragment key={`${key}-l-${idx}`}>
|
|
230
|
+
{idx > 0 && <br />}
|
|
231
|
+
{parseInline(line, counter)}
|
|
232
|
+
</React.Fragment>
|
|
233
|
+
))}
|
|
234
|
+
</blockquote>
|
|
235
|
+
);
|
|
236
|
+
case "ul":
|
|
237
|
+
return (
|
|
238
|
+
<ul key={key} className="min-w-0 max-w-full list-disc space-y-xxs pl-lg text-body-md text-body">
|
|
239
|
+
{block.items.map((item, idx) => (
|
|
240
|
+
<li key={`${key}-i-${idx}`} className={`min-w-0 max-w-full ${inlineWrap}`}>
|
|
241
|
+
{parseInline(item, counter)}
|
|
242
|
+
</li>
|
|
243
|
+
))}
|
|
244
|
+
</ul>
|
|
245
|
+
);
|
|
246
|
+
case "ol":
|
|
247
|
+
return (
|
|
248
|
+
<ol key={key} className="min-w-0 max-w-full list-decimal space-y-xxs pl-lg text-body-md text-body">
|
|
249
|
+
{block.items.map((item, idx) => (
|
|
250
|
+
<li key={`${key}-i-${idx}`} className={`min-w-0 max-w-full ${inlineWrap}`}>
|
|
251
|
+
{parseInline(item, counter)}
|
|
252
|
+
</li>
|
|
253
|
+
))}
|
|
254
|
+
</ol>
|
|
255
|
+
);
|
|
256
|
+
case "table":
|
|
257
|
+
return (
|
|
258
|
+
<div key={key} className="min-w-0 w-full max-w-full overflow-x-auto">
|
|
259
|
+
<table className="w-full min-w-max border-collapse text-body-sm text-body">
|
|
260
|
+
<thead>
|
|
261
|
+
<tr>
|
|
262
|
+
{block.header.map((cell, idx) => (
|
|
263
|
+
<th
|
|
264
|
+
key={`${key}-h-${idx}`}
|
|
265
|
+
className="border-b border-hairline-strong p-xs text-left font-weight-heading-sm text-ink"
|
|
266
|
+
>
|
|
267
|
+
{parseInline(cell, counter)}
|
|
268
|
+
</th>
|
|
269
|
+
))}
|
|
270
|
+
</tr>
|
|
271
|
+
</thead>
|
|
272
|
+
<tbody>
|
|
273
|
+
{block.rows.map((row, rIdx) => (
|
|
274
|
+
<tr key={`${key}-r-${rIdx}`}>
|
|
275
|
+
{row.map((cell, cIdx) => (
|
|
276
|
+
<td
|
|
277
|
+
key={`${key}-r-${rIdx}-c-${cIdx}`}
|
|
278
|
+
className="border-b border-hairline p-xs text-left align-top"
|
|
279
|
+
>
|
|
280
|
+
{parseInline(cell, counter)}
|
|
281
|
+
</td>
|
|
282
|
+
))}
|
|
283
|
+
</tr>
|
|
284
|
+
))}
|
|
285
|
+
</tbody>
|
|
286
|
+
</table>
|
|
287
|
+
</div>
|
|
288
|
+
);
|
|
289
|
+
case "paragraph":
|
|
290
|
+
default:
|
|
291
|
+
return (
|
|
292
|
+
<p key={key} className={`min-w-0 max-w-full text-body-md text-body ${inlineWrap}`}>
|
|
293
|
+
{block.text.split("\n").map((line, idx) => (
|
|
294
|
+
<React.Fragment key={`${key}-l-${idx}`}>
|
|
295
|
+
{idx > 0 && <br />}
|
|
296
|
+
{parseInline(line, counter)}
|
|
297
|
+
</React.Fragment>
|
|
298
|
+
))}
|
|
299
|
+
</p>
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** Renders a markdown string as React nodes using only token-driven classes. */
|
|
306
|
+
export function renderMarkdown(content: string): React.ReactNode {
|
|
307
|
+
const blocks = parseBlocks(content);
|
|
308
|
+
const counter = { n: 0 };
|
|
309
|
+
return <>{renderBlocks(blocks, counter)}</>;
|
|
310
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ExpandableMessage } from "./ExpandableMessage";
|
|
3
|
+
|
|
4
|
+
const shortLines = [
|
|
5
|
+
"Step 1 — provisioned the new cluster.",
|
|
6
|
+
"Step 2 — migrated the schema.",
|
|
7
|
+
"Step 3 — warmed the caches.",
|
|
8
|
+
"Step 4 — switched traffic over.",
|
|
9
|
+
"Step 5 — retired the old nodes.",
|
|
10
|
+
"Step 6 — closed the change ticket.",
|
|
11
|
+
].join("\n");
|
|
12
|
+
|
|
13
|
+
const longParagraph =
|
|
14
|
+
"Deployment finished without issues and every health check is passing across all regions. The rollout completed ahead of schedule, the canary held at five percent for the full observation window, and no error budget was consumed. Hot caches were warmed before traffic moved, connection pools were resized to the new limits, and the read replicas caught up within ninety seconds. Alerts stayed quiet for the entire window and the on-call rotation confirmed there is nothing left to follow up on.";
|
|
15
|
+
|
|
16
|
+
const mixed = [
|
|
17
|
+
"Here is the summary for this release:",
|
|
18
|
+
"The migration ran in the background and did not block writes.",
|
|
19
|
+
"Rollback instructions live in the runbook, section four.",
|
|
20
|
+
longParagraph,
|
|
21
|
+
].join("\n");
|
|
22
|
+
|
|
23
|
+
export default function ExpandableMessagePreview() {
|
|
24
|
+
const [shortExpanded, setShortExpanded] = React.useState(false);
|
|
25
|
+
const [longExpanded, setLongExpanded] = React.useState(false);
|
|
26
|
+
const [mixedExpanded, setMixedExpanded] = React.useState(false);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div className="w-full max-w-3xl mx-auto p-lg space-y-lg">
|
|
30
|
+
<div>
|
|
31
|
+
<p className="mb-xs text-body-sm text-muted">
|
|
32
|
+
Six short lines — no chunk overflows, so no toggle appears
|
|
33
|
+
</p>
|
|
34
|
+
<ExpandableMessage
|
|
35
|
+
content={shortLines}
|
|
36
|
+
maxLines={3}
|
|
37
|
+
expanded={shortExpanded}
|
|
38
|
+
onExpandedChange={setShortExpanded}
|
|
39
|
+
/>
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<div>
|
|
43
|
+
<p className="mb-xs text-body-sm text-muted">
|
|
44
|
+
A single long paragraph — one chunk, still clamps
|
|
45
|
+
</p>
|
|
46
|
+
<ExpandableMessage
|
|
47
|
+
content={longParagraph}
|
|
48
|
+
maxLines={3}
|
|
49
|
+
expanded={longExpanded}
|
|
50
|
+
onExpandedChange={setLongExpanded}
|
|
51
|
+
/>
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<div>
|
|
55
|
+
<p className="mb-xs text-body-sm text-muted">
|
|
56
|
+
Mixed — only the long chunk clamps, the short ones stay whole
|
|
57
|
+
</p>
|
|
58
|
+
<ExpandableMessage
|
|
59
|
+
content={mixed}
|
|
60
|
+
maxLines={3}
|
|
61
|
+
expanded={mixedExpanded}
|
|
62
|
+
onExpandedChange={setMixedExpanded}
|
|
63
|
+
/>
|
|
64
|
+
</div>
|
|
65
|
+
|
|
66
|
+
<div>
|
|
67
|
+
<p className="mb-xs text-body-sm text-muted">
|
|
68
|
+
Flush variant inside a chat bubble — disabled toggle
|
|
69
|
+
</p>
|
|
70
|
+
<div className="w-full max-w-md rounded-lg bg-primary p-md">
|
|
71
|
+
<ExpandableMessage
|
|
72
|
+
variant="flush"
|
|
73
|
+
content={longParagraph}
|
|
74
|
+
maxLines={2}
|
|
75
|
+
disabled
|
|
76
|
+
defaultExpanded={false}
|
|
77
|
+
className="text-on-primary"
|
|
78
|
+
/>
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
);
|
|
83
|
+
}
|