-
-
Notifications
You must be signed in to change notification settings - Fork 118
/
index.d.ts
138 lines (117 loc) · 4.1 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { CartDetails, CartState, Config, Product } from '../core'
import * as React from 'react'
export { actions, filterCart, formatCurrencyString } from '../core/index.d'
type ProviderProps = Config & {
children: React.ReactNode
loading?: React.ReactNode
}
/**
* Context provider to interact with Stripe API
*/
export const CartProvider: React.FunctionComponent<ProviderProps>
export interface CartActions {
/**
* Add `count` amount of a product to the cart
* @param product The product to add to the cart
* @param count The quantity of the product to add
*/
addItem: (
product: Product,
options?: {
count: number
price_metadata?: { [propName: string]: any }
product_metadata?: { [propName: string]: any }
}
) => undefined
/**
* Remove an item from the cart by its product ID
* @param id The product ID of the item in the cart to remove
*/
removeItem: (id: string) => undefined
/**
* Reduce the quantity of an item in the cart by `count`
* @param id The product ID of the item to reduce in quantity
* @param options.count The quantity to decrease by, defaults to 1
*/
decrementItem: (id: string, options?: { count: number }) => undefined
/**
* Increase the quantity of an item in the cart by `count`
* @param id The product ID of the item to increase in quantity
* @param options.count The quantity to increase by, defaults to 1
*/
incrementItem: (id: string, options?: { count: number }) => undefined
/**
* Set the quantity of an item in the cart to a specific value
* @param id The product ID of the item whose quantity you wish to change
* @param quantity The quantity to set the item to
*/
setItemQuantity: (id: string, quantity: number) => undefined
/**
* Redirects customers to the Stripe checkout. Works in both
* CheckoutSession and ClientOnly mode.
* @param sessionId Used in CheckoutSession mode, it is the ID of the
* checkout session created by your server/serverless function.
* @returns Nothing or an error wrapped in a promise if an error occurred
*/
redirectToCheckout: (sessionId?: string) => Promise<any>
/**
* Redirects customers to the Stripe checkout with a single product.
* Only works in ClientOnly mode.
* @param productId The ID of the product to buy one of.
* @returns Nothing or an error wrapped in a promise if an error occurred
*/
checkoutSingleItem: (productId: string) => Promise<any>
/**
* Totally clears the cart of all items
*/
clearCart: () => undefined
/**
* @param cartDetails The cart cartDetails stored somewhere (e.g. on the server).
* @param shouldMerge Defaults to true. When false, it replaces cartDetails entirely.
* @see CartDetails
*/
loadCart: (cartDetails: CartDetails, shouldMerge?: boolean) => undefined
/**
* Sets `shouldDisplayCart` to `true`.
*/
handleCartHover: () => undefined
/**
* Toggles `shouldDisplayCart` between `true` and `false`.
*/
handleCartClick: () => undefined
/**
* Sets `shouldDisplayCart` to `false`.
*/
handleCloseCart: () => undefined
/**
* Given a product ID, it sets `lastClicked` to that value.
*/
storeLastClicked: (lastClicked: string) => undefined
/**
* Given a public Stripe key string, it sets `stripe` to that value.
*/
changeStripeKey: (stripeKey: string) => undefined
/**
* Given an ISO language code (e.g. en-US), it sets `language` to that value.
*/
changeLanguage: (language: string) => undefined
/**
* Given an ISO currency code (e.g. USD), it sets `currency` to that value.
*/
changeCurrency: (currency: string) => undefined
}
/**
* Provides several utilities and pieces of data for you to use in your application.
*/
export function useShoppingCart<SelectorResult extends Partial<CartState>>(
selector?: (state: CartState) => SelectorResult
): SelectorResult & CartActions
/**
* Displays the values returned by `useShoppingCart()` in a table format.
*/
export const DebugCart: React.FunctionComponent<
React.DetailedHTMLProps<
React.TableHTMLAttributes<HTMLTableElement>,
HTMLTableElement
>
>