swift-css
swift-css copied to clipboard
Gradient stop percentage
A gradients stops can have a percentage to specify where the color starts.
For example, these are the same:
linear-gradient(red, orange, yellow, green, blue);
linear-gradient(red 0%, orange 25%, yellow 50%, green 75%, blue 100%);
Currently the gradient cases on Color only receive [Color] as stops.
I think there should be a Color case that looks something like:
case linearGradient(_ direction: LinearGradient.Direction, _ stops: [(Color, Int)])
or:
case linearGradient(_ direction: LinearGradient.Direction, _ stops: [ColorStop])
// ...
public struct ColorStop: CustomStringConvertible {
let color: Color
let positions: [Int]
public var description: String {
color.description + positions.map { String($0) + "%" } .joined(separator: " ")
}
public static func color(_ color: Color, at percentages: Int...) -> ColorStop {
return ColorStop(color: color, positions: percentages)
}
}
Link to article about stop percentages: https://developer.mozilla.org/en-US/docs/Web/CSS/linear-gradient#Customizing_Gradients
Thanks for this! I like the first one better. If you make a PR, I’ll merge it.