Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snackbar: Fix icon positioning #57377

Merged
merged 6 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- `Truncate`: improve handling of non-string `children` ([#57261](https://github.com/WordPress/gutenberg/pull/57261)).
- `PaletteEdit`: Don't discard colors with default name and slug ([#54332](https://github.com/WordPress/gutenberg/pull/54332)).
- `RadioControl`: Fully encapsulate styles ([#57347](https://github.com/WordPress/gutenberg/pull/57347)).
- `Snackbar`: Fix icon positioning ([#57377](https://github.com/WordPress/gutenberg/pull/57377)).

### Enhancements

Expand Down
12 changes: 7 additions & 5 deletions packages/components/src/snackbar/stories/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
*/
import type { Meta, StoryFn } from '@storybook/react';

/**
* WordPress dependencies
*/
import { wordpress } from '@wordpress/icons';

/**
* Internal dependencies
*/
import Icon from '../../icon';
import Snackbar from '..';

const meta: Meta< typeof Snackbar > = {
Expand Down Expand Up @@ -63,11 +69,7 @@ WithActions.args = {
export const WithIcon: StoryFn< typeof Snackbar > = DefaultTemplate.bind( {} );
WithIcon.args = {
children: 'Add an icon to make your snackbar stand out',
icon: (
<span role="img" aria-label="Icon" style={ { fontSize: 21 } }>
🌮
</span>
),
icon: <Icon style={ { fill: 'currentcolor' } } icon={ wordpress } />,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not great that this requires a style, but we can't really add it in the component CSS due to back-compat.

Hopefully things will be nicer once we have #40102.

};

export const WithExplicitDismiss: StoryFn< typeof Snackbar > =
Expand Down
7 changes: 4 additions & 3 deletions packages/components/src/snackbar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@
}

.components-snackbar__content-with-icon {
margin-left: $grid-unit-30;
position: relative;
padding-left: $grid-unit-30;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to suggest using logical properties (inline-start instead of left), but I guess that it doesn't matter much in Sass files, since RTL styles should be automatically generated.

}

.components-snackbar__icon {
position: absolute;
top: 24px;
left: 28px;
left: $grid-unit-10 * -1;
top: -3px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the icon supposed to be top aligned when the snackbar text breaks on 2+ lines?

Screenshot 2024-01-02 at 18 04 49

More in general, we should probably switch to a more generic approach to vertically centering the icon that doesn't rely on an exact px value, since it would make the alignment more resilient to things like font changes, etc.

Copy link
Member Author

@mirka mirka Jan 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the icon supposed to be top aligned when the snackbar text breaks on 2+ lines?

Correct. It matches the alignment of the actions and dismiss button as well.

Snackbar with actions and dismiss button

More in general, we should probably switch to a more generic approach to vertically centering the icon that doesn't rely on an exact px value, since it would make the alignment more resilient to things like font changes, etc.

Added a few tweaks to avoid this in 312752d 👍

}

.components-snackbar__dismiss-button {
Expand Down