@meterbox/react 0.1.11 → 0.1.13
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 +11 -6
- package/package.json +2 -2
- package/src/PricingTable.js +105 -10
- package/src/i18n.js +4 -0
package/README.md
CHANGED
|
@@ -63,21 +63,26 @@ whichever interval was selected, ready to hand straight to
|
|
|
63
63
|
`<CheckoutButton billingInterval>`. `PricingTable.annualPriceUsd(plan)` is
|
|
64
64
|
exposed as a static if you need the same total outside the grid.
|
|
65
65
|
|
|
66
|
+
`PricingTable.fetchPricingPage({ publishableKey, baseUrl? })` resolves to the public pricing
|
|
67
|
+
snapshot as `{ plans, branding }`, each plan in the shape `<PricingTable plans>` takes: for a page
|
|
68
|
+
that uses the same plans elsewhere (a sign-up form's plan picker), or shows its own until the live
|
|
69
|
+
ones arrive.
|
|
70
|
+
|
|
66
71
|
From the snapshot, the featured plan is highlighted with its badge ("Most
|
|
67
72
|
popular"), a plan's free trial shows as "14-day free trial", and, without
|
|
68
73
|
`onSelect`, each plan's button is its own call-to-action link (e.g. Enterprise
|
|
69
74
|
to a contact page); `customerEmail` fills `{CUSTOMER_EMAIL}` in it.
|
|
70
75
|
|
|
71
76
|
Plans from the snapshot (or the customer portal's plan list) also carry
|
|
72
|
-
`usage
|
|
73
|
-
pay for usage: the amounts included each month,
|
|
74
|
-
(billed, stopped until next month, or an upgrade), and
|
|
75
|
-
and output rates per 1M tokens, tier ladders included.
|
|
77
|
+
`usage`. With `showUsage` (off by default), each card then shows what an AI
|
|
78
|
+
product's customers actually pay for usage: the amounts included each month,
|
|
79
|
+
what happens past them (billed, stopped until next month, or an upgrade), and
|
|
80
|
+
every model's input and output rates per 1M tokens, tier ladders included.
|
|
76
81
|
|
|
77
82
|
A plan lists its included credits first ("1,500 Bits a month", in the tenant's credit unit), then
|
|
78
83
|
its `bullet_details`, which `GET /v1/plans`, the pricing snapshot and the customer portal's plans
|
|
79
|
-
all carry: each feature by its name on the plan, else by its label with its description
|
|
80
|
-
by its description when it has no label, and by its id only when it has neither. Without them, it
|
|
84
|
+
all carry: each feature by its name on the plan, else by its label with its description behind an
|
|
85
|
+
info icon, by its description when it has no label, and by its id only when it has neither. Without them, it
|
|
81
86
|
lists its `bullets`, else its `features` (`[{ id, name }]`) by name, else by id. A
|
|
82
87
|
pricing-page plan with a public promotion shows its promotional price, the regular one struck
|
|
83
88
|
through, and the code to use ("Save 50% with code LAUNCH50 for 3 months").
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meterbox/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
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/PricingTable.js
CHANGED
|
@@ -21,23 +21,24 @@
|
|
|
21
21
|
* total divided back into a misleading "$X/mo" figure — a shopper who
|
|
22
22
|
* commits annually is billed once for the year, not monthly.
|
|
23
23
|
*
|
|
24
|
-
*
|
|
25
|
-
* list carry it) also shows its
|
|
26
|
-
* and its models' input and output
|
|
27
|
-
* included.
|
|
24
|
+
* With `showUsage` (off by default), a plan with `usage` (the pricing
|
|
25
|
+
* snapshot and the customer portal's plan list carry it) also shows its
|
|
26
|
+
* included amounts, what happens past them, and its models' input and output
|
|
27
|
+
* rates per 1M tokens, tier ladders included.
|
|
28
28
|
*
|
|
29
29
|
* Self-fetching, it takes the tenant's branding (Settings → Branding) from
|
|
30
30
|
* the snapshot; `branding` overrides it, and a <BrandingProvider> around it
|
|
31
31
|
* applies when neither is set.
|
|
32
32
|
*
|
|
33
33
|
* From the snapshot, the featured plan is highlighted with its `badge`, a
|
|
34
|
-
* plan's `trial_days` shows as "14-day free trial",
|
|
34
|
+
* plan's `trial_days` shows as "14-day free trial", its `ends_after_days` as
|
|
35
|
+
* "For 90 days, then choose a plan", and without `onSelect`
|
|
35
36
|
* each plan's button is its call-to-action link (`customerEmail` fills
|
|
36
37
|
* {CUSTOMER_EMAIL} in it).
|
|
37
38
|
*
|
|
38
39
|
* A plan's list is its `bullet_details` (the API's plans, the snapshot and the
|
|
39
40
|
* customer portal's plan list all carry it: each feature by its name on the
|
|
40
|
-
* plan, else its label with its description
|
|
41
|
+
* plan, else its label with its description behind an info icon, by its description
|
|
41
42
|
* when it has no label, by its id when it has neither), else its `bullets`,
|
|
42
43
|
* else its features (`{ id, name }`) by name, else by id; its included
|
|
43
44
|
* credits come first ("1,500 Bits a month"). A snapshot plan's
|
|
@@ -58,7 +59,7 @@
|
|
|
58
59
|
|
|
59
60
|
const React = require("react");
|
|
60
61
|
const theme = require("./theme");
|
|
61
|
-
const { useBaseUrl } = require("./config");
|
|
62
|
+
const { useBaseUrl, DEFAULT_BASE_URL } = require("./config");
|
|
62
63
|
const { brandingVars } = require("./branding");
|
|
63
64
|
const { useI18n } = require("./i18n");
|
|
64
65
|
|
|
@@ -142,7 +143,38 @@ const styles = {
|
|
|
142
143
|
borderTop: `1px solid ${theme.border}`,
|
|
143
144
|
paddingTop: 10,
|
|
144
145
|
},
|
|
145
|
-
|
|
146
|
+
infoWrap: { position: "relative", display: "inline-block", marginLeft: 4 },
|
|
147
|
+
infoButton: {
|
|
148
|
+
width: 16,
|
|
149
|
+
height: 16,
|
|
150
|
+
padding: 0,
|
|
151
|
+
border: `1px solid ${theme.border}`,
|
|
152
|
+
borderRadius: "50%",
|
|
153
|
+
background: "transparent",
|
|
154
|
+
color: "inherit",
|
|
155
|
+
fontSize: 10,
|
|
156
|
+
fontWeight: 700,
|
|
157
|
+
lineHeight: "14px",
|
|
158
|
+
opacity: 0.6,
|
|
159
|
+
cursor: "pointer",
|
|
160
|
+
verticalAlign: "middle",
|
|
161
|
+
},
|
|
162
|
+
infoBubble: {
|
|
163
|
+
position: "absolute",
|
|
164
|
+
top: "calc(100% + 6px)",
|
|
165
|
+
left: -8,
|
|
166
|
+
zIndex: 10,
|
|
167
|
+
width: 220,
|
|
168
|
+
padding: "8px 10px",
|
|
169
|
+
border: `1px solid ${theme.border}`,
|
|
170
|
+
borderRadius: 8,
|
|
171
|
+
background: theme.card,
|
|
172
|
+
color: theme.text,
|
|
173
|
+
fontSize: 12,
|
|
174
|
+
fontWeight: 400,
|
|
175
|
+
lineHeight: 1.4,
|
|
176
|
+
boxShadow: "0 4px 16px rgba(0,0,0,0.18)",
|
|
177
|
+
},
|
|
146
178
|
badge: {
|
|
147
179
|
fontSize: 11,
|
|
148
180
|
fontWeight: 600,
|
|
@@ -208,6 +240,50 @@ function ladderText({ t, money, number }, tiers, scale) {
|
|
|
208
240
|
.join(` ${t("pricing.then")} `);
|
|
209
241
|
}
|
|
210
242
|
|
|
243
|
+
/**
|
|
244
|
+
* A feature's description, behind an info icon next to its name: opens on
|
|
245
|
+
* click (so touch works too), closes on a second click, Escape or a click
|
|
246
|
+
* anywhere else.
|
|
247
|
+
*/
|
|
248
|
+
function FeatureInfo({ label, children }) {
|
|
249
|
+
const [open, setOpen] = React.useState(false);
|
|
250
|
+
const ref = React.useRef(null);
|
|
251
|
+
React.useEffect(() => {
|
|
252
|
+
if (!open) return undefined;
|
|
253
|
+
const onPointer = (e) => {
|
|
254
|
+
if (ref.current && !ref.current.contains(e.target)) setOpen(false);
|
|
255
|
+
};
|
|
256
|
+
const onKey = (e) => {
|
|
257
|
+
if (e.key === "Escape") setOpen(false);
|
|
258
|
+
};
|
|
259
|
+
// No document outside a DOM renderer (tests, server rendering).
|
|
260
|
+
const doc = ref.current?.ownerDocument;
|
|
261
|
+
if (!doc) return undefined;
|
|
262
|
+
doc.addEventListener("mousedown", onPointer);
|
|
263
|
+
doc.addEventListener("keydown", onKey);
|
|
264
|
+
return () => {
|
|
265
|
+
doc.removeEventListener("mousedown", onPointer);
|
|
266
|
+
doc.removeEventListener("keydown", onKey);
|
|
267
|
+
};
|
|
268
|
+
}, [open]);
|
|
269
|
+
return React.createElement(
|
|
270
|
+
"span",
|
|
271
|
+
{ ref, style: styles.infoWrap },
|
|
272
|
+
React.createElement(
|
|
273
|
+
"button",
|
|
274
|
+
{
|
|
275
|
+
type: "button",
|
|
276
|
+
"aria-label": label,
|
|
277
|
+
"aria-expanded": open,
|
|
278
|
+
style: styles.infoButton,
|
|
279
|
+
onClick: () => setOpen((o) => !o),
|
|
280
|
+
},
|
|
281
|
+
"i",
|
|
282
|
+
),
|
|
283
|
+
open && React.createElement("span", { role: "tooltip", style: styles.infoBubble }, children),
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
211
287
|
/** Included amounts, what happens past them, and the models' rates. */
|
|
212
288
|
function PlanUsage({ usage }) {
|
|
213
289
|
const i18n = useI18n();
|
|
@@ -291,6 +367,7 @@ function fromSnapshot(p) {
|
|
|
291
367
|
highlight: !!p.highlight,
|
|
292
368
|
badge: p.badge || null,
|
|
293
369
|
trial_days: p.trial_days || null,
|
|
370
|
+
ends_after_days: p.ends_after_days || null,
|
|
294
371
|
cta: p.cta || null,
|
|
295
372
|
};
|
|
296
373
|
}
|
|
@@ -318,6 +395,7 @@ function PricingTable({
|
|
|
318
395
|
baseUrl: baseUrlProp,
|
|
319
396
|
publishableKey,
|
|
320
397
|
fetch: fetchImpl,
|
|
398
|
+
showUsage = false,
|
|
321
399
|
}) {
|
|
322
400
|
const baseUrl = useBaseUrl(baseUrlProp);
|
|
323
401
|
const selfFetch = !Array.isArray(plans) && !!publishableKey;
|
|
@@ -514,6 +592,12 @@ function PricingTable({
|
|
|
514
592
|
{ style: styles.trial },
|
|
515
593
|
t("pricing.trial", { days: plan.trial_days }),
|
|
516
594
|
),
|
|
595
|
+
plan.ends_after_days > 0 &&
|
|
596
|
+
React.createElement(
|
|
597
|
+
"div",
|
|
598
|
+
{ style: styles.trial },
|
|
599
|
+
t("pricing.endsAfter", { days: plan.ends_after_days }),
|
|
600
|
+
),
|
|
517
601
|
bullets.length > 0 &&
|
|
518
602
|
React.createElement(
|
|
519
603
|
"ul",
|
|
@@ -525,11 +609,11 @@ function PricingTable({
|
|
|
525
609
|
React.createElement("span", { "aria-hidden": true }, "• "),
|
|
526
610
|
React.createElement("span", null, b.text),
|
|
527
611
|
b.description &&
|
|
528
|
-
React.createElement(
|
|
612
|
+
React.createElement(FeatureInfo, { label: `About ${b.text}` }, b.description),
|
|
529
613
|
),
|
|
530
614
|
),
|
|
531
615
|
),
|
|
532
|
-
plan.usage && React.createElement(PlanUsage, { usage: plan.usage }),
|
|
616
|
+
showUsage && plan.usage && React.createElement(PlanUsage, { usage: plan.usage }),
|
|
533
617
|
action,
|
|
534
618
|
);
|
|
535
619
|
}),
|
|
@@ -538,4 +622,15 @@ function PricingTable({
|
|
|
538
622
|
}
|
|
539
623
|
|
|
540
624
|
PricingTable.annualPriceUsd = annualPriceUsd;
|
|
625
|
+
/**
|
|
626
|
+
* The public pricing snapshot, as `{ plans, branding }` with each plan in the
|
|
627
|
+
* shape this table takes: for a page that also uses the plans elsewhere (a
|
|
628
|
+
* sign-up form's plan picker), or shows its own plans until the live ones
|
|
629
|
+
* arrive. Rejects on an HTTP error.
|
|
630
|
+
*/
|
|
631
|
+
PricingTable.fetchPricingPage = ({
|
|
632
|
+
baseUrl = DEFAULT_BASE_URL,
|
|
633
|
+
publishableKey,
|
|
634
|
+
fetch: fetchImpl,
|
|
635
|
+
}) => fetchCatalog({ baseUrl, publishableKey, fetchImpl: fetchImpl || globalThis.fetch });
|
|
541
636
|
module.exports = PricingTable;
|
package/src/i18n.js
CHANGED
|
@@ -78,6 +78,7 @@ const en = {
|
|
|
78
78
|
"pricing.perMonth": "/ month",
|
|
79
79
|
"pricing.billedAnnually": "billed annually",
|
|
80
80
|
"pricing.trial": "{days}-day free trial",
|
|
81
|
+
"pricing.endsAfter": "For {days} days, then choose a plan",
|
|
81
82
|
"pricing.includes": "Includes {parts} a month",
|
|
82
83
|
"pricing.inputTokens": "{n} input tokens",
|
|
83
84
|
"pricing.outputTokens": "{n} output tokens",
|
|
@@ -230,6 +231,7 @@ const es = {
|
|
|
230
231
|
"pricing.perMonth": "/ mes",
|
|
231
232
|
"pricing.billedAnnually": "facturado anualmente",
|
|
232
233
|
"pricing.trial": "Prueba gratuita de {days} días",
|
|
234
|
+
"pricing.endsAfter": "Durante {days} días; luego elige un plan",
|
|
233
235
|
"pricing.includes": "Incluye {parts} al mes",
|
|
234
236
|
"pricing.inputTokens": "{n} tokens de entrada",
|
|
235
237
|
"pricing.outputTokens": "{n} tokens de salida",
|
|
@@ -382,6 +384,7 @@ const fr = {
|
|
|
382
384
|
"pricing.perMonth": "/ mois",
|
|
383
385
|
"pricing.billedAnnually": "facturé annuellement",
|
|
384
386
|
"pricing.trial": "Essai gratuit de {days} jours",
|
|
387
|
+
"pricing.endsAfter": "Pendant {days} jours, puis choisissez une offre",
|
|
385
388
|
"pricing.includes": "Inclut {parts} par mois",
|
|
386
389
|
"pricing.inputTokens": "{n} tokens en entrée",
|
|
387
390
|
"pricing.outputTokens": "{n} tokens en sortie",
|
|
@@ -535,6 +538,7 @@ const de = {
|
|
|
535
538
|
"pricing.perMonth": "/ Monat",
|
|
536
539
|
"pricing.billedAnnually": "jährlich abgerechnet",
|
|
537
540
|
"pricing.trial": "{days} Tage kostenlos testen",
|
|
541
|
+
"pricing.endsAfter": "{days} Tage lang, danach einen Tarif wählen",
|
|
538
542
|
"pricing.includes": "Enthält {parts} pro Monat",
|
|
539
543
|
"pricing.inputTokens": "{n} Input-Tokens",
|
|
540
544
|
"pricing.outputTokens": "{n} Output-Tokens",
|