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

Adding basic badge component #2005

Merged
merged 16 commits into from
Dec 1, 2023
Merged

Conversation

bryancunningham-okta
Copy link
Contributor

@bryancunningham-okta bryancunningham-okta commented Oct 23, 2023

REPLACE_WITH_JIRA_TICKET_NUMBER

Summary

Testing & Screenshots

  • I have confirmed this change with my designer and the Odyssey Design Team.

styleOverrides: {
badge: ({ ownerState }) => ({
...(ownerState.color === "primary" && {
backgroundColor: odysseyTokens.HueBlue500,
Copy link
Contributor

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"];
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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

Copy link
Contributor

@KevinGhadyani-Okta KevinGhadyani-Okta Oct 30, 2023

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?

Copy link
Contributor

@KevinGhadyani-Okta KevinGhadyani-Okta left a 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;
Copy link
Contributor

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?

Copy link
Contributor Author

@bryancunningham-okta bryancunningham-okta Oct 30, 2023

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.

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.

Copy link
Contributor

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!

Copy link
Contributor Author

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 +.

@gretchen-okta
Copy link

gretchen-okta commented Oct 31, 2023

From eng, this looks good.

@jordankoschei-okta will wanna review the design piece, and @gretchen-okta will wanna review the Storybook text.

Please just send me a staging Storybook link or let me know when it's available. TY
cc @benlister-okta

Copy link
Contributor

@chrispulsinelli-okta chrispulsinelli-okta left a 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
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

packages/odyssey-react-mui/src/Badge.tsx Show resolved Hide resolved
padding: `0 calc(${odysseyDesignTokens.Spacing1} * 1.5)`,
backgroundColor: badgeTypeColors(odysseyDesignTokens)[type].background,
color: badgeTypeColors(odysseyDesignTokens)[type].font,
borderRadius: contentIsLongerThanOneChar ? "10px" : "50%",
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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;
Copy link
Contributor

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

Copy link
Contributor Author

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]
Copy link
Contributor

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).

packages/odyssey-react-mui/src/Badge.tsx Show resolved Hide resolved
packages/odyssey-react-mui/src/Badge.tsx Show resolved Hide resolved
Comment on lines +87 to +91
if (shouldHideBadge) {
return null;
}
Copy link
Contributor

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;

@bryancunningham-okta bryancunningham-okta merged commit f19896f into main Dec 1, 2023
1 check passed
@bryancunningham-okta bryancunningham-okta deleted the bc/add-badge-component branch December 1, 2023 18:22
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.

5 participants