59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
/**
|
|
* External dependencies
|
|
*/
|
|
import { createContext, useContext } from '@wordpress/element';
|
|
|
|
/**
|
|
* Context consumed by inner blocks.
|
|
*/
|
|
export type CheckoutBlockContextProps = {
|
|
showCompanyField: boolean;
|
|
requireCompanyField: boolean;
|
|
showApartmentField: boolean;
|
|
requireApartmentField: boolean;
|
|
showPhoneField: boolean;
|
|
requirePhoneField: boolean;
|
|
showOrderNotes: boolean;
|
|
showPolicyLinks: boolean;
|
|
showReturnToCart: boolean;
|
|
cartPageId: number;
|
|
showRateAfterTaxName: boolean;
|
|
hasDarkControls: boolean;
|
|
showFormStepNumbers: boolean;
|
|
};
|
|
|
|
export type CheckoutBlockControlsContextProps = {
|
|
addressFieldControls: () => JSX.Element | null;
|
|
};
|
|
|
|
export const CheckoutBlockContext: React.Context< CheckoutBlockContextProps > =
|
|
createContext< CheckoutBlockContextProps >( {
|
|
showCompanyField: false,
|
|
requireCompanyField: false,
|
|
showApartmentField: false,
|
|
requireApartmentField: false,
|
|
showPhoneField: false,
|
|
requirePhoneField: false,
|
|
showOrderNotes: true,
|
|
showPolicyLinks: true,
|
|
showReturnToCart: true,
|
|
cartPageId: 0,
|
|
showRateAfterTaxName: false,
|
|
hasDarkControls: false,
|
|
showFormStepNumbers: false,
|
|
} );
|
|
|
|
export const CheckoutBlockControlsContext: React.Context< CheckoutBlockControlsContextProps > =
|
|
createContext< CheckoutBlockControlsContextProps >( {
|
|
addressFieldControls: () => null,
|
|
} );
|
|
|
|
export const useCheckoutBlockContext = (): CheckoutBlockContextProps => {
|
|
return useContext( CheckoutBlockContext );
|
|
};
|
|
|
|
export const useCheckoutBlockControlsContext =
|
|
(): CheckoutBlockControlsContextProps => {
|
|
return useContext( CheckoutBlockControlsContext );
|
|
};
|