[EuiBetaBadge] Add color and size props and support for click event#4798
[EuiBetaBadge] Add color and size props and support for click event#4798andreadelrio merged 17 commits intoelastic:masterfrom
Conversation
|
@miukimiu I know you recently added the |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_4798/ |
elizabetdev
left a comment
There was a problem hiding this comment.
Thanks @andreadelrio for improving the EuiBetaBadge. The new size looks great and also the new props to support click events. 🎉
I have a few suggestions.
Also noticed, that when passing a href with color hollow the link get's blue:
This PR can also close #4190. But we also need to allow passing these props to the EuiCard.
Right now we can only pass the following beta badge props:
So maybe we can allow passing all the rest of the beta badge props like betaBadgeProps.
|
|
||
| import { EuiBetaBadge, EuiSpacer, EuiTitle } from '../../../../src/components'; | ||
|
|
||
| const colors = ['hollow', 'accent', 'subdued']; |
There was a problem hiding this comment.
Hm I wonder if the beta badge's use cases are better suited for a limited set of colors. Likely @cchaos can weigh in as I think she's the one who proposed adding two more colors only.
There was a problem hiding this comment.
I think it could sway either way, keeping it limited may help users notice it more since they tend to mark product features. If we were to change the set to accept the same as regular badges, are they then any different really? I would then consider if there's any real necessity to keep separate components. But I'd suggest starting a more targeted discussion for that and keep this PR scoped to the current changeset.
|
@miukimiu I pushed some changes addressing feedback. There's a TS error I'll probably need Greg's (or your) help with. Should |
|
By default, the EuiBetaBadge should respect the EuiCard's We just want to give more flexibility to consumers. So in case, consumers want a card with a EuiBetaBadge with a different color, click event, non-disabled state, they can override the default props with the |
| { | ||
| 'euiBetaBadge--iconOnly': iconType, | ||
| }, | ||
| { | ||
| 'euiBetaBadge--singleLetter': singleLetter, | ||
| }, | ||
| { | ||
| 'euiBetaBadge-isClickable': onClick || href, | ||
| }, |
There was a problem hiding this comment.
Quick suggestion 😉 . All of these can actually be combined in one object
| { | |
| 'euiBetaBadge--iconOnly': iconType, | |
| }, | |
| { | |
| 'euiBetaBadge--singleLetter': singleLetter, | |
| }, | |
| { | |
| 'euiBetaBadge-isClickable': onClick || href, | |
| }, | |
| { | |
| 'euiBetaBadge--iconOnly': iconType, | |
| 'euiBetaBadge--singleLetter': singleLetter, | |
| 'euiBetaBadge-isClickable': onClick || href, | |
| }, |
|
As a reminder, one of the use-cases for clickable beta badges on cards is to direct users towards license info/upgrade for disabled features. So we want to be sure that it's very easy to have a |
Keeping this in mind and after discussing with @miukimiu we agreed to go with the EuiBetaBadge following EuiCard's |
There was a problem hiding this comment.
LGTM! 🎉
Tested again in different browsers and locally. You just need to do a small change to allow passing a custom CSS class.
I tried to look into the TS error, and this code seems to make it disappear:
const betaBadgeClickEventsProps = betaBadgeProps?.href
? {
...(betaBadgeProps as React.MouseEventHandler<HTMLAnchorElement>),
}
: {
...(betaBadgeProps as React.MouseEventHandler<HTMLButtonElement>),
};
optionalBetaBadge = (
<span className="euiCard__betaBadgeWrapper">
<EuiBetaBadge
id={optionalBetaBadgeID}
label={betaBadgeLabel}
title={betaBadgeTitle}
tooltipContent={betaBadgeTooltipContent}
className="euiCard__betaBadge"
{...betaBadgeClickEventsProps}
/>
</span>
);But I'm not completely sure if this is the right solution, so it's better if @thompsongl takes a look! 😄
src/components/card/card.tsx
Outdated
| title={betaBadgeTitle} | ||
| tooltipContent={betaBadgeTooltipContent} | ||
| {...betaBadgeProps} | ||
| className="euiCard__betaBadge" |
There was a problem hiding this comment.
We also need to be able to pass a custom className:
| className="euiCard__betaBadge" | |
| className={classNames( | |
| 'euiCard__betaBadge', | |
| betaBadgeProps?.className | |
| )} |
|
I'd like to propose that we deprecate |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_4798/ |
|
There's an axe test failure, too:
|
Co-authored-by: Caroline Horn <549577+cchaos@users.noreply.github.com>
Co-authored-by: Greg Thompson <thompson.glowe@gmail.com>
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_4798/ |
thompsongl
left a comment
There was a problem hiding this comment.
andreadelrio#15 has a couple TS things I was working on
Otherwise just the additional comments
[EuiBetaBadge] A couple TS changes
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_4798/ |





Summary
colorprop and added two more color options (subduedandaccent) and turned previous default intohollow.sizeprop.onClickorhref.Checklist
- [ ] Checked in mobile- [ ] Checked Code Sandbox works for the any docs examples- [ ] Checked for breaking changes and labeled appropriately- [ ] Checked for accessibility including keyboard-only and screenreader modes