woocommerce/plugins/woocommerce-blocks/assets/js/blocks/product-gallery/frontend.tsx

67 lines
1.1 KiB
TypeScript
Raw Normal View History

/**
* External dependencies
*/
import { store as interactivityApiStore } from '@woocommerce/interactivity';
interface State {
[ key: string ]: unknown;
}
interface Context {
woocommerce: {
selectedImage: string;
imageId: string;
isDialogOpen: boolean;
};
}
interface Selectors {
woocommerce: {
isSelected: ( store: unknown ) => boolean;
isDialogOpen: ( store: unknown ) => boolean;
};
}
interface Actions {
woocommerce: {
thumbnails: {
handleClick: ( context: Context ) => void;
};
};
}
interface Store {
state: State;
context: Context;
selectors: Selectors;
actions: Actions;
ref?: HTMLElement;
}
interactivityApiStore( {
state: {},
selectors: {
woocommerce: {
isSelected: ( { context }: Store ) => {
return (
context?.woocommerce.selectedImage ===
context?.woocommerce.imageId
);
},
isDialogOpen: ( { context }: Store ) => {
return context?.woocommerce.isDialogOpen;
},
},
},
actions: {
woocommerce: {
thumbnails: {
handleClick: ( { context }: Store ) => {
context.woocommerce.selectedImage =
context.woocommerce.imageId;
},
},
},
},
} );