@gechiui/block-editor
Version:
76 lines (72 loc) • 1.87 kB
JavaScript
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* GeChiUI dependencies
*/
import { useViewportMatch } from '@gechiui/compose';
import { DropdownMenu, MenuGroup, MenuItem } from '@gechiui/components';
import { __ } from '@gechiui/i18n';
import { check } from '@gechiui/icons';
export default function PreviewOptions( {
children,
className,
isEnabled = true,
deviceType,
setDeviceType,
} ) {
const isMobile = useViewportMatch( 'small', '<' );
if ( isMobile ) return null;
const popoverProps = {
className: classnames(
className,
'block-editor-post-preview__dropdown-content'
),
position: 'bottom left',
};
const toggleProps = {
variant: 'tertiary',
className: 'block-editor-post-preview__button-toggle',
disabled: ! isEnabled,
/* translators: button label text should, if possible, be under 16 characters. */
children: __( '预览' ),
};
return (
<DropdownMenu
className="block-editor-post-preview__dropdown"
popoverProps={ popoverProps }
toggleProps={ toggleProps }
icon={ null }
>
{ () => (
<>
<MenuGroup>
<MenuItem
className="block-editor-post-preview__button-resize"
onClick={ () => setDeviceType( 'Desktop' ) }
icon={ deviceType === 'Desktop' && check }
>
{ __( '桌面端' ) }
</MenuItem>
<MenuItem
className="block-editor-post-preview__button-resize"
onClick={ () => setDeviceType( 'Tablet' ) }
icon={ deviceType === 'Tablet' && check }
>
{ __( '平板电脑' ) }
</MenuItem>
<MenuItem
className="block-editor-post-preview__button-resize"
onClick={ () => setDeviceType( 'Mobile' ) }
icon={ deviceType === 'Mobile' && check }
>
{ __( '移动端' ) }
</MenuItem>
</MenuGroup>
{ children }
</>
) }
</DropdownMenu>
);
}