Skip to content

Conversation

Mash707
Copy link
Contributor

@Mash707 Mash707 commented May 28, 2025

Closes #11809

@patternfly-build
Copy link
Contributor

patternfly-build commented May 28, 2025

@thatblindgeye thatblindgeye marked this pull request as draft May 29, 2025 11:00
Copy link
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

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

Just some initial comments below, the animation works nicely so far ⭐

We should also add a console warning if isFavorite && !ariaLabel stating that each favorite button must have a unique aria-label that indicates the current favorited state

@Mash707 Mash707 requested a review from thatblindgeye June 3, 2025 14:10
@thatblindgeye
Copy link
Contributor

@srambach @andrew-ronaldson just FYI, the no-padding variant is visually broken. If you go to the favorite button example from this PR and add hasNoPadding to the button component in the example code, you should notice that there's no color change when favorited.

@srambach
Copy link
Member

srambach commented Jun 3, 2025

@srambach @andrew-ronaldson just FYI, the no-padding variant is visually broken. If you go to the favorite button example from this PR and add hasNoPadding to the button component in the example code, you should notice that there's no color change when favorited.

Hmm yes, looks like we're setting the icon color for a plain no-padding button and that's overriding the favorited color. https://github.com/patternfly/patternfly/blob/d375e1dc0f924f11149fe105875caedbcefd1705/src/patternfly/components/Button/button.scss#L617

@andrew-ronaldson
Copy link
Collaborator

Screenshot 2025-06-03 at 9 41 14 PM
We also have the unfilled to filled icon in core
https://core-staging.patternfly.org/components/button#favorite

@thatblindgeye thatblindgeye marked this pull request as ready for review June 4, 2025 12:13
@thatblindgeye thatblindgeye requested review from a team, andrew-ronaldson, rebeccaalpert and srambach and removed request for a team June 4, 2025 12:13
Copy link
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

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

Lengthy comment below.

We should also add some unit tests for the new props/classes being applied.

isFavorite
isFavorited={isFavorited}
onClick={toggleFavorite}
icon={<StarIcon />}
Copy link
Contributor

Choose a reason for hiding this comment

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

In addition to Andrew's comment above about using the outlined star icon when the button isn't favorited, we should apply the icons internal to the Button component when it's a favorite button since we also need to wrap these star icons in additional class wrappers and both icons should be rendered in the DOM at the same time (rather than dynamically rendering the correct icon, as these additional class wrappers will determine which one is hidden or not).

Here's the Core markup for the icons:

Markup of the Core PatternFly favorite button icons

vs the markup in the PR preview:

Markup of the favorite button icons in this PR preview build

Though @andrew-ronaldson would we want to allow a consumer to customize the favorite icon(s) at all? If we always have both icons rendered we'd most likely need to add some other props (favoriteIcon and favoritedIcon or something) since we need to place the correct icons in the correct icon wrapper. Dynamically rendering the correct star icon might be a little cleaner, since then you only need to pass in the existing icon prop, and the animation still seems to work, but it makes some of the Core styling unused in React/creates a mismatch in markup between Core and React.

Figure I'd ask this now because depending on the answer (and the approach if the answer is "yes"), might be less of a headache to deal with it now than try to finagle something without causing a breaking change to the markup later.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need to allow for their own custom favorite icon. Side note, Would it be better if it was one icon with a stroke and a fill that gets set by a class? the hamburger icon is unique and we play with paths so thought i'd ask.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we go into it with the stance that we don't want consumers to be able to customize the "favorites" icon, I think the current implementation (2 icons that need their own distinct wrappers) isn't too bad. 1 icon that just gets a class applied to handle the filling of the icon would be less to deal with, but I don't think it's absolutely needed, especially since - even though it would probably be a quick Core update - it's still time being taken away from any remaining animations work we need to get done.

Comment on lines +129 to +130
### Favorite

You can pass both the `isFavorite` and `variant="plain"` properties into the `<Button>` to create a favorite button. Passing the `isFavorited` property will determine the current favorited state and update styling accordingly.
Copy link
Contributor

Choose a reason for hiding this comment

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

@edonehoo can you give this a quick review?

@thatblindgeye thatblindgeye requested a review from nicolethoen June 5, 2025 17:13
@Mash707 Mash707 force-pushed the button-add-favorite-variant branch from 27c1ba7 to 46fddb2 Compare June 6, 2025 17:45
Copy link
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

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

Just a couple comments that need design input below cc @andrew-ronaldson @kaylachumley , but this is continuing to shape up awesomely

Comment on lines 225 to 226
isFavorite && variant === ButtonVariant.plain && styles.modifiers.favorite,
isFavorite && isFavorited && variant === ButtonVariant.plain && styles.modifiers.favorited,
Copy link
Contributor

Choose a reason for hiding this comment

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

This would need design input, but rather than needing the consumer to explicitly pass the plain variant in, we could force the plain button styling when isFavorite is true.

Copy link
Contributor

Choose a reason for hiding this comment

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

Per conversation from an animation sync today, we want to not restrict the variant for these buttons. Our design guidelines will recommend when to use what variants for these. So we can remove the && variant === ButtonVariant.plain from these 2 conditionals (but keep the example so that we're passing variant="plain")

};

const _icon = renderIcon();
const _children = children && <span className={css('pf-v6-c-button__text')}>{children}</span>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Also design input needed, but if intend to not allow text content for a favorite button, we could add a && !isFavorite check here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Disregard this comment, we don't want to restrict the rendering of children for these buttons

@srambach
Copy link
Member

Looks good to me! ⭐

Copy link
Member

@rebeccaalpert rebeccaalpert left a comment

Choose a reason for hiding this comment

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

Looks good to me. Animation is very cute!

Copy link
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

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

In addition to the below comments, let's add another test that checks that the icon prop is overridden when isFavorite is passed in.

Comment on lines 252 to 255
test('Renders favorite icon with class pf-m-favorite when isFavorited = false', () => {
render(<Button isFavorite />);
expect(screen.getByRole('button')).toHaveClass('pf-m-favorite');
});
Copy link
Contributor

Choose a reason for hiding this comment

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

For this test, let's use the imported styles object rather than hardcoding the class names to expect. So we can replace pf-m-favorite with styles.modifiers.favorite (or whatever the modifier property is, I assume it'd be favorite though) both in the test name and the toHaveClass call

Additionally, let's update the test name to reflect more what that test is expecting: "Renders with class [classname here] when isFavorite is true".

And then last thing is we should include a test that checks this class isn't applied by default/when isFavorite is false.

Comment on lines 257 to 275
test('Renders favorite icon with class pf-m-favorite when isFavorited = true', () => {
render(<Button isFavorite isFavorited />);
expect(screen.getByRole('button')).toHaveClass('pf-m-favorited');
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Same updates here as the above test: using the styles object, updating the test name, and including a test that check the pf-m-favorited class isn't applied by default

Copy link
Collaborator

@andrew-ronaldson andrew-ronaldson left a comment

Choose a reason for hiding this comment

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

you're a ⭐

@Mash707 Mash707 force-pushed the button-add-favorite-variant branch from af39a79 to d3f6e65 Compare June 12, 2025 19:12
Copy link
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

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

Awesome work! 🤩 You could say this is my pf-m-favorite

@thatblindgeye thatblindgeye merged commit 84c5af6 into patternfly:main Jun 13, 2025
16 of 19 checks passed
@patternfly-build
Copy link
Contributor

Your changes have been released in:

  • @patternfly/react-code-editor@6.3.0-prerelease.19
  • @patternfly/react-core@6.3.0-prerelease.19
  • @patternfly/react-docs@7.3.0-prerelease.25
  • @patternfly/react-drag-drop@6.3.0-prerelease.19
  • demo-app-ts@6.0.0-prerelease.122
  • @patternfly/react-table@6.3.0-prerelease.19
  • @patternfly/react-templates@6.3.0-prerelease.19

Thanks for your contribution! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Button - add favorite variant

6 participants