Skip to content

Commit

Permalink
Ensure the classic block allows diplaying at fullscreen, allowing for…
Browse files Browse the repository at this point in the history
… toggling (#53449)

Update the height so that more content is displayed in the tinymce editor in smaller viewports
  • Loading branch information
ramonjd authored Aug 10, 2023
1 parent b60e368 commit 00ef602
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/block-library/src/freeform/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,20 @@ div[data-type="core/freeform"] {
}

.block-editor-freeform-modal {
.components-modal__frame {
.block-editor-freeform-modal__content {
.mce-edit-area iframe {
height: 50vh !important;
}
// On large screens, make the TinyMCE edit area grow to take all the
// available height so that the Cancel/Save buttons are always into the
// view. On smaller screens, the modal content is scrollable.
@include break-large() {

// On medium and large screens, the modal component sets a max-height.
// We want the modal to be as tall as possible also when the content is short.
height: 9999rem;
&:not(.is-full-screen) {
height: 9999rem;
}

.components-modal__header + div {
height: 100%;
Expand All @@ -397,6 +403,7 @@ div[data-type="core/freeform"] {
height: 100%;
display: flex;
flex-direction: column;
min-width: 50vw;
}

.mce-edit-area {
Expand Down
34 changes: 34 additions & 0 deletions packages/block-library/src/freeform/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,29 @@ import {
import { useEffect, useState, RawHTML } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { fullscreen } from '@wordpress/icons';
import { useViewportMatch } from '@wordpress/compose';

function ModalAuxiliaryActions( { onClick, isModalFullScreen } ) {
// 'small' to match the rules in editor.scss.
const isMobileViewport = useViewportMatch( 'small', '<' );
if ( isMobileViewport ) {
return null;
}

return (
<Button
onClick={ onClick }
icon={ fullscreen }
isPressed={ isModalFullScreen }
label={
isModalFullScreen
? __( 'Exit fullscreen' )
: __( 'Enter fullscreen' )
}
/>
);
}

function ClassicEdit( props ) {
const styles = useSelect(
Expand Down Expand Up @@ -58,6 +81,7 @@ export default function ModalEdit( props ) {
onReplace,
} = props;
const [ isOpen, setOpen ] = useState( false );
const [ isModalFullScreen, setIsModalFullScreen ] = useState( false );
const id = `editor-${ clientId }`;

const onClose = () => ( content ? setOpen( false ) : onReplace( [] ) );
Expand All @@ -78,6 +102,16 @@ export default function ModalEdit( props ) {
onRequestClose={ onClose }
shouldCloseOnClickOutside={ false }
overlayClassName="block-editor-freeform-modal"
isFullScreen={ isModalFullScreen }
className="block-editor-freeform-modal__content"
headerActions={
<ModalAuxiliaryActions
onClick={ () =>
setIsModalFullScreen( ! isModalFullScreen )
}
isModalFullScreen={ isModalFullScreen }
/>
}
>
<ClassicEdit id={ id } defaultValue={ content } />
<Flex
Expand Down

0 comments on commit 00ef602

Please sign in to comment.