@uibot/blocks-studio 0.0.0-stage → 0.2.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.
@@ -0,0 +1,531 @@
1
+ import type { RendererComponent } from "@uibot/renderer-react";
2
+
3
+ /**
4
+ * Conversion-oriented "Schematic Editorial" marketing blocks.
5
+ *
6
+ * A second tier of presentation primitives focused on landing-page conversion:
7
+ * PricingTable, Testimonials, LogoCloud, StatBand, Newsletter. Like the rest of
8
+ * blocks-studio they ship with **zero third-party runtime deps** — all glyphs
9
+ * are inline SVG, all colour/material comes from theme tokens
10
+ * (foreground / muted / border / primary / card) so each block renders in any
11
+ * context and in both light/dark themes. Under a `.marketing` scope they pick up
12
+ * the brand serif (`--font-display`), mono (`--font-marketing-mono`) and warm
13
+ * amber / teal / rose / indigo accents (`--marketing-accent`, `--mk-accent-2..4`)
14
+ * plus the hairline `.mkt-card` material with hover lift.
15
+ *
16
+ * CTA props ({label, href}) render as accessible anchors styled as button /
17
+ * outline / inverse, mirroring the presentation block convention.
18
+ */
19
+
20
+ function cn(...cls: (string | false | null | undefined)[]): string {
21
+ return cls.filter(Boolean).join(" ");
22
+ }
23
+
24
+ function str(v: unknown): string | undefined {
25
+ return typeof v === "string" && v.length > 0 ? v : undefined;
26
+ }
27
+
28
+ function strArr(raw: unknown): string[] {
29
+ if (!Array.isArray(raw)) return [];
30
+ return raw.map((v) => str(v)).filter((v): v is string => Boolean(v));
31
+ }
32
+
33
+ interface Cta {
34
+ label: string;
35
+ href: string;
36
+ }
37
+
38
+ function parseCta(raw: unknown): Cta | undefined {
39
+ if (!raw || typeof raw !== "object") return undefined;
40
+ const rec = raw as Record<string, unknown>;
41
+ const label = str(rec["label"]);
42
+ const href = str(rec["href"]);
43
+ if (!label) return undefined;
44
+ return { label, href: href ?? "#" };
45
+ }
46
+
47
+ function records(raw: unknown): Record<string, unknown>[] {
48
+ if (!Array.isArray(raw)) return [];
49
+ return raw.filter((it): it is Record<string, unknown> => Boolean(it) && typeof it === "object");
50
+ }
51
+
52
+ // First-letter avatar token from a name ("Ada Lovelace" → "AL").
53
+ function initials(name: string): string {
54
+ const parts = name.trim().split(/\s+/).slice(0, 2);
55
+ return parts.map((p) => p.charAt(0).toUpperCase()).join("") || "?";
56
+ }
57
+
58
+ // ── Shared inline glyphs ────────────────────────────────────────────────────────
59
+
60
+ function CheckIcon(): React.ReactElement {
61
+ return (
62
+ <svg
63
+ viewBox="0 0 24 24"
64
+ fill="none"
65
+ stroke="currentColor"
66
+ strokeWidth={2.4}
67
+ strokeLinecap="round"
68
+ strokeLinejoin="round"
69
+ className="size-3.5"
70
+ aria-hidden="true"
71
+ >
72
+ <path d="m4 12 5 5L20 6" />
73
+ </svg>
74
+ );
75
+ }
76
+
77
+ function Star({ filled }: { filled: boolean }): React.ReactElement {
78
+ return (
79
+ <svg
80
+ viewBox="0 0 24 24"
81
+ fill={filled ? "currentColor" : "none"}
82
+ stroke="currentColor"
83
+ strokeWidth={1.4}
84
+ strokeLinejoin="round"
85
+ className="size-4"
86
+ aria-hidden="true"
87
+ >
88
+ <path d="m12 3 2.9 5.9 6.5.9-4.7 4.6 1.1 6.5L12 18.8 6.2 21l1.1-6.5L2.6 9.8l6.5-.9z" />
89
+ </svg>
90
+ );
91
+ }
92
+
93
+ // ── Shared CTA anchor ────────────────────────────────────────────────────────────
94
+
95
+ function CtaLink({
96
+ cta,
97
+ variant,
98
+ block,
99
+ }: {
100
+ cta: Cta;
101
+ variant: "primary" | "outline" | "inverse";
102
+ block?: boolean;
103
+ }): React.ReactElement {
104
+ const base =
105
+ "inline-flex items-center justify-center gap-2 rounded-md px-5 py-2.5 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2";
106
+ const variants: Record<typeof variant, string> = {
107
+ primary:
108
+ "bg-[var(--marketing-accent)] text-[var(--marketing-accent-foreground)] hover:bg-[var(--marketing-accent-strong)] focus-visible:ring-[var(--marketing-accent)]",
109
+ outline:
110
+ "border border-border bg-transparent text-foreground hover:border-[var(--marketing-accent)] hover:text-[var(--marketing-accent)] focus-visible:ring-border",
111
+ inverse:
112
+ "bg-gradient-to-r from-[var(--marketing-accent)] to-[var(--mk-accent-3)] text-[var(--marketing-accent-foreground)] hover:opacity-90 focus-visible:ring-[var(--marketing-accent)]",
113
+ };
114
+ return (
115
+ <a href={cta.href} className={cn(base, variants[variant], block && "w-full")}>
116
+ {cta.label}
117
+ </a>
118
+ );
119
+ }
120
+
121
+ // ── PricingTable ──────────────────────────────────────────────────────────────
122
+
123
+ interface Plan {
124
+ name: string;
125
+ price: string;
126
+ period?: string | undefined;
127
+ description?: string | undefined;
128
+ features: string[];
129
+ cta?: Cta | undefined;
130
+ highlighted: boolean;
131
+ }
132
+
133
+ function parsePlans(raw: unknown): Plan[] {
134
+ return records(raw).map((p) => ({
135
+ name: str(p["name"]) ?? "",
136
+ price: str(p["price"]) ?? "",
137
+ period: str(p["period"]),
138
+ description: str(p["description"]),
139
+ features: strArr(p["features"]),
140
+ cta: parseCta(p["cta"]),
141
+ highlighted: Boolean(p["highlighted"]),
142
+ }));
143
+ }
144
+
145
+ const PRICING_COLS: Record<number, string> = {
146
+ 2: "sm:grid-cols-2",
147
+ 3: "sm:grid-cols-2 lg:grid-cols-3",
148
+ 4: "sm:grid-cols-2 lg:grid-cols-4",
149
+ };
150
+
151
+ /**
152
+ * Responsive 2–4 column pricing grid. Each plan is a hairline `.mkt-card`; the
153
+ * `highlighted` plan gets an amber border, an amber "Popular" badge and a solid
154
+ * amber CTA while the rest use an outline CTA. Features list with amber check
155
+ * glyphs. CTAs render as anchors via the {label, href} contract.
156
+ */
157
+ export const PricingTable: RendererComponent = (props) => {
158
+ const plans = parsePlans(props["plans"]);
159
+ const billingNote = str(props["billingNote"]);
160
+ const colsCls = PRICING_COLS[Math.min(Math.max(plans.length, 2), 4)] ?? PRICING_COLS[3];
161
+
162
+ return (
163
+ <section className="marketing mx-auto max-w-6xl px-6 md:px-0" data-uibot-type="PricingTable">
164
+ <div className={cn("grid grid-cols-1 items-stretch gap-5", colsCls)}>
165
+ {plans.map((plan, i) => (
166
+ <article
167
+ key={i}
168
+ className={cn(
169
+ "mkt-card mkt-reveal relative flex flex-col p-6",
170
+ `mkt-reveal-${Math.min(i + 1, 6)}`,
171
+ plan.highlighted &&
172
+ "border-[var(--marketing-accent)] shadow-[0_0_0_1px_var(--marketing-accent)]",
173
+ )}
174
+ >
175
+ {plan.highlighted && (
176
+ <span className="absolute -top-3 left-6 rounded-full bg-[var(--marketing-accent)] px-3 py-1 font-[family-name:var(--font-marketing-mono)] text-[0.625rem] font-semibold uppercase tracking-[0.16em] text-[var(--marketing-accent-foreground)]">
177
+ Popular
178
+ </span>
179
+ )}
180
+ <h3 className="text-xl">{plan.name}</h3>
181
+ {plan.description && (
182
+ <p className="mt-1 text-sm leading-relaxed text-muted-foreground">
183
+ {plan.description}
184
+ </p>
185
+ )}
186
+ <div className="mt-5 flex items-baseline gap-1">
187
+ <span className="mkt-display text-4xl md:text-5xl">{plan.price}</span>
188
+ {plan.period && (
189
+ <span className="font-[family-name:var(--font-marketing-mono)] text-sm text-muted-foreground">
190
+ {plan.period}
191
+ </span>
192
+ )}
193
+ </div>
194
+ {plan.features.length > 0 && (
195
+ <ul className="mt-6 flex flex-1 flex-col gap-3 text-sm">
196
+ {plan.features.map((f, fi) => (
197
+ <li key={fi} className="flex items-start gap-2.5">
198
+ <span
199
+ className={cn(
200
+ "mt-0.5 inline-flex size-4 shrink-0 items-center justify-center rounded-full",
201
+ plan.highlighted
202
+ ? "bg-[color-mix(in_oklch,var(--marketing-accent)_22%,transparent)] text-[var(--marketing-accent)]"
203
+ : "bg-muted text-foreground",
204
+ )}
205
+ >
206
+ <CheckIcon />
207
+ </span>
208
+ <span className="text-foreground/90">{f}</span>
209
+ </li>
210
+ ))}
211
+ </ul>
212
+ )}
213
+ {plan.cta && (
214
+ <div className="mt-7">
215
+ <CtaLink cta={plan.cta} variant={plan.highlighted ? "primary" : "outline"} block />
216
+ </div>
217
+ )}
218
+ </article>
219
+ ))}
220
+ </div>
221
+ {billingNote && (
222
+ <p className="mt-6 text-center font-[family-name:var(--font-marketing-mono)] text-xs uppercase tracking-[0.18em] text-muted-foreground">
223
+ {billingNote}
224
+ </p>
225
+ )}
226
+ </section>
227
+ );
228
+ };
229
+
230
+ // ── Testimonials ──────────────────────────────────────────────────────────────
231
+
232
+ interface Testimonial {
233
+ quote: string;
234
+ author: string;
235
+ role?: string | undefined;
236
+ avatar?: string | undefined;
237
+ rating?: number | undefined;
238
+ }
239
+
240
+ function parseTestimonials(raw: unknown): Testimonial[] {
241
+ return records(raw).map((t) => {
242
+ const ratingRaw = Number(t["rating"]);
243
+ return {
244
+ quote: str(t["quote"]) ?? "",
245
+ author: str(t["author"]) ?? "",
246
+ role: str(t["role"]),
247
+ avatar: str(t["avatar"]),
248
+ rating:
249
+ Number.isFinite(ratingRaw) && ratingRaw > 0
250
+ ? Math.min(Math.round(ratingRaw), 5)
251
+ : undefined,
252
+ };
253
+ });
254
+ }
255
+
256
+ const TESTI_COLS: Record<number, string> = {
257
+ 1: "",
258
+ 2: "sm:grid-cols-2",
259
+ 3: "sm:grid-cols-2 lg:grid-cols-3",
260
+ };
261
+
262
+ /**
263
+ * Grid of testimonial cards (`.mkt-card` with hover lift). Each card shows an
264
+ * optional star rating, a serif italic pull-quote, and an avatar token (initials
265
+ * derived from the author name, or an explicit `avatar` string) + author + role.
266
+ * `columns` (1–3) controls the grid; the tint cycles through the four accents.
267
+ */
268
+ export const Testimonials: RendererComponent = (props) => {
269
+ const items = parseTestimonials(props["items"]);
270
+ const colsRaw = Number(props["columns"]);
271
+ const cols = Number.isFinite(colsRaw)
272
+ ? Math.min(Math.max(colsRaw, 1), 3)
273
+ : Math.min(items.length || 1, 3);
274
+ const colsCls = TESTI_COLS[cols] ?? TESTI_COLS[3];
275
+
276
+ return (
277
+ <section className="marketing mx-auto max-w-6xl px-6 md:px-0" data-uibot-type="Testimonials">
278
+ <div className={cn("grid grid-cols-1 gap-5", colsCls)}>
279
+ {items.map((t, i) => (
280
+ <figure
281
+ key={i}
282
+ className={cn(
283
+ "mkt-card mkt-reveal flex flex-col p-6",
284
+ `mkt-reveal-${Math.min(i + 1, 6)}`,
285
+ )}
286
+ >
287
+ {t.rating && (
288
+ <div
289
+ className="flex gap-0.5 text-[var(--marketing-accent)]"
290
+ aria-label={`${t.rating} out of 5`}
291
+ >
292
+ {Array.from({ length: 5 }, (_, s) => (
293
+ <Star key={s} filled={s < (t.rating ?? 0)} />
294
+ ))}
295
+ </div>
296
+ )}
297
+ <blockquote className="mkt-display-italic mt-4 flex-1 text-lg leading-relaxed text-foreground">
298
+ “{t.quote}”
299
+ </blockquote>
300
+ <figcaption className="mt-6 flex items-center gap-3">
301
+ <span
302
+ className={cn(
303
+ "inline-flex size-10 shrink-0 items-center justify-center rounded-full border font-[family-name:var(--font-marketing-mono)] text-sm font-semibold mkt-tint",
304
+ `mkt-tint-${i % 4}`,
305
+ )}
306
+ >
307
+ {t.avatar ?? initials(t.author)}
308
+ </span>
309
+ <span className="min-w-0">
310
+ <span className="block truncate text-sm font-medium text-foreground">
311
+ {t.author}
312
+ </span>
313
+ {t.role && (
314
+ <span className="block truncate text-xs text-muted-foreground">{t.role}</span>
315
+ )}
316
+ </span>
317
+ </figcaption>
318
+ </figure>
319
+ ))}
320
+ </div>
321
+ </section>
322
+ );
323
+ };
324
+
325
+ // ── LogoCloud ──────────────────────────────────────────────────────────────────
326
+
327
+ interface Logo {
328
+ name: string;
329
+ }
330
+
331
+ function parseLogos(raw: unknown): Logo[] {
332
+ // Accept ["Acme", ...] or [{name}, ...]
333
+ if (Array.isArray(raw) && raw.every((v) => typeof v === "string")) {
334
+ return strArr(raw).map((name) => ({ name }));
335
+ }
336
+ return records(raw)
337
+ .map((l) => ({ name: str(l["name"]) ?? "" }))
338
+ .filter((l) => l.name.length > 0);
339
+ }
340
+
341
+ /**
342
+ * A single grayscale "trusted by" logo strip. With no external images, each logo
343
+ * is a mono wordmark (or initials for long names) sitting in a faint hairline
344
+ * pill; the row is desaturated/dimmed by default and lifts to full foreground on
345
+ * hover. An optional mono `label` sits above the row.
346
+ */
347
+ export const LogoCloud: RendererComponent = (props) => {
348
+ const label = str(props["label"]);
349
+ const logos = parseLogos(props["logos"]);
350
+
351
+ return (
352
+ <section className="marketing mx-auto max-w-6xl px-6 md:px-0" data-uibot-type="LogoCloud">
353
+ {label && <p className="mkt-eyebrow text-center">{label}</p>}
354
+ <div
355
+ className={cn(
356
+ "flex flex-wrap items-center justify-center gap-x-8 gap-y-5",
357
+ label && "mt-6",
358
+ )}
359
+ >
360
+ {logos.map((logo, i) => (
361
+ <span
362
+ key={i}
363
+ className="font-[family-name:var(--font-marketing-mono)] text-base font-semibold uppercase tracking-[0.14em] text-muted-foreground/60 opacity-70 transition-all duration-200 hover:text-foreground hover:opacity-100"
364
+ >
365
+ {logo.name.length > 14 ? initials(logo.name) : logo.name}
366
+ </span>
367
+ ))}
368
+ </div>
369
+ </section>
370
+ );
371
+ };
372
+
373
+ // ── StatBand ──────────────────────────────────────────────────────────────────
374
+
375
+ interface Stat {
376
+ value: string;
377
+ label: string;
378
+ sub?: string | undefined;
379
+ }
380
+
381
+ function parseStats(raw: unknown): Stat[] {
382
+ return records(raw)
383
+ .map((s) => ({
384
+ value: str(s["value"]) ?? "",
385
+ label: str(s["label"]) ?? "",
386
+ sub: str(s["sub"]),
387
+ }))
388
+ .filter((s) => s.value.length > 0);
389
+ }
390
+
391
+ const STAT_COLS: Record<number, string> = {
392
+ 1: "",
393
+ 2: "sm:grid-cols-2",
394
+ 3: "sm:grid-cols-3",
395
+ 4: "sm:grid-cols-2 lg:grid-cols-4",
396
+ };
397
+
398
+ /**
399
+ * Big-number statistics band. Oversized serif values with mono labels, divided
400
+ * by hairline rules. `tone` switches the surface: "plain" (transparent),
401
+ * "muted" (soft card panel) or "inverse" (ink-black panel with a warm amber→rose
402
+ * glow + grain, matching CtaBand) for a high-contrast metrics moment.
403
+ */
404
+ export const StatBand: RendererComponent = (props) => {
405
+ const stats = parseStats(props["stats"]);
406
+ const tone = str(props["tone"]) ?? "plain"; // plain | muted | inverse
407
+ const inverse = tone === "inverse";
408
+ const colsCls = STAT_COLS[Math.min(Math.max(stats.length, 1), 4)] ?? STAT_COLS[4];
409
+
410
+ const grid = (
411
+ <div
412
+ className={cn(
413
+ "grid grid-cols-1 divide-y divide-border sm:divide-x sm:divide-y-0",
414
+ colsCls,
415
+ inverse && "divide-background/15 sm:divide-background/15",
416
+ )}
417
+ >
418
+ {stats.map((s, i) => (
419
+ <div
420
+ key={i}
421
+ className={cn(
422
+ "mkt-reveal flex flex-col items-center px-6 py-6 text-center",
423
+ `mkt-reveal-${Math.min(i + 1, 6)}`,
424
+ )}
425
+ >
426
+ <span
427
+ className={cn(
428
+ "mkt-display text-4xl md:text-6xl",
429
+ inverse ? "text-background" : "text-foreground",
430
+ )}
431
+ >
432
+ {s.value}
433
+ </span>
434
+ <span
435
+ className={cn(
436
+ "mt-3 font-[family-name:var(--font-marketing-mono)] text-xs uppercase tracking-[0.18em]",
437
+ inverse ? "text-background/70" : "text-muted-foreground",
438
+ )}
439
+ >
440
+ {s.label}
441
+ </span>
442
+ {s.sub && (
443
+ <span
444
+ className={cn(
445
+ "mt-1 text-xs",
446
+ inverse ? "text-background/55" : "text-muted-foreground/80",
447
+ )}
448
+ >
449
+ {s.sub}
450
+ </span>
451
+ )}
452
+ </div>
453
+ ))}
454
+ </div>
455
+ );
456
+
457
+ if (inverse) {
458
+ return (
459
+ <section className="marketing mx-auto max-w-6xl px-6 md:px-0" data-uibot-type="StatBand">
460
+ <div className="mkt-hero relative overflow-hidden rounded-2xl bg-foreground py-6 md:py-8">
461
+ <span
462
+ aria-hidden="true"
463
+ className="pointer-events-none absolute inset-0"
464
+ style={{
465
+ background:
466
+ "radial-gradient(60% 120% at 12% 0%, color-mix(in oklch, var(--marketing-accent) 26%, transparent) 0%, transparent 55%), radial-gradient(60% 120% at 100% 100%, color-mix(in oklch, var(--mk-accent-3) 22%, transparent) 0%, transparent 55%)",
467
+ }}
468
+ />
469
+ <span className="mkt-grain" aria-hidden="true" />
470
+ <div className="relative">{grid}</div>
471
+ </div>
472
+ </section>
473
+ );
474
+ }
475
+
476
+ return (
477
+ <section className="marketing mx-auto max-w-6xl px-6 md:px-0" data-uibot-type="StatBand">
478
+ <div
479
+ className={cn(
480
+ tone === "muted" && "mkt-band rounded-2xl border border-border bg-card/50 py-4",
481
+ )}
482
+ >
483
+ {grid}
484
+ </div>
485
+ </section>
486
+ );
487
+ };
488
+
489
+ // ── Newsletter ──────────────────────────────────────────────────────────────────
490
+
491
+ /**
492
+ * Email-capture band: serif title + supporting line, then an email input styled
493
+ * with theme tokens beside a CTA anchor. Purely presentational — the input is
494
+ * decorative and the CTA navigates via {label, href}; wire real submission at the
495
+ * host level. On a `.marketing` surface it sits on a soft amber-tinted band.
496
+ */
497
+ export const Newsletter: RendererComponent = (props) => {
498
+ const title = str(props["title"]) ?? "";
499
+ const subtitle = str(props["subtitle"]);
500
+ const placeholder = str(props["placeholder"]) ?? "you@example.com";
501
+ const cta = parseCta(props["cta"]) ?? { label: "Subscribe", href: "#" };
502
+
503
+ return (
504
+ <section className="marketing mx-auto max-w-3xl px-6 md:px-0" data-uibot-type="Newsletter">
505
+ <div className="mkt-band-accent rounded-2xl border border-border bg-card/40 px-6 py-10 text-center md:px-10">
506
+ <h2 className="text-2xl md:text-3xl">{title}</h2>
507
+ {subtitle && (
508
+ <p className="mx-auto mt-3 max-w-xl text-sm leading-relaxed text-muted-foreground">
509
+ {subtitle}
510
+ </p>
511
+ )}
512
+ <form
513
+ className="mx-auto mt-7 flex w-full max-w-md flex-col gap-3 sm:flex-row"
514
+ action={cta.href}
515
+ >
516
+ <label className="sr-only" htmlFor="uibot-newsletter-email">
517
+ Email address
518
+ </label>
519
+ <input
520
+ id="uibot-newsletter-email"
521
+ type="email"
522
+ name="email"
523
+ placeholder={placeholder}
524
+ className="h-11 flex-1 rounded-md border border-border bg-background px-4 text-sm text-foreground placeholder:text-muted-foreground focus-visible:border-[var(--marketing-accent)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[color-mix(in_oklch,var(--marketing-accent)_30%,transparent)]"
525
+ />
526
+ <CtaLink cta={cta} variant="primary" />
527
+ </form>
528
+ </div>
529
+ </section>
530
+ );
531
+ };