/** * External dependencies */ import { createElement } from '@wordpress/element'; import { Toolbar, ToolbarButton, ToolbarGroup } from '@wordpress/components'; import { chevronRight, chevronLeft, trash } from '@wordpress/icons'; import { MediaItem, MediaUpload } from '@wordpress/media-utils'; import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ import { CoverImageIcon } from './icons'; import { SortableHandle } from '../sortable'; import { MediaUploadComponentType } from './types'; export type ImageGalleryToolbarProps = { childIndex: number; moveItem: ( fromIndex: number, toIndex: number ) => void; removeItem: ( removeIndex: number ) => void; replaceItem: ( replaceIndex: number, media: { id: number } & MediaItem ) => void; setToolBarItem: ( key: string | null ) => void; lastChild: boolean; MediaUploadComponent: MediaUploadComponentType; } & React.HTMLAttributes< HTMLDivElement >; export const ImageGalleryToolbar: React.FC< ImageGalleryToolbarProps > = ( { childIndex, moveItem, removeItem, replaceItem, setToolBarItem, lastChild, MediaUploadComponent = MediaUpload, }: ImageGalleryToolbarProps ) => { const moveNext = () => { moveItem( childIndex, childIndex + 1 ); }; const movePrevious = () => { moveItem( childIndex, childIndex - 1 ); }; const setAsCoverImage = ( coverIndex: number ) => { moveItem( coverIndex, 0 ); setToolBarItem( null ); }; const isCoverItem = childIndex === 0; return (
e.stopPropagation() } label={ __( 'Options', 'woocommerce' ) } id="options-toolbar" > { ! isCoverItem && ( ( ) } label={ __( 'Drag', 'woocommerce' ) } /> movePrevious() } icon={ chevronLeft } label={ __( 'Move previous', 'woocommerce' ) } /> moveNext() } icon={ chevronRight } label={ __( 'Move next', 'woocommerce' ) } disabled={ lastChild } /> ) } { ! isCoverItem && ( setAsCoverImage( childIndex ) } icon={ CoverImageIcon } label={ __( 'Set as cover image', 'woocommerce' ) } /> ) } replaceItem( childIndex, media as MediaItem ) } allowedTypes={ [ 'image' ] } render={ ( { open } ) => ( { __( 'Replace', 'woocommerce' ) } ) } /> removeItem( childIndex ) } icon={ trash } label={ __( 'Delete', 'woocommerce' ) } />
); };