@meterbox/react 0.1.7 → 0.1.8
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 +5 -0
- package/package.json +1 -1
- package/src/PricingTable.js +56 -7
- package/src/i18n.js +32 -0
package/README.md
CHANGED
|
@@ -74,6 +74,11 @@ pay for usage: the amounts included each month, what happens past them
|
|
|
74
74
|
(billed, stopped until next month, or an upgrade), and every model's input
|
|
75
75
|
and output rates per 1M tokens, tier ladders included.
|
|
76
76
|
|
|
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").
|
|
81
|
+
|
|
77
82
|
### Branding: `<BrandingProvider branding>`
|
|
78
83
|
|
|
79
84
|
Every component styles itself from `--mbx-*` CSS variables (`--mbx-accent`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meterbox/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
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",
|
package/src/PricingTable.js
CHANGED
|
@@ -35,6 +35,13 @@
|
|
|
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").
|
|
44
|
+
*
|
|
38
45
|
* Pure presentational + inline styles — no CSS pipeline required from the
|
|
39
46
|
* tenant.
|
|
40
47
|
*/
|
|
@@ -115,6 +122,8 @@ const styles = {
|
|
|
115
122
|
cursor: "default",
|
|
116
123
|
},
|
|
117
124
|
trial: { fontSize: 13, fontWeight: 600 },
|
|
125
|
+
wasPrice: { fontSize: 16, opacity: 0.5, marginRight: 6 },
|
|
126
|
+
promo: { fontSize: 12, fontWeight: 600, color: theme.accent },
|
|
118
127
|
usage: {
|
|
119
128
|
display: "grid",
|
|
120
129
|
gap: 4,
|
|
@@ -133,6 +142,34 @@ const styles = {
|
|
|
133
142
|
},
|
|
134
143
|
};
|
|
135
144
|
|
|
145
|
+
/** What a plan lists: its bullets, else its own display text, else its feature ids. */
|
|
146
|
+
function planBullets(plan) {
|
|
147
|
+
if (Array.isArray(plan.bullets)) return plan.bullets;
|
|
148
|
+
if (plan.display_features?.length) return plan.display_features;
|
|
149
|
+
return (plan.features || []).map((f) => f.replace(/_/g, " "));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** "1,500 Bits a month", or "$15 of credit a month" without a credit unit. */
|
|
153
|
+
function creditsText({ t, number, money }, c) {
|
|
154
|
+
return c.credit_units != null && c.credit_unit_name
|
|
155
|
+
? t("pricing.credits.units", { n: number(c.credit_units), unit: c.credit_unit_name })
|
|
156
|
+
: t("pricing.credits.usd", { amount: money(c.amount_usd) });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** "Save 50% with code LAUNCH50 for 3 months" */
|
|
160
|
+
function promoText({ t, money }, c) {
|
|
161
|
+
const save =
|
|
162
|
+
c.percent_off != null
|
|
163
|
+
? t("pricing.promo.percent", { pct: c.percent_off })
|
|
164
|
+
: t("pricing.promo.amount", { amount: money(c.amount_off_usd) });
|
|
165
|
+
const offer = t("pricing.promo.code", { save, code: c.code });
|
|
166
|
+
if (c.duration === "once") return t("pricing.promo.once", { offer });
|
|
167
|
+
if (c.duration === "repeating" && c.duration_in_months) {
|
|
168
|
+
return t("pricing.promo.months", { offer, count: c.duration_in_months });
|
|
169
|
+
}
|
|
170
|
+
return offer;
|
|
171
|
+
}
|
|
172
|
+
|
|
136
173
|
/** "$3.00 to 10M then $2.50" — a tier ladder priced per 1,000 units × `scale`. */
|
|
137
174
|
function ladderText({ t, money, number }, tiers, scale) {
|
|
138
175
|
const rate = (perUnit) => {
|
|
@@ -225,6 +262,9 @@ function fromSnapshot(p) {
|
|
|
225
262
|
name: p.name,
|
|
226
263
|
description: p.description || null,
|
|
227
264
|
features: p.features || [],
|
|
265
|
+
bullets: p.bullets || null,
|
|
266
|
+
included_credits: p.included_credits || null,
|
|
267
|
+
promotion: p.promotion || null,
|
|
228
268
|
stripe_price_monthly_usd: p.price ? p.price.monthly_usd : 0,
|
|
229
269
|
annual_free_months: p.annual_free_months == null ? null : p.annual_free_months,
|
|
230
270
|
localized_prices: p.localized_prices || [],
|
|
@@ -260,7 +300,8 @@ function PricingTable({
|
|
|
260
300
|
const selfFetch = !Array.isArray(plans) && !!baseUrl && !!publishableKey;
|
|
261
301
|
const [fetched, setFetched] = React.useState(null);
|
|
262
302
|
const [billingInterval, setBillingInterval] = React.useState("monthly");
|
|
263
|
-
const
|
|
303
|
+
const i18n = useI18n();
|
|
304
|
+
const { t, money } = i18n;
|
|
264
305
|
|
|
265
306
|
React.useEffect(() => {
|
|
266
307
|
if (!selfFetch) return undefined;
|
|
@@ -330,6 +371,12 @@ function PricingTable({
|
|
|
330
371
|
// toggle above is set to "Annual" for its siblings.
|
|
331
372
|
const annual = billingInterval === "annual" ? annualPriceUsd(plan) : null;
|
|
332
373
|
const link = !onSelect && !isCurrent ? ctaLink(plan, customerEmail) : null;
|
|
374
|
+
// A promotion is on the monthly USD price.
|
|
375
|
+
const promo = annual == null && displayCurrency === "USD" ? plan.promotion : null;
|
|
376
|
+
const bullets = [
|
|
377
|
+
...(plan.included_credits ? [creditsText(i18n, plan.included_credits)] : []),
|
|
378
|
+
...planBullets(plan),
|
|
379
|
+
];
|
|
333
380
|
return React.createElement(
|
|
334
381
|
"div",
|
|
335
382
|
{
|
|
@@ -351,10 +398,14 @@ function PricingTable({
|
|
|
351
398
|
React.createElement(
|
|
352
399
|
"div",
|
|
353
400
|
null,
|
|
401
|
+
promo && React.createElement("s", { style: styles.wasPrice }, money(monthlyAmount)),
|
|
354
402
|
React.createElement(
|
|
355
403
|
"span",
|
|
356
404
|
{ style: styles.price },
|
|
357
|
-
money(
|
|
405
|
+
money(
|
|
406
|
+
promo ? promo.monthly_usd : annual != null ? annual : monthlyAmount,
|
|
407
|
+
displayCurrency,
|
|
408
|
+
),
|
|
358
409
|
),
|
|
359
410
|
React.createElement(
|
|
360
411
|
"span",
|
|
@@ -362,20 +413,18 @@ function PricingTable({
|
|
|
362
413
|
annual != null ? t("pricing.billedAnnually") : t("pricing.perMonth"),
|
|
363
414
|
),
|
|
364
415
|
),
|
|
416
|
+
promo && React.createElement("div", { style: styles.promo }, promoText(i18n, promo)),
|
|
365
417
|
plan.trial_days > 0 &&
|
|
366
418
|
React.createElement(
|
|
367
419
|
"div",
|
|
368
420
|
{ style: styles.trial },
|
|
369
421
|
t("pricing.trial", { days: plan.trial_days }),
|
|
370
422
|
),
|
|
371
|
-
|
|
372
|
-
plan.features.length > 0 &&
|
|
423
|
+
bullets.length > 0 &&
|
|
373
424
|
React.createElement(
|
|
374
425
|
"ul",
|
|
375
426
|
{ style: styles.features },
|
|
376
|
-
|
|
377
|
-
React.createElement("li", { key: f }, `• ${f.replace(/_/g, " ")}`),
|
|
378
|
-
),
|
|
427
|
+
bullets.map((b, i) => React.createElement("li", { key: `${i}:${b}` }, `• ${b}`)),
|
|
379
428
|
),
|
|
380
429
|
plan.usage && React.createElement(PlanUsage, { usage: plan.usage }),
|
|
381
430
|
link
|
package/src/i18n.js
CHANGED
|
@@ -89,6 +89,14 @@ const en = {
|
|
|
89
89
|
"pricing.apiCallRates": "API calls: {ladder} per 1K",
|
|
90
90
|
"pricing.upTo": "{rate} to {n}",
|
|
91
91
|
"pricing.then": "then",
|
|
92
|
+
"pricing.promo.percent": "Save {pct}%",
|
|
93
|
+
"pricing.promo.amount": "Save {amount}",
|
|
94
|
+
"pricing.promo.code": "{save} with code {code}",
|
|
95
|
+
"pricing.promo.once": "{offer} on your first month",
|
|
96
|
+
"pricing.promo.months.one": "{offer} for {count} month",
|
|
97
|
+
"pricing.promo.months.other": "{offer} for {count} months",
|
|
98
|
+
"pricing.credits.units": "{n} {unit} a month",
|
|
99
|
+
"pricing.credits.usd": "{amount} of credit a month",
|
|
92
100
|
|
|
93
101
|
"planChange.scheduledOn": "Scheduled: applies on {date}.",
|
|
94
102
|
"planChange.changed": "Plan changed.",
|
|
@@ -231,6 +239,14 @@ const es = {
|
|
|
231
239
|
"pricing.apiCallRates": "Llamadas a la API: {ladder} por cada 1000",
|
|
232
240
|
"pricing.upTo": "{rate} hasta {n}",
|
|
233
241
|
"pricing.then": "luego",
|
|
242
|
+
"pricing.promo.percent": "Ahorra {pct}%",
|
|
243
|
+
"pricing.promo.amount": "Ahorra {amount}",
|
|
244
|
+
"pricing.promo.code": "{save} con el código {code}",
|
|
245
|
+
"pricing.promo.once": "{offer} el primer mes",
|
|
246
|
+
"pricing.promo.months.one": "{offer} durante {count} mes",
|
|
247
|
+
"pricing.promo.months.other": "{offer} durante {count} meses",
|
|
248
|
+
"pricing.credits.units": "{n} {unit} al mes",
|
|
249
|
+
"pricing.credits.usd": "{amount} de crédito al mes",
|
|
234
250
|
|
|
235
251
|
"planChange.scheduledOn": "Programado: se aplica el {date}.",
|
|
236
252
|
"planChange.changed": "Plan cambiado.",
|
|
@@ -373,6 +389,14 @@ const fr = {
|
|
|
373
389
|
"pricing.apiCallRates": "Appels API : {ladder} les 1 000",
|
|
374
390
|
"pricing.upTo": "{rate} jusqu'à {n}",
|
|
375
391
|
"pricing.then": "puis",
|
|
392
|
+
"pricing.promo.percent": "Économisez {pct} %",
|
|
393
|
+
"pricing.promo.amount": "Économisez {amount}",
|
|
394
|
+
"pricing.promo.code": "{save} avec le code {code}",
|
|
395
|
+
"pricing.promo.once": "{offer} le premier mois",
|
|
396
|
+
"pricing.promo.months.one": "{offer} pendant {count} mois",
|
|
397
|
+
"pricing.promo.months.other": "{offer} pendant {count} mois",
|
|
398
|
+
"pricing.credits.units": "{n} {unit} par mois",
|
|
399
|
+
"pricing.credits.usd": "{amount} de crédit par mois",
|
|
376
400
|
|
|
377
401
|
"planChange.scheduledOn": "Programmé : s'applique le {date}.",
|
|
378
402
|
"planChange.changed": "Forfait modifié.",
|
|
@@ -515,6 +539,14 @@ const de = {
|
|
|
515
539
|
"pricing.apiCallRates": "API-Aufrufe: {ladder} pro 1.000",
|
|
516
540
|
"pricing.upTo": "{rate} bis {n}",
|
|
517
541
|
"pricing.then": "danach",
|
|
542
|
+
"pricing.promo.percent": "Sparen Sie {pct} %",
|
|
543
|
+
"pricing.promo.amount": "Sparen Sie {amount}",
|
|
544
|
+
"pricing.promo.code": "{save} mit dem Code {code}",
|
|
545
|
+
"pricing.promo.once": "{offer} im ersten Monat",
|
|
546
|
+
"pricing.promo.months.one": "{offer} für {count} Monat",
|
|
547
|
+
"pricing.promo.months.other": "{offer} für {count} Monate",
|
|
548
|
+
"pricing.credits.units": "{n} {unit} pro Monat",
|
|
549
|
+
"pricing.credits.usd": "{amount} Guthaben pro Monat",
|
|
518
550
|
|
|
519
551
|
"planChange.scheduledOn": "Geplant: gilt ab {date}.",
|
|
520
552
|
"planChange.changed": "Tarif geändert.",
|