@vllnt/ui 0.2.1-canary.e1bc2b3 → 0.2.1-canary.ee942df
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/dist/components/agent-activity/agent-activity.js +311 -0
- package/dist/components/agent-activity/index.js +18 -0
- package/dist/components/ai-artifact/ai-artifact.js +422 -0
- package/dist/components/ai-artifact/index.js +24 -0
- package/dist/components/ai-sidebar/ai-sidebar.js +254 -0
- package/dist/components/ai-sidebar/index.js +22 -0
- package/dist/components/alert-pulse/alert-pulse.js +93 -0
- package/dist/components/alert-pulse/index.js +6 -0
- package/dist/components/auto-reload/auto-reload.js +367 -0
- package/dist/components/auto-reload/index.js +6 -0
- package/dist/components/banner/banner.js +155 -0
- package/dist/components/banner/index.js +10 -0
- package/dist/components/bottom-activity-strip/bottom-activity-strip.js +91 -0
- package/dist/components/bottom-activity-strip/index.js +6 -0
- package/dist/components/choropleth-map/choropleth-map.js +373 -0
- package/dist/components/choropleth-map/index.js +10 -0
- package/dist/components/chronological-timeline/chronological-timeline.js +337 -0
- package/dist/components/chronological-timeline/index.js +8 -0
- package/dist/components/civilization-card/civilization-card.js +258 -0
- package/dist/components/civilization-card/index.js +8 -0
- package/dist/components/comment-pin/comment-pin.js +104 -0
- package/dist/components/comment-pin/index.js +6 -0
- package/dist/components/context-lens/context-lens.js +98 -0
- package/dist/components/context-lens/index.js +6 -0
- package/dist/components/copy-button/copy-button.js +189 -0
- package/dist/components/copy-button/index.js +8 -0
- package/dist/components/document-sibling-nav/document-sibling-nav.js +111 -0
- package/dist/components/document-sibling-nav/index.js +8 -0
- package/dist/components/empty-state/empty-state.js +93 -0
- package/dist/components/empty-state/index.js +8 -0
- package/dist/components/era-comparison/era-comparison.js +198 -0
- package/dist/components/era-comparison/index.js +16 -0
- package/dist/components/floating-toolbar/floating-toolbar.js +66 -0
- package/dist/components/floating-toolbar/index.js +6 -0
- package/dist/components/follow-mode/follow-mode.js +89 -0
- package/dist/components/follow-mode/index.js +6 -0
- package/dist/components/gantt-chart/gantt-chart.js +331 -0
- package/dist/components/gantt-chart/index.js +6 -0
- package/dist/components/geography-quiz-map/geography-quiz-map.js +343 -0
- package/dist/components/geography-quiz-map/index.js +12 -0
- package/dist/components/globe-3d/globe-3d.js +417 -0
- package/dist/components/globe-3d/index.js +10 -0
- package/dist/components/handoff-beacon/handoff-beacon.js +78 -0
- package/dist/components/handoff-beacon/index.js +6 -0
- package/dist/components/heat-map-overlay/heat-map-overlay.js +215 -0
- package/dist/components/heat-map-overlay/index.js +6 -0
- package/dist/components/heat-overlay/heat-overlay.js +92 -0
- package/dist/components/heat-overlay/index.js +6 -0
- package/dist/components/historic-timeline/historic-timeline.js +342 -0
- package/dist/components/historic-timeline/index.js +6 -0
- package/dist/components/historical-figure-card/historical-figure-card.js +273 -0
- package/dist/components/historical-figure-card/index.js +6 -0
- package/dist/components/index.js +432 -1
- package/dist/components/infinite-plane/index.js +6 -0
- package/dist/components/infinite-plane/infinite-plane.js +75 -0
- package/dist/components/interactive-timeline/index.js +16 -0
- package/dist/components/interactive-timeline/interactive-timeline.js +708 -0
- package/dist/components/jarvis-dock/index.js +6 -0
- package/dist/components/jarvis-dock/jarvis-dock.js +98 -0
- package/dist/components/kbd/index.js +5 -0
- package/dist/components/kbd/kbd.js +117 -0
- package/dist/components/knowledge-check/index.js +6 -0
- package/dist/components/knowledge-check/knowledge-check.js +448 -0
- package/dist/components/live-cursor/index.js +6 -0
- package/dist/components/live-cursor/live-cursor.js +62 -0
- package/dist/components/map-2d/index.js +20 -0
- package/dist/components/map-2d/map-2d.js +455 -0
- package/dist/components/map-timeline/index.js +16 -0
- package/dist/components/map-timeline/map-timeline.js +506 -0
- package/dist/components/metric-cluster/index.js +6 -0
- package/dist/components/metric-cluster/metric-cluster.js +96 -0
- package/dist/components/model-comparison/index.js +12 -0
- package/dist/components/model-comparison/model-comparison.js +211 -0
- package/dist/components/multi-select-lasso/index.js +6 -0
- package/dist/components/multi-select-lasso/multi-select-lasso.js +76 -0
- package/dist/components/newsletter-signup/index.js +8 -0
- package/dist/components/newsletter-signup/newsletter-signup.js +269 -0
- package/dist/components/object-inspector/index.js +6 -0
- package/dist/components/object-inspector/object-inspector.js +136 -0
- package/dist/components/parallel-timeline/index.js +6 -0
- package/dist/components/parallel-timeline/parallel-timeline.js +251 -0
- package/dist/components/playback-ghost/index.js +6 -0
- package/dist/components/playback-ghost/playback-ghost.js +83 -0
- package/dist/components/policy-delivery-panel/index.js +6 -0
- package/dist/components/policy-delivery-panel/policy-delivery-panel.js +99 -0
- package/dist/components/presence-stack/index.js +6 -0
- package/dist/components/presence-stack/presence-stack.js +108 -0
- package/dist/components/presence-sync-indicator/index.js +6 -0
- package/dist/components/presence-sync-indicator/presence-sync-indicator.js +73 -0
- package/dist/components/pricing-table/index.js +8 -0
- package/dist/components/pricing-table/pricing-table.js +247 -0
- package/dist/components/primary-source-viewer/index.js +26 -0
- package/dist/components/primary-source-viewer/primary-source-viewer.js +439 -0
- package/dist/components/prompt-templates/index.js +6 -0
- package/dist/components/prompt-templates/prompt-templates.js +403 -0
- package/dist/components/property-section/index.js +6 -0
- package/dist/components/property-section/property-section.js +101 -0
- package/dist/components/relationship-inspector/index.js +6 -0
- package/dist/components/relationship-inspector/relationship-inspector.js +102 -0
- package/dist/components/route-map/index.js +6 -0
- package/dist/components/route-map/route-map.js +339 -0
- package/dist/components/routing-assignment-panel/index.js +6 -0
- package/dist/components/routing-assignment-panel/routing-assignment-panel.js +122 -0
- package/dist/components/run-timeline/index.js +6 -0
- package/dist/components/run-timeline/run-timeline.js +221 -0
- package/dist/components/runtime-overview-panel/index.js +6 -0
- package/dist/components/runtime-overview-panel/runtime-overview-panel.js +89 -0
- package/dist/components/selection-halo/index.js +6 -0
- package/dist/components/selection-halo/selection-halo.js +72 -0
- package/dist/components/selection-presence/index.js +6 -0
- package/dist/components/selection-presence/selection-presence.js +50 -0
- package/dist/components/snap-guides/index.js +6 -0
- package/dist/components/snap-guides/snap-guides.js +45 -0
- package/dist/components/state-badge-overlay/index.js +6 -0
- package/dist/components/state-badge-overlay/state-badge-overlay.js +90 -0
- package/dist/components/sticky-metric/index.js +6 -0
- package/dist/components/sticky-metric/sticky-metric.js +83 -0
- package/dist/components/story-map/index.js +8 -0
- package/dist/components/story-map/story-map.js +414 -0
- package/dist/components/thread-bubble/index.js +6 -0
- package/dist/components/thread-bubble/thread-bubble.js +85 -0
- package/dist/components/threshold-ring/index.js +6 -0
- package/dist/components/threshold-ring/threshold-ring.js +160 -0
- package/dist/components/timeline/index.js +12 -0
- package/dist/components/timeline/timeline.js +239 -0
- package/dist/components/timeline-scrubber/index.js +6 -0
- package/dist/components/timeline-scrubber/timeline-scrubber.js +179 -0
- package/dist/components/transaction-list/index.js +14 -0
- package/dist/components/transaction-list/transaction-list.js +226 -0
- package/dist/components/tree-view/index.js +6 -0
- package/dist/components/tree-view/tree-view.js +298 -0
- package/dist/components/viewport-bookmarks/index.js +6 -0
- package/dist/components/viewport-bookmarks/viewport-bookmarks.js +116 -0
- package/dist/components/world-breadcrumbs/index.js +6 -0
- package/dist/components/world-breadcrumbs/world-breadcrumbs.js +114 -0
- package/dist/index.d.ts +7135 -141
- package/package.json +1 -1
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
forwardRef,
|
|
6
|
+
useCallback,
|
|
7
|
+
useContext,
|
|
8
|
+
useId,
|
|
9
|
+
useMemo,
|
|
10
|
+
useState
|
|
11
|
+
} from "react";
|
|
12
|
+
import { Eye, EyeOff } from "lucide-react";
|
|
13
|
+
import { cn } from "../../lib/utils";
|
|
14
|
+
import { Badge } from "../badge/badge";
|
|
15
|
+
import { Button } from "../button/button";
|
|
16
|
+
const HIDDEN_LABEL_PREFIX = "Model";
|
|
17
|
+
const DEFAULT_LABELS = {
|
|
18
|
+
cost: "Cost",
|
|
19
|
+
hide: "Hide models",
|
|
20
|
+
latency: "Latency",
|
|
21
|
+
prompt: "Prompt",
|
|
22
|
+
reveal: "Reveal models",
|
|
23
|
+
tokens: "Tokens",
|
|
24
|
+
voteHeading: "Which response is better?",
|
|
25
|
+
voteTie: "Tie"
|
|
26
|
+
};
|
|
27
|
+
const DEFAULT_CONTEXT = {
|
|
28
|
+
blind: false,
|
|
29
|
+
labels: DEFAULT_LABELS
|
|
30
|
+
};
|
|
31
|
+
const ModelComparisonContext = createContext(DEFAULT_CONTEXT);
|
|
32
|
+
function ComparisonHeader({
|
|
33
|
+
blind,
|
|
34
|
+
hideBlindToggle,
|
|
35
|
+
labels,
|
|
36
|
+
onToggleBlind,
|
|
37
|
+
prompt
|
|
38
|
+
}) {
|
|
39
|
+
if (!prompt && hideBlindToggle) return null;
|
|
40
|
+
return /* @__PURE__ */ jsxs("header", { className: "flex items-start justify-between gap-3", children: [
|
|
41
|
+
prompt ? /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-col gap-1", children: [
|
|
42
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-semibold uppercase tracking-wide text-muted-foreground", children: labels.prompt }),
|
|
43
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-foreground", children: prompt })
|
|
44
|
+
] }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true" }),
|
|
45
|
+
hideBlindToggle ? null : /* @__PURE__ */ jsx(
|
|
46
|
+
Button,
|
|
47
|
+
{
|
|
48
|
+
"aria-pressed": blind,
|
|
49
|
+
onClick: onToggleBlind,
|
|
50
|
+
size: "sm",
|
|
51
|
+
type: "button",
|
|
52
|
+
variant: "outline",
|
|
53
|
+
children: blind ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
54
|
+
/* @__PURE__ */ jsx(Eye, { "aria-hidden": "true", className: "mr-2 h-4 w-4" }),
|
|
55
|
+
labels.reveal
|
|
56
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
57
|
+
/* @__PURE__ */ jsx(EyeOff, { "aria-hidden": "true", className: "mr-2 h-4 w-4" }),
|
|
58
|
+
labels.hide
|
|
59
|
+
] })
|
|
60
|
+
}
|
|
61
|
+
)
|
|
62
|
+
] });
|
|
63
|
+
}
|
|
64
|
+
const ModelComparison = forwardRef(
|
|
65
|
+
(props, ref) => {
|
|
66
|
+
const {
|
|
67
|
+
blindDefault = false,
|
|
68
|
+
children,
|
|
69
|
+
className,
|
|
70
|
+
hideBlindToggle = false,
|
|
71
|
+
labels,
|
|
72
|
+
prompt,
|
|
73
|
+
...rest
|
|
74
|
+
} = props;
|
|
75
|
+
const resolvedLabels = useMemo(
|
|
76
|
+
() => ({ ...DEFAULT_LABELS, ...labels }),
|
|
77
|
+
[labels]
|
|
78
|
+
);
|
|
79
|
+
const [blind, setBlind] = useState(blindDefault);
|
|
80
|
+
const contextValue = useMemo(
|
|
81
|
+
() => ({ blind, labels: resolvedLabels }),
|
|
82
|
+
[blind, resolvedLabels]
|
|
83
|
+
);
|
|
84
|
+
const handleToggleBlind = useCallback(() => {
|
|
85
|
+
setBlind((value) => !value);
|
|
86
|
+
}, []);
|
|
87
|
+
return /* @__PURE__ */ jsx(ModelComparisonContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxs(
|
|
88
|
+
"section",
|
|
89
|
+
{
|
|
90
|
+
className: cn(
|
|
91
|
+
"flex flex-col gap-4 rounded-2xl border bg-background p-4",
|
|
92
|
+
className
|
|
93
|
+
),
|
|
94
|
+
ref,
|
|
95
|
+
...rest,
|
|
96
|
+
children: [
|
|
97
|
+
/* @__PURE__ */ jsx(
|
|
98
|
+
ComparisonHeader,
|
|
99
|
+
{
|
|
100
|
+
blind,
|
|
101
|
+
hideBlindToggle,
|
|
102
|
+
labels: resolvedLabels,
|
|
103
|
+
onToggleBlind: handleToggleBlind,
|
|
104
|
+
prompt
|
|
105
|
+
}
|
|
106
|
+
),
|
|
107
|
+
/* @__PURE__ */ jsx("div", { className: "grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-3", children })
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
) });
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
ModelComparison.displayName = "ModelComparison";
|
|
114
|
+
const ModelComparisonColumn = forwardRef((props, ref) => {
|
|
115
|
+
const { badge, children, className, label, model, ...rest } = props;
|
|
116
|
+
const id = useId();
|
|
117
|
+
const { blind } = useContext(ModelComparisonContext);
|
|
118
|
+
const displayLabel = blind ? `${HIDDEN_LABEL_PREFIX} ${id.slice(-2)}` : label ?? model;
|
|
119
|
+
return /* @__PURE__ */ jsxs(
|
|
120
|
+
"article",
|
|
121
|
+
{
|
|
122
|
+
"aria-label": typeof displayLabel === "string" ? displayLabel : void 0,
|
|
123
|
+
className: cn(
|
|
124
|
+
"flex flex-col gap-3 rounded-xl border border-border bg-muted/30 p-3",
|
|
125
|
+
className
|
|
126
|
+
),
|
|
127
|
+
"data-blind": blind ? "true" : "false",
|
|
128
|
+
"data-model": blind ? void 0 : model,
|
|
129
|
+
ref,
|
|
130
|
+
...rest,
|
|
131
|
+
children: [
|
|
132
|
+
/* @__PURE__ */ jsxs("header", { className: "flex items-center justify-between gap-2", children: [
|
|
133
|
+
/* @__PURE__ */ jsx("h4", { className: "text-sm font-semibold tracking-tight text-foreground", children: displayLabel }),
|
|
134
|
+
badge ? /* @__PURE__ */ jsx(Badge, { variant: "secondary", children: badge }) : null
|
|
135
|
+
] }),
|
|
136
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col gap-2 text-sm text-foreground", children })
|
|
137
|
+
]
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
ModelComparisonColumn.displayName = "ModelComparisonColumn";
|
|
142
|
+
const ModelComparisonMeta = forwardRef((props, ref) => {
|
|
143
|
+
const { className, cost, latency, tokens, ...rest } = props;
|
|
144
|
+
const { labels } = useContext(ModelComparisonContext);
|
|
145
|
+
const items = [];
|
|
146
|
+
if (tokens !== void 0 && tokens !== null) {
|
|
147
|
+
items.push({
|
|
148
|
+
caption: labels.tokens,
|
|
149
|
+
value: typeof tokens === "number" ? tokens.toLocaleString() : tokens
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
if (latency !== void 0 && latency !== null) {
|
|
153
|
+
items.push({ caption: labels.latency, value: latency });
|
|
154
|
+
}
|
|
155
|
+
if (cost !== void 0 && cost !== null) {
|
|
156
|
+
items.push({ caption: labels.cost, value: cost });
|
|
157
|
+
}
|
|
158
|
+
if (items.length === 0) return null;
|
|
159
|
+
return /* @__PURE__ */ jsx(
|
|
160
|
+
"dl",
|
|
161
|
+
{
|
|
162
|
+
className: cn(
|
|
163
|
+
"mt-auto flex flex-wrap gap-x-3 gap-y-1 border-t border-border pt-2 text-xs",
|
|
164
|
+
className
|
|
165
|
+
),
|
|
166
|
+
ref,
|
|
167
|
+
...rest,
|
|
168
|
+
children: items.map((item) => /* @__PURE__ */ jsxs("div", { className: "flex items-baseline gap-1", children: [
|
|
169
|
+
/* @__PURE__ */ jsx("dt", { className: "font-medium uppercase tracking-wide text-muted-foreground", children: item.caption }),
|
|
170
|
+
/* @__PURE__ */ jsx("dd", { className: "text-foreground", children: item.value })
|
|
171
|
+
] }, item.caption))
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
});
|
|
175
|
+
ModelComparisonMeta.displayName = "ModelComparisonMeta";
|
|
176
|
+
const ModelComparisonVote = forwardRef((props, ref) => {
|
|
177
|
+
const { buttonLabels, className, onVote, ...rest } = props;
|
|
178
|
+
const { labels: contextLabels } = useContext(ModelComparisonContext);
|
|
179
|
+
const handleLeft = useCallback(() => {
|
|
180
|
+
onVote?.("left");
|
|
181
|
+
}, [onVote]);
|
|
182
|
+
const handleTie = useCallback(() => {
|
|
183
|
+
onVote?.("tie");
|
|
184
|
+
}, [onVote]);
|
|
185
|
+
const handleRight = useCallback(() => {
|
|
186
|
+
onVote?.("right");
|
|
187
|
+
}, [onVote]);
|
|
188
|
+
return /* @__PURE__ */ jsxs(
|
|
189
|
+
"div",
|
|
190
|
+
{
|
|
191
|
+
className: cn("flex flex-col items-center gap-2", className),
|
|
192
|
+
ref,
|
|
193
|
+
...rest,
|
|
194
|
+
children: [
|
|
195
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium text-foreground", children: contextLabels.voteHeading }),
|
|
196
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-center gap-2", children: [
|
|
197
|
+
/* @__PURE__ */ jsx(Button, { onClick: handleLeft, size: "sm", type: "button", variant: "outline", children: buttonLabels?.left ?? "\u2190 Left" }),
|
|
198
|
+
/* @__PURE__ */ jsx(Button, { onClick: handleTie, size: "sm", type: "button", variant: "ghost", children: buttonLabels?.tie ?? contextLabels.voteTie }),
|
|
199
|
+
/* @__PURE__ */ jsx(Button, { onClick: handleRight, size: "sm", type: "button", variant: "outline", children: buttonLabels?.right ?? "Right \u2192" })
|
|
200
|
+
] })
|
|
201
|
+
]
|
|
202
|
+
}
|
|
203
|
+
);
|
|
204
|
+
});
|
|
205
|
+
ModelComparisonVote.displayName = "ModelComparisonVote";
|
|
206
|
+
export {
|
|
207
|
+
ModelComparison,
|
|
208
|
+
ModelComparisonColumn,
|
|
209
|
+
ModelComparisonMeta,
|
|
210
|
+
ModelComparisonVote
|
|
211
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import {
|
|
4
|
+
forwardRef
|
|
5
|
+
} from "react";
|
|
6
|
+
import { cn } from "../../lib/utils";
|
|
7
|
+
const DEFAULT_LABELS = {
|
|
8
|
+
plural: "items",
|
|
9
|
+
region: "Multi-select lasso",
|
|
10
|
+
singular: "item"
|
|
11
|
+
};
|
|
12
|
+
const normalizeRect = (rect) => {
|
|
13
|
+
const x = rect.width < 0 ? rect.x + rect.width : rect.x;
|
|
14
|
+
const y = rect.height < 0 ? rect.y + rect.height : rect.y;
|
|
15
|
+
const width = Math.abs(rect.width);
|
|
16
|
+
const height = Math.abs(rect.height);
|
|
17
|
+
return { height, width, x, y };
|
|
18
|
+
};
|
|
19
|
+
const MultiSelectLasso = forwardRef((props, ref) => {
|
|
20
|
+
const { className, count, hint, labels, rect, ...rest } = props;
|
|
21
|
+
if (!rect) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const resolvedLabels = { ...DEFAULT_LABELS, ...labels };
|
|
25
|
+
const normalized = normalizeRect(rect);
|
|
26
|
+
if (normalized.width === 0 || normalized.height === 0) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const noun = count === 1 ? resolvedLabels.singular : resolvedLabels.plural;
|
|
30
|
+
return /* @__PURE__ */ jsxs(
|
|
31
|
+
"div",
|
|
32
|
+
{
|
|
33
|
+
"aria-hidden": "true",
|
|
34
|
+
"aria-label": resolvedLabels.region,
|
|
35
|
+
className: cn(
|
|
36
|
+
"pointer-events-none absolute z-30 rounded-md border-2 border-blue-500/70 bg-blue-500/10",
|
|
37
|
+
className
|
|
38
|
+
),
|
|
39
|
+
"data-multi-select-lasso": true,
|
|
40
|
+
ref,
|
|
41
|
+
style: {
|
|
42
|
+
height: normalized.height,
|
|
43
|
+
left: normalized.x,
|
|
44
|
+
top: normalized.y,
|
|
45
|
+
width: normalized.width
|
|
46
|
+
},
|
|
47
|
+
...rest,
|
|
48
|
+
children: [
|
|
49
|
+
hint ? /* @__PURE__ */ jsx(
|
|
50
|
+
"span",
|
|
51
|
+
{
|
|
52
|
+
className: "absolute -top-7 left-0 rounded-md bg-foreground/90 px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide text-background",
|
|
53
|
+
"data-multi-select-hint": true,
|
|
54
|
+
children: hint
|
|
55
|
+
}
|
|
56
|
+
) : null,
|
|
57
|
+
typeof count === "number" ? /* @__PURE__ */ jsxs(
|
|
58
|
+
"span",
|
|
59
|
+
{
|
|
60
|
+
className: "absolute -bottom-7 right-0 rounded-full bg-foreground px-2 py-0.5 text-[10px] font-semibold text-background",
|
|
61
|
+
"data-multi-select-count": true,
|
|
62
|
+
children: [
|
|
63
|
+
count,
|
|
64
|
+
" ",
|
|
65
|
+
noun
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
) : null
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
MultiSelectLasso.displayName = "MultiSelectLasso";
|
|
74
|
+
export {
|
|
75
|
+
MultiSelectLasso
|
|
76
|
+
};
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import {
|
|
4
|
+
forwardRef,
|
|
5
|
+
useCallback,
|
|
6
|
+
useId,
|
|
7
|
+
useReducer,
|
|
8
|
+
useRef
|
|
9
|
+
} from "react";
|
|
10
|
+
import { CheckCircle2, Loader2, XCircle } from "lucide-react";
|
|
11
|
+
import { cn } from "../../lib/utils";
|
|
12
|
+
import { Button } from "../button/button";
|
|
13
|
+
import { Input } from "../input/input";
|
|
14
|
+
const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
15
|
+
const DEFAULT_LABELS = {
|
|
16
|
+
emailInvalid: "Enter a valid email address.",
|
|
17
|
+
emailLabel: "Email address",
|
|
18
|
+
errorFallback: "Something went wrong. Try again.",
|
|
19
|
+
placeholder: "you@example.com",
|
|
20
|
+
sending: "Subscribing\u2026",
|
|
21
|
+
submit: "Subscribe",
|
|
22
|
+
success: "You're on the list. Check your inbox to confirm.",
|
|
23
|
+
tryAgain: "Try again"
|
|
24
|
+
};
|
|
25
|
+
function reducer(state, action) {
|
|
26
|
+
switch (action.kind) {
|
|
27
|
+
case "fail":
|
|
28
|
+
return { kind: "error", message: action.message };
|
|
29
|
+
case "reset":
|
|
30
|
+
return { kind: "idle" };
|
|
31
|
+
case "send":
|
|
32
|
+
return state.kind === "sending" ? state : { kind: "sending" };
|
|
33
|
+
case "succeed":
|
|
34
|
+
return { kind: "sent" };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function actionToStatus(action) {
|
|
38
|
+
switch (action.kind) {
|
|
39
|
+
case "fail":
|
|
40
|
+
return "error";
|
|
41
|
+
case "reset":
|
|
42
|
+
return "idle";
|
|
43
|
+
case "send":
|
|
44
|
+
return "sending";
|
|
45
|
+
case "succeed":
|
|
46
|
+
return "sent";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function defaultValidate(email, label) {
|
|
50
|
+
const trimmed = email.trim();
|
|
51
|
+
if (!trimmed) return label;
|
|
52
|
+
if (!EMAIL_PATTERN.test(trimmed)) return label;
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
function extractErrorMessage(value, fallback) {
|
|
56
|
+
if (value instanceof Error && value.message) return value.message;
|
|
57
|
+
if (typeof value === "string" && value.length > 0) return value;
|
|
58
|
+
return fallback;
|
|
59
|
+
}
|
|
60
|
+
function SubmitButton({
|
|
61
|
+
labels,
|
|
62
|
+
stacked,
|
|
63
|
+
status
|
|
64
|
+
}) {
|
|
65
|
+
let content;
|
|
66
|
+
if (status === "sending") {
|
|
67
|
+
content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
68
|
+
/* @__PURE__ */ jsx(Loader2, { "aria-hidden": "true", className: "mr-2 h-4 w-4 animate-spin" }),
|
|
69
|
+
labels.sending
|
|
70
|
+
] });
|
|
71
|
+
} else if (status === "error") {
|
|
72
|
+
content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
73
|
+
/* @__PURE__ */ jsx(XCircle, { "aria-hidden": "true", className: "mr-2 h-4 w-4" }),
|
|
74
|
+
labels.tryAgain
|
|
75
|
+
] });
|
|
76
|
+
} else {
|
|
77
|
+
content = labels.submit;
|
|
78
|
+
}
|
|
79
|
+
return /* @__PURE__ */ jsx(
|
|
80
|
+
Button,
|
|
81
|
+
{
|
|
82
|
+
className: stacked ? "w-full" : "",
|
|
83
|
+
disabled: status === "sending",
|
|
84
|
+
type: "submit",
|
|
85
|
+
children: content
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
function SuccessPanel({ className, message }) {
|
|
90
|
+
return /* @__PURE__ */ jsxs(
|
|
91
|
+
"div",
|
|
92
|
+
{
|
|
93
|
+
"aria-live": "polite",
|
|
94
|
+
className: cn(
|
|
95
|
+
"flex items-start gap-2 rounded-lg border border-emerald-500/40 bg-emerald-500/10 p-3 text-sm text-emerald-900 dark:text-emerald-200",
|
|
96
|
+
className
|
|
97
|
+
),
|
|
98
|
+
role: "status",
|
|
99
|
+
children: [
|
|
100
|
+
/* @__PURE__ */ jsx(CheckCircle2, { "aria-hidden": "true", className: "mt-0.5 h-4 w-4 shrink-0" }),
|
|
101
|
+
/* @__PURE__ */ jsx("span", { children: message })
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
function useNewsletterSignupController(options) {
|
|
107
|
+
const { labels, onStatusChange, onSubmit, validate } = options;
|
|
108
|
+
const inputRef = useRef(null);
|
|
109
|
+
const [state, dispatch] = useReducer(reducer, { kind: "idle" });
|
|
110
|
+
const status = state.kind;
|
|
111
|
+
const transition = useCallback(
|
|
112
|
+
(action) => {
|
|
113
|
+
dispatch(action);
|
|
114
|
+
onStatusChange?.(actionToStatus(action));
|
|
115
|
+
},
|
|
116
|
+
[onStatusChange]
|
|
117
|
+
);
|
|
118
|
+
const handleChange = useCallback(() => {
|
|
119
|
+
if (state.kind === "error") transition({ kind: "reset" });
|
|
120
|
+
}, [state.kind, transition]);
|
|
121
|
+
const performSubmit = useCallback(
|
|
122
|
+
async (value) => {
|
|
123
|
+
const validator = validate ?? ((email) => defaultValidate(email, labels.emailInvalid));
|
|
124
|
+
const validation = validator(value);
|
|
125
|
+
if (validation !== true) {
|
|
126
|
+
transition({ kind: "fail", message: validation });
|
|
127
|
+
inputRef.current?.focus();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
transition({ kind: "send" });
|
|
131
|
+
try {
|
|
132
|
+
await onSubmit(value);
|
|
133
|
+
transition({ kind: "succeed" });
|
|
134
|
+
} catch (error) {
|
|
135
|
+
transition({
|
|
136
|
+
kind: "fail",
|
|
137
|
+
message: extractErrorMessage(error, labels.errorFallback)
|
|
138
|
+
});
|
|
139
|
+
inputRef.current?.focus();
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
[labels.emailInvalid, labels.errorFallback, onSubmit, transition, validate]
|
|
143
|
+
);
|
|
144
|
+
const handleSubmit = useCallback(
|
|
145
|
+
(event) => {
|
|
146
|
+
event.preventDefault();
|
|
147
|
+
if (state.kind === "sending") return;
|
|
148
|
+
const value = inputRef.current?.value.trim() ?? "";
|
|
149
|
+
void performSubmit(value);
|
|
150
|
+
},
|
|
151
|
+
[performSubmit, state.kind]
|
|
152
|
+
);
|
|
153
|
+
return {
|
|
154
|
+
errorMessage: state.kind === "error" ? state.message : null,
|
|
155
|
+
handleChange,
|
|
156
|
+
handleSubmit,
|
|
157
|
+
inputRef,
|
|
158
|
+
status
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
const NewsletterSignup = forwardRef((props, ref) => {
|
|
162
|
+
const {
|
|
163
|
+
autoComplete = "email",
|
|
164
|
+
className,
|
|
165
|
+
labels,
|
|
166
|
+
onStatusChange,
|
|
167
|
+
onSubmit,
|
|
168
|
+
validate,
|
|
169
|
+
variant = "inline",
|
|
170
|
+
...rest
|
|
171
|
+
} = props;
|
|
172
|
+
const resolvedLabels = { ...DEFAULT_LABELS, ...labels };
|
|
173
|
+
const inputId = useId();
|
|
174
|
+
const errorId = useId();
|
|
175
|
+
const controller = useNewsletterSignupController({
|
|
176
|
+
labels: resolvedLabels,
|
|
177
|
+
onStatusChange,
|
|
178
|
+
onSubmit,
|
|
179
|
+
validate
|
|
180
|
+
});
|
|
181
|
+
if (controller.status === "sent") {
|
|
182
|
+
return /* @__PURE__ */ jsx(SuccessPanel, { className, message: resolvedLabels.success });
|
|
183
|
+
}
|
|
184
|
+
return /* @__PURE__ */ jsx(
|
|
185
|
+
FormBody,
|
|
186
|
+
{
|
|
187
|
+
autoComplete,
|
|
188
|
+
className,
|
|
189
|
+
errorId,
|
|
190
|
+
formRef: ref,
|
|
191
|
+
inputId,
|
|
192
|
+
inputRef: controller.inputRef,
|
|
193
|
+
labels: resolvedLabels,
|
|
194
|
+
message: controller.errorMessage,
|
|
195
|
+
onChange: controller.handleChange,
|
|
196
|
+
onSubmit: controller.handleSubmit,
|
|
197
|
+
rest,
|
|
198
|
+
stacked: variant === "stacked",
|
|
199
|
+
status: controller.status
|
|
200
|
+
}
|
|
201
|
+
);
|
|
202
|
+
});
|
|
203
|
+
NewsletterSignup.displayName = "NewsletterSignup";
|
|
204
|
+
function FormBody({
|
|
205
|
+
autoComplete,
|
|
206
|
+
className,
|
|
207
|
+
errorId,
|
|
208
|
+
formRef,
|
|
209
|
+
inputId,
|
|
210
|
+
inputRef,
|
|
211
|
+
labels,
|
|
212
|
+
message,
|
|
213
|
+
onChange,
|
|
214
|
+
onSubmit,
|
|
215
|
+
rest,
|
|
216
|
+
stacked,
|
|
217
|
+
status
|
|
218
|
+
}) {
|
|
219
|
+
return /* @__PURE__ */ jsxs(
|
|
220
|
+
"form",
|
|
221
|
+
{
|
|
222
|
+
"aria-busy": status === "sending",
|
|
223
|
+
className: cn(
|
|
224
|
+
"flex w-full",
|
|
225
|
+
stacked ? "flex-col gap-2" : "flex-col gap-2 sm:flex-row sm:items-start",
|
|
226
|
+
className
|
|
227
|
+
),
|
|
228
|
+
noValidate: true,
|
|
229
|
+
onSubmit,
|
|
230
|
+
ref: formRef,
|
|
231
|
+
...rest,
|
|
232
|
+
children: [
|
|
233
|
+
/* @__PURE__ */ jsxs("div", { className: cn("flex flex-col gap-1", stacked ? "" : "sm:flex-1"), children: [
|
|
234
|
+
/* @__PURE__ */ jsx("label", { className: "sr-only", htmlFor: inputId, children: labels.emailLabel }),
|
|
235
|
+
/* @__PURE__ */ jsx(
|
|
236
|
+
Input,
|
|
237
|
+
{
|
|
238
|
+
"aria-describedby": message ? errorId : void 0,
|
|
239
|
+
"aria-invalid": message !== null,
|
|
240
|
+
autoComplete,
|
|
241
|
+
disabled: status === "sending",
|
|
242
|
+
id: inputId,
|
|
243
|
+
name: "email",
|
|
244
|
+
onChange,
|
|
245
|
+
placeholder: labels.placeholder,
|
|
246
|
+
ref: inputRef,
|
|
247
|
+
type: "email"
|
|
248
|
+
}
|
|
249
|
+
),
|
|
250
|
+
/* @__PURE__ */ jsx(
|
|
251
|
+
"p",
|
|
252
|
+
{
|
|
253
|
+
"aria-live": "polite",
|
|
254
|
+
className: cn("text-xs", message ? "text-destructive" : "sr-only"),
|
|
255
|
+
id: errorId,
|
|
256
|
+
role: message ? "alert" : void 0,
|
|
257
|
+
children: message ?? ""
|
|
258
|
+
}
|
|
259
|
+
)
|
|
260
|
+
] }),
|
|
261
|
+
/* @__PURE__ */ jsx(SubmitButton, { labels, stacked, status })
|
|
262
|
+
]
|
|
263
|
+
}
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
export {
|
|
267
|
+
NewsletterSignup,
|
|
268
|
+
reducer as newsletterSignupReducer
|
|
269
|
+
};
|