index.js
74 lines
| 1 | import './editor.scss'; |
| 2 | |
| 3 | import { |
| 4 | Component, |
| 5 | Fragment, |
| 6 | } from '@wordpress/element'; |
| 7 | |
| 8 | import { |
| 9 | __, |
| 10 | } from '@wordpress/i18n'; |
| 11 | |
| 12 | import { |
| 13 | Tooltip, |
| 14 | Button, |
| 15 | } from '@wordpress/components'; |
| 16 | |
| 17 | import { |
| 18 | applyFilters, |
| 19 | } from '@wordpress/hooks'; |
| 20 | import { Icon, desktop, tablet, mobile } from '@wordpress/icons'; |
| 21 | |
| 22 | export default class ResponsiveTabs extends Component { |
| 23 | render() { |
| 24 | const { |
| 25 | onClick, |
| 26 | selectedDevice, |
| 27 | } = this.props; |
| 28 | |
| 29 | const panelHeader = document.querySelector( '.edit-post-sidebar .edit-post-sidebar__panel-tabs' ); |
| 30 | const panelHeaderHeight = panelHeader ? panelHeader.offsetHeight : 0; |
| 31 | |
| 32 | return ( |
| 33 | <Fragment> |
| 34 | <div className="gb-responsive-tabs" style={ { top: panelHeaderHeight + 'px' } }> |
| 35 | <Tooltip text={ __( 'Show options for all devices', 'generateblocks' ) }> |
| 36 | <Button |
| 37 | isPressed={ 'Desktop' === selectedDevice ? true : false } |
| 38 | onClick={ () => { |
| 39 | onClick( 'Desktop' ); |
| 40 | } } |
| 41 | > |
| 42 | <Icon icon={ desktop } /> |
| 43 | </Button> |
| 44 | </Tooltip> |
| 45 | |
| 46 | <Tooltip text={ __( 'Show options for tablet devices', 'generateblocks' ) }> |
| 47 | <Button |
| 48 | isPressed={ 'Tablet' === selectedDevice ? true : false } |
| 49 | onClick={ () => { |
| 50 | onClick( 'Tablet' ); |
| 51 | } } |
| 52 | > |
| 53 | <Icon icon={ tablet } /> |
| 54 | </Button> |
| 55 | </Tooltip> |
| 56 | |
| 57 | <Tooltip text={ __( 'Show options for mobile devices', 'generateblocks' ) }> |
| 58 | <Button |
| 59 | isPressed={ 'Mobile' === selectedDevice ? true : false } |
| 60 | onClick={ () => { |
| 61 | onClick( 'Mobile' ); |
| 62 | } } |
| 63 | > |
| 64 | <Icon icon={ mobile } /> |
| 65 | </Button> |
| 66 | </Tooltip> |
| 67 | </div> |
| 68 | |
| 69 | { applyFilters( 'generateblocks.editor.controls', '', 'afterResponsiveTabs', this.props, this.state ) } |
| 70 | </Fragment> |
| 71 | ); |
| 72 | } |
| 73 | } |
| 74 |