Skip to content

Commit

Permalink
Modal: Decrease close button size (WordPress#65131)
Browse files Browse the repository at this point in the history
* Modal: Decrease close button size

* Remove close button offset

* Update story example to show real-life usage

* Update header action button size in Freeform block

* Add spacer to component itself

* Add changelog

Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Co-authored-by: jasmussen <joen@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
  • Loading branch information
6 people committed Sep 10, 2024
1 parent 8b4ca34 commit cdeb12e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 28 deletions.
3 changes: 1 addition & 2 deletions packages/block-library/src/freeform/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ function ModalAuxiliaryActions( { onClick, isModalFullScreen } ) {

return (
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
size="small"
onClick={ onClick }
icon={ fullscreen }
isPressed={ isModalFullScreen }
Expand Down
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

- `Composite`: add stable version of the component ([#63569](https://github.com/WordPress/gutenberg/pull/63569)).

### Enhancements

- `Modal`: Decrease close button size and remove horizontal offset ([#65131](https://github.com/WordPress/gutenberg/pull/65131)).

### Internal

- `Composite`: Remove from private APIs ([#63569](https://github.com/WordPress/gutenberg/pull/63569)).
Expand Down
23 changes: 16 additions & 7 deletions packages/components/src/modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import Button from '../button';
import StyleProvider from '../style-provider';
import type { ModalProps } from './types';
import { withIgnoreIMEEvents } from '../utils/with-ignore-ime-events';
import { Spacer } from '../spacer';

// Used to track and dismiss the prior modal when another opens unless nested.
type Dismissers = Set<
Expand Down Expand Up @@ -323,13 +324,21 @@ function UnforwardedModal(
</div>
{ headerActions }
{ isDismissible && (
<Button
onClick={ onRequestClose }
icon={ close }
label={
closeButtonLabel || __( 'Close' )
}
/>
<>
<Spacer
marginBottom={ 0 }
marginLeft={ 3 }
/>
<Button
size="small"
onClick={ onRequestClose }
icon={ close }
label={
closeButtonLabel ||
__( 'Close' )
}
/>
</>
) }
</div>
) }
Expand Down
22 changes: 8 additions & 14 deletions packages/components/src/modal/stories/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { StoryFn, Meta } from '@storybook/react';
* WordPress dependencies
*/
import { useState } from '@wordpress/element';
import { starEmpty, starFilled } from '@wordpress/icons';
import { fullscreen } from '@wordpress/icons';

/**
* Internal dependencies
Expand Down Expand Up @@ -103,22 +103,16 @@ WithsizeSmall.args = {
};
WithsizeSmall.storyName = 'With size: small';

const LikeButton = () => {
const [ isLiked, setIsLiked ] = useState( false );
return (
<Button
icon={ isLiked ? starFilled : starEmpty }
label="Like"
onClick={ () => setIsLiked( ! isLiked ) }
/>
);
};

/**
* The `headerActions` prop can be used to add auxiliary actions to the header, for example a fullscreen mode toggle.
*/
export const WithHeaderActions: StoryFn< typeof Modal > = Template.bind( {} );
WithHeaderActions.args = {
...Default.args,
headerActions: <LikeButton />,
isDismissible: false,
headerActions: (
<Button icon={ fullscreen } label="Fullscreen mode" size="small" />
),
children: <div style={ { height: '200px' } } />,
};
WithHeaderActions.parameters = {
...Default.parameters,
Expand Down
5 changes: 0 additions & 5 deletions packages/components/src/modal/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@
margin: 0;
}

.components-button {
position: relative;
left: $grid-unit-10;
}

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

0 comments on commit cdeb12e

Please sign in to comment.