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 all 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 @@ -16,6 +16,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)).
- `GradientPicker`: Use slug while iterating over gradient entries to avoid React "duplicated key" warning ([#57361](https://github.com/WordPress/gutenberg/pull/57361)).

### 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: $icon-size;
}

.components-snackbar__icon {
position: absolute;
top: 24px;
left: 28px;
left: $grid-unit-10 * -1;
top: calc((#{$icon-size - ($default-font-size * $default-line-height)}) / -2);
}

.components-snackbar__dismiss-button {
Expand Down