-
Notifications
You must be signed in to change notification settings - Fork 841
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
[EuiBetaBadge] Add color and size props and support for click event #4798
Conversation
@miukimiu I know you recently added the |
Preview documentation changes for this PR: https://eui.elastic.co/pr_4798/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.
@@ -2,23 +2,36 @@ import React from 'react'; | |||
|
|||
import { EuiBetaBadge, EuiSpacer, EuiTitle } from '../../../../src/components'; | |||
|
|||
const colors = ['hollow', 'accent', 'subdued']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -298,6 +303,7 @@ export const EuiCard: FunctionComponent<EuiCardProps> = ({ | |||
label={betaBadgeLabel} | |||
title={betaBadgeTitle} | |||
tooltipContent={betaBadgeTooltipContent} | |||
{...betaBadgeProps} | |||
className="euiCard__betaBadge" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
Co-authored-by: Greg Thompson <[email protected]>
Preview documentation changes for this PR: https://eui.elastic.co/pr_4798/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code changes LGTM!
Summary
color
prop and added two more color options (subdued
andaccent
) and turned previous default intohollow
.size
prop.onClick
orhref
.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