-
Notifications
You must be signed in to change notification settings - Fork 34
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
Adding basic badge component #2005
Conversation
styleOverrides: { | ||
badge: ({ ownerState }) => ({ | ||
...(ownerState.color === "primary" && { | ||
backgroundColor: odysseyTokens.HueBlue500, |
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.
Whenever possible, use the semantic rather than palette token (ie, PalettePrimaryMain
rather than HueBlue500
. These aren't always available, so fall back to the Hue
versions when needed.
export type BadgeProps = { | ||
children?: ReactNode; | ||
badgeContent?: number; | ||
max?: MuiBadgeProps["max"]; |
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.
Let's find a more explicit name for max
, it wasn't immediately clear to me that this was the max number before truncation.
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.
@jordankoschei-okta Can do. max
is the prop that MUI uses by default so, just brought that over. Wasn't sure if we tried to carry prop names over from MUI or not. Any suggestions?
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.
@jordankoschei-okta Went with badgeContentMax. Seem ok to you? Def open to suggestion still. Not in love with that name
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.
What about maxNumberOfCharacters
or maxCharacterCount
?
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.
From eng, this looks good.
@jordankoschei-okta will wanna review the design piece, and @gretchen-okta will wanna review the Storybook text.
variant = "standard", | ||
type = "default", | ||
}: BadgeProps) => { | ||
const threeDigitLimitedMax = badgeContentMax > 999 ? 999 : badgeContentMax; |
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.
What's with the 999
?
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.
@KevinGhadyani-Okta We wanted to ensure that the content never goes past 3 chars. So, if the consumer passed in a max of anything higher than 999, the component would still limit it to 3 chars.
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.
If it goes over 999, would it count as 4 characters to have it show 999+? Just wondering. Support 3 characters because it saves us from comma/period internationalization issues with 1000 etc.
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.
That's a great point!
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 hadn't thought about the complications with comma/period. @benlister-okta just wanted the max number to be 3 chars long. We're fine with 3 chars and +
.
Please just send me a staging Storybook link or let me know when it's available. TY |
5e4bb8c
to
b56da18
Compare
4813e05
to
9948fde
Compare
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's a few changes you need to make and I have some questions about the logic. Let me know if you want to discuss in DM's - happy to clarify any questions or suggestions.
const threeDigitLimitedMax = | ||
greaterThanZeroContentMax > 999 ? 999 : greaterThanZeroContentMax; | ||
const isOverContentMax = Boolean( | ||
badgeContent && badgeContent > threeDigitLimitedMax |
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.
This won't work if badgeContent
is 0
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 that is fine. We'd want to hide the badge if the content is 0
.
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.
Maybe a test should be added for this if one doesn't exist yet? If badgeContent = 0
, isOverContentMax
will be false
(which seems incorrect to me as 0 is definitely less than 999), and formattedContent
will be 0
. I think it will render, no? Apologies if I didn't follow the logic correctly, but this is what it seems like it will do.
padding: `0 calc(${odysseyDesignTokens.Spacing1} * 1.5)`, | ||
backgroundColor: badgeTypeColors(odysseyDesignTokens)[type].background, | ||
color: badgeTypeColors(odysseyDesignTokens)[type].font, | ||
borderRadius: contentIsLongerThanOneChar ? "10px" : "50%", |
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.
Are there any radius variables we can use instead?
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 only have 1 radius variable currently, I think. I hate using 10px
here but, our standard spacing variables just didn't work quite right. 10px
was the magic number
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 updated this to use one of our standard radius variables
[type, contentIsLongerThanOneChar] | ||
); | ||
|
||
const shouldHideBadge = !badgeContent; |
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 don't believe we need this variable
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.
Yeah, we don't need it per se. My goal was just to make it easier to see at a glance why the badge was hidden. Can remove if we think it's unnecessary
fontWeight: `${odysseyDesignTokens.TypographyWeightBodyBold}`, | ||
lineHeight: 1, | ||
}), | ||
[type, contentIsLongerThanOneChar] |
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.
You're missing a dependency in this callback (odysseyDesignTokens
).
if (shouldHideBadge) { | ||
return null; | ||
} |
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'd suggest moving this right up to the top. This way, we short circuit all the logic if we don't actually have to do anything.
I'd also make this more clear by stating const shouldHideBadge = badgeContent === 0;
0d8704b
to
a113c16
Compare
…a standalone component
REPLACE_WITH_JIRA_TICKET_NUMBER
Summary
Testing & Screenshots