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

[WIP] Add icon parameter to st.expander #8716

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from

Conversation

snehankekre
Copy link
Collaborator

@snehankekre snehankekre commented May 20, 2024

Describe your changes

Adds an icon kwarg to st.expander to optionally support single-character emojis or material icons.

  • Reused the existing icon proto field
  • Replaced the custom check and error icons in st.status with DynamicIcon material icons

GitHub Issue Link (if applicable)

N/A

Testing Plan

  • Python unit tests
  • FE JS test
  • E2E test

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@snehankekre snehankekre marked this pull request as ready for review May 21, 2024 07:06
lib/streamlit/elements/layouts.py Show resolved Hide resolved
e2e_playwright/st_expander.py Outdated Show resolved Hide resolved
e2e_playwright/st_expander_test.py Outdated Show resolved Hide resolved
Comment on lines +49 to +56
<StyledDynamicIcon iconValue={icon} {...props}>
<MaterialFontIcon pack={pack} iconName={icon} {...props} />
</StyledDynamicIcon>
)
case "emoji":
default:
return <EmojiIcon {...props}>{icon}</EmojiIcon>
return (
<StyledDynamicIcon iconValue={icon} {...props}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it might be good to add data-testid to both of these options, e.g.: stIconEmoji and stIconMaterial and use these test ids in the tests. Or maybe we actually set the testid from DynamicIconProps here, at the moment it seems to be unused, or?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added data-testids for stIconEmoji and stIconMaterial and used these in the tests 👍
But I also did the following and not sure the last part is needed:

  • For st.status's check and error icons, we used to add data-testid: stExpanderIconCheck and stExpanderIconError. I continue passing them to <DynamicIcon>
  • When the icon value is neither check nor error, I added a generic data-testid stExpanderIcon. Not sure if this is really needed or if I should remove it and not specify one.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, I think both solutions would be fine... but I'm slightly favoring removing this distinction and only have one test id to have lower tech debt. I think the related unit tests aren't that important since we are anyways testing this via e2e snapshot tests as well.

frontend/lib/src/components/shared/Icon/DynamicIcon.tsx Outdated Show resolved Hide resolved
e2e_playwright/st_expander_test.py Outdated Show resolved Hide resolved
frontend/lib/src/components/elements/Expander/Expander.tsx Outdated Show resolved Hide resolved
Copy link
Collaborator

@LukasMasuch LukasMasuch left a comment

Choose a reason for hiding this comment

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

LGTM 👍 A couple more comments.

Comment on lines 47 to 48
* If the icon is "check", it will render a check icon.
* If the icon is "error", it will render an error icon.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I think these two comments can be removed with the recent change

<DynamicIcon
color="inherit"
iconValue={icon}
aria-hidden={statusIconTestIds[icon] ? "true" : undefined}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I don't think we have to differentiate here, I think we can even just remove the aria-hidden completely since the new icons are probably more accessible since they actually contain descriptive text.

Comment on lines +49 to +56
<StyledDynamicIcon iconValue={icon} {...props}>
<MaterialFontIcon pack={pack} iconName={icon} {...props} />
</StyledDynamicIcon>
)
case "emoji":
default:
return <EmojiIcon {...props}>{icon}</EmojiIcon>
return (
<StyledDynamicIcon iconValue={icon} {...props}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, I think both solutions would be fine... but I'm slightly favoring removing this distinction and only have one test id to have lower tech debt. I think the related unit tests aren't that important since we are anyways testing this via e2e snapshot tests as well.

Comment on lines +86 to +91
iconValue: string
size?: IconSize
margin?: string
padding?: string
testid?: string
color?: ThemeColor
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can remove a couple of properties here that are not used for styling: iconValue and testid

color="inherit"
iconValue={icon}
aria-hidden={statusIconTestIds[icon] ? "true" : undefined}
data-testid={statusIconTestIds[icon] || "stExpanderIcon"}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It think we better should use the testid prop defined in DynamicIcon here instead. Using other props here is working since we are routing it through to the styled component, but that's a very unusual pattern (maybe we should even remove this part). It is better torelyy on the props that are explicitly defined in DynamicIcon.

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

Successfully merging this pull request may close these issues.

None yet

2 participants