index.js
57 lines
| 1 | import { Dropdown, ToolbarButton } from '@wordpress/components'; |
| 2 | import './styles.scss'; |
| 3 | import { __ } from '@wordpress/i18n'; |
| 4 | import Matrix from './components/matrix'; |
| 5 | |
| 6 | function AlignmentMatrix( { activeCell, onChange, direction, children } ) { |
| 7 | return ( |
| 8 | <Dropdown |
| 9 | className="gb-alignment-matrix" |
| 10 | contentClassName="gb-alignment-matrix-content" |
| 11 | popoverProps={ { variant: 'toolbar', placement: 'bottom-center' } } |
| 12 | focusOnMount={ true } |
| 13 | renderToggle={ ( { isOpen, onToggle } ) => { |
| 14 | const openOnArrowDown = ( event ) => { |
| 15 | if ( ! isOpen && event.keyCode === 40 ) { |
| 16 | event.preventDefault(); |
| 17 | onToggle(); |
| 18 | } |
| 19 | }; |
| 20 | |
| 21 | return ( |
| 22 | <ToolbarButton |
| 23 | onClick={ onToggle } |
| 24 | aria-haspopup="true" |
| 25 | aria-expanded={ isOpen } |
| 26 | onKeyDown={ openOnArrowDown } |
| 27 | label={ __( 'Change content position', 'generateblocks' ) } |
| 28 | icon={ ( |
| 29 | <Matrix |
| 30 | isCompact |
| 31 | isOpen={ isOpen } |
| 32 | direction={ direction } |
| 33 | activeCell={ activeCell } |
| 34 | /> |
| 35 | ) } |
| 36 | showTooltip |
| 37 | disabled={ false } |
| 38 | /> |
| 39 | ); |
| 40 | } } |
| 41 | renderContent={ () => ( |
| 42 | <div className="gb-alignment-matrix-content"> |
| 43 | <div className="gb-alignment-matrix-content-buttons"> |
| 44 | { children } |
| 45 | </div> |
| 46 | <Matrix |
| 47 | activeCell={ activeCell } |
| 48 | onChange={ onChange } |
| 49 | /> |
| 50 | </div> |
| 51 | ) } |
| 52 | /> |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | export default AlignmentMatrix; |
| 57 |