@metrifox/react-sdk 0.0.8 → 0.0.10

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 CHANGED
@@ -39,7 +39,9 @@ metrifoxInit({
39
39
 
40
40
  ---
41
41
 
42
- ## Core Widget: `CustomerPortal`
42
+ ## Widgets
43
+
44
+ ## `CustomerPortal`
43
45
 
44
46
  Displays a customizable customer dashboard with plans, subscriptions, billing, credits, and more.
45
47
 
@@ -64,7 +66,7 @@ export default function MyPortalPage() {
64
66
 
65
67
  ---
66
68
 
67
- ## Section Configuration
69
+ #### Section Configuration
68
70
 
69
71
  The `sectionsConfig` prop controls what appears in the portal.
70
72
 
@@ -75,7 +77,7 @@ The `sectionsConfig` prop controls what appears in the portal.
75
77
  | `component` | `React.ComponentType` | Replace the default section with your own component |
76
78
  | `props` | `Record<string, unknown>` | Extra props passed to the custom or default section |
77
79
 
78
- ### Built-in Section Keys
80
+ #### Built-in Section Keys
79
81
 
80
82
  | Key | Description |
81
83
  | ------------------ | ----------------------------- |
@@ -87,7 +89,7 @@ The `sectionsConfig` prop controls what appears in the portal.
87
89
  | `billingHistory` | List of past transactions |
88
90
  | `plan` | Current plan details |
89
91
 
90
- ### Section Anchors
92
+ #### Section Anchors
91
93
 
92
94
  Each portal section now renders inside a `<section id="...">` wrapper so you can link directly to segments of a customer portal view. The default anchor IDs are:
93
95
 
@@ -105,184 +107,158 @@ Use these anchors when embedding the SDK or sharing deep links (e.g., `https://a
105
107
 
106
108
  ---
107
109
 
108
- ## Core Widget: `PriceCard`
110
+ ## Pricing Table
109
111
 
110
- Display individual pricing plan cards with detailed pricing information, entitlements, and call-to-action buttons. Ideal for pricing pages, plan comparison views, or standalone plan displays.
112
+ Displays subscription plans and one-time purchases in a configurable pricing table component.
111
113
 
112
114
  ```tsx
113
- import { PriceCard } from "@metrifox/react-sdk"
115
+ import { PricingTable } from "@metrifox/react-sdk"
114
116
 
115
117
  export default function PricingPage() {
116
- const plan = {
117
- id: "plan-123",
118
- name: "Professional Plan",
119
- description: "Perfect for growing teams",
120
- is_visible: true,
121
- is_free: false,
122
- is_custom: false,
123
- is_current_plan: false,
124
- price_options: [
125
- {
126
- id: "price-1",
127
- amount: 2900, // $29.00 in cents
128
- currency: "USD",
129
- interval: "monthly",
130
- },
131
- ],
132
- entitlements: [
133
- {
134
- id: "ent-1",
135
- feature_id: "users",
136
- feature_key: "users",
137
- feature_name: "Team Members",
138
- limit_value: 10,
139
- is_visible: true,
140
- },
141
- ],
142
- // ... other plan properties
143
- }
144
-
145
- const featureOrderMap = new Map([
146
- ["users", 0],
147
- ["storage", 1],
148
- ])
149
-
150
- return (
151
- <PriceCard
152
- plan={plan}
153
- interval="monthly"
154
- featureOrderMap={featureOrderMap}
155
- buttonText="Start Free Trial"
156
- buttonAction={() => window.open(plan.checkout_url, "_blank")}
157
- isPricePage={true}
118
+ return(
119
+ <PricingTable
120
+ checkoutUsername="your-checkout-username"
121
+ productKey="your-product-key"
158
122
  />
159
123
  )
160
124
  }
161
125
  ```
162
126
 
163
- ### PriceCard Props
127
+ ---
164
128
 
165
- | Property | Type | Required | Description |
166
- | ------------------ | --------------------- | -------- | ------------------------------------------------------------ |
167
- | `plan` | `Offering` | ✅ | The plan/offering object containing pricing and feature data |
168
- | `interval` | `string` | ✅ | Billing interval to display (e.g., "monthly", "yearly") |
169
- | `featureOrderMap` | `Map<string, number>` | ✅ | Map defining the display order of features |
170
- | `isPricePage` | `boolean` | ❌ | Enable pricing page mode with enhanced styling |
171
- | `isCustomerPortal` | `boolean` | ❌ | Enable customer portal mode for subscription management |
172
- | `buttonText` | `string` | ❌ | Custom text for the action button |
173
- | `buttonAction` | `() => void` | ❌ | Function called when action button is clicked |
174
- | `isCurrentPlan` | `boolean` | ❌ | Highlight card as the customer's current plan |
175
- | `statusTag` | `React.ReactNode` | ❌ | Custom status indicator (e.g., "Popular", "Recommended") |
176
- | `addPriceButton` | `React.ReactNode` | ❌ | Additional custom button element |
177
- | `planActions` | `React.ReactNode` | ❌ | Custom actions area (e.g., edit, delete buttons) |
178
- | `cardAction` | `() => void` | ❌ | Function called when the entire card is clicked |
129
+ #### Props
179
130
 
180
- ### Plan Data Structure (Offering)
131
+ The props control how the pricing table is configured.
181
132
 
182
- The `plan` prop expects an object with the following structure:
133
+ | Property | Type | Required | Default | Description |
134
+ | --------------------- | --------- | -------- | ------- | -------------------------------------------------------------------------------- |
135
+ | `checkoutUsername` | `string` | Yes | — | Unique username used for checkout. This can be found in **Settings → Checkout**. |
136
+ | `productKey` | `string` | Yes | — | Unique product identifier. This can be found on the product page. |
137
+ | `plansOnly` | `boolean` | No | `false` | Controls whether only subscription plans are rendered. |
138
+ | `singlePurchasesOnly` | `boolean` | No | `false` | Controls whether only single purchases are rendered. |
139
+ | `showTabHeader` | `boolean` | No | `true` | Controls whether the tab header for switching between offerings is rendered. |
183
140
 
184
- ```tsx
185
- interface Offering {
186
- id: string
187
- name: string
188
- description: string
189
- is_visible: boolean
190
- is_free: boolean
191
- is_custom: boolean
192
- is_current_plan: boolean
193
- checkout_url?: string
194
- custom_cta_text?: string
195
- trial_duration_unit?: string
196
- trial_duration_value?: number
197
-
198
- // Pricing options for different intervals
199
- price_options: PriceOption[]
200
- entitlement_price_options: PriceOption[]
201
- credit_attachment_price_options: PriceOption[]
202
-
203
- // Features and entitlements
204
- entitlements: Entitlement[]
205
- credit_attachments?: CreditSystemProps[]
206
- base_entitlements_plan_name?: string
207
-
208
- // Metadata
209
- version_id: string
210
- status: string
211
- // ... other properties
212
- }
213
- ```
141
+ > **Note:** If both `plansOnly` and `singlePurchasesOnly` are `false` or undefined, both plans and single purchases are displayed.
214
142
 
215
- ### Usage Patterns
143
+ ## Styling
216
144
 
217
- #### Basic Pricing Page
145
+ Import the SDK’s global styles into your app entry (e.g., `src/index.tsx` or `_app.tsx`):
218
146
 
219
147
  ```tsx
220
- const plans = [
221
- { /* Basic plan data */ },
222
- { /* Pro plan data */ },
223
- { /* Enterprise plan data */ }
224
- ]
225
-
226
- const featureOrderMap = new Map([
227
- ["users", 0],
228
- ["storage", 1],
229
- ["api_calls", 2]
230
- ])
231
-
232
- return (
233
- <div className="grid grid-cols-1 md:grid-cols-3 gap-6">
234
- {plans.map(plan => (
235
- <PriceCard
236
- key={plan.id}
237
- plan={plan}
238
- interval={selectedInterval}
239
- featureOrderMap={featureOrderMap}
240
- isPricePage={true}
241
- buttonAction={() => handlePlanSelection(plan)}
242
- />
243
- ))}
244
- </div>
245
- )
148
+ import "@metrifox/react-sdk/dist/styles.css"
246
149
  ```
247
150
 
248
- #### Customer Portal Integration
151
+ > This is required for proper styling of all widgets.
249
152
 
250
- ```tsx
251
- <PriceCard
252
- plan={plan}
253
- interval={selectedInterval}
254
- featureOrderMap={featureOrderMap}
255
- isCustomerPortal={true}
256
- isCurrentPlan={plan.is_current_plan}
257
- buttonText={plan.is_current_plan ? "Current Plan" : "Upgrade"}
258
- buttonAction={() => handleUpgrade(plan.checkout_url)}
259
- />
260
- ```
153
+ #### Pricing Table
154
+ The SDK accepts an optional `pricingTableTheme` object during initialization. This theme is applied to Pricing Table component and UI elements within it to match your brand styles.
155
+
156
+ Any values not provided will fall back to the default theme.
157
+
158
+ ```ts
159
+ // Pricing table theme configuration
160
+ pricingTableTheme?: {
161
+ card?: {
162
+ background?: string
163
+ borderColor?: string
164
+ descriptionColor?: string
165
+
166
+ header?: {
167
+ background?: string
168
+ textColor?: string
169
+ }
170
+
171
+ description?: {
172
+ textColor?: string
173
+ textButtonColor?: string
174
+ }
175
+
176
+ price?: {
177
+ amountColor?: string
178
+ primaryTextColor?: string
179
+ secondaryTextColor?: string
180
+ textButtonColor?: string
181
+ background?: string
182
+ borderColor?: string
183
+ }
184
+ }
261
185
 
262
- #### With Custom Status Tags
186
+ button?: {
187
+ background?: string
188
+ textColor?: string
189
+ secondaryBackground?: string
190
+ secondaryTextColor?: string
191
+ textButtonColor?: string
192
+ }
263
193
 
264
- ```tsx
265
- <PriceCard
266
- plan={plan}
267
- interval="monthly"
268
- featureOrderMap={featureOrderMap}
269
- statusTag={<span className="bg-blue-500 text-white px-2 py-1 rounded text-xs">Most Popular</span>}
270
- buttonAction={() => selectPlan(plan)}
271
- />
272
- ```
194
+ featureList?: {
195
+ textColor?: string
196
+ iconColor?: string
197
+ }
273
198
 
274
- ---
199
+ tabs?: {
200
+ inactiveText?: string
201
+ activeText?: string
202
+ indicator?: string
203
+ borderColor?: string
204
+ }
275
205
 
276
- ## Styling
206
+ intervalToggle?: {
207
+ background?: string
208
+ activeBackground?: string
209
+ activeText?: string
210
+ inactiveText?: string
211
+ }
277
212
 
278
- Import the SDK’s global styles into your app entry (e.g., `src/index.tsx` or `_app.tsx`):
213
+ currentSubscriptionCard?: {
214
+ header?: {
215
+ background?: string
216
+ textColor?: string
217
+ }
218
+ gradientColor?: string
219
+ }
279
220
 
280
- ```tsx
281
- import "@metrifox/react-sdk/dist/styles.css"
221
+ freeTrialTag?: {
222
+ background?: string
223
+ textColor?: string
224
+ }
225
+
226
+ checkoutBar?: {
227
+ background?: string
228
+ borderColor?: string
229
+ textColor?: string
230
+ buttonBackground?: string
231
+ buttonTextColor?: string
232
+ }
233
+ }
282
234
  ```
235
+ ###### Example usage
236
+ ```tsx
237
+ import { metrifoxInit } from "@metrifox/react-sdk"
283
238
 
284
- > This is required for proper styling of all widgets.
239
+ const pricingTableTheme = {
240
+ pricingTable: {
241
+ card: {
242
+ background: "#ffffff",
243
+ price: {
244
+ amountColor: "#111827",
245
+ textButtonColor: "#2563eb",
246
+ },
247
+ },
248
+ button: {
249
+ background: "#2563eb",
250
+ },
251
+ tabs: {
252
+ activeText: "#2563eb",
253
+ },
254
+ },
255
+ }
285
256
 
257
+ metrifoxInit({
258
+ clientKey: "your-client-key",
259
+ pricingTableTheme,
260
+ })
261
+ ```
286
262
  ---
287
263
 
288
264
  ## Local Development