Implement progress element for Slipstream#223
Merged
jverkoey merged 4 commits intoNov 5, 2025
Conversation
Add a new Progress view that represents the HTML <progress> element, allowing developers to display task completion progress in their Slipstream applications. Features: - Supports both determinate and indeterminate progress states - Optional value parameter (nil = indeterminate) - Configurable max parameter (defaults to 1.0 for percentage-style use) - Follows Slipstream patterns for SwiftUI-like API - Comprehensive test coverage including edge cases The implementation balances W3C HTML semantics with SwiftUI idioms, providing a familiar API for SwiftUI developers while emitting standard HTML progress elements.
Rename the Progress struct to ProgressView to align with SwiftUI naming conventions, making it more familiar to SwiftUI developers. Changes: - Rename Progress.swift to ProgressView.swift - Update struct name from Progress to ProgressView - Update all documentation references - Rename ProgressTests to ProgressViewTests - Update all test cases to use ProgressView The view still emits the HTML <progress> element as specified by W3C.
Per the W3C spec, the max attribute defaults to 1.0 when not specified. Update ProgressView to only render the max attribute when it differs from the default value, producing more concise HTML output. Before: ProgressView() → <progress max="1.0"></progress> ProgressView(value: 0.7) → <progress value="0.7" max="1.0"></progress> After: ProgressView() → <progress></progress> ProgressView(value: 0.7) → <progress value="0.7"></progress> Custom max values are still rendered when specified: ProgressView(value: 70, max: 100) → <progress value="70.0" max="100.0"></progress>
Change max parameter from Double with a default value to Double?
to avoid unreliable floating point equality checks. When max is nil,
the attribute is omitted from the HTML, allowing the W3C default of
1.0 to be used implicitly.
This approach is more robust and aligns with Swift best practices
for optional values versus default values with equality checks.
Before:
public init(value: Double? = nil, max: Double = 1.0)
if max != 1.0 { // Unreliable floating point comparison
After:
public init(value: Double? = nil, max: Double? = nil)
if let max { // Safe optional binding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a new Progress view that represents the HTML element, allowing developers to display task completion progress in their Slipstream applications.
Features:
The implementation balances W3C HTML semantics with SwiftUI idioms, providing a familiar API for SwiftUI developers while emitting standard HTML progress elements.
Part of #25