Version 0.24.0
This update introduces a suite of new functions to the styles
sub-package aimed at providing a type-safe approach to generating CSS style strings.
New Features: Type-Safe CSS Value Functions Added
Length and Size Functions
Em(value float64) string
and Rem(value float64) string
These functions return a string representation of the given value with the "em" and "rem" units, respectively.
emValue := styles.Em(2.5) // Returns "2.5em"
remValue := styles.Rem(1.5) // Returns "1.5rem"
Pixels(value int) string
This function returns a string representation of the given value with the "px" unit.
pxValue := styles.Pixels(10) // Returns "10px"
Percent(value int) string
This function returns a string representation of the given value with the "%" unit.
percentValue := styles.Percent(50) // Returns "50%"
Viewport Functions
ViewportHeight(value int) string
and ViewportWidth(value int) string
These functions return a string representation of the given value with the "vh" and "vw" units, respectively.
vhValue := styles.ViewportHeight(50) // Returns "50vh"
vwValue := styles.ViewportWidth(25) // Returns "25vw"
ViewportMin(value int) string
and ViewportMax(value int) string
These functions return a string representation of the given value with the "vmin" and "vmax" units, respectively.
vminValue := styles.ViewportMin(10) // Returns "10vmin"
vmaxValue := styles.ViewportMax(20) // Returns "20vmax"
Color Functions
RGB(r, g, b int) string
This function returns a string representation of the given RGB color.
rgbColor := styles.RGB(255, 0, 0) // Returns "rgb(255, 0, 0)"
RGBA(r, g, b int, a float64) string
This function returns a string representation of the given RGBA color.
rgbaColor := styles.RGBA(255, 0, 0, 0.5) // Returns "rgba(255, 0, 0, 0.5)"
Other Functions
Int(value int) string
This function returns a string representation of the given integer value.
intValue := styles.Int(100) // Returns "100"
Float(value float64) string
This function returns a string representation of the given float value.
floatValue := styles.Float(3.14) // Returns "3.14"
URL(url string) string
This function returns a string representation as a formatted CSS URL.
urlValue := styles.URL("https://example.com/image.jpg") // Returns "url('https://example.com/image.jpg')"
Var(name string) string
This function returns a string representation as a CSS variable.
varValue := styles.Var("primary-color") // Returns "var(--primary-color)"