@meterbox/react 0.1.4 → 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 +14 -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 +29 -16
- 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? customerEmail? />` 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`.
|
|
@@ -74,6 +74,19 @@ 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
|
+
### 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
|
+
|
|
77
90
|
### `<PlanComparison from to onSwitch? />`
|
|
78
91
|
|
|
79
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,6 +26,10 @@
|
|
|
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
|
+
*
|
|
29
33
|
* From the snapshot, the featured plan is highlighted with its `badge`, a
|
|
30
34
|
* plan's `trial_days` shows as "14-day free trial", and without `onSelect`
|
|
31
35
|
* each plan's button is its call-to-action link (`customerEmail` fills
|
|
@@ -36,6 +40,8 @@
|
|
|
36
40
|
*/
|
|
37
41
|
|
|
38
42
|
const React = require("react");
|
|
43
|
+
const theme = require("./theme");
|
|
44
|
+
const { brandingVars } = require("./branding");
|
|
39
45
|
|
|
40
46
|
/**
|
|
41
47
|
* Total charged for one year prepaid upfront, or null when the plan
|
|
@@ -68,27 +74,27 @@ const styles = {
|
|
|
68
74
|
color: "#4b5563",
|
|
69
75
|
fontSize: 13,
|
|
70
76
|
fontWeight: 600,
|
|
71
|
-
fontFamily:
|
|
77
|
+
fontFamily: theme.font,
|
|
72
78
|
cursor: "pointer",
|
|
73
79
|
},
|
|
74
|
-
toggleBtnActive: { background:
|
|
80
|
+
toggleBtnActive: { background: theme.accent, color: "#fff" },
|
|
75
81
|
grid: {
|
|
76
82
|
display: "grid",
|
|
77
83
|
gridTemplateColumns: "repeat(auto-fit, minmax(220px, 1fr))",
|
|
78
84
|
gap: 16,
|
|
79
|
-
fontFamily:
|
|
80
|
-
color:
|
|
85
|
+
fontFamily: theme.font,
|
|
86
|
+
color: theme.text,
|
|
81
87
|
},
|
|
82
88
|
card: {
|
|
83
89
|
border: "1px solid #e5e7eb",
|
|
84
90
|
borderRadius: 12,
|
|
85
91
|
padding: 20,
|
|
86
|
-
background:
|
|
92
|
+
background: theme.card,
|
|
87
93
|
display: "flex",
|
|
88
94
|
flexDirection: "column",
|
|
89
95
|
gap: 12,
|
|
90
96
|
},
|
|
91
|
-
cardCurrent: { borderColor:
|
|
97
|
+
cardCurrent: { borderColor: theme.accent, boxShadow: `0 0 0 3px ${theme.accentTint(13)}` },
|
|
92
98
|
name: { fontSize: 18, fontWeight: 600, margin: 0 },
|
|
93
99
|
price: { fontSize: 28, fontWeight: 700 },
|
|
94
100
|
perMonth: { fontSize: 12, opacity: 0.6, marginLeft: 4 },
|
|
@@ -96,14 +102,17 @@ const styles = {
|
|
|
96
102
|
cta: {
|
|
97
103
|
marginTop: "auto",
|
|
98
104
|
padding: "10px 14px",
|
|
99
|
-
|
|
100
|
-
borderRadius: 8,
|
|
101
|
-
background: "#5045e8",
|
|
102
|
-
color: "#fff",
|
|
105
|
+
...theme.button,
|
|
106
|
+
borderRadius: theme.radius(8),
|
|
103
107
|
fontWeight: 600,
|
|
104
108
|
cursor: "pointer",
|
|
105
109
|
},
|
|
106
|
-
ctaCurrent: {
|
|
110
|
+
ctaCurrent: {
|
|
111
|
+
background: "#e5e7eb",
|
|
112
|
+
color: theme.text,
|
|
113
|
+
border: "1px solid transparent",
|
|
114
|
+
cursor: "default",
|
|
115
|
+
},
|
|
107
116
|
trial: { fontSize: 13, fontWeight: 600 },
|
|
108
117
|
usage: {
|
|
109
118
|
display: "grid",
|
|
@@ -115,7 +124,7 @@ const styles = {
|
|
|
115
124
|
badge: {
|
|
116
125
|
fontSize: 11,
|
|
117
126
|
fontWeight: 600,
|
|
118
|
-
background:
|
|
127
|
+
background: theme.accent,
|
|
119
128
|
color: "#fff",
|
|
120
129
|
padding: "2px 8px",
|
|
121
130
|
borderRadius: 999,
|
|
@@ -232,7 +241,7 @@ async function fetchCatalog({ baseUrl, publishableKey, fetchImpl }) {
|
|
|
232
241
|
const res = await fetchImpl(url, { method: "GET" });
|
|
233
242
|
if (!res.ok) throw new Error(`pricing-table: ${res.status}`);
|
|
234
243
|
const body = await res.json();
|
|
235
|
-
return (body.plans || []).map(fromSnapshot);
|
|
244
|
+
return { plans: (body.plans || []).map(fromSnapshot), branding: body.branding || null };
|
|
236
245
|
}
|
|
237
246
|
|
|
238
247
|
function PricingTable({
|
|
@@ -241,6 +250,7 @@ function PricingTable({
|
|
|
241
250
|
currency = "USD",
|
|
242
251
|
onSelect,
|
|
243
252
|
customerEmail,
|
|
253
|
+
branding,
|
|
244
254
|
baseUrl,
|
|
245
255
|
publishableKey,
|
|
246
256
|
fetch: fetchImpl,
|
|
@@ -257,14 +267,17 @@ function PricingTable({
|
|
|
257
267
|
if (alive) setFetched(d);
|
|
258
268
|
})
|
|
259
269
|
.catch(() => {
|
|
260
|
-
if (alive) setFetched([]);
|
|
270
|
+
if (alive) setFetched({ plans: [], branding: null });
|
|
261
271
|
});
|
|
262
272
|
return () => {
|
|
263
273
|
alive = false;
|
|
264
274
|
};
|
|
265
275
|
}, [selfFetch, baseUrl, publishableKey, fetchImpl]);
|
|
266
276
|
|
|
267
|
-
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);
|
|
268
281
|
if (!Array.isArray(list) || list.length === 0) {
|
|
269
282
|
return React.createElement(
|
|
270
283
|
"div",
|
|
@@ -277,7 +290,7 @@ function PricingTable({
|
|
|
277
290
|
|
|
278
291
|
return React.createElement(
|
|
279
292
|
"div",
|
|
280
|
-
{ className: "meterbox-pricing-table", style: styles.wrap },
|
|
293
|
+
{ className: "meterbox-pricing-table", style: { ...styles.wrap, ...vars } },
|
|
281
294
|
hasAnnualOption &&
|
|
282
295
|
React.createElement(
|
|
283
296
|
"div",
|
|
@@ -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
|
+
};
|