react-shopping-cart-kit 1.0.0

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.
@@ -0,0 +1,449 @@
1
+ import { Component } from 'react';
2
+ import { default as default_2 } from 'react';
3
+ import { ErrorInfo } from 'react';
4
+ import { JSX as JSX_2 } from 'react/jsx-runtime';
5
+ import { PersistOptions } from 'zustand/middleware';
6
+ import { ReactNode } from 'react';
7
+ import { StoreApi } from 'zustand';
8
+ import { UseBoundStore } from 'zustand';
9
+
10
+ export declare interface BaseProduct {
11
+ id: string | number;
12
+ name: string;
13
+ price: number;
14
+ image?: string;
15
+ quantity?: number;
16
+ }
17
+
18
+ export declare const calculateDiscount: (subtotal: number, discount: Discount | null) => number;
19
+
20
+ export declare const calculateSubtotal: <T extends BaseProduct>(items: CartItem<T>[]) => number;
21
+
22
+ export declare const calculateTax: (subtotal: number, discount: number, taxRate: number) => number;
23
+
24
+ export declare const calculateTotal: (subtotal: number, discount: number, tax: number) => number;
25
+
26
+ export declare const calculateTotalItems: <T extends BaseProduct>(items: CartItem<T>[]) => number;
27
+
28
+ export declare interface CartActions<T extends BaseProduct = BaseProduct> {
29
+ addItem: (product: T) => void;
30
+ removeItem: (id: string | number) => void;
31
+ updateItemQuantity: (id: string | number, quantity: number) => void;
32
+ clearCart: () => void;
33
+ applyDiscount: (code: string, amount: number, type?: 'percentage' | 'fixed') => void;
34
+ removeDiscount: () => void;
35
+ applyVoucher: (voucher: Voucher) => void;
36
+ removeVoucher: () => void;
37
+ validateVoucher: (code: string) => Voucher | null;
38
+ getActiveDiscounts: () => DiscountRule[];
39
+ getActiveVouchers: () => Voucher[];
40
+ }
41
+
42
+ export declare const CartButton: ({ className, iconClassName, badgeClassName, onClick, showBadge, badgePosition, }: CartButtonProps) => JSX_2.Element;
43
+
44
+ export declare interface CartButtonProps {
45
+ className?: string;
46
+ iconClassName?: string;
47
+ badgeClassName?: string;
48
+ onClick?: () => void;
49
+ showBadge?: boolean;
50
+ badgePosition?: 'top-right' | 'top-left';
51
+ }
52
+
53
+ export declare interface CartConfig {
54
+ storageKey?: string;
55
+ currency?: string;
56
+ taxRate?: number;
57
+ showTax?: boolean;
58
+ showDiscount?: boolean;
59
+ showShipping?: boolean;
60
+ showCurrencySelector?: boolean;
61
+ availableCurrencies?: Currency[];
62
+ shippingMethods?: ShippingMethod[];
63
+ discountCodes?: DiscountCode[];
64
+ }
65
+
66
+ export declare const CartDrawer: ({ className, overlayClassName, contentClassName, position, closeOnOverlayClick, showCheckoutButton, checkoutButtonText, onCheckout, }: CartDrawerProps) => JSX_2.Element | null;
67
+
68
+ export declare interface CartDrawerProps {
69
+ className?: string;
70
+ overlayClassName?: string;
71
+ contentClassName?: string;
72
+ position?: 'right' | 'left' | 'center' | 'start' | 'end';
73
+ closeOnOverlayClick?: boolean;
74
+ showCheckoutButton?: boolean;
75
+ checkoutButtonText?: string;
76
+ onCheckout?: () => void;
77
+ }
78
+
79
+ export declare type CartItem<T extends BaseProduct = BaseProduct> = T & {
80
+ quantity: number;
81
+ };
82
+
83
+ export declare const CartItemComponent: default_2.MemoExoticComponent<({ item, className, showRemoveButton, imageClassName, onRemove, }: CartItemProps) => JSX_2.Element>;
84
+
85
+ export declare interface CartItemProps {
86
+ item: CartItem;
87
+ className?: string;
88
+ showRemoveButton?: boolean;
89
+ imageClassName?: string;
90
+ onRemove?: (item: CartItem) => void;
91
+ }
92
+
93
+ export declare const CartItems: ({ className, emptyMessage, showRemoveButton, }: CartItemsProps) => JSX_2.Element;
94
+
95
+ export declare interface CartItemsProps {
96
+ className?: string;
97
+ emptyMessage?: string;
98
+ showRemoveButton?: boolean;
99
+ }
100
+
101
+ export declare const CartProvider: ({ children, config, language, taxRate, shippingMethods, }: CartProviderProps) => JSX_2.Element;
102
+
103
+ export declare interface CartProviderProps {
104
+ children: ReactNode;
105
+ config?: CartConfig;
106
+ language?: string;
107
+ taxRate?: number;
108
+ shippingMethods?: ShippingMethod[];
109
+ }
110
+
111
+ export declare interface CartState<T extends BaseProduct = BaseProduct> {
112
+ items: CartItem<T>[];
113
+ totalItems: number;
114
+ subtotal: number;
115
+ tax: number;
116
+ discount: Discount | null;
117
+ voucher: Voucher | null;
118
+ appliedRules: DiscountRule[];
119
+ total: number;
120
+ }
121
+
122
+ export declare const CartSummary: ({ className, showTax, showDiscount, }: CartSummaryProps) => JSX_2.Element;
123
+
124
+ export declare interface CartSummaryProps {
125
+ className?: string;
126
+ showTax?: boolean;
127
+ showDiscount?: boolean;
128
+ }
129
+
130
+ export declare const CheckoutButton: ({ className, disabled, loading, onClick, children, }: CheckoutButtonProps) => JSX_2.Element;
131
+
132
+ export declare interface CheckoutButtonProps {
133
+ className?: string;
134
+ disabled?: boolean;
135
+ loading?: boolean;
136
+ onClick?: () => void;
137
+ children?: React.ReactNode;
138
+ }
139
+
140
+ export declare const createCartStore: <T extends BaseProduct = BaseProduct>(config?: CartConfig) => UseBoundStore<Omit<StoreApi<StoreState<T>>, "persist"> & {
141
+ persist: {
142
+ setOptions: (options: Partial<PersistOptions<StoreState<T>, {
143
+ items: CartItem<T>[];
144
+ discount: Discount | null;
145
+ voucher: Voucher | null;
146
+ selectedShippingMethod: string;
147
+ selectedCurrency: string;
148
+ }>>) => void;
149
+ clearStorage: () => void;
150
+ rehydrate: () => Promise<void> | void;
151
+ hasHydrated: () => boolean;
152
+ onHydrate: (fn: (state: StoreState<T>) => void) => () => void;
153
+ onFinishHydration: (fn: (state: StoreState<T>) => void) => () => void;
154
+ getOptions: () => Partial<PersistOptions<StoreState<T>, {
155
+ items: CartItem<T>[];
156
+ discount: Discount | null;
157
+ voucher: Voucher | null;
158
+ selectedShippingMethod: string;
159
+ selectedCurrency: string;
160
+ }>>;
161
+ };
162
+ }>;
163
+
164
+ export declare interface Currency {
165
+ code: string;
166
+ symbol: string;
167
+ name: string;
168
+ conversionRate: number;
169
+ decimalPlaces: number;
170
+ thousandsSeparator: string;
171
+ decimalSeparator: string;
172
+ symbolOnLeft?: boolean;
173
+ }
174
+
175
+ export declare const CurrencySelector: ({ className, showCurrencyName, compact, }: CurrencySelectorProps) => JSX_2.Element | null;
176
+
177
+ export declare interface CurrencySelectorProps {
178
+ className?: string;
179
+ showCurrencyName?: boolean;
180
+ compact?: boolean;
181
+ }
182
+
183
+ export declare interface Discount {
184
+ code: string;
185
+ amount: number;
186
+ type: 'percentage' | 'fixed';
187
+ description?: string;
188
+ expiryDate?: Date;
189
+ minimumOrderValue?: number;
190
+ applicableProducts?: string[];
191
+ usageLimit?: number;
192
+ usageCount?: number;
193
+ }
194
+
195
+ export declare interface DiscountCode {
196
+ code: string;
197
+ amount: number;
198
+ type: 'percentage' | 'fixed';
199
+ description?: string;
200
+ expiryDate?: Date;
201
+ minimumOrderValue?: number;
202
+ usageLimit?: number;
203
+ }
204
+
205
+ export declare interface DiscountRule {
206
+ id: string;
207
+ name: string;
208
+ type: 'percentage' | 'fixed' | 'bogo' | 'bundle';
209
+ value: number;
210
+ conditions?: {
211
+ minimumOrderValue?: number;
212
+ applicableProducts?: string[];
213
+ excludedProducts?: string[];
214
+ maximumDiscount?: number;
215
+ expiryDate?: Date;
216
+ usageLimit?: number;
217
+ usageCount?: number;
218
+ };
219
+ isActive?: boolean;
220
+ priority?: number;
221
+ }
222
+
223
+ export declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
224
+ constructor(props: ErrorBoundaryProps);
225
+ static getDerivedStateFromError(error: Error): ErrorBoundaryState;
226
+ componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
227
+ render(): string | number | boolean | Iterable<ReactNode> | JSX_2.Element | null | undefined;
228
+ }
229
+
230
+ declare interface ErrorBoundaryProps {
231
+ children: ReactNode;
232
+ fallback?: ReactNode;
233
+ onError?: (error: Error, errorInfo: ErrorInfo) => void;
234
+ }
235
+
236
+ declare interface ErrorBoundaryState {
237
+ hasError: boolean;
238
+ error: Error | null;
239
+ }
240
+
241
+ export declare interface ShippingMethod {
242
+ id: string;
243
+ name: string;
244
+ description: string;
245
+ cost: number;
246
+ estimatedDays: string;
247
+ isDefault?: boolean;
248
+ }
249
+
250
+ declare interface StoreState<T extends BaseProduct = BaseProduct> {
251
+ items: CartItem<T>[];
252
+ discount: Discount | null;
253
+ voucher: Voucher | null;
254
+ selectedShippingMethod: string;
255
+ selectedCurrency: string;
256
+ isDrawerOpen: boolean;
257
+ config: CartConfig;
258
+ addItem: (product: T) => void;
259
+ removeItem: (id: string | number) => void;
260
+ updateItemQuantity: (id: string | number, quantity: number) => void;
261
+ clearCart: () => void;
262
+ applyDiscount: (code: string) => void;
263
+ removeDiscount: () => void;
264
+ applyVoucher: (voucher: Voucher) => void;
265
+ removeVoucher: () => void;
266
+ validateVoucher: (code: string, currentSubtotal?: number) => Voucher | null;
267
+ getActiveDiscounts: () => Discount[];
268
+ getActiveVouchers: () => Voucher[];
269
+ setIsDrawerOpen: (open: boolean) => void;
270
+ setConfig: (config: Partial<CartConfig>) => void;
271
+ setSelectedShippingMethod: (methodId: string) => void;
272
+ setSelectedCurrency: (currencyCode: string) => void;
273
+ validateDiscountCode: (code: string, currentSubtotal?: number) => DiscountCode | null;
274
+ getCurrentCurrency: () => Currency | null;
275
+ convertAmount: (amount: number) => number;
276
+ formatCurrency: (amount: number) => string;
277
+ }
278
+
279
+ export declare const supportedLanguages: {
280
+ code: string;
281
+ name: string;
282
+ dir: string;
283
+ }[];
284
+
285
+ export declare interface Translation {
286
+ cart: {
287
+ title: string;
288
+ empty: string;
289
+ addItem: string;
290
+ removeItem: string;
291
+ updateQuantity: string;
292
+ clearCart: string;
293
+ subtotal: string;
294
+ tax: string;
295
+ discount: string;
296
+ voucher: string;
297
+ total: string;
298
+ checkout: string;
299
+ applyVoucher: string;
300
+ removeVoucher: string;
301
+ invalidVoucher: string;
302
+ voucherApplied: string;
303
+ minimumOrderValue: string;
304
+ expiredVoucher: string;
305
+ usageLimitExceeded: string;
306
+ discountCode: string;
307
+ enterDiscountCode: string;
308
+ shippingMethod: string;
309
+ standardShipping: string;
310
+ expressShipping: string;
311
+ freeShipping: string;
312
+ item: string;
313
+ items: string;
314
+ addItemsToStart: string;
315
+ clear: string;
316
+ sortByName: string;
317
+ sortByPrice: string;
318
+ sortByQuantity: string;
319
+ paymentMethod: string;
320
+ hide: string;
321
+ change: string;
322
+ processing: string;
323
+ remove: string;
324
+ };
325
+ product: {
326
+ addToCart: string;
327
+ outOfStock: string;
328
+ inStock: string;
329
+ price: string;
330
+ quantity: string;
331
+ saveForLater: string;
332
+ save: string;
333
+ edit: string;
334
+ remove: string;
335
+ };
336
+ ui: {
337
+ loading: string;
338
+ error: string;
339
+ success: string;
340
+ close: string;
341
+ open: string;
342
+ save: string;
343
+ edit: string;
344
+ remove: string;
345
+ apply: string;
346
+ cancel: string;
347
+ continue: string;
348
+ search: string;
349
+ filter: string;
350
+ sort: string;
351
+ currency: string;
352
+ selectRequestedCurrency: string;
353
+ };
354
+ currencies: {
355
+ USD: string;
356
+ EUR: string;
357
+ GBP: string;
358
+ JOD: string;
359
+ AED: string;
360
+ SAR: string;
361
+ CAD: string;
362
+ AUD: string;
363
+ JPY: string;
364
+ [key: string]: string;
365
+ };
366
+ }
367
+
368
+ declare interface TranslationContextType {
369
+ language: string;
370
+ setLanguage: (language: string) => void;
371
+ t: ReturnType<typeof useTranslation>;
372
+ direction: 'ltr' | 'rtl';
373
+ }
374
+
375
+ export declare const TranslationProvider: ({ children, defaultLanguage, language: languageProp }: TranslationProviderProps) => default_2.FunctionComponentElement<default_2.ProviderProps<TranslationContextType | undefined>>;
376
+
377
+ declare interface TranslationProviderProps {
378
+ children: ReactNode;
379
+ defaultLanguage?: string;
380
+ language?: string;
381
+ }
382
+
383
+ export declare const useLanguageSwitcher: () => {
384
+ currentLanguage: string;
385
+ switchLanguage: (newLanguage: string) => void;
386
+ supportedLanguages: {
387
+ code: string;
388
+ name: string;
389
+ dir: string;
390
+ }[];
391
+ };
392
+
393
+ export declare const useShoppingCart: <T extends BaseProduct = BaseProduct>() => UseShoppingCartReturn<T>;
394
+
395
+ declare interface UseShoppingCartReturn<T extends BaseProduct = BaseProduct> {
396
+ items: CartItem<T>[];
397
+ totalItems: number;
398
+ subtotal: number;
399
+ tax: number;
400
+ discount: Discount | null;
401
+ discountAmount: number;
402
+ voucher: Voucher | null;
403
+ total: number;
404
+ isDrawerOpen: boolean;
405
+ config: CartConfig;
406
+ selectedShippingMethod: string;
407
+ shippingMethods: ShippingMethod[];
408
+ shippingCost: number;
409
+ selectedCurrency: string;
410
+ availableCurrencies: Currency[];
411
+ currentCurrency: Currency | null;
412
+ addItem: (product: T) => void;
413
+ removeItem: (id: string | number) => void;
414
+ updateItemQuantity: (id: string | number, quantity: number) => void;
415
+ clearCart: () => void;
416
+ applyDiscount: (code: string) => void;
417
+ removeDiscount: () => void;
418
+ applyVoucher: (voucher: Voucher) => void;
419
+ removeVoucher: () => void;
420
+ validateVoucher: (code: string) => Voucher | null;
421
+ getActiveDiscounts: () => Discount[];
422
+ getActiveVouchers: () => Voucher[];
423
+ setIsDrawerOpen: (open: boolean) => void;
424
+ setSelectedShippingMethod: (methodId: string) => void;
425
+ setSelectedCurrency: (currencyCode: string) => void;
426
+ validateDiscountCode: (code: string) => DiscountCode | null;
427
+ getCurrentCurrency: () => Currency | null;
428
+ convertAmount: (amount: number) => number;
429
+ formatCurrency: (amount: number) => string;
430
+ }
431
+
432
+ export declare const useTranslation: (language?: string) => Translation;
433
+
434
+ export declare const useTranslationContext: () => TranslationContextType;
435
+
436
+ export declare interface Voucher {
437
+ code: string;
438
+ amount: number;
439
+ type: 'percentage' | 'fixed';
440
+ description?: string;
441
+ expiryDate?: Date;
442
+ minimumOrderValue?: number;
443
+ applicableProducts?: string[];
444
+ usageLimit?: number;
445
+ usageCount?: number;
446
+ isValid?: boolean;
447
+ }
448
+
449
+ export { }