File size: 1,443 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import { Button } from '@wordpress/components';
import { Icon, desktop, mobile, tablet } from '@wordpress/icons';
import clsx from 'clsx';
import { translate } from 'i18n-calypso';
import { useRef } from 'react';
import { DEVICES_SUPPORTED, DEVICE_TYPES } from './constants';
import type { Device } from './types';
import './toolbar.scss';
interface ToolbarProps {
device: Device;
onDeviceClick: ( device: Device ) => void;
}
const DeviceSwitcherToolbar = ( { device: currentDevice, onDeviceClick }: ToolbarProps ) => {
const devices = useRef( {
[ DEVICE_TYPES.COMPUTER ]: { title: translate( 'Desktop' ), icon: desktop, iconSize: 24 },
[ DEVICE_TYPES.TABLET ]: { title: translate( 'Tablet' ), icon: tablet, iconSize: 24 },
[ DEVICE_TYPES.PHONE ]: { title: translate( 'Phone' ), icon: mobile, iconSize: 24 },
} );
return (
<div className="device-switcher__toolbar">
<div className="device-switcher__toolbar-devices">
{ DEVICES_SUPPORTED.map( ( device ) => (
<Button
key={ device }
aria-label={ devices.current[ device ].title }
className={ clsx( {
[ device ]: true,
'is-selected': device === currentDevice,
} ) }
onClick={ () => onDeviceClick( device ) }
>
<Icon
icon={ devices.current[ device ].icon }
size={ devices.current[ device ].iconSize }
/>
</Button>
) ) }
</div>
</div>
);
};
export default DeviceSwitcherToolbar;
|