@meterbox/react 0.1.9 → 0.1.10

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 CHANGED
@@ -45,7 +45,7 @@ import {
45
45
  } from "@meterbox/react";
46
46
  ```
47
47
 
48
- ### `<PricingTable plans currentPlanId? currency? onSelect? customerEmail? branding? />` or `<PricingTable publishableKey … />`
48
+ ### `<PricingTable plans currentPlanId? currency? onSelect? customerEmail? branding? selectedPlanId? onPlanClick? renderFooter? />` or `<PricingTable publishableKey … />`
49
49
 
50
50
  On a public page with no backend of its own, pass a
51
51
  publishable key (`mb_pub_...`, from Settings > API keys) instead of `plans`.
@@ -75,9 +75,21 @@ pay for usage: the amounts included each month, what happens past them
75
75
  and output rates per 1M tokens, tier ladders included.
76
76
 
77
77
  A plan lists its included credits first ("1,500 Bits a month", in the tenant's credit unit), then
78
- its `bullets`: the tenant's own pricing-page bullets, else its features' names. A pricing-page
79
- plan with a public promotion shows its promotional price, the regular one struck through, and the
80
- code to use ("Save 50% with code LAUNCH50 for 3 months").
78
+ its `bullet_details`, which `GET /v1/plans`, the pricing snapshot and the customer portal's plans
79
+ all carry: the tenant's own pricing-page bullets, else each feature by its name with its
80
+ description under it, by its description when it has no name, and by its id only when it has
81
+ neither. Without them, it lists its `bullets`, its `display_features` or its feature ids. A
82
+ pricing-page plan with a public promotion shows its promotional price, the regular one struck
83
+ through, and the code to use ("Save 50% with code LAUNCH50 for 3 months").
84
+
85
+ A plan whose `stripe_price_monthly_usd` is `null` has no fixed price and shows "Custom". A plan's
86
+ own `cta.label` names its button, and its `cta.url` may also be a path on your site
87
+ (`/signup?plan=pro`). A plan's `badges` (an array of text) show next to its `badge`.
88
+
89
+ For a catalog you manage rather than sell from, such as an admin page: `selectedPlanId` and
90
+ `onPlanClick(plan)` make each card selectable, and `renderFooter(plan)` puts your own content
91
+ (counts, edit buttons) where each card's button would be. A click inside it doesn't select the
92
+ card.
81
93
 
82
94
  ### Base URL: `<MeterboxProvider baseUrl>`
83
95
 
@@ -89,8 +101,8 @@ resolved URL for your own calls.
89
101
  ### Branding: `<BrandingProvider branding>`
90
102
 
91
103
  Every component styles itself from `--mbx-*` CSS variables (`--mbx-accent`,
92
- `--mbx-text`, `--mbx-card`, `--mbx-font`, `--mbx-radius` and the button
93
- variables), with Meterbox's defaults as fallbacks. Wrap them in
104
+ `--mbx-text`, `--mbx-card`, `--mbx-border`, `--mbx-font`, `--mbx-radius` and the
105
+ button variables), with Meterbox's defaults as fallbacks. Wrap them in
94
106
  `<BrandingProvider branding={branding}>` to apply your branding from
95
107
  Settings → Branding (`GET /v1/settings/branding`): logo, colors, font and
96
108
  button style. `<PricingTable publishableKey>` applies it from the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meterbox/react",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "Embeddable React components for Meterbox: pricing tables, subscription preview, credit balance and usage charts. Presentational by default, with data fetched by your backend via @meterbox/node.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://meterbox.ai",
@@ -35,12 +35,22 @@
35
35
  * each plan's button is its call-to-action link (`customerEmail` fills
36
36
  * {CUSTOMER_EMAIL} in it).
37
37
  *
38
- * A plan's list is its `bullets` (the snapshot and the customer portal's plan
39
- * list: the tenant's own bullets, else its features' labels), else its
40
- * `display_features`, else its feature ids made readable; its included
41
- * credits come first ("1,500 Bits a month"). A snapshot plan's `promotion`
42
- * shows its monthly price with the regular one struck through, and how to
43
- * get it ("Save 50% with code LAUNCH50 for 3 months").
38
+ * A plan's list is its `bullet_details` (the API's plans, the snapshot and the
39
+ * customer portal's plan list all carry it: the tenant's own bullets, else
40
+ * each feature by its label with its description under it, by its
41
+ * description when it has no label, by its id when it has neither), else
42
+ * its `bullets`, else its `display_features`, else its feature ids; its
43
+ * included credits come first ("1,500 Bits a month"). A snapshot plan's
44
+ * `promotion` shows its monthly price with the regular one struck through,
45
+ * and how to get it ("Save 50% with code LAUNCH50 for 3 months").
46
+ *
47
+ * A plan whose `stripe_price_monthly_usd` is null has no fixed price and
48
+ * shows "Custom". A plan's `cta.label` names its button, and its `cta.url`
49
+ * may also be a path on your own site ("/signup?plan=pro"). A plan's
50
+ * `badges` add to its `badge`. For a catalog you manage rather than sell
51
+ * from: `selectedPlanId` + `onPlanClick(plan)` make each card selectable,
52
+ * and `renderFooter(plan)` replaces each card's button with your own
53
+ * content (a click inside it doesn't select the card).
44
54
  *
45
55
  * Pure presentational + inline styles — no CSS pipeline required from the
46
56
  * tenant.
@@ -71,8 +81,8 @@ const styles = {
71
81
  padding: 4,
72
82
  width: "fit-content",
73
83
  margin: "0 auto",
74
- background: "#f3f4f6",
75
- border: "1px solid #e5e7eb",
84
+ background: theme.accentTint(6),
85
+ border: `1px solid ${theme.border}`,
76
86
  borderRadius: 999,
77
87
  },
78
88
  toggleBtn: {
@@ -80,7 +90,7 @@ const styles = {
80
90
  borderRadius: 999,
81
91
  border: "none",
82
92
  background: "transparent",
83
- color: "#4b5563",
93
+ color: theme.text,
84
94
  fontSize: 13,
85
95
  fontWeight: 600,
86
96
  fontFamily: theme.font,
@@ -95,7 +105,7 @@ const styles = {
95
105
  color: theme.text,
96
106
  },
97
107
  card: {
98
- border: "1px solid #e5e7eb",
108
+ border: `1px solid ${theme.border}`,
99
109
  borderRadius: 12,
100
110
  padding: 20,
101
111
  background: theme.card,
@@ -117,7 +127,7 @@ const styles = {
117
127
  cursor: "pointer",
118
128
  },
119
129
  ctaCurrent: {
120
- background: "#e5e7eb",
130
+ background: theme.accentTint(12),
121
131
  color: theme.text,
122
132
  border: "1px solid transparent",
123
133
  cursor: "default",
@@ -129,9 +139,10 @@ const styles = {
129
139
  display: "grid",
130
140
  gap: 4,
131
141
  fontSize: 12,
132
- borderTop: "1px solid #e5e7eb",
142
+ borderTop: `1px solid ${theme.border}`,
133
143
  paddingTop: 10,
134
144
  },
145
+ bulletDescription: { fontSize: 12, opacity: 0.65, marginLeft: 12 },
135
146
  badge: {
136
147
  fontSize: 11,
137
148
  fontWeight: 600,
@@ -139,15 +150,20 @@ const styles = {
139
150
  color: "#fff",
140
151
  padding: "2px 8px",
141
152
  borderRadius: 999,
142
- alignSelf: "flex-start",
143
153
  },
154
+ badges: { display: "flex", flexWrap: "wrap", gap: 6 },
144
155
  };
145
156
 
146
- /** What a plan lists: its bullets, else its own display text, else its feature ids. */
157
+ /**
158
+ * What a plan lists, as `{ text, description }`: its `bullet_details`, else
159
+ * its bullets, else its own display text, else its feature ids.
160
+ */
147
161
  function planBullets(plan) {
148
- if (Array.isArray(plan.bullets)) return plan.bullets;
149
- if (plan.display_features?.length) return plan.display_features;
150
- return (plan.features || []).map((f) => f.replace(/_/g, " "));
162
+ if (Array.isArray(plan.bullet_details)) return plan.bullet_details;
163
+ let texts = plan.features || [];
164
+ if (Array.isArray(plan.bullets)) texts = plan.bullets;
165
+ else if (plan.display_features?.length) texts = plan.display_features;
166
+ return texts.map((text) => ({ text, description: null }));
151
167
  }
152
168
 
153
169
  /** "1,500 Bits a month", or "$15 of credit a month" without a credit unit. */
@@ -243,8 +259,8 @@ function PlanUsage({ usage }) {
243
259
  );
244
260
  }
245
261
 
246
- // A plan's call-to-action link from the snapshot, {CUSTOMER_EMAIL} filled in;
247
- // null unless it's an http(s), mailto: or tel: link.
262
+ // A plan's call-to-action link, {CUSTOMER_EMAIL} filled in; null unless it's
263
+ // an http(s), mailto: or tel: link, or a path on this site.
248
264
  function ctaLink(plan, customerEmail) {
249
265
  if (!plan.cta?.url) return null;
250
266
  const email = encodeURIComponent(customerEmail || "");
@@ -253,7 +269,7 @@ function ctaLink(plan, customerEmail) {
253
269
  .join(email)
254
270
  .split("%7BCUSTOMER_EMAIL%7D")
255
271
  .join(email);
256
- return /^(https?:|mailto:|tel:)/i.test(url) ? { url, label: plan.cta.label } : null;
272
+ return /^(https?:|mailto:|tel:|\/(?!\/))/i.test(url) ? { url, label: plan.cta.label } : null;
257
273
  }
258
274
 
259
275
  /** A plan from the public snapshot, in the shape the table renders. */
@@ -264,6 +280,7 @@ function fromSnapshot(p) {
264
280
  description: p.description || null,
265
281
  features: p.features || [],
266
282
  bullets: p.bullets || null,
283
+ bullet_details: p.bullet_details || null,
267
284
  included_credits: p.included_credits || null,
268
285
  promotion: p.promotion || null,
269
286
  stripe_price_monthly_usd: p.price ? p.price.monthly_usd : 0,
@@ -292,6 +309,9 @@ function PricingTable({
292
309
  currentPlanId,
293
310
  currency = "USD",
294
311
  onSelect,
312
+ selectedPlanId,
313
+ onPlanClick,
314
+ renderFooter,
295
315
  customerEmail,
296
316
  branding,
297
317
  baseUrl: baseUrlProp,
@@ -363,33 +383,121 @@ function PricingTable({
363
383
  { style: styles.grid },
364
384
  list.map((plan) => {
365
385
  const isCurrent = plan.id === currentPlanId;
386
+ const isSelected = plan.id === selectedPlanId;
366
387
  const localized = (plan.localized_prices || []).find(
367
388
  (p) => (p.currency || "").toUpperCase() === currency.toUpperCase(),
368
389
  );
369
390
  const monthlyAmount = localized ? localized.monthly_amount : plan.stripe_price_monthly_usd;
370
391
  const displayCurrency = localized ? localized.currency : "USD";
392
+ // No fixed price: "Custom", with no period, annual total or promotion.
393
+ const custom = monthlyAmount == null;
371
394
  // Annual only applies when THIS plan offers it — a plan without
372
395
  // annual_free_months always shows its monthly price, even while the
373
396
  // toggle above is set to "Annual" for its siblings.
374
397
  const annual = billingInterval === "annual" ? annualPriceUsd(plan) : null;
375
398
  const link = !onSelect && !isCurrent ? ctaLink(plan, customerEmail) : null;
376
399
  // A promotion is on the monthly USD price.
377
- const promo = annual == null && displayCurrency === "USD" ? plan.promotion : null;
400
+ const promo =
401
+ !custom && annual == null && displayCurrency === "USD" ? plan.promotion : null;
378
402
  const bullets = [
379
- ...(plan.included_credits ? [creditsText(i18n, plan.included_credits)] : []),
403
+ ...(plan.included_credits
404
+ ? [{ text: creditsText(i18n, plan.included_credits), description: null }]
405
+ : []),
380
406
  ...planBullets(plan),
381
407
  ];
408
+ const badges = [isCurrent ? t("pricing.current") : plan.badge, ...(plan.badges || [])];
409
+ const select = onPlanClick ? () => onPlanClick(plan) : null;
410
+ const outlined = isCurrent || isSelected || plan.highlight;
411
+ let price;
412
+ if (custom) {
413
+ price = React.createElement("span", { style: styles.price }, t("pricing.custom"));
414
+ } else {
415
+ price = [
416
+ promo &&
417
+ React.createElement(
418
+ "s",
419
+ { key: "was", style: styles.wasPrice },
420
+ money(monthlyAmount),
421
+ ),
422
+ React.createElement(
423
+ "span",
424
+ { key: "price", style: styles.price },
425
+ money(
426
+ promo ? promo.monthly_usd : annual != null ? annual : monthlyAmount,
427
+ displayCurrency,
428
+ ),
429
+ ),
430
+ React.createElement(
431
+ "span",
432
+ { key: "period", style: styles.perMonth },
433
+ annual != null ? t("pricing.billedAnnually") : t("pricing.perMonth"),
434
+ ),
435
+ ];
436
+ }
437
+ let action;
438
+ if (renderFooter) {
439
+ // Its own controls: a click inside it doesn't select the card.
440
+ action = React.createElement(
441
+ "div",
442
+ { style: { marginTop: "auto" }, onClick: select ? (e) => e.stopPropagation() : null },
443
+ renderFooter(plan),
444
+ );
445
+ } else if (link) {
446
+ action = React.createElement(
447
+ "a",
448
+ {
449
+ href: link.url,
450
+ style: { ...styles.cta, textAlign: "center", textDecoration: "none" },
451
+ },
452
+ link.label,
453
+ );
454
+ } else {
455
+ action = React.createElement(
456
+ "button",
457
+ {
458
+ type: "button",
459
+ style: isCurrent ? { ...styles.cta, ...styles.ctaCurrent } : styles.cta,
460
+ disabled: isCurrent,
461
+ onClick: () => (onSelect ? onSelect(plan, billingInterval) : undefined),
462
+ "aria-label": t(isCurrent ? "pricing.currentlyOn" : "pricing.choose", {
463
+ plan: plan.name || plan.id,
464
+ }),
465
+ },
466
+ isCurrent ? t("pricing.currentPlan") : plan.cta?.label || t("pricing.choosePlan"),
467
+ );
468
+ }
382
469
  return React.createElement(
383
470
  "div",
384
471
  {
385
472
  key: plan.id,
386
- style:
387
- isCurrent || plan.highlight ? { ...styles.card, ...styles.cardCurrent } : styles.card,
473
+ style: {
474
+ ...styles.card,
475
+ ...(outlined ? styles.cardCurrent : null),
476
+ ...(select ? { cursor: "pointer" } : null),
477
+ },
478
+ ...(select && {
479
+ role: "button",
480
+ tabIndex: 0,
481
+ "aria-pressed": isSelected,
482
+ onClick: select,
483
+ onKeyDown: (e) => {
484
+ if (e.target === e.currentTarget && (e.key === "Enter" || e.key === " ")) {
485
+ e.preventDefault();
486
+ select();
487
+ }
488
+ },
489
+ }),
388
490
  },
389
- isCurrent && React.createElement("span", { style: styles.badge }, t("pricing.current")),
390
- !isCurrent &&
391
- plan.badge &&
392
- React.createElement("span", { style: styles.badge }, plan.badge),
491
+ badges.some(Boolean) &&
492
+ React.createElement(
493
+ "div",
494
+ { style: styles.badges },
495
+ badges
496
+ .filter(Boolean)
497
+ .map((b, i) =>
498
+ React.createElement("span", { key: `${i}:${b}`, style: styles.badge }, b),
499
+ ),
500
+ ),
393
501
  React.createElement("h3", { style: styles.name }, plan.name || plan.id),
394
502
  plan.description &&
395
503
  React.createElement(
@@ -397,24 +505,7 @@ function PricingTable({
397
505
  { style: { fontSize: 13, opacity: 0.75, margin: 0 } },
398
506
  plan.description,
399
507
  ),
400
- React.createElement(
401
- "div",
402
- null,
403
- promo && React.createElement("s", { style: styles.wasPrice }, money(monthlyAmount)),
404
- React.createElement(
405
- "span",
406
- { style: styles.price },
407
- money(
408
- promo ? promo.monthly_usd : annual != null ? annual : monthlyAmount,
409
- displayCurrency,
410
- ),
411
- ),
412
- React.createElement(
413
- "span",
414
- { style: styles.perMonth },
415
- annual != null ? t("pricing.billedAnnually") : t("pricing.perMonth"),
416
- ),
417
- ),
508
+ React.createElement("div", null, price),
418
509
  promo && React.createElement("div", { style: styles.promo }, promoText(i18n, promo)),
419
510
  plan.trial_days > 0 &&
420
511
  React.createElement(
@@ -426,31 +517,19 @@ function PricingTable({
426
517
  React.createElement(
427
518
  "ul",
428
519
  { style: styles.features },
429
- bullets.map((b, i) => React.createElement("li", { key: `${i}:${b}` }, `• ${b}`)),
520
+ bullets.map((b, i) =>
521
+ React.createElement(
522
+ "li",
523
+ { key: `${i}:${b.text}` },
524
+ React.createElement("span", { "aria-hidden": true }, "• "),
525
+ React.createElement("span", null, b.text),
526
+ b.description &&
527
+ React.createElement("div", { style: styles.bulletDescription }, b.description),
528
+ ),
529
+ ),
430
530
  ),
431
531
  plan.usage && React.createElement(PlanUsage, { usage: plan.usage }),
432
- link
433
- ? React.createElement(
434
- "a",
435
- {
436
- href: link.url,
437
- style: { ...styles.cta, textAlign: "center", textDecoration: "none" },
438
- },
439
- link.label,
440
- )
441
- : React.createElement(
442
- "button",
443
- {
444
- type: "button",
445
- style: isCurrent ? { ...styles.cta, ...styles.ctaCurrent } : styles.cta,
446
- disabled: isCurrent,
447
- onClick: () => (onSelect ? onSelect(plan, billingInterval) : undefined),
448
- "aria-label": t(isCurrent ? "pricing.currentlyOn" : "pricing.choose", {
449
- plan: plan.name || plan.id,
450
- }),
451
- },
452
- isCurrent ? t("pricing.currentPlan") : t("pricing.choosePlan"),
453
- ),
532
+ action,
454
533
  );
455
534
  }),
456
535
  ),
package/src/i18n.js CHANGED
@@ -73,6 +73,7 @@ const en = {
73
73
  "pricing.choose": "Choose {plan}",
74
74
  "pricing.currentPlan": "Current plan",
75
75
  "pricing.choosePlan": "Choose plan",
76
+ "pricing.custom": "Custom",
76
77
  "pricing.perMonth": "/ month",
77
78
  "pricing.billedAnnually": "billed annually",
78
79
  "pricing.trial": "{days}-day free trial",
@@ -223,6 +224,7 @@ const es = {
223
224
  "pricing.choose": "Elegir {plan}",
224
225
  "pricing.currentPlan": "Plan actual",
225
226
  "pricing.choosePlan": "Elegir plan",
227
+ "pricing.custom": "Personalizado",
226
228
  "pricing.perMonth": "/ mes",
227
229
  "pricing.billedAnnually": "facturado anualmente",
228
230
  "pricing.trial": "Prueba gratuita de {days} días",
@@ -373,6 +375,7 @@ const fr = {
373
375
  "pricing.choose": "Choisir {plan}",
374
376
  "pricing.currentPlan": "Forfait actuel",
375
377
  "pricing.choosePlan": "Choisir ce forfait",
378
+ "pricing.custom": "Sur mesure",
376
379
  "pricing.perMonth": "/ mois",
377
380
  "pricing.billedAnnually": "facturé annuellement",
378
381
  "pricing.trial": "Essai gratuit de {days} jours",
@@ -523,6 +526,7 @@ const de = {
523
526
  "pricing.choose": "{plan} wählen",
524
527
  "pricing.currentPlan": "Aktueller Tarif",
525
528
  "pricing.choosePlan": "Tarif wählen",
529
+ "pricing.custom": "Individuell",
526
530
  "pricing.perMonth": "/ Monat",
527
531
  "pricing.billedAnnually": "jährlich abgerechnet",
528
532
  "pricing.trial": "{days} Tage kostenlos testen",
package/src/theme.js CHANGED
@@ -13,6 +13,7 @@ module.exports = {
13
13
  accentTint: (pct = 12) => `color-mix(in srgb, ${accent} ${pct}%, transparent)`,
14
14
  text: "var(--mbx-text, #111)",
15
15
  card: "var(--mbx-card, #fff)",
16
+ border: "var(--mbx-border, #e5e7eb)",
16
17
  font: "var(--mbx-font, system-ui, -apple-system, sans-serif)",
17
18
  // Primary buttons: filled with the accent, or outlined (branding's button_style).
18
19
  button: {