index.tsx
29 lines
| 1 | import {createContext, ReactNode, useContext} from 'react'; |
| 2 | import {CurrencySwitcherSetting} from '@givewp/forms/types'; |
| 3 | |
| 4 | const StoreContext = createContext(null); |
| 5 | StoreContext.displayName = 'DonationFormSettings'; |
| 6 | |
| 7 | type PropTypes = { |
| 8 | value: { |
| 9 | [key: string]: unknown; |
| 10 | currencySwitcherSettings?: CurrencySwitcherSetting[]; |
| 11 | currencySwitcherMessage?: string; |
| 12 | donateButtonCaption: string; |
| 13 | multiStepNextButtonText: string; |
| 14 | multiStepFirstButtonText: string; |
| 15 | }; |
| 16 | children: ReactNode; |
| 17 | }; |
| 18 | |
| 19 | /** |
| 20 | * @since 3.0.0 |
| 21 | */ |
| 22 | const DonationFormSettingsProvider = ({value, children}: PropTypes) => { |
| 23 | return <StoreContext.Provider value={value}>{children}</StoreContext.Provider>; |
| 24 | }; |
| 25 | |
| 26 | const useDonationFormSettings = () => useContext<PropTypes['value']>(StoreContext); |
| 27 | |
| 28 | export {DonationFormSettingsProvider, useDonationFormSettings}; |
| 29 |