Skip to content

Commit

Permalink
Update the modal design (#40781)
Browse files Browse the repository at this point in the history
* Blur the content behind modal
* Increase modal heading size
* Use `Close` icon
* Remove the stroke beneath the modal header (re-appears on scroll)

Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
Co-authored-by: Robert Anderson <robert@noisysocks.com>
  • Loading branch information
3 people committed Jul 6, 2022
1 parent f23d3e8 commit 1339b96
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 65 deletions.
Expand Up @@ -175,7 +175,7 @@ const BlockPatternSetup = ( {
activeSlide={ activeSlide }
patterns={ patterns }
onBlockPatternSelect={ onPatternSelectCallback }
height={ contentHeight - 2 * 60 }
height={ contentHeight - ( 74 + 60 ) } // Content - ( modal header + modal actions )
/>
<SetupToolbar
viewMode={ viewMode }
Expand Down
Expand Up @@ -17,6 +17,7 @@
display: block;
width: 100%;
padding: $grid-unit-40;
padding-top: 0;
column-count: 2;

@include break-huge() {
Expand Down Expand Up @@ -54,7 +55,6 @@
margin: 0;
color: $gray-900;
// Block UI appearance.
border-radius: $radius-block-ui $radius-block-ui 0 0;
background-color: $white;
display: flex;
flex-direction: row;
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/components/inserter/style.scss
Expand Up @@ -342,7 +342,7 @@ $block-inserter-tabs-height: 44px;
.block-editor-block-patterns-explorer {
&__sidebar {
position: absolute;
top: $header-height;
top: $header-height + $grid-unit-20;
left: 0;
bottom: 0;
width: $sidebar-width;
Expand Down
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Expand Up @@ -167,6 +167,7 @@

- `InputControl`: Add `__next36pxDefaultSize` flag for larger default size ([#40622](https://github.com/WordPress/gutenberg/pull/40622)).
- `UnitControl`: Add `__next36pxDefaultSize` flag for larger default size ([#40627](https://github.com/WordPress/gutenberg/pull/40627)).
- `Modal` design adjustments: Blur elements outside of the modal, increase modal title size, use larger close icon, remove header border when modal contents are scrolled. ([#40781](https://github.com/WordPress/gutenberg/pull/40781)).
- `SelectControl`: Improved TypeScript support ([#40737](https://github.com/WordPress/gutenberg/pull/40737)).
- `ToggleControlGroup`: Switch to internal `Icon` component for dashicon support ([40717](https://github.com/WordPress/gutenberg/pull/40717)).
- Improve `ToolsPanel` accessibility. ([#40716](https://github.com/WordPress/gutenberg/pull/40716))
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/guide/style.scss
Expand Up @@ -20,6 +20,7 @@
border-bottom: none;
padding: 0;
position: sticky;
height: $header-height;

.components-button {
align-self: flex-start;
Expand Down
23 changes: 21 additions & 2 deletions packages/components/src/modal/index.js
Expand Up @@ -10,8 +10,10 @@ import classnames from 'classnames';
*/
import {
createPortal,
useCallback,
useEffect,
useRef,
useState,
forwardRef,
} from '@wordpress/element';
import {
Expand All @@ -24,7 +26,7 @@ import {
} from '@wordpress/compose';
import { ESCAPE } from '@wordpress/keycodes';
import { __ } from '@wordpress/i18n';
import { closeSmall } from '@wordpress/icons';
import { close } from '@wordpress/icons';

/**
* Internal dependencies
Expand Down Expand Up @@ -73,6 +75,8 @@ function Modal( props, forwardedRef ) {
const focusReturnRef = useFocusReturn();
const focusOutsideProps = useFocusOutside( onRequestClose );

const [ hasScrolledContent, setHasScrolledContent ] = useState( false );

useEffect( () => {
openModalCount++;

Expand Down Expand Up @@ -104,6 +108,19 @@ function Modal( props, forwardedRef ) {
}
}

const onContentContainerScroll = useCallback(
( e ) => {
const scrollY = e?.target?.scrollTop ?? -1;

if ( ! hasScrolledContent && scrollY > 0 ) {
setHasScrolledContent( true );
} else if ( hasScrolledContent && scrollY <= 0 ) {
setHasScrolledContent( false );
}
},
[ hasScrolledContent ]
);

return createPortal(
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
<div
Expand Down Expand Up @@ -142,8 +159,10 @@ function Modal( props, forwardedRef ) {
<div
className={ classnames( 'components-modal__content', {
'hide-header': __experimentalHideHeader,
'has-scrolled-content': hasScrolledContent,
} ) }
role="document"
onScroll={ onContentContainerScroll }
>
{ ! __experimentalHideHeader && (
<div className="components-modal__header">
Expand All @@ -168,7 +187,7 @@ function Modal( props, forwardedRef ) {
{ isDismissible && (
<Button
onClick={ onRequestClose }
icon={ closeSmall }
icon={ close }
label={
closeButtonLabel ||
__( 'Close dialog' )
Expand Down
18 changes: 17 additions & 1 deletion packages/components/src/modal/stories/index.js
Expand Up @@ -35,7 +35,23 @@ const ModalExample = ( props ) => {
Open Modal
</Button>
{ isOpen && (
<Modal { ...props } onRequestClose={ closeModal }>
<Modal
{ ...props }
onRequestClose={ closeModal }
style={ { maxWidth: '600px' } }
>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et magna
aliqua. Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquip ex ea ea
commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit
anim id est laborum.
</p>

<Button variant="secondary" onClick={ closeModal }>
Close Modal
</Button>
Expand Down
27 changes: 9 additions & 18 deletions packages/components/src/modal/style.scss
Expand Up @@ -8,6 +8,7 @@
background-color: rgba($black, 0.35);
z-index: z-index(".components-modal__screen-overlay");
display: flex;
backdrop-filter: blur($grid-unit);

// This animates the appearance of the white background.
@include edit-post__fade-in-animation();
Expand Down Expand Up @@ -63,21 +64,21 @@
// modal screen).
.components-modal__header {
box-sizing: border-box;
border-bottom: $border-width solid $gray-300;
border-bottom: $border-width solid transparent;
padding: 0 $grid-unit-40;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
height: $header-height;
height: $header-height + $grid-unit-20;
width: 100%;
z-index: z-index(".components-modal__header");
position: absolute;
top: 0;
left: 0;

.components-modal__header-heading {
font-size: 1rem;
font-size: 1.2rem;
font-weight: 600;
}

Expand All @@ -90,6 +91,10 @@
position: relative;
left: $grid-unit-10;
}

.components-modal__content.has-scrolled-content:not(.hide-header) & {
border-bottom-color: $gray-300;
}
}

.components-modal__header-heading-container {
Expand All @@ -113,26 +118,12 @@
// Modal contents.
.components-modal__content {
flex: 1;
margin-top: $header-height;
margin-top: $header-height + $grid-unit-20;
padding: 0 $grid-unit-40 $grid-unit-30;
overflow: auto;

// Emulate margin-bottom for the header. Uses a pseudo-element since the
// absolutely positioned header’s margins wouldn’t effect siblings and
// padding-top on the content element would effect positioning of any
// sticky elements within.
&::before {
content: "";
display: block;
margin-bottom: $grid-unit-30;
}

&.hide-header {
margin-top: 0;
padding-top: $grid-unit-30;

&::before {
content: none;
}
}
}
Expand Up @@ -3,11 +3,6 @@
margin: 0 0 2rem 0;
}

&__main-shortcuts .edit-post-keyboard-shortcut-help-modal__shortcut-list {
// Push the shortcut to be flush with top modal header.
margin-top: -$grid-unit-30 -$border-width;
}

&__section-title {
font-size: 0.9rem;
font-weight: 600;
Expand Down
10 changes: 0 additions & 10 deletions packages/edit-post/src/components/sidebar/post-template/style.scss
Expand Up @@ -29,16 +29,6 @@
margin: $grid-unit-10;
}

.edit-post-post-template__create-modal {
.components-modal__header {
border-bottom: none;
}

.components-modal__content::before {
margin-bottom: $grid-unit-05;
}
}

.edit-post-post-template__create-form {
@include break-medium() {
width: $grid-unit * 40;
Expand Down
35 changes: 35 additions & 0 deletions packages/edit-post/src/components/sidebar/template/style.scss
@@ -0,0 +1,35 @@
.edit-post-template__modal {
.components-base-control {
@include break-medium() {
width: $grid-unit * 40;
}
}
}

.edit-post-template__modal-actions {
margin-top: $grid-unit-15;
}

.edit-post-template-modal__tip {
padding: $grid-unit-20 $grid-unit-30;
background: $gray-100;
border-radius: $radius-block-ui;

@include break-medium() {
width: $grid-unit * 30;
}
}

.edit-post-template__notice {
margin: 0 0 $grid-unit-10 0;

.components-notice__content {
margin: 0;
}
}

.edit-post-template__actions {
button:not(:last-child) {
margin-right: $grid-unit-10;
}
}
Expand Up @@ -11,15 +11,6 @@
@include break-large() {
height: 70%;
}

// @todo: Consider this for a minimal modal prop.
.components-modal__header {
border-bottom: none;
}

.components-modal__content::before {
content: none;
}
}

// 2 column masonry layout.
Expand Down
Expand Up @@ -3,11 +3,6 @@
margin: 0 0 2rem 0;
}

&__main-shortcuts .edit-site-keyboard-shortcut-help-modal__shortcut-list {
// Push the shortcut to be flush with top modal header.
margin-top: -$grid-unit-30 -$border-width;
}

&__section-title {
font-size: 0.9rem;
font-weight: 600;
Expand Down
8 changes: 0 additions & 8 deletions packages/edit-site/src/components/list/style.scss
Expand Up @@ -131,14 +131,6 @@
width: $grid-unit * 40;
}
}

.components-modal__header {
border-bottom: none;
}

.components-modal__content::before {
margin-bottom: $grid-unit-05;
}
}

.edit-site-list__rename-modal-actions {
Expand Down
Expand Up @@ -16,10 +16,6 @@
@media (max-width: #{ ($break-medium - 1) }) {
.components-modal__content {
padding: 0;

&::before {
content: none;
}
}
}
}

0 comments on commit 1339b96

Please sign in to comment.