| 1 |
/** |
| 2 |
* JavaScript code for the "Edit" section integration of the "Save Changes" and "Preview" buttons. |
| 3 |
* |
| 4 |
* @package TablePress |
| 5 |
* @subpackage Views JavaScript |
| 6 |
* @author Tobias Bäthge |
| 7 |
* @since 3.0.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
/** |
| 11 |
* WordPress dependencies. |
| 12 |
*/ |
| 13 |
import { |
| 14 |
Button, |
| 15 |
__experimentalHStack as HStack, // eslint-disable-line @wordpress/no-unsafe-wp-apis |
| 16 |
__experimentalVStack as VStack, // eslint-disable-line @wordpress/no-unsafe-wp-apis |
| 17 |
} from '@wordpress/components'; |
| 18 |
import { __, _x, sprintf } from '@wordpress/i18n'; |
| 19 |
|
| 20 |
/** |
| 21 |
* Internal dependencies. |
| 22 |
*/ |
| 23 |
import { initializeReactComponentInPortal } from '../common/react-loader'; |
| 24 |
|
| 25 |
const modifierKey = ( window?.navigator?.platform?.includes( 'Mac' ) ) ? |
| 26 |
_x( '⌘', 'keyboard shortcut modifier key on a Mac keyboard', 'tablepress' ) : |
| 27 |
_x( 'Ctrl+', 'keyboard shortcut modifier key on a non-Mac keyboard', 'tablepress' ); |
| 28 |
|
| 29 |
const Section = () => { |
| 30 |
return ( |
| 31 |
<VStack |
| 32 |
style={ { |
| 33 |
margin: '1.5rem 0', |
| 34 |
} } |
| 35 |
> |
| 36 |
<HStack alignment="left"> |
| 37 |
{ |
| 38 |
( tp.screen_options.currentUserCanPreviewTable ) && ( |
| 39 |
<Button |
| 40 |
variant="secondary" |
| 41 |
href={ tp.screen_options.previewUrl } |
| 42 |
className="button-preview" |
| 43 |
text={ __( 'Preview', 'tablepress' ) } |
| 44 |
title={ sprintf( __( 'Keyboard Shortcut: %s', 'tablepress' ), sprintf( _x( '%1$sP', 'keyboard shortcut for Preview', 'tablepress' ), modifierKey ) ) } |
| 45 |
onClick={ ( event ) => ( tp.callbacks.table_preview.process( event ) ) } |
| 46 |
/> |
| 47 |
) |
| 48 |
} |
| 49 |
<Button |
| 50 |
variant="primary" |
| 51 |
className="button-save-changes" |
| 52 |
text={ __( 'Save Changes', 'tablepress' ) } |
| 53 |
title={ sprintf( __( 'Keyboard Shortcut: %s', 'tablepress' ), sprintf( _x( '%1$sS', 'keyboard shortcut for Save Changes', 'tablepress' ), modifierKey ) ) } |
| 54 |
onClick={ ( event ) => ( tp.callbacks.save_changes.process( event ) ) } |
| 55 |
/> |
| 56 |
</HStack> |
| 57 |
</VStack> |
| 58 |
); |
| 59 |
}; |
| 60 |
|
| 61 |
initializeReactComponentInPortal( |
| 62 |
'tablepress_edit-buttons-1', |
| 63 |
'edit', |
| 64 |
Section, |
| 65 |
); |
| 66 |
|
| 67 |
initializeReactComponentInPortal( |
| 68 |
'tablepress_edit-buttons-2', |
| 69 |
'edit', |
| 70 |
Section, |
| 71 |
); |
| 72 |
|