Closed bitspittle closed 1 year ago
So, after digging into this a bit more, I think it's a great idea that deserves getting done right. The approach should support more functions than just "clamp", so the above suggested code but a bit more abstract.
I'm thinking of doing something like this:
package com.varabyte.kobweb.compose.css.functions
import org.jetbrains.compose.web.css.StylePropertyString
interface CSSFunction : StylePropertyString
interface CSSNumericFunction : CSSFunction
// Later, CSSFilterFunction, etc.
data class Clamp(val min: CSSNumeric, val value: CSSNumeric, val max: CSSNumeric): CSSNumericFunction {
override fun toString(): String = "clamp($min, $value, $max)"
}
data class Min(val first: CSSNumeric, val second: CSSNumeric): CSSNumericFunction { ... }
fun StyleScope.fontSize(numericFunc: CSSNumericFunction) = property("font-size", numericFunc)
fun Modifier.fontSize(numericFunc: CSSNumericFunction) = styleModifier { fontSize(numericFunc) }
After talking on the Kotlin slack, found a developer shared their own approach which makes CSSClamp directly a CSSNumeric, which I think is really nice.
Reference: https://github.com/Ayfri/Ayfri.github.io/blob/master/src/main/kotlin/style/utils/CSSFunctions.kt
Awesome! Thanks for supporting this feature :)
A suggestion from the Discord!
See also: https://developer.mozilla.org/en-US/docs/Web/CSS/clamp