@meterbox/react 0.1.10 → 0.1.12
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 +3 -3
- package/package.json +2 -2
- package/src/PlanComparison.js +21 -12
- package/src/PricingTable.js +90 -14
- package/src/SubscriptionPreview.js +3 -1
- package/src/UsageProgress.js +6 -3
- package/src/i18n.js +5 -0
package/README.md
CHANGED
|
@@ -76,9 +76,9 @@ 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
78
|
its `bullet_details`, which `GET /v1/plans`, the pricing snapshot and the customer portal's plans
|
|
79
|
-
all carry:
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
all carry: each feature by its name on the plan, else by its label with its description behind an
|
|
80
|
+
info icon, by its description when it has no label, and by its id only when it has neither. Without them, it
|
|
81
|
+
lists its `bullets`, else its `features` (`[{ id, name }]`) by name, else by id. A
|
|
82
82
|
pricing-page plan with a public promotion shows its promotional price, the regular one struck
|
|
83
83
|
through, and the code to use ("Save 50% with code LAUNCH50 for 3 months").
|
|
84
84
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meterbox/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
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",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@meterbox/node": "0.1.
|
|
20
|
+
"@meterbox/node": "0.1.2"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"react": ">=17",
|
package/src/PlanComparison.js
CHANGED
|
@@ -45,6 +45,18 @@ const styles = {
|
|
|
45
45
|
},
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
+
// A plan's features by id, each as it reads: its name on the plan, else its
|
|
49
|
+
// id in words (`{ id, name }`; ids alone in older records).
|
|
50
|
+
function featuresOf(plan) {
|
|
51
|
+
const list = Array.isArray(plan.features) ? plan.features : [];
|
|
52
|
+
return new Map(
|
|
53
|
+
list.map((f) => {
|
|
54
|
+
const id = typeof f === "string" ? f : f.id;
|
|
55
|
+
return [id, (typeof f === "string" ? null : f.name) || id.replace(/_/g, " ")];
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
48
60
|
function PlanComparison({ from, to, onSwitch }) {
|
|
49
61
|
if (!from || !to) {
|
|
50
62
|
return React.createElement(
|
|
@@ -53,10 +65,11 @@ function PlanComparison({ from, to, onSwitch }) {
|
|
|
53
65
|
"Pick a plan to compare.",
|
|
54
66
|
);
|
|
55
67
|
}
|
|
56
|
-
const fromFeatures =
|
|
57
|
-
const toFeatures =
|
|
58
|
-
const
|
|
59
|
-
const
|
|
68
|
+
const fromFeatures = featuresOf(from);
|
|
69
|
+
const toFeatures = featuresOf(to);
|
|
70
|
+
const text = (id) => toFeatures.get(id) || fromFeatures.get(id);
|
|
71
|
+
const added = [...toFeatures.keys()].filter((f) => !fromFeatures.has(f));
|
|
72
|
+
const removed = [...fromFeatures.keys()].filter((f) => !toFeatures.has(f));
|
|
60
73
|
|
|
61
74
|
function FeatureList(features, extras) {
|
|
62
75
|
return React.createElement(
|
|
@@ -66,17 +79,13 @@ function PlanComparison({ from, to, onSwitch }) {
|
|
|
66
79
|
React.createElement(
|
|
67
80
|
"li",
|
|
68
81
|
{ key: f, style: extras?.removed?.has(f) ? styles.removed : null },
|
|
69
|
-
`• ${f
|
|
82
|
+
`• ${text(f)}`,
|
|
70
83
|
),
|
|
71
84
|
),
|
|
72
85
|
added.length > 0 &&
|
|
73
86
|
extras?.showAdded &&
|
|
74
87
|
added.map((f) =>
|
|
75
|
-
React.createElement(
|
|
76
|
-
"li",
|
|
77
|
-
{ key: `added-${f}`, style: styles.added },
|
|
78
|
-
`+ ${f.replace(/_/g, " ")}`,
|
|
79
|
-
),
|
|
88
|
+
React.createElement("li", { key: `added-${f}`, style: styles.added }, `+ ${text(f)}`),
|
|
80
89
|
),
|
|
81
90
|
);
|
|
82
91
|
}
|
|
@@ -89,7 +98,7 @@ function PlanComparison({ from, to, onSwitch }) {
|
|
|
89
98
|
{ style: styles.col },
|
|
90
99
|
React.createElement("h4", { style: styles.heading }, "Current"),
|
|
91
100
|
React.createElement("h3", { style: styles.planName }, from.name || from.id),
|
|
92
|
-
FeatureList(Array.from(fromFeatures), { removed: new Set(removed) }),
|
|
101
|
+
FeatureList(Array.from(fromFeatures.keys()), { removed: new Set(removed) }),
|
|
93
102
|
),
|
|
94
103
|
React.createElement(
|
|
95
104
|
"div",
|
|
@@ -97,7 +106,7 @@ function PlanComparison({ from, to, onSwitch }) {
|
|
|
97
106
|
React.createElement("h4", { style: styles.heading }, "Switching to"),
|
|
98
107
|
React.createElement("h3", { style: styles.planName }, to.name || to.id),
|
|
99
108
|
FeatureList(
|
|
100
|
-
Array.from(toFeatures).filter((f) => !added.includes(f)),
|
|
109
|
+
Array.from(toFeatures.keys()).filter((f) => !added.includes(f)),
|
|
101
110
|
{ showAdded: true },
|
|
102
111
|
),
|
|
103
112
|
onSwitch &&
|
package/src/PricingTable.js
CHANGED
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
* {CUSTOMER_EMAIL} in it).
|
|
37
37
|
*
|
|
38
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:
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* its `
|
|
43
|
-
*
|
|
39
|
+
* customer portal's plan list all carry it: each feature by its name on the
|
|
40
|
+
* plan, else its label with its description behind an info icon, by its description
|
|
41
|
+
* when it has no label, by its id when it has neither), else its `bullets`,
|
|
42
|
+
* else its features (`{ id, name }`) by name, else by id; its included
|
|
43
|
+
* credits come first ("1,500 Bits a month"). A snapshot plan's
|
|
44
44
|
* `promotion` shows its monthly price with the regular one struck through,
|
|
45
45
|
* and how to get it ("Save 50% with code LAUNCH50 for 3 months").
|
|
46
46
|
*
|
|
@@ -142,7 +142,38 @@ const styles = {
|
|
|
142
142
|
borderTop: `1px solid ${theme.border}`,
|
|
143
143
|
paddingTop: 10,
|
|
144
144
|
},
|
|
145
|
-
|
|
145
|
+
infoWrap: { position: "relative", display: "inline-block", marginLeft: 4 },
|
|
146
|
+
infoButton: {
|
|
147
|
+
width: 16,
|
|
148
|
+
height: 16,
|
|
149
|
+
padding: 0,
|
|
150
|
+
border: `1px solid ${theme.border}`,
|
|
151
|
+
borderRadius: "50%",
|
|
152
|
+
background: "transparent",
|
|
153
|
+
color: "inherit",
|
|
154
|
+
fontSize: 10,
|
|
155
|
+
fontWeight: 700,
|
|
156
|
+
lineHeight: "14px",
|
|
157
|
+
opacity: 0.6,
|
|
158
|
+
cursor: "pointer",
|
|
159
|
+
verticalAlign: "middle",
|
|
160
|
+
},
|
|
161
|
+
infoBubble: {
|
|
162
|
+
position: "absolute",
|
|
163
|
+
top: "calc(100% + 6px)",
|
|
164
|
+
left: -8,
|
|
165
|
+
zIndex: 10,
|
|
166
|
+
width: 220,
|
|
167
|
+
padding: "8px 10px",
|
|
168
|
+
border: `1px solid ${theme.border}`,
|
|
169
|
+
borderRadius: 8,
|
|
170
|
+
background: theme.card,
|
|
171
|
+
color: theme.text,
|
|
172
|
+
fontSize: 12,
|
|
173
|
+
fontWeight: 400,
|
|
174
|
+
lineHeight: 1.4,
|
|
175
|
+
boxShadow: "0 4px 16px rgba(0,0,0,0.18)",
|
|
176
|
+
},
|
|
146
177
|
badge: {
|
|
147
178
|
fontSize: 11,
|
|
148
179
|
fontWeight: 600,
|
|
@@ -156,13 +187,13 @@ const styles = {
|
|
|
156
187
|
|
|
157
188
|
/**
|
|
158
189
|
* What a plan lists, as `{ text, description }`: its `bullet_details`, else
|
|
159
|
-
* its bullets, else its
|
|
190
|
+
* its bullets, else its features by name, else by id.
|
|
160
191
|
*/
|
|
161
192
|
function planBullets(plan) {
|
|
162
193
|
if (Array.isArray(plan.bullet_details)) return plan.bullet_details;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
194
|
+
const texts = Array.isArray(plan.bullets)
|
|
195
|
+
? plan.bullets
|
|
196
|
+
: (plan.features || []).map((f) => (typeof f === "string" ? f : f.name || f.id));
|
|
166
197
|
return texts.map((text) => ({ text, description: null }));
|
|
167
198
|
}
|
|
168
199
|
|
|
@@ -208,6 +239,50 @@ function ladderText({ t, money, number }, tiers, scale) {
|
|
|
208
239
|
.join(` ${t("pricing.then")} `);
|
|
209
240
|
}
|
|
210
241
|
|
|
242
|
+
/**
|
|
243
|
+
* A feature's description, behind an info icon next to its name: opens on
|
|
244
|
+
* click (so touch works too), closes on a second click, Escape or a click
|
|
245
|
+
* anywhere else.
|
|
246
|
+
*/
|
|
247
|
+
function FeatureInfo({ label, children }) {
|
|
248
|
+
const [open, setOpen] = React.useState(false);
|
|
249
|
+
const ref = React.useRef(null);
|
|
250
|
+
React.useEffect(() => {
|
|
251
|
+
if (!open) return undefined;
|
|
252
|
+
const onPointer = (e) => {
|
|
253
|
+
if (ref.current && !ref.current.contains(e.target)) setOpen(false);
|
|
254
|
+
};
|
|
255
|
+
const onKey = (e) => {
|
|
256
|
+
if (e.key === "Escape") setOpen(false);
|
|
257
|
+
};
|
|
258
|
+
// No document outside a DOM renderer (tests, server rendering).
|
|
259
|
+
const doc = ref.current?.ownerDocument;
|
|
260
|
+
if (!doc) return undefined;
|
|
261
|
+
doc.addEventListener("mousedown", onPointer);
|
|
262
|
+
doc.addEventListener("keydown", onKey);
|
|
263
|
+
return () => {
|
|
264
|
+
doc.removeEventListener("mousedown", onPointer);
|
|
265
|
+
doc.removeEventListener("keydown", onKey);
|
|
266
|
+
};
|
|
267
|
+
}, [open]);
|
|
268
|
+
return React.createElement(
|
|
269
|
+
"span",
|
|
270
|
+
{ ref, style: styles.infoWrap },
|
|
271
|
+
React.createElement(
|
|
272
|
+
"button",
|
|
273
|
+
{
|
|
274
|
+
type: "button",
|
|
275
|
+
"aria-label": label,
|
|
276
|
+
"aria-expanded": open,
|
|
277
|
+
style: styles.infoButton,
|
|
278
|
+
onClick: () => setOpen((o) => !o),
|
|
279
|
+
},
|
|
280
|
+
"i",
|
|
281
|
+
),
|
|
282
|
+
open && React.createElement("span", { role: "tooltip", style: styles.infoBubble }, children),
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
|
|
211
286
|
/** Included amounts, what happens past them, and the models' rates. */
|
|
212
287
|
function PlanUsage({ usage }) {
|
|
213
288
|
const i18n = useI18n();
|
|
@@ -260,7 +335,8 @@ function PlanUsage({ usage }) {
|
|
|
260
335
|
}
|
|
261
336
|
|
|
262
337
|
// 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
|
|
338
|
+
// an http(s), mailto: or tel: link, or a path on this site (not one a
|
|
339
|
+
// browser reads as another host: "//", "/\\").
|
|
264
340
|
function ctaLink(plan, customerEmail) {
|
|
265
341
|
if (!plan.cta?.url) return null;
|
|
266
342
|
const email = encodeURIComponent(customerEmail || "");
|
|
@@ -269,7 +345,7 @@ function ctaLink(plan, customerEmail) {
|
|
|
269
345
|
.join(email)
|
|
270
346
|
.split("%7BCUSTOMER_EMAIL%7D")
|
|
271
347
|
.join(email);
|
|
272
|
-
return /^(https?:|mailto:|tel:|\/(
|
|
348
|
+
return /^(https?:|mailto:|tel:|\/(?![/\\]))/i.test(url) ? { url, label: plan.cta.label } : null;
|
|
273
349
|
}
|
|
274
350
|
|
|
275
351
|
/** A plan from the public snapshot, in the shape the table renders. */
|
|
@@ -283,7 +359,7 @@ function fromSnapshot(p) {
|
|
|
283
359
|
bullet_details: p.bullet_details || null,
|
|
284
360
|
included_credits: p.included_credits || null,
|
|
285
361
|
promotion: p.promotion || null,
|
|
286
|
-
stripe_price_monthly_usd: p.price ? p.price.monthly_usd :
|
|
362
|
+
stripe_price_monthly_usd: p.price ? p.price.monthly_usd : null,
|
|
287
363
|
annual_free_months: p.annual_free_months == null ? null : p.annual_free_months,
|
|
288
364
|
localized_prices: p.localized_prices || [],
|
|
289
365
|
usage: p.usage || null,
|
|
@@ -524,7 +600,7 @@ function PricingTable({
|
|
|
524
600
|
React.createElement("span", { "aria-hidden": true }, "• "),
|
|
525
601
|
React.createElement("span", null, b.text),
|
|
526
602
|
b.description &&
|
|
527
|
-
React.createElement(
|
|
603
|
+
React.createElement(FeatureInfo, { label: `About ${b.text}` }, b.description),
|
|
528
604
|
),
|
|
529
605
|
),
|
|
530
606
|
),
|
|
@@ -148,7 +148,9 @@ function SubscriptionPreview({
|
|
|
148
148
|
// admin endpoint). Field names match the backend exactly.
|
|
149
149
|
const current = data.current || null;
|
|
150
150
|
const target = data.target || null;
|
|
151
|
-
|
|
151
|
+
// Null new_mrr_usd: the plan has no fixed price, so the new MRR isn't known.
|
|
152
|
+
const newMrr =
|
|
153
|
+
"new_mrr_usd" in data ? data.new_mrr_usd : (data.proration?.new_plan_prorated_usd ?? null);
|
|
152
154
|
const prevMrr = current ? current.price_monthly_usd : null;
|
|
153
155
|
const mrrDelta = newMrr != null && prevMrr != null ? newMrr - prevMrr : null;
|
|
154
156
|
const amountDue = data.amount_due_usd ?? null;
|
package/src/UsageProgress.js
CHANGED
|
@@ -96,8 +96,11 @@ function UsageProgress({
|
|
|
96
96
|
if (!data) return null;
|
|
97
97
|
|
|
98
98
|
const used = data.usage?.[metric] ?? 0;
|
|
99
|
-
|
|
100
|
-
const
|
|
99
|
+
// No limit (null): no bar to fill. None included (0): any use fills it.
|
|
100
|
+
const cap = data.plan?.limits?.[metric] ?? null;
|
|
101
|
+
let fraction = 0;
|
|
102
|
+
if (cap > 0) fraction = Math.min(1, used / cap);
|
|
103
|
+
else if (cap === 0 && used > 0) fraction = 1;
|
|
101
104
|
const fillStyle = { ...styles.fill, width: `${fraction * 100}%` };
|
|
102
105
|
if (fraction >= dangerAt) Object.assign(fillStyle, styles.danger);
|
|
103
106
|
else if (fraction >= warnAt) Object.assign(fillStyle, styles.warn);
|
|
@@ -112,7 +115,7 @@ function UsageProgress({
|
|
|
112
115
|
React.createElement(
|
|
113
116
|
"span",
|
|
114
117
|
{ style: styles.value },
|
|
115
|
-
`${used.toLocaleString()}${cap
|
|
118
|
+
`${used.toLocaleString()}${cap != null ? ` / ${cap.toLocaleString()}` : ""}`,
|
|
116
119
|
),
|
|
117
120
|
),
|
|
118
121
|
React.createElement(
|
package/src/i18n.js
CHANGED
|
@@ -42,6 +42,7 @@ const en = {
|
|
|
42
42
|
"plans.error": "Could not load plans.",
|
|
43
43
|
"plans.annualNote":
|
|
44
44
|
"Cost preview isn't available for annual billing yet — the amount due will be confirmed at checkout.",
|
|
45
|
+
"plans.noFixedPrice": "{plan} has no fixed price. Get in touch to move to it.",
|
|
45
46
|
|
|
46
47
|
"cancel.button": "Cancel subscription",
|
|
47
48
|
"cancel.why": "Why are you cancelling?",
|
|
@@ -193,6 +194,7 @@ const es = {
|
|
|
193
194
|
"plans.error": "No se pudieron cargar los planes.",
|
|
194
195
|
"plans.annualNote":
|
|
195
196
|
"La vista previa del costo aún no está disponible para la facturación anual. El importe se confirma al pagar.",
|
|
197
|
+
"plans.noFixedPrice": "{plan} no tiene un precio fijo. Contáctanos para cambiarte a este plan.",
|
|
196
198
|
|
|
197
199
|
"cancel.button": "Cancelar suscripción",
|
|
198
200
|
"cancel.why": "¿Por qué cancelas?",
|
|
@@ -344,6 +346,7 @@ const fr = {
|
|
|
344
346
|
"plans.error": "Impossible de charger les forfaits.",
|
|
345
347
|
"plans.annualNote":
|
|
346
348
|
"L'aperçu du coût n'est pas encore disponible pour la facturation annuelle. Le montant dû est confirmé au paiement.",
|
|
349
|
+
"plans.noFixedPrice": "{plan} n'a pas de prix fixe. Contactez-nous pour passer à ce forfait.",
|
|
347
350
|
|
|
348
351
|
"cancel.button": "Résilier l'abonnement",
|
|
349
352
|
"cancel.why": "Pourquoi résiliez-vous ?",
|
|
@@ -495,6 +498,8 @@ const de = {
|
|
|
495
498
|
"plans.error": "Die Tarife konnten nicht geladen werden.",
|
|
496
499
|
"plans.annualNote":
|
|
497
500
|
"Eine Kostenvorschau ist für die jährliche Abrechnung noch nicht verfügbar. Der fällige Betrag wird beim Bezahlen bestätigt.",
|
|
501
|
+
"plans.noFixedPrice":
|
|
502
|
+
"{plan} hat keinen Festpreis. Kontaktieren Sie uns, um zu diesem Tarif zu wechseln.",
|
|
498
503
|
|
|
499
504
|
"cancel.button": "Abonnement kündigen",
|
|
500
505
|
"cancel.why": "Warum möchten Sie kündigen?",
|