@metrifox/react-sdk 0.0.6 → 0.0.8
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 +168 -0
- package/dist/index.cjs +14 -14
- package/dist/index.d.ts +220 -1
- package/dist/index.js +14 -14
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -105,6 +105,174 @@ Use these anchors when embedding the SDK or sharing deep links (e.g., `https://a
|
|
|
105
105
|
|
|
106
106
|
---
|
|
107
107
|
|
|
108
|
+
## Core Widget: `PriceCard`
|
|
109
|
+
|
|
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.
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
import { PriceCard } from "@metrifox/react-sdk"
|
|
114
|
+
|
|
115
|
+
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}
|
|
158
|
+
/>
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### PriceCard Props
|
|
164
|
+
|
|
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 |
|
|
179
|
+
|
|
180
|
+
### Plan Data Structure (Offering)
|
|
181
|
+
|
|
182
|
+
The `plan` prop expects an object with the following structure:
|
|
183
|
+
|
|
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
|
+
```
|
|
214
|
+
|
|
215
|
+
### Usage Patterns
|
|
216
|
+
|
|
217
|
+
#### Basic Pricing Page
|
|
218
|
+
|
|
219
|
+
```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
|
+
)
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
#### Customer Portal Integration
|
|
249
|
+
|
|
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
|
+
```
|
|
261
|
+
|
|
262
|
+
#### With Custom Status Tags
|
|
263
|
+
|
|
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
|
+
```
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
108
276
|
## Styling
|
|
109
277
|
|
|
110
278
|
Import the SDK’s global styles into your app entry (e.g., `src/index.tsx` or `_app.tsx`):
|