@meterbox/react 0.1.3 → 0.1.5
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 +19 -1
- package/package.json +1 -1
- package/src/CheckoutButton.js +4 -5
- package/src/CreditBalance.js +8 -7
- package/src/CreditGrantsTable.js +6 -5
- package/src/CreditUtilization.js +6 -5
- package/src/InvoiceHistory.js +5 -4
- package/src/OutcomeHistory.js +4 -3
- package/src/Paywall.js +5 -6
- package/src/PlanChangeCard.js +7 -10
- package/src/PlanComparison.js +7 -8
- package/src/PricingTable.js +87 -30
- package/src/SubscriptionPreview.js +4 -3
- package/src/TrialBanner.js +6 -7
- package/src/UsageChart.js +5 -4
- package/src/UsageProgress.js +4 -3
- package/src/branding.js +66 -0
- package/src/index.js +11 -0
- package/src/theme.js +24 -0
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ import {
|
|
|
45
45
|
} from "@meterbox/react";
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
### `<PricingTable plans currentPlanId? currency? onSelect? />` or `<PricingTable baseUrl publishableKey … />`
|
|
48
|
+
### `<PricingTable plans currentPlanId? currency? onSelect? customerEmail? branding? />` or `<PricingTable baseUrl publishableKey … />`
|
|
49
49
|
|
|
50
50
|
On a public page with no backend of its own, pass `baseUrl` and a
|
|
51
51
|
publishable key (`mb_pub_...`, from Settings > API keys) instead of `plans`.
|
|
@@ -63,12 +63,30 @@ 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
|
+
From the snapshot, the featured plan is highlighted with its badge ("Most
|
|
67
|
+
popular"), a plan's free trial shows as "14-day free trial", and, without
|
|
68
|
+
`onSelect`, each plan's button is its own call-to-action link (e.g. Enterprise
|
|
69
|
+
to a contact page); `customerEmail` fills `{CUSTOMER_EMAIL}` in it.
|
|
70
|
+
|
|
66
71
|
Plans from the snapshot (or the customer portal's plan list) also carry
|
|
67
72
|
`usage`, and each card then shows what an AI product's customers actually
|
|
68
73
|
pay for usage: the amounts included each month, what happens past them
|
|
69
74
|
(billed, stopped until next month, or an upgrade), and every model's input
|
|
70
75
|
and output rates per 1M tokens, tier ladders included.
|
|
71
76
|
|
|
77
|
+
### Branding: `<BrandingProvider branding>`
|
|
78
|
+
|
|
79
|
+
Every component styles itself from `--mbx-*` CSS variables (`--mbx-accent`,
|
|
80
|
+
`--mbx-text`, `--mbx-card`, `--mbx-font`, `--mbx-radius` and the button
|
|
81
|
+
variables), with Meterbox's defaults as fallbacks. Wrap them in
|
|
82
|
+
`<BrandingProvider branding={branding}>` to apply your branding from
|
|
83
|
+
Settings → Branding (`GET /v1/settings/branding`): logo, colors, font and
|
|
84
|
+
button style. `<PricingTable baseUrl publishableKey>` applies it from the
|
|
85
|
+
pricing snapshot by itself, and any component's surroundings can set the
|
|
86
|
+
variables in CSS. `useBranding()` reads the values (e.g. the logo), and
|
|
87
|
+
`theme` exports the variable references for styling your own elements to
|
|
88
|
+
match.
|
|
89
|
+
|
|
72
90
|
### `<PlanComparison from to onSwitch? />`
|
|
73
91
|
|
|
74
92
|
Side-by-side comparison of two plan records with added / removed feature
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meterbox/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
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/CheckoutButton.js
CHANGED
|
@@ -19,17 +19,16 @@
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
const React = require("react");
|
|
22
|
+
const theme = require("./theme");
|
|
22
23
|
|
|
23
24
|
const styles = {
|
|
24
25
|
btn: {
|
|
25
26
|
padding: "10px 18px",
|
|
26
|
-
|
|
27
|
-
borderRadius: 8,
|
|
28
|
-
background: "#5045e8",
|
|
29
|
-
color: "#fff",
|
|
27
|
+
...theme.button,
|
|
28
|
+
borderRadius: theme.radius(8),
|
|
30
29
|
fontWeight: 600,
|
|
31
30
|
cursor: "pointer",
|
|
32
|
-
fontFamily:
|
|
31
|
+
fontFamily: theme.font,
|
|
33
32
|
},
|
|
34
33
|
disabled: { opacity: 0.6, cursor: "default" },
|
|
35
34
|
};
|
package/src/CreditBalance.js
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
const React = require("react");
|
|
23
|
+
const theme = require("./theme");
|
|
23
24
|
|
|
24
25
|
async function fetchBalance({ baseUrl, customerId, customerToken, fetchImpl }) {
|
|
25
26
|
const url = `${String(baseUrl).replace(/\/+$/, "")}/v1/customer-portal/${encodeURIComponent(
|
|
@@ -40,12 +41,12 @@ async function fetchBalance({ baseUrl, customerId, customerToken, fetchImpl }) {
|
|
|
40
41
|
|
|
41
42
|
const styles = {
|
|
42
43
|
card: {
|
|
43
|
-
fontFamily:
|
|
44
|
-
color:
|
|
44
|
+
fontFamily: theme.font,
|
|
45
|
+
color: theme.text,
|
|
45
46
|
border: "1px solid #e5e7eb",
|
|
46
47
|
borderRadius: 12,
|
|
47
48
|
padding: 16,
|
|
48
|
-
background:
|
|
49
|
+
background: theme.card,
|
|
49
50
|
display: "grid",
|
|
50
51
|
gap: 8,
|
|
51
52
|
maxWidth: 320,
|
|
@@ -56,10 +57,10 @@ const styles = {
|
|
|
56
57
|
hint: { fontSize: 12, opacity: 0.65 },
|
|
57
58
|
topUp: {
|
|
58
59
|
padding: "8px 12px",
|
|
59
|
-
border:
|
|
60
|
-
borderRadius: 8,
|
|
61
|
-
background:
|
|
62
|
-
color:
|
|
60
|
+
border: `1px solid ${theme.accent}`,
|
|
61
|
+
borderRadius: theme.radius(8),
|
|
62
|
+
background: theme.card,
|
|
63
|
+
color: theme.accent,
|
|
63
64
|
fontWeight: 600,
|
|
64
65
|
cursor: "pointer",
|
|
65
66
|
width: "fit-content",
|
package/src/CreditGrantsTable.js
CHANGED
|
@@ -21,15 +21,16 @@
|
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
const React = require("react");
|
|
24
|
+
const theme = require("./theme");
|
|
24
25
|
|
|
25
26
|
const styles = {
|
|
26
27
|
card: {
|
|
27
|
-
fontFamily:
|
|
28
|
-
color:
|
|
28
|
+
fontFamily: theme.font,
|
|
29
|
+
color: theme.text,
|
|
29
30
|
border: "1px solid #e5e7eb",
|
|
30
31
|
borderRadius: 12,
|
|
31
32
|
padding: 16,
|
|
32
|
-
background:
|
|
33
|
+
background: theme.card,
|
|
33
34
|
display: "grid",
|
|
34
35
|
gap: 12,
|
|
35
36
|
maxWidth: 720,
|
|
@@ -46,8 +47,8 @@ const styles = {
|
|
|
46
47
|
borderRadius: 999,
|
|
47
48
|
fontSize: 11,
|
|
48
49
|
fontWeight: 600,
|
|
49
|
-
background:
|
|
50
|
-
color:
|
|
50
|
+
background: theme.accentTint(),
|
|
51
|
+
color: theme.accent,
|
|
51
52
|
},
|
|
52
53
|
};
|
|
53
54
|
|
package/src/CreditUtilization.js
CHANGED
|
@@ -18,23 +18,24 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
const React = require("react");
|
|
21
|
+
const theme = require("./theme");
|
|
21
22
|
|
|
22
23
|
const styles = {
|
|
23
24
|
wrap: {
|
|
24
|
-
fontFamily:
|
|
25
|
-
color:
|
|
25
|
+
fontFamily: theme.font,
|
|
26
|
+
color: theme.text,
|
|
26
27
|
border: "1px solid #e5e7eb",
|
|
27
28
|
borderRadius: 12,
|
|
28
29
|
padding: 16,
|
|
29
|
-
background:
|
|
30
|
+
background: theme.card,
|
|
30
31
|
display: "grid",
|
|
31
32
|
gap: 8,
|
|
32
33
|
maxWidth: 480,
|
|
33
34
|
},
|
|
34
35
|
label: { fontSize: 12, opacity: 0.6, textTransform: "uppercase", letterSpacing: 0.4 },
|
|
35
36
|
current: { fontSize: 24, fontWeight: 700 },
|
|
36
|
-
area: { fill:
|
|
37
|
-
line: { fill: "none", stroke:
|
|
37
|
+
area: { fill: theme.accentTint(15) },
|
|
38
|
+
line: { fill: "none", stroke: theme.accent, strokeWidth: 1.5 },
|
|
38
39
|
};
|
|
39
40
|
|
|
40
41
|
function dollars(n) {
|
package/src/InvoiceHistory.js
CHANGED
|
@@ -14,15 +14,16 @@
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
const React = require("react");
|
|
17
|
+
const theme = require("./theme");
|
|
17
18
|
|
|
18
19
|
const styles = {
|
|
19
20
|
card: {
|
|
20
|
-
fontFamily:
|
|
21
|
-
color:
|
|
21
|
+
fontFamily: theme.font,
|
|
22
|
+
color: theme.text,
|
|
22
23
|
border: "1px solid #e5e7eb",
|
|
23
24
|
borderRadius: 12,
|
|
24
25
|
padding: 16,
|
|
25
|
-
background:
|
|
26
|
+
background: theme.card,
|
|
26
27
|
display: "grid",
|
|
27
28
|
gap: 12,
|
|
28
29
|
maxWidth: 720,
|
|
@@ -38,7 +39,7 @@ const styles = {
|
|
|
38
39
|
},
|
|
39
40
|
td: { padding: "6px 8px", borderBottom: "1px solid #f3f4f6" },
|
|
40
41
|
links: { display: "flex", gap: 10 },
|
|
41
|
-
link: { color:
|
|
42
|
+
link: { color: theme.accent, textDecoration: "none", fontWeight: 600 },
|
|
42
43
|
muted: { opacity: 0.6 },
|
|
43
44
|
};
|
|
44
45
|
|
package/src/OutcomeHistory.js
CHANGED
|
@@ -25,15 +25,16 @@
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
const React = require("react");
|
|
28
|
+
const theme = require("./theme");
|
|
28
29
|
|
|
29
30
|
const styles = {
|
|
30
31
|
card: {
|
|
31
|
-
fontFamily:
|
|
32
|
-
color:
|
|
32
|
+
fontFamily: theme.font,
|
|
33
|
+
color: theme.text,
|
|
33
34
|
border: "1px solid #e5e7eb",
|
|
34
35
|
borderRadius: 12,
|
|
35
36
|
padding: 16,
|
|
36
|
-
background:
|
|
37
|
+
background: theme.card,
|
|
37
38
|
display: "grid",
|
|
38
39
|
gap: 12,
|
|
39
40
|
maxWidth: 720,
|
package/src/Paywall.js
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
const React = require("react");
|
|
25
|
+
const theme = require("./theme");
|
|
25
26
|
|
|
26
27
|
const defaultStyles = {
|
|
27
28
|
fallback: {
|
|
@@ -29,8 +30,8 @@ const defaultStyles = {
|
|
|
29
30
|
borderRadius: 10,
|
|
30
31
|
border: "1px solid #e5e7eb",
|
|
31
32
|
background: "#fafafa",
|
|
32
|
-
fontFamily:
|
|
33
|
-
color:
|
|
33
|
+
fontFamily: theme.font,
|
|
34
|
+
color: theme.text,
|
|
34
35
|
display: "flex",
|
|
35
36
|
flexDirection: "column",
|
|
36
37
|
gap: 8,
|
|
@@ -40,10 +41,8 @@ const defaultStyles = {
|
|
|
40
41
|
cta: {
|
|
41
42
|
marginTop: 4,
|
|
42
43
|
padding: "8px 14px",
|
|
43
|
-
|
|
44
|
-
borderRadius: 8,
|
|
45
|
-
background: "#5045e8",
|
|
46
|
-
color: "#fff",
|
|
44
|
+
...theme.button,
|
|
45
|
+
borderRadius: theme.radius(8),
|
|
47
46
|
fontWeight: 600,
|
|
48
47
|
cursor: "pointer",
|
|
49
48
|
alignSelf: "flex-start",
|
package/src/PlanChangeCard.js
CHANGED
|
@@ -37,11 +37,12 @@
|
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
39
|
const React = require("react");
|
|
40
|
+
const theme = require("./theme");
|
|
40
41
|
const SubscriptionPreview = require("./SubscriptionPreview");
|
|
41
42
|
|
|
42
43
|
const styles = {
|
|
43
44
|
wrap: {
|
|
44
|
-
fontFamily:
|
|
45
|
+
fontFamily: theme.font,
|
|
45
46
|
display: "grid",
|
|
46
47
|
gap: 12,
|
|
47
48
|
maxWidth: 480,
|
|
@@ -61,19 +62,15 @@ const styles = {
|
|
|
61
62
|
btn: {
|
|
62
63
|
padding: "10px 16px",
|
|
63
64
|
border: "1px solid #d1d5db",
|
|
64
|
-
borderRadius: 8,
|
|
65
|
-
background:
|
|
66
|
-
color:
|
|
65
|
+
borderRadius: theme.radius(8),
|
|
66
|
+
background: theme.card,
|
|
67
|
+
color: theme.text,
|
|
67
68
|
fontWeight: 600,
|
|
68
69
|
cursor: "pointer",
|
|
69
|
-
fontFamily:
|
|
70
|
+
fontFamily: theme.font,
|
|
70
71
|
fontSize: 14,
|
|
71
72
|
},
|
|
72
|
-
btnPrimary:
|
|
73
|
-
border: "none",
|
|
74
|
-
background: "#5045e8",
|
|
75
|
-
color: "#fff",
|
|
76
|
-
},
|
|
73
|
+
btnPrimary: theme.button,
|
|
77
74
|
disabled: { opacity: 0.6, cursor: "default" },
|
|
78
75
|
message: { fontSize: 13 },
|
|
79
76
|
success: { color: "#16a34a" },
|
package/src/PlanComparison.js
CHANGED
|
@@ -11,24 +11,25 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
const React = require("react");
|
|
14
|
+
const theme = require("./theme");
|
|
14
15
|
|
|
15
16
|
const styles = {
|
|
16
17
|
grid: {
|
|
17
18
|
display: "grid",
|
|
18
19
|
gridTemplateColumns: "1fr 1fr",
|
|
19
20
|
gap: 24,
|
|
20
|
-
fontFamily:
|
|
21
|
-
color:
|
|
21
|
+
fontFamily: theme.font,
|
|
22
|
+
color: theme.text,
|
|
22
23
|
},
|
|
23
24
|
col: {
|
|
24
25
|
border: "1px solid #e5e7eb",
|
|
25
26
|
borderRadius: 12,
|
|
26
27
|
padding: 16,
|
|
27
|
-
background:
|
|
28
|
+
background: theme.card,
|
|
28
29
|
display: "grid",
|
|
29
30
|
gap: 10,
|
|
30
31
|
},
|
|
31
|
-
colTo: { borderColor:
|
|
32
|
+
colTo: { borderColor: theme.accent },
|
|
32
33
|
heading: { fontSize: 14, fontWeight: 600, opacity: 0.7, margin: 0 },
|
|
33
34
|
planName: { fontSize: 20, fontWeight: 700, margin: 0 },
|
|
34
35
|
features: { margin: 0, padding: 0, listStyle: "none", fontSize: 13, display: "grid", gap: 4 },
|
|
@@ -37,10 +38,8 @@ const styles = {
|
|
|
37
38
|
switchBtn: {
|
|
38
39
|
marginTop: 8,
|
|
39
40
|
padding: "10px 14px",
|
|
40
|
-
|
|
41
|
-
borderRadius: 8,
|
|
42
|
-
background: "#5045e8",
|
|
43
|
-
color: "#fff",
|
|
41
|
+
...theme.button,
|
|
42
|
+
borderRadius: theme.radius(8),
|
|
44
43
|
fontWeight: 600,
|
|
45
44
|
cursor: "pointer",
|
|
46
45
|
},
|
package/src/PricingTable.js
CHANGED
|
@@ -26,11 +26,22 @@
|
|
|
26
26
|
* and its models' input and output rates per 1M tokens, tier ladders
|
|
27
27
|
* included.
|
|
28
28
|
*
|
|
29
|
+
* Self-fetching, it takes the tenant's branding (Settings → Branding) from
|
|
30
|
+
* the snapshot; `branding` overrides it, and a <BrandingProvider> around it
|
|
31
|
+
* applies when neither is set.
|
|
32
|
+
*
|
|
33
|
+
* From the snapshot, the featured plan is highlighted with its `badge`, a
|
|
34
|
+
* plan's `trial_days` shows as "14-day free trial", and without `onSelect`
|
|
35
|
+
* each plan's button is its call-to-action link (`customerEmail` fills
|
|
36
|
+
* {CUSTOMER_EMAIL} in it).
|
|
37
|
+
*
|
|
29
38
|
* Pure presentational + inline styles — no CSS pipeline required from the
|
|
30
39
|
* tenant.
|
|
31
40
|
*/
|
|
32
41
|
|
|
33
42
|
const React = require("react");
|
|
43
|
+
const theme = require("./theme");
|
|
44
|
+
const { brandingVars } = require("./branding");
|
|
34
45
|
|
|
35
46
|
/**
|
|
36
47
|
* Total charged for one year prepaid upfront, or null when the plan
|
|
@@ -63,27 +74,27 @@ const styles = {
|
|
|
63
74
|
color: "#4b5563",
|
|
64
75
|
fontSize: 13,
|
|
65
76
|
fontWeight: 600,
|
|
66
|
-
fontFamily:
|
|
77
|
+
fontFamily: theme.font,
|
|
67
78
|
cursor: "pointer",
|
|
68
79
|
},
|
|
69
|
-
toggleBtnActive: { background:
|
|
80
|
+
toggleBtnActive: { background: theme.accent, color: "#fff" },
|
|
70
81
|
grid: {
|
|
71
82
|
display: "grid",
|
|
72
83
|
gridTemplateColumns: "repeat(auto-fit, minmax(220px, 1fr))",
|
|
73
84
|
gap: 16,
|
|
74
|
-
fontFamily:
|
|
75
|
-
color:
|
|
85
|
+
fontFamily: theme.font,
|
|
86
|
+
color: theme.text,
|
|
76
87
|
},
|
|
77
88
|
card: {
|
|
78
89
|
border: "1px solid #e5e7eb",
|
|
79
90
|
borderRadius: 12,
|
|
80
91
|
padding: 20,
|
|
81
|
-
background:
|
|
92
|
+
background: theme.card,
|
|
82
93
|
display: "flex",
|
|
83
94
|
flexDirection: "column",
|
|
84
95
|
gap: 12,
|
|
85
96
|
},
|
|
86
|
-
cardCurrent: { borderColor:
|
|
97
|
+
cardCurrent: { borderColor: theme.accent, boxShadow: `0 0 0 3px ${theme.accentTint(13)}` },
|
|
87
98
|
name: { fontSize: 18, fontWeight: 600, margin: 0 },
|
|
88
99
|
price: { fontSize: 28, fontWeight: 700 },
|
|
89
100
|
perMonth: { fontSize: 12, opacity: 0.6, marginLeft: 4 },
|
|
@@ -91,14 +102,18 @@ const styles = {
|
|
|
91
102
|
cta: {
|
|
92
103
|
marginTop: "auto",
|
|
93
104
|
padding: "10px 14px",
|
|
94
|
-
|
|
95
|
-
borderRadius: 8,
|
|
96
|
-
background: "#5045e8",
|
|
97
|
-
color: "#fff",
|
|
105
|
+
...theme.button,
|
|
106
|
+
borderRadius: theme.radius(8),
|
|
98
107
|
fontWeight: 600,
|
|
99
108
|
cursor: "pointer",
|
|
100
109
|
},
|
|
101
|
-
ctaCurrent: {
|
|
110
|
+
ctaCurrent: {
|
|
111
|
+
background: "#e5e7eb",
|
|
112
|
+
color: theme.text,
|
|
113
|
+
border: "1px solid transparent",
|
|
114
|
+
cursor: "default",
|
|
115
|
+
},
|
|
116
|
+
trial: { fontSize: 13, fontWeight: 600 },
|
|
102
117
|
usage: {
|
|
103
118
|
display: "grid",
|
|
104
119
|
gap: 4,
|
|
@@ -109,7 +124,7 @@ const styles = {
|
|
|
109
124
|
badge: {
|
|
110
125
|
fontSize: 11,
|
|
111
126
|
fontWeight: 600,
|
|
112
|
-
background:
|
|
127
|
+
background: theme.accent,
|
|
113
128
|
color: "#fff",
|
|
114
129
|
padding: "2px 8px",
|
|
115
130
|
borderRadius: 999,
|
|
@@ -188,6 +203,19 @@ function PlanUsage({ usage }) {
|
|
|
188
203
|
);
|
|
189
204
|
}
|
|
190
205
|
|
|
206
|
+
// A plan's call-to-action link from the snapshot, {CUSTOMER_EMAIL} filled in;
|
|
207
|
+
// null unless it's an http(s), mailto: or tel: link.
|
|
208
|
+
function ctaLink(plan, customerEmail) {
|
|
209
|
+
if (!plan.cta?.url) return null;
|
|
210
|
+
const email = encodeURIComponent(customerEmail || "");
|
|
211
|
+
const url = plan.cta.url
|
|
212
|
+
.split("{CUSTOMER_EMAIL}")
|
|
213
|
+
.join(email)
|
|
214
|
+
.split("%7BCUSTOMER_EMAIL%7D")
|
|
215
|
+
.join(email);
|
|
216
|
+
return /^(https?:|mailto:|tel:)/i.test(url) ? { url, label: plan.cta.label } : null;
|
|
217
|
+
}
|
|
218
|
+
|
|
191
219
|
/** A plan from the public snapshot, in the shape the table renders. */
|
|
192
220
|
function fromSnapshot(p) {
|
|
193
221
|
return {
|
|
@@ -199,6 +227,10 @@ function fromSnapshot(p) {
|
|
|
199
227
|
annual_free_months: p.annual_free_months == null ? null : p.annual_free_months,
|
|
200
228
|
localized_prices: p.localized_prices || [],
|
|
201
229
|
usage: p.usage || null,
|
|
230
|
+
highlight: !!p.highlight,
|
|
231
|
+
badge: p.badge || null,
|
|
232
|
+
trial_days: p.trial_days || null,
|
|
233
|
+
cta: p.cta || null,
|
|
202
234
|
};
|
|
203
235
|
}
|
|
204
236
|
|
|
@@ -209,7 +241,7 @@ async function fetchCatalog({ baseUrl, publishableKey, fetchImpl }) {
|
|
|
209
241
|
const res = await fetchImpl(url, { method: "GET" });
|
|
210
242
|
if (!res.ok) throw new Error(`pricing-table: ${res.status}`);
|
|
211
243
|
const body = await res.json();
|
|
212
|
-
return (body.plans || []).map(fromSnapshot);
|
|
244
|
+
return { plans: (body.plans || []).map(fromSnapshot), branding: body.branding || null };
|
|
213
245
|
}
|
|
214
246
|
|
|
215
247
|
function PricingTable({
|
|
@@ -217,6 +249,8 @@ function PricingTable({
|
|
|
217
249
|
currentPlanId,
|
|
218
250
|
currency = "USD",
|
|
219
251
|
onSelect,
|
|
252
|
+
customerEmail,
|
|
253
|
+
branding,
|
|
220
254
|
baseUrl,
|
|
221
255
|
publishableKey,
|
|
222
256
|
fetch: fetchImpl,
|
|
@@ -233,14 +267,17 @@ function PricingTable({
|
|
|
233
267
|
if (alive) setFetched(d);
|
|
234
268
|
})
|
|
235
269
|
.catch(() => {
|
|
236
|
-
if (alive) setFetched([]);
|
|
270
|
+
if (alive) setFetched({ plans: [], branding: null });
|
|
237
271
|
});
|
|
238
272
|
return () => {
|
|
239
273
|
alive = false;
|
|
240
274
|
};
|
|
241
275
|
}, [selfFetch, baseUrl, publishableKey, fetchImpl]);
|
|
242
276
|
|
|
243
|
-
const list = Array.isArray(plans) ? plans : fetched;
|
|
277
|
+
const list = Array.isArray(plans) ? plans : fetched?.plans;
|
|
278
|
+
// Its own `branding`, else the tenant's from the snapshot; inside a
|
|
279
|
+
// <BrandingProvider>, neither overrides the provider unless given.
|
|
280
|
+
const vars = brandingVars(branding || fetched?.branding);
|
|
244
281
|
if (!Array.isArray(list) || list.length === 0) {
|
|
245
282
|
return React.createElement(
|
|
246
283
|
"div",
|
|
@@ -253,7 +290,7 @@ function PricingTable({
|
|
|
253
290
|
|
|
254
291
|
return React.createElement(
|
|
255
292
|
"div",
|
|
256
|
-
{ className: "meterbox-pricing-table", style: styles.wrap },
|
|
293
|
+
{ className: "meterbox-pricing-table", style: { ...styles.wrap, ...vars } },
|
|
257
294
|
hasAnnualOption &&
|
|
258
295
|
React.createElement(
|
|
259
296
|
"div",
|
|
@@ -289,13 +326,18 @@ function PricingTable({
|
|
|
289
326
|
// annual_free_months always shows its monthly price, even while the
|
|
290
327
|
// toggle above is set to "Annual" for its siblings.
|
|
291
328
|
const annual = billingInterval === "annual" ? annualPriceUsd(plan) : null;
|
|
329
|
+
const link = !onSelect && !isCurrent ? ctaLink(plan, customerEmail) : null;
|
|
292
330
|
return React.createElement(
|
|
293
331
|
"div",
|
|
294
332
|
{
|
|
295
333
|
key: plan.id,
|
|
296
|
-
style:
|
|
334
|
+
style:
|
|
335
|
+
isCurrent || plan.highlight ? { ...styles.card, ...styles.cardCurrent } : styles.card,
|
|
297
336
|
},
|
|
298
337
|
isCurrent && React.createElement("span", { style: styles.badge }, "Current"),
|
|
338
|
+
!isCurrent &&
|
|
339
|
+
plan.badge &&
|
|
340
|
+
React.createElement("span", { style: styles.badge }, plan.badge),
|
|
299
341
|
React.createElement("h3", { style: styles.name }, plan.name || plan.id),
|
|
300
342
|
plan.description &&
|
|
301
343
|
React.createElement(
|
|
@@ -319,6 +361,12 @@ function PricingTable({
|
|
|
319
361
|
annual != null ? "billed annually" : "/ month",
|
|
320
362
|
),
|
|
321
363
|
),
|
|
364
|
+
plan.trial_days > 0 &&
|
|
365
|
+
React.createElement(
|
|
366
|
+
"div",
|
|
367
|
+
{ style: styles.trial },
|
|
368
|
+
`${plan.trial_days}-day free trial`,
|
|
369
|
+
),
|
|
322
370
|
Array.isArray(plan.features) &&
|
|
323
371
|
plan.features.length > 0 &&
|
|
324
372
|
React.createElement(
|
|
@@ -329,19 +377,28 @@ function PricingTable({
|
|
|
329
377
|
),
|
|
330
378
|
),
|
|
331
379
|
plan.usage && React.createElement(PlanUsage, { usage: plan.usage }),
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
380
|
+
link
|
|
381
|
+
? React.createElement(
|
|
382
|
+
"a",
|
|
383
|
+
{
|
|
384
|
+
href: link.url,
|
|
385
|
+
style: { ...styles.cta, textAlign: "center", textDecoration: "none" },
|
|
386
|
+
},
|
|
387
|
+
link.label,
|
|
388
|
+
)
|
|
389
|
+
: React.createElement(
|
|
390
|
+
"button",
|
|
391
|
+
{
|
|
392
|
+
type: "button",
|
|
393
|
+
style: isCurrent ? { ...styles.cta, ...styles.ctaCurrent } : styles.cta,
|
|
394
|
+
disabled: isCurrent,
|
|
395
|
+
onClick: () => (onSelect ? onSelect(plan, billingInterval) : undefined),
|
|
396
|
+
"aria-label": isCurrent
|
|
397
|
+
? `Currently on ${plan.name || plan.id}`
|
|
398
|
+
: `Choose ${plan.name || plan.id}`,
|
|
399
|
+
},
|
|
400
|
+
isCurrent ? "Current plan" : "Choose plan",
|
|
401
|
+
),
|
|
345
402
|
);
|
|
346
403
|
}),
|
|
347
404
|
),
|
|
@@ -21,15 +21,16 @@
|
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
const React = require("react");
|
|
24
|
+
const theme = require("./theme");
|
|
24
25
|
|
|
25
26
|
const styles = {
|
|
26
27
|
panel: {
|
|
27
|
-
fontFamily:
|
|
28
|
-
color:
|
|
28
|
+
fontFamily: theme.font,
|
|
29
|
+
color: theme.text,
|
|
29
30
|
border: "1px solid #e5e7eb",
|
|
30
31
|
borderRadius: 12,
|
|
31
32
|
padding: 20,
|
|
32
|
-
background:
|
|
33
|
+
background: theme.card,
|
|
33
34
|
display: "grid",
|
|
34
35
|
gap: 12,
|
|
35
36
|
maxWidth: 480,
|
package/src/TrialBanner.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
const React = require("react");
|
|
13
|
+
const theme = require("./theme");
|
|
13
14
|
|
|
14
15
|
const styles = {
|
|
15
16
|
banner: {
|
|
@@ -19,18 +20,16 @@ const styles = {
|
|
|
19
20
|
gap: 12,
|
|
20
21
|
padding: "10px 14px",
|
|
21
22
|
borderRadius: 10,
|
|
22
|
-
background:
|
|
23
|
-
color:
|
|
24
|
-
fontFamily:
|
|
23
|
+
background: theme.accentTint(),
|
|
24
|
+
color: theme.accent,
|
|
25
|
+
fontFamily: theme.font,
|
|
25
26
|
fontSize: 14,
|
|
26
27
|
},
|
|
27
28
|
expired: { background: "#fee2e2", color: "#991b1b" },
|
|
28
29
|
cta: {
|
|
29
30
|
padding: "6px 12px",
|
|
30
|
-
|
|
31
|
-
borderRadius: 6,
|
|
32
|
-
background: "#5045e8",
|
|
33
|
-
color: "#fff",
|
|
31
|
+
...theme.button,
|
|
32
|
+
borderRadius: theme.radius(6),
|
|
34
33
|
fontWeight: 600,
|
|
35
34
|
cursor: "pointer",
|
|
36
35
|
},
|
package/src/UsageChart.js
CHANGED
|
@@ -12,21 +12,22 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
const React = require("react");
|
|
15
|
+
const theme = require("./theme");
|
|
15
16
|
|
|
16
17
|
const styles = {
|
|
17
18
|
wrap: {
|
|
18
|
-
fontFamily:
|
|
19
|
-
color:
|
|
19
|
+
fontFamily: theme.font,
|
|
20
|
+
color: theme.text,
|
|
20
21
|
border: "1px solid #e5e7eb",
|
|
21
22
|
borderRadius: 12,
|
|
22
23
|
padding: 16,
|
|
23
|
-
background:
|
|
24
|
+
background: theme.card,
|
|
24
25
|
display: "grid",
|
|
25
26
|
gap: 8,
|
|
26
27
|
},
|
|
27
28
|
label: { fontSize: 12, opacity: 0.6, textTransform: "uppercase", letterSpacing: 0.4 },
|
|
28
29
|
total: { fontSize: 24, fontWeight: 700 },
|
|
29
|
-
bar: { fill:
|
|
30
|
+
bar: { fill: theme.accent },
|
|
30
31
|
};
|
|
31
32
|
|
|
32
33
|
const VALUE_LABELS = {
|
package/src/UsageProgress.js
CHANGED
|
@@ -16,19 +16,20 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
const React = require("react");
|
|
19
|
+
const theme = require("./theme");
|
|
19
20
|
|
|
20
21
|
const styles = {
|
|
21
22
|
wrap: {
|
|
22
23
|
display: "grid",
|
|
23
24
|
gap: 6,
|
|
24
|
-
fontFamily:
|
|
25
|
-
color:
|
|
25
|
+
fontFamily: theme.font,
|
|
26
|
+
color: theme.text,
|
|
26
27
|
},
|
|
27
28
|
header: { display: "flex", justifyContent: "space-between", fontSize: 13 },
|
|
28
29
|
label: { fontWeight: 600 },
|
|
29
30
|
value: { opacity: 0.75, fontFamily: "monospace" },
|
|
30
31
|
track: { background: "#e5e7eb", borderRadius: 6, height: 8, overflow: "hidden" },
|
|
31
|
-
fill: { height: "100%", background:
|
|
32
|
+
fill: { height: "100%", background: theme.accent, transition: "width 200ms ease" },
|
|
32
33
|
warn: { background: "#d97706" },
|
|
33
34
|
danger: { background: "#dc2626" },
|
|
34
35
|
stale: { fontSize: 11, opacity: 0.55, alignSelf: "flex-end" },
|
package/src/branding.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* branding.js — apply the tenant's branding (GET /v1/settings/branding, as
|
|
3
|
+
* the pricing snapshot and GET /v1/customer-portal/:id/branding return it) to
|
|
4
|
+
* the components: it becomes the --mbx-* CSS variables theme.js reads.
|
|
5
|
+
*
|
|
6
|
+
* <BrandingProvider branding={branding}>…</BrandingProvider>
|
|
7
|
+
*
|
|
8
|
+
* themes everything inside it; `useBranding()` reads the raw values (e.g. the
|
|
9
|
+
* logo). Values are checked again here (hex colors, a font list, an https
|
|
10
|
+
* logo), so a bad one is dropped rather than reaching a style.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const React = require("react");
|
|
14
|
+
|
|
15
|
+
const COLOR = /^#(?:[0-9a-fA-F]{3}){1,2}$/;
|
|
16
|
+
const FONT = /^[A-Za-z0-9 ,'"-]{1,100}$/;
|
|
17
|
+
const LOGO = /^https:\/\/[^\s"'<>()\\]+$/;
|
|
18
|
+
|
|
19
|
+
const BrandingContext = React.createContext(null);
|
|
20
|
+
|
|
21
|
+
/** The --mbx-* CSS variables for `branding`; anything invalid is left out. */
|
|
22
|
+
function brandingVars(branding) {
|
|
23
|
+
const b = branding || {};
|
|
24
|
+
const vars = {};
|
|
25
|
+
if (COLOR.test(b.accent_color || "")) vars["--mbx-accent"] = b.accent_color;
|
|
26
|
+
if (COLOR.test(b.text_color || "")) vars["--mbx-text"] = b.text_color;
|
|
27
|
+
if (COLOR.test(b.background_color || "")) vars["--mbx-card"] = b.background_color;
|
|
28
|
+
if (FONT.test(b.font_family || "")) vars["--mbx-font"] = b.font_family;
|
|
29
|
+
const radius = Number(b.button_radius_px);
|
|
30
|
+
if (b.button_radius_px != null && radius >= 0 && radius <= 32) {
|
|
31
|
+
vars["--mbx-radius"] = `${Math.round(radius)}px`;
|
|
32
|
+
}
|
|
33
|
+
if (b.button_style === "outline") {
|
|
34
|
+
vars["--mbx-button-bg"] = "transparent";
|
|
35
|
+
vars["--mbx-button-text"] = "var(--mbx-accent, #5045e8)";
|
|
36
|
+
vars["--mbx-button-border"] = "var(--mbx-accent, #5045e8)";
|
|
37
|
+
}
|
|
38
|
+
return vars;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The logo URL, when it's a valid https URL. */
|
|
42
|
+
function logoUrl(branding) {
|
|
43
|
+
return LOGO.test(branding?.logo_url || "") ? branding.logo_url : null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Themes its children with `branding`. The wrapper is `display: contents`, so
|
|
48
|
+
* it adds no box to the layout; CSS variables still inherit through it.
|
|
49
|
+
*/
|
|
50
|
+
function BrandingProvider({ branding, children }) {
|
|
51
|
+
return React.createElement(
|
|
52
|
+
BrandingContext.Provider,
|
|
53
|
+
{ value: branding || null },
|
|
54
|
+
React.createElement(
|
|
55
|
+
"div",
|
|
56
|
+
{ className: "meterbox-branding", style: { display: "contents", ...brandingVars(branding) } },
|
|
57
|
+
children,
|
|
58
|
+
),
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function useBranding() {
|
|
63
|
+
return React.useContext(BrandingContext);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = { BrandingProvider, useBranding, brandingVars, logoUrl };
|
package/src/index.js
CHANGED
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
* `/v1/customer-portal/*` endpoints using a short-lived customer-scoped
|
|
12
12
|
* JWT minted server-side (`POST /v1/tokens/:id`).
|
|
13
13
|
*
|
|
14
|
+
* Branding: `<BrandingProvider branding>` themes every component inside it
|
|
15
|
+
* with the tenant's branding (GET /v1/settings/branding); `theme` is the
|
|
16
|
+
* --mbx-* CSS variables they read, for matching your own elements.
|
|
17
|
+
*
|
|
14
18
|
* Re-exports `@meterbox/node` for convenience: `import { plans } from
|
|
15
19
|
* '@meterbox/react'` works the same as importing the SDK directly.
|
|
16
20
|
*/
|
|
@@ -32,6 +36,8 @@ const Paywall = require("./Paywall");
|
|
|
32
36
|
const UsageProgress = require("./UsageProgress");
|
|
33
37
|
const TrialBanner = require("./TrialBanner");
|
|
34
38
|
const CheckoutButton = require("./CheckoutButton");
|
|
39
|
+
const { BrandingProvider, useBranding, brandingVars, logoUrl } = require("./branding");
|
|
40
|
+
const theme = require("./theme");
|
|
35
41
|
|
|
36
42
|
module.exports = {
|
|
37
43
|
PricingTable,
|
|
@@ -48,6 +54,11 @@ module.exports = {
|
|
|
48
54
|
UsageProgress,
|
|
49
55
|
TrialBanner,
|
|
50
56
|
CheckoutButton,
|
|
57
|
+
BrandingProvider,
|
|
58
|
+
useBranding,
|
|
59
|
+
brandingVars,
|
|
60
|
+
logoUrl,
|
|
61
|
+
theme,
|
|
51
62
|
sdk,
|
|
52
63
|
MeterboxClient: sdk.MeterboxClient,
|
|
53
64
|
};
|
package/src/theme.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* theme.js — the style values every component uses: --mbx-* CSS variables,
|
|
3
|
+
* with Meterbox's defaults as fallbacks. The tenant's branding (Settings →
|
|
4
|
+
* Branding) sets the variables through <BrandingProvider> (branding.js) or a
|
|
5
|
+
* component's own `branding`; a page can also set them in its CSS.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const accent = "var(--mbx-accent, #5045e8)";
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
accent,
|
|
12
|
+
// A light wash of the accent (badges, banners, the current plan's glow).
|
|
13
|
+
accentTint: (pct = 12) => `color-mix(in srgb, ${accent} ${pct}%, transparent)`,
|
|
14
|
+
text: "var(--mbx-text, #111)",
|
|
15
|
+
card: "var(--mbx-card, #fff)",
|
|
16
|
+
font: "var(--mbx-font, system-ui, -apple-system, sans-serif)",
|
|
17
|
+
// Primary buttons: filled with the accent, or outlined (branding's button_style).
|
|
18
|
+
button: {
|
|
19
|
+
background: `var(--mbx-button-bg, ${accent})`,
|
|
20
|
+
color: "var(--mbx-button-text, #fff)",
|
|
21
|
+
border: "1px solid var(--mbx-button-border, transparent)",
|
|
22
|
+
},
|
|
23
|
+
radius: (px) => `var(--mbx-radius, ${px}px)`,
|
|
24
|
+
};
|