@gechiui/block-editor
Version:
38 lines (33 loc) • 898 B
JavaScript
/**
* GeChiUI dependencies
*/
import { withSelect } from '@gechiui/data';
import { __ } from '@gechiui/i18n';
import { Button } from '@gechiui/components';
/**
* Internal dependencies
*/
import { store as blockEditorStore } from '../../store';
import { __unstableUseBlockRef as useBlockRef } from '../block-list/use-block-props/use-block-refs';
const SkipToSelectedBlock = ( { selectedBlockClientId } ) => {
const ref = useBlockRef( selectedBlockClientId );
const onClick = () => {
ref.current.focus();
};
return selectedBlockClientId ? (
<Button
variant="secondary"
className="block-editor-skip-to-selected-block"
onClick={ onClick }
>
{ __( '跳转至选定的区块' ) }
</Button>
) : null;
};
export default withSelect( ( select ) => {
return {
selectedBlockClientId: select(
blockEditorStore
).getBlockSelectionStart(),
};
} )( SkipToSelectedBlock );