@ttoss/react-billing 0.5.11 → 0.5.13
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/dist/index.cjs +834 -0
- package/dist/index.d.cts +459 -0
- package/dist/index.d.mts +459 -0
- package/dist/index.mjs +801 -0
- package/package.json +9 -9
- package/dist/esm/index.js +0 -710
- package/dist/index.d.ts +0 -434
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
|
|
2
|
+
import { IconType } from "@ttoss/react-icons";
|
|
3
|
+
import { ButtonProps, CardProps } from "@ttoss/ui";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
|
|
6
|
+
//#region src/components/planCard/PlanCardVariants.d.ts
|
|
7
|
+
type PlanCardVariantType = 'primary' | 'secondary'
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated Use `primary`.
|
|
10
|
+
*/
|
|
11
|
+
| 'default'
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use `secondary`.
|
|
14
|
+
*/
|
|
15
|
+
| 'enterprise';
|
|
16
|
+
type PlanCardVariant = PlanCardVariantType;
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/components/planCard/PlanCardMetadataSlot.d.ts
|
|
19
|
+
type PlanCardMetadataSlotParameter = {
|
|
20
|
+
name: string;
|
|
21
|
+
value: React.ReactNode;
|
|
22
|
+
};
|
|
23
|
+
type PlanCardMetadataSlotService = {
|
|
24
|
+
label: string;
|
|
25
|
+
icon?: IconType;
|
|
26
|
+
parameters: PlanCardMetadataSlotParameter[];
|
|
27
|
+
id?: string;
|
|
28
|
+
key?: string;
|
|
29
|
+
};
|
|
30
|
+
type PlanCardMetadataSlotVariant = PlanCardVariantType;
|
|
31
|
+
interface PlanCardMetadataSlotProps {
|
|
32
|
+
metadata: PlanCardMetadataSlotService[];
|
|
33
|
+
variant?: PlanCardMetadataSlotVariant;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/components/planCard/PlanCard.d.ts
|
|
37
|
+
type PlanCardMetadata = PlanCardMetadataSlotService[];
|
|
38
|
+
type PlanCardPrice = {
|
|
39
|
+
value: string | number;
|
|
40
|
+
interval: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
};
|
|
43
|
+
type PlanCardButtonProps = Omit<ButtonProps, 'children'> & {
|
|
44
|
+
label?: string;
|
|
45
|
+
leftIcon?: IconType;
|
|
46
|
+
};
|
|
47
|
+
interface PlanCardProps extends Omit<CardProps, 'children'> {
|
|
48
|
+
variant?: PlanCardVariant;
|
|
49
|
+
topTag?: React.ReactNode;
|
|
50
|
+
title: string;
|
|
51
|
+
subtitle?: string;
|
|
52
|
+
metadata?: PlanCardMetadata;
|
|
53
|
+
metadataVariant?: PlanCardMetadataSlotVariant;
|
|
54
|
+
price: PlanCardPrice;
|
|
55
|
+
features?: unknown[];
|
|
56
|
+
buttonProps?: PlanCardButtonProps;
|
|
57
|
+
}
|
|
58
|
+
declare const PlanCard: (props: PlanCardProps) => import("react/jsx-runtime").JSX.Element;
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/components/plansPanel/PlansPanel.types.d.ts
|
|
61
|
+
/**
|
|
62
|
+
* A single option inside a PlansPanel filter.
|
|
63
|
+
*/
|
|
64
|
+
interface PlansPanelFilterOption {
|
|
65
|
+
/** Display label shown in the SegmentedControl. */
|
|
66
|
+
label: string;
|
|
67
|
+
/** Value used for filtering plans. */
|
|
68
|
+
value: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Defines one filter dimension rendered as a SegmentedControl above the plans grid.
|
|
72
|
+
*/
|
|
73
|
+
interface PlansPanelFilter {
|
|
74
|
+
/** Unique identifier for this filter dimension. */
|
|
75
|
+
id: string;
|
|
76
|
+
/** Optional label rendered above the SegmentedControl. */
|
|
77
|
+
label?: string;
|
|
78
|
+
/** List of selectable options. */
|
|
79
|
+
options: PlansPanelFilterOption[];
|
|
80
|
+
/** Initial value used in uncontrolled mode. */
|
|
81
|
+
defaultValue?: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* A plan displayed inside the PlansPanel.
|
|
85
|
+
*/
|
|
86
|
+
interface PlansPanelPlan {
|
|
87
|
+
/** Unique plan identifier. */
|
|
88
|
+
id: string;
|
|
89
|
+
/**
|
|
90
|
+
* Maps each filter id to the value this plan belongs to.
|
|
91
|
+
* Plans are only shown when all active filter values match.
|
|
92
|
+
*/
|
|
93
|
+
filterValues?: Record<string, string>;
|
|
94
|
+
/** Plan title (e.g. "Basic", "Pro"). */
|
|
95
|
+
title: string;
|
|
96
|
+
/** Optional subtitle displayed below the title. */
|
|
97
|
+
subtitle?: string;
|
|
98
|
+
/** Pricing information. */
|
|
99
|
+
price: PlanCardPrice;
|
|
100
|
+
/** Feature list items. */
|
|
101
|
+
features?: unknown[];
|
|
102
|
+
/** Optional metadata sections. */
|
|
103
|
+
metadata?: PlanCardMetadata;
|
|
104
|
+
/** Props forwarded to the CTA button. onClick is merged with onSelectPlan. */
|
|
105
|
+
buttonProps?: PlanCardButtonProps;
|
|
106
|
+
/** Visual variant for the PlanCard. Active plans override this with "secondary". */
|
|
107
|
+
variant?: PlanCardVariant;
|
|
108
|
+
/** Optional content rendered at the top of the PlanCard. */
|
|
109
|
+
topTag?: React.ReactNode;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Props for the PlansPanel component.
|
|
113
|
+
*/
|
|
114
|
+
interface PlansPanelProps {
|
|
115
|
+
/**
|
|
116
|
+
* Filter dimensions rendered as SegmentedControl rows above the plan grid.
|
|
117
|
+
* Each dimension independently narrows the visible set of plans.
|
|
118
|
+
*/
|
|
119
|
+
filters?: PlansPanelFilter[];
|
|
120
|
+
/** All available plans. Only plans matching every active filter value are shown. */
|
|
121
|
+
plans: PlansPanelPlan[];
|
|
122
|
+
/** ID of the currently active/subscribed plan. That card is highlighted. */
|
|
123
|
+
activePlanId?: string;
|
|
124
|
+
/**
|
|
125
|
+
* Called when the user clicks the CTA button of a plan.
|
|
126
|
+
* @param planId - The id of the selected plan.
|
|
127
|
+
*/
|
|
128
|
+
onSelectPlan?: (planId: string) => void;
|
|
129
|
+
/**
|
|
130
|
+
* Controlled filter values (record of filterId → selected value).
|
|
131
|
+
* When provided the component operates in controlled mode and internal
|
|
132
|
+
* state is not used.
|
|
133
|
+
*/
|
|
134
|
+
filterValues?: Record<string, string>;
|
|
135
|
+
/**
|
|
136
|
+
* Called when a filter value changes in controlled mode.
|
|
137
|
+
* @param id - The filter id that changed.
|
|
138
|
+
* @param value - The new selected value.
|
|
139
|
+
*/
|
|
140
|
+
onFilterChange?: (id: string, value: string) => void;
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region src/components/plansPanel/PlansPanel.d.ts
|
|
144
|
+
/**
|
|
145
|
+
* PlansPanel renders a grid of PlanCard components with optional multi-dimensional
|
|
146
|
+
* SegmentedControl filters above them.
|
|
147
|
+
*
|
|
148
|
+
* Each filter dimension independently narrows the visible set of plan cards.
|
|
149
|
+
* The component supports both uncontrolled mode (internal state from `defaultValue`)
|
|
150
|
+
* and controlled mode (via `filterValues` + `onFilterChange`).
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```tsx
|
|
154
|
+
* // Uncontrolled — component manages filter state internally
|
|
155
|
+
* <PlansPanel
|
|
156
|
+
* filters={[
|
|
157
|
+
* {
|
|
158
|
+
* id: 'interval',
|
|
159
|
+
* label: 'Billing Frequency',
|
|
160
|
+
* options: [
|
|
161
|
+
* { label: 'Monthly', value: 'monthly' },
|
|
162
|
+
* { label: 'Yearly', value: 'yearly' },
|
|
163
|
+
* ],
|
|
164
|
+
* defaultValue: 'monthly',
|
|
165
|
+
* },
|
|
166
|
+
* ]}
|
|
167
|
+
* plans={plans}
|
|
168
|
+
* activePlanId="plan_basic_monthly"
|
|
169
|
+
* onSelectPlan={(planId) => console.log(planId)}
|
|
170
|
+
* />
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```tsx
|
|
175
|
+
* // Controlled — consumer owns filter state
|
|
176
|
+
* <PlansPanel
|
|
177
|
+
* filters={filters}
|
|
178
|
+
* filterValues={{ interval: 'yearly' }}
|
|
179
|
+
* onFilterChange={(id, value) =>
|
|
180
|
+
* setFilterValues((prev) => ({ ...prev, [id]: value }))
|
|
181
|
+
* }
|
|
182
|
+
* plans={plans}
|
|
183
|
+
* onSelectPlan={(planId) => checkout(planId)}
|
|
184
|
+
* />
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
declare const PlansPanel: ({
|
|
188
|
+
filters,
|
|
189
|
+
plans,
|
|
190
|
+
activePlanId,
|
|
191
|
+
onSelectPlan,
|
|
192
|
+
filterValues: controlledFilterValues,
|
|
193
|
+
onFilterChange
|
|
194
|
+
}: PlansPanelProps) => import("react/jsx-runtime").JSX.Element;
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/components/subscriptionPanel/SubscriptionPanel.styles.d.ts
|
|
197
|
+
type SubscriptionPanelVariant = 'spotlight-accent' | 'spotlight-primary' | 'primary' | 'secondary' | 'accent';
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region src/components/subscriptionPanel/SubscriptionPanel.types.d.ts
|
|
200
|
+
/**
|
|
201
|
+
* Subscription status indicating the current state of the subscription.
|
|
202
|
+
*/
|
|
203
|
+
type SubscriptionStatus = 'active' | 'inactive' | 'cancelled';
|
|
204
|
+
/**
|
|
205
|
+
* Base metric properties shared by all metric types.
|
|
206
|
+
*/
|
|
207
|
+
interface BaseMetric {
|
|
208
|
+
/**
|
|
209
|
+
* Label displayed above the metric value.
|
|
210
|
+
*/
|
|
211
|
+
label: string;
|
|
212
|
+
/**
|
|
213
|
+
* Optional tooltip text or action handler for additional context.
|
|
214
|
+
* When a string is provided, it displays a simple tooltip.
|
|
215
|
+
* When a function is provided, it's called when the tooltip icon is clicked (e.g., to open help articles).
|
|
216
|
+
*/
|
|
217
|
+
tooltip?: string | (() => void);
|
|
218
|
+
/**
|
|
219
|
+
* Icon to display alongside the metric.
|
|
220
|
+
*/
|
|
221
|
+
icon?: IconType;
|
|
222
|
+
/**
|
|
223
|
+
* Optional click handler to make the metric card interactive.
|
|
224
|
+
*/
|
|
225
|
+
onClick?: () => void;
|
|
226
|
+
/**
|
|
227
|
+
* Optional help article action handler.
|
|
228
|
+
*/
|
|
229
|
+
helpArticleAction?: () => void;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Date-based metric for displaying dates like expiration or renewal.
|
|
233
|
+
*/
|
|
234
|
+
interface DateMetric extends BaseMetric {
|
|
235
|
+
type: 'date';
|
|
236
|
+
/**
|
|
237
|
+
* The date value to display.
|
|
238
|
+
*/
|
|
239
|
+
date: string;
|
|
240
|
+
/**
|
|
241
|
+
* Optional message showing remaining days.
|
|
242
|
+
*/
|
|
243
|
+
remainingDaysMessage?: string;
|
|
244
|
+
/**
|
|
245
|
+
* Whether to show a warning indicator.
|
|
246
|
+
*/
|
|
247
|
+
isWarning?: boolean;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Percentage-based metric with progress bar.
|
|
251
|
+
*/
|
|
252
|
+
interface PercentageMetric extends BaseMetric {
|
|
253
|
+
type: 'percentage';
|
|
254
|
+
/**
|
|
255
|
+
* Current value.
|
|
256
|
+
*/
|
|
257
|
+
current: number;
|
|
258
|
+
/**
|
|
259
|
+
* Maximum value. Use null for unlimited.
|
|
260
|
+
*/
|
|
261
|
+
max: number | null;
|
|
262
|
+
/**
|
|
263
|
+
* Custom formatter for displaying values.
|
|
264
|
+
*/
|
|
265
|
+
formatValue?: (value: number) => string;
|
|
266
|
+
/**
|
|
267
|
+
* Percentage threshold at which to show an alert.
|
|
268
|
+
*/
|
|
269
|
+
showAlertThreshold?: number;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Number-based metric for displaying counts.
|
|
273
|
+
*/
|
|
274
|
+
interface NumberMetric extends BaseMetric {
|
|
275
|
+
type: 'number';
|
|
276
|
+
/**
|
|
277
|
+
* Current value.
|
|
278
|
+
*/
|
|
279
|
+
current: number;
|
|
280
|
+
/**
|
|
281
|
+
* Maximum value. Use null for unlimited.
|
|
282
|
+
*/
|
|
283
|
+
max: number | null;
|
|
284
|
+
/**
|
|
285
|
+
* Custom formatter for displaying values.
|
|
286
|
+
*/
|
|
287
|
+
formatValue?: (value: number) => string;
|
|
288
|
+
/**
|
|
289
|
+
* Optional footer text below the metric.
|
|
290
|
+
*/
|
|
291
|
+
footerText?: string;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Union type for all metric types.
|
|
295
|
+
*/
|
|
296
|
+
type MetricType = DateMetric | PercentageMetric | NumberMetric;
|
|
297
|
+
/**
|
|
298
|
+
* Status badge configuration.
|
|
299
|
+
*/
|
|
300
|
+
interface SubscriptionPanelStatusBadgeProps {
|
|
301
|
+
/**
|
|
302
|
+
* The subscription status.
|
|
303
|
+
*/
|
|
304
|
+
status: SubscriptionStatus;
|
|
305
|
+
/**
|
|
306
|
+
* Billing interval (e.g., "Mensal", "Anual").
|
|
307
|
+
*/
|
|
308
|
+
interval?: string;
|
|
309
|
+
/**
|
|
310
|
+
* Whether the subscription has a pending cancellation.
|
|
311
|
+
*/
|
|
312
|
+
hasCancellation?: boolean;
|
|
313
|
+
/**
|
|
314
|
+
* Whether the subscription has a scheduled update.
|
|
315
|
+
*/
|
|
316
|
+
hasScheduledUpdate?: boolean;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Feature tag displayed in the card header.
|
|
320
|
+
*/
|
|
321
|
+
interface SubscriptionPanelFeatureTag {
|
|
322
|
+
/**
|
|
323
|
+
* Label text for the feature.
|
|
324
|
+
*/
|
|
325
|
+
label: string;
|
|
326
|
+
/**
|
|
327
|
+
* Optional icon for the feature.
|
|
328
|
+
*/
|
|
329
|
+
icon?: IconType;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Action button configuration.
|
|
333
|
+
*/
|
|
334
|
+
interface SubscriptionPanelAction extends Omit<ButtonProps, 'children'> {
|
|
335
|
+
/**
|
|
336
|
+
* Button label text.
|
|
337
|
+
*/
|
|
338
|
+
label: string;
|
|
339
|
+
/**
|
|
340
|
+
* Click handler for the action.
|
|
341
|
+
*/
|
|
342
|
+
onClick: () => void;
|
|
343
|
+
/**
|
|
344
|
+
* Optional icon for the button.
|
|
345
|
+
*/
|
|
346
|
+
leftIcon?: IconType;
|
|
347
|
+
/**
|
|
348
|
+
* Whether the action is currently loading.
|
|
349
|
+
*/
|
|
350
|
+
isLoading?: boolean;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Price configuration.
|
|
354
|
+
*/
|
|
355
|
+
interface SubscriptionPanelPrice {
|
|
356
|
+
/**
|
|
357
|
+
* Price value (e.g., "R$ 5,00").
|
|
358
|
+
*/
|
|
359
|
+
value: string;
|
|
360
|
+
/**
|
|
361
|
+
* Price interval (e.g., "mês", "ano").
|
|
362
|
+
*/
|
|
363
|
+
interval?: string;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Main SubscriptionPanel props.
|
|
367
|
+
*/
|
|
368
|
+
interface SubscriptionPanelProps {
|
|
369
|
+
/**
|
|
370
|
+
* Visual variant for the accent bar and header icon.
|
|
371
|
+
* @default 'spotlight'
|
|
372
|
+
*/
|
|
373
|
+
variant?: SubscriptionPanelVariant;
|
|
374
|
+
/**
|
|
375
|
+
* Plan icon to display. Can be a ReactNode or an IconType string.
|
|
376
|
+
*/
|
|
377
|
+
icon?: string;
|
|
378
|
+
/**
|
|
379
|
+
* Name of the subscription plan.
|
|
380
|
+
*/
|
|
381
|
+
planName: string;
|
|
382
|
+
/**
|
|
383
|
+
* Price configuration.
|
|
384
|
+
*/
|
|
385
|
+
price: SubscriptionPanelPrice;
|
|
386
|
+
/**
|
|
387
|
+
* Status badge configuration.
|
|
388
|
+
*/
|
|
389
|
+
status: SubscriptionPanelStatusBadgeProps;
|
|
390
|
+
/**
|
|
391
|
+
* Feature tags to display.
|
|
392
|
+
*/
|
|
393
|
+
features?: SubscriptionPanelFeatureTag[];
|
|
394
|
+
/**
|
|
395
|
+
* Action buttons.
|
|
396
|
+
*/
|
|
397
|
+
actions?: SubscriptionPanelAction[];
|
|
398
|
+
/**
|
|
399
|
+
* Metrics to display in the card.
|
|
400
|
+
*/
|
|
401
|
+
metrics?: MetricType[];
|
|
402
|
+
/**
|
|
403
|
+
* Whether the card is in a loading state.
|
|
404
|
+
*/
|
|
405
|
+
isLoading?: boolean;
|
|
406
|
+
}
|
|
407
|
+
//#endregion
|
|
408
|
+
//#region src/components/subscriptionPanel/SubscriptionPanel.d.ts
|
|
409
|
+
/**
|
|
410
|
+
* SubscriptionPanel displays comprehensive subscription information including
|
|
411
|
+
* plan details, status, actions, and various metrics.
|
|
412
|
+
*
|
|
413
|
+
* It supports three types of metrics:
|
|
414
|
+
* - **Date**: For displaying dates like expiration or renewal
|
|
415
|
+
* - **Percentage**: For usage-based metrics with progress bars
|
|
416
|
+
* - **Number**: For count-based metrics
|
|
417
|
+
*
|
|
418
|
+
* @example
|
|
419
|
+
* ```tsx
|
|
420
|
+
* <SubscriptionPanel
|
|
421
|
+
* planName="Premium Plan"
|
|
422
|
+
* price={{ value: "R$ 99,00", interval: "mês" }}
|
|
423
|
+
* status={{ status: "active", interval: "Mensal" }}
|
|
424
|
+
* features={[{ label: "Feature 1" }, { label: "Feature 2" }]}
|
|
425
|
+
* actions={[
|
|
426
|
+
* { label: "Upgrade", onClick: () => {}, variant: "accent" },
|
|
427
|
+
* { label: "Cancel", onClick: () => {}, variant: "danger" },
|
|
428
|
+
* ]}
|
|
429
|
+
* metrics={[
|
|
430
|
+
* { type: "date", label: "Expira em", date: "15/01/2025", icon: "fluent:calendar-24-regular" },
|
|
431
|
+
* { type: "percentage", label: "Uso", current: 75, max: 100, icon: "fluent:data-usage-24-regular" },
|
|
432
|
+
* ]}
|
|
433
|
+
* />
|
|
434
|
+
* ```
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
* ```tsx
|
|
438
|
+
* // Compact mode for smaller spaces
|
|
439
|
+
* <SubscriptionPanel
|
|
440
|
+
* planName="Basic Plan"
|
|
441
|
+
* price={{ value: "R$ 29,00", interval: "mês" }}
|
|
442
|
+
* status={{ status: "active" }}
|
|
443
|
+
* compact
|
|
444
|
+
* />
|
|
445
|
+
* ```
|
|
446
|
+
*/
|
|
447
|
+
declare const SubscriptionPanel: ({
|
|
448
|
+
variant,
|
|
449
|
+
icon,
|
|
450
|
+
planName,
|
|
451
|
+
price,
|
|
452
|
+
status,
|
|
453
|
+
features,
|
|
454
|
+
actions,
|
|
455
|
+
metrics,
|
|
456
|
+
isLoading
|
|
457
|
+
}: SubscriptionPanelProps) => import("react/jsx-runtime").JSX.Element;
|
|
458
|
+
//#endregion
|
|
459
|
+
export { PlanCard, type PlanCardButtonProps, type PlanCardMetadata, type PlanCardMetadataSlotParameter, type PlanCardMetadataSlotProps, type PlanCardMetadataSlotService, type PlanCardMetadataSlotVariant, type PlanCardPrice, type PlanCardProps, type PlanCardVariant, PlansPanel, type PlansPanelFilter, type PlansPanelFilterOption, type PlansPanelPlan, type PlansPanelProps, SubscriptionPanel };
|