-
Notifications
You must be signed in to change notification settings - Fork 4k
Support pre-defined formats in format of st.slider
#13392
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
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ PR preview is ready!
|
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.
Pull request overview
This PR adds support for predefined format options in the format parameter of st.slider, bringing it in line with similar formatting capabilities already available in column configs (DateTimeColumn, DateColumn, TimeColumn, NumberColumn, ProgressColumn) and st.metric.
Key changes:
- Extended Python type signatures to accept
NumberFormatfor numeric sliders andDateTimeFormatfor date-like sliders - Created reusable
formatMomentutility in TypeScript to handle moment formatting logic - Updated slider documentation with comprehensive examples of predefined formats
- Refactored DataFrame column utilities to use the shared
formatMomentutility
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/streamlit/elements/widgets/slider.py | Updated type annotations to accept NumberFormat and DateTimeFormat predefined formats, and expanded documentation with examples of all supported format options |
| lib/streamlit/elements/lib/column_types.py | Introduced DateTimeFormat type alias and refactored DatetimeColumn to use it for consistency |
| frontend/lib/src/util/formatMoment.ts | New utility module extracted from DataFrame columns for formatting moment dates with support for predefined formats ("localized", "distance", "calendar", "iso8601") |
| frontend/lib/src/util/formatMoment.test.ts | Comprehensive test suite for the new formatMoment utility covering various format strings and momentKind options |
| frontend/lib/src/components/widgets/Slider/Slider.tsx | Refactored formatValue to use formatNumber and formatMoment utilities, replacing direct sprintf usage and enabling predefined format support |
| frontend/lib/src/components/widgets/DataFrame/columns/utils.ts | Removed duplicated formatMoment implementation and imported from the new shared utility module, with re-export for backward compatibility |
| ) | ||
| }) | ||
|
|
||
| withTimezones(() => { |
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.
just moved this into a dedicated shared file
| * Otherwise, it is interpreted as momentJS format string: https://momentjs.com/docs/#/displaying/format/ | ||
| * @returns The formatted date as a string. | ||
| */ | ||
| export function formatMoment( |
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.
Just moved this into a dedicated shared file
SummaryThis PR adds support for pre-defined format strings in the Key Changes:
Code QualityPython ChangesWell-Implemented:
One Minor Observation:
Frontend ChangesWell-Implemented:
Code Organization
Test CoverageUnit Tests (Python)
Typing Tests (Python)
Frontend Tests
E2E Tests
E2E tests follow best practices:
Backwards Compatibility✅ Fully Backwards Compatible
Security & RiskLow Risk:
No Regression Risk:
RecommendationsNo blocking issues found. The implementation is clean, well-tested, and follows existing patterns in the codebase. Optional improvements for future consideration (not blocking):
VerdictAPPROVED: This PR cleanly adds pre-defined format support to This is an automated AI review. Please verify the feedback and use your judgment. |
Describe your changes
Adds support for pre-defined formats in
formatofst.slider. These are the same formats also supported in NumberColumn, DateTimeColumn, DateColumn, TimeColumn, ProgressColumn, andst.metric.formatparameter ofst.slider#13243Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.