Skip to content

Conversation

@lukasmasuch
Copy link
Collaborator

@lukasmasuch lukasmasuch commented Nov 11, 2024

Describe your changes

Reuse the DynamicButtonLabel for pills & segmented control. Currently, the usage of markdown in pills / segmented control is not limited -> which isn't desired. Using DynamicButtonLabel applies the same limits to the markdown as in all other button labels.

This also changes the starting emojis to be treated as icons instead of text to have the same special icon spacing that we also have for emoji icons on buttons.

Github Issues

Testing Plan

  • Only visual changes -> Update snapshots.

Contribution License Agreement

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

@lukasmasuch lukasmasuch changed the title Use dynamic button label for button group [WIP] Use dynamic button label for button group Nov 11, 2024
@lukasmasuch lukasmasuch added security-assessment-completed Security assessment has been completed for PR impact:internal PR changes only affect internal code change:refactor PR contains code refactoring without behavior change labels Jan 9, 2025
@lukasmasuch lukasmasuch changed the title [WIP] Use dynamic button label for button group Use dynamic button label for button group Jan 9, 2025
@lukasmasuch lukasmasuch marked this pull request as ready for review January 9, 2025 13:30
if len(transformed_parts) > 0:
maybe_icon = transformed_parts[0].strip()
try:
# we only want to extract material icons because we treat them
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What was the reason to not treat emojis as icons?

Copy link
Collaborator

@kajarenc kajarenc Jan 9, 2025

Choose a reason for hiding this comment

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

I am not sure why, @raethlein could know better, but this is based on the comment below

transformed = " ".join(transformed_parts[1:])

happened previously only for material icon cases, but not for emoji (transformed_parts are after applying format_func)

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 chatted with @raethlein and concluded that it is probably OK to merge it this way. There probably where some concerns around the styling / spacing.. but merging this makes it more consistent with how its treated in our buttons.

label: string
icon?: string
label?: string
iconSize?: "sm" | "md" | "lg" | "base" | "xs" | "xl" | "twoXL" | "threeXL"
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: Can we derive this by exporting the type from frontend/lib/src/theme/primitives/iconSizes.ts instead?

export const iconSizes = {
  xs: "0.5rem",
  sm: "0.75rem",
  md: "0.9rem",
  base: "1rem",
  lg: "1.25rem",
  xl: "1.5rem",
  twoXL: "1.8rem",
  threeXL: "2.3rem",
} as const

export type IconSize = keyof typeof iconSizes

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep sounds good 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The type was already exported in @streamlit/lib/src/theme" -> so I just had to use it

@lukasmasuch lukasmasuch enabled auto-merge (squash) January 10, 2025 03:25
@lukasmasuch lukasmasuch merged commit 961ef35 into develop Jan 10, 2025
33 checks passed
edegp pushed a commit to edegp/streamlit that referenced this pull request Jan 19, 2025
## Describe your changes

Reuse the `DynamicButtonLabel` for pills & segmented control. Currently,
the usage of markdown in pills / segmented control is not limited ->
which isn't desired. Using `DynamicButtonLabel` applies the same limits
to the markdown as in all other button labels.

This also changes the starting emojis to be treated as icons instead of
text to have the same special icon spacing that we also have for emoji
icons on buttons.

## Testing Plan

- Only visual changes -> Update snapshots.

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
@lukasmasuch lukasmasuch deleted the refactor/use-dynamic-button-label-for-button-group branch March 5, 2025 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:refactor PR contains code refactoring without behavior change impact:internal PR changes only affect internal code security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pills and segmented_control with customized image display for options

4 participants