@meterbox/react 0.1.11 → 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 +2 -2
- package/package.json +2 -2
- package/src/PricingTable.js +78 -3
package/README.md
CHANGED
|
@@ -76,8 +76,8 @@ 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: 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
|
|
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
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").
|
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/PricingTable.js
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
*
|
|
38
38
|
* A plan's list is its `bullet_details` (the API's plans, the snapshot and the
|
|
39
39
|
* customer portal's plan list all carry it: each feature by its name on the
|
|
40
|
-
* plan, else its label with its description
|
|
40
|
+
* plan, else its label with its description behind an info icon, by its description
|
|
41
41
|
* when it has no label, by its id when it has neither), else its `bullets`,
|
|
42
42
|
* else its features (`{ id, name }`) by name, else by id; its included
|
|
43
43
|
* credits come first ("1,500 Bits a month"). A snapshot plan's
|
|
@@ -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,
|
|
@@ -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();
|
|
@@ -525,7 +600,7 @@ function PricingTable({
|
|
|
525
600
|
React.createElement("span", { "aria-hidden": true }, "• "),
|
|
526
601
|
React.createElement("span", null, b.text),
|
|
527
602
|
b.description &&
|
|
528
|
-
React.createElement(
|
|
603
|
+
React.createElement(FeatureInfo, { label: `About ${b.text}` }, b.description),
|
|
529
604
|
),
|
|
530
605
|
),
|
|
531
606
|
),
|