package testcssusage import ( "fmt" "math" ) templ StyleTagsAreSupported() {
Style tags are supported
} // CSS components. const red = "#00ff00" css cssComponentGreen() { color: { red }; } templ CSSComponentsAreSupported() {
CSS components are supported
} // Both CSS components and constants are supported. // Only string names are really required. There is no need to use templ.Class or templ.SafeClass. templ CSSComponentsAndConstantsAreSupported() {
Both CSS components and constants are supported
// The following is also valid, but not required - you can put the class names in directly.
Both CSS components and constants are supported
} // Maps can be used to determine if a class should be added or not. templ MapsCanBeUsedToConditionallySetClasses() {
Maps can be used to determine if a class should be added or not.
} // The templ.KV function can be used to add a class if a condition is true. css d() { font-size: 12pt; } css e() { font-size: 14pt; } templ KVCanBeUsedToConditionallySetClasses() {
KV can be used to conditionally set classes.
} // Pseudo attributes can be used without any special syntax. templ PseudoAttributesAndComplexClassNamesAreSupported() {
Pseudo attributes and complex class names are supported.
} // Class names are HTML escaped. templ ClassNamesAreHTMLEscaped() {
Class names are HTML escaped.
} // CSS components can be used with arguments. css loading(percent int) { width: { fmt.Sprintf("%d%%", percent) }; } templ CSSComponentsCanBeUsedWithArguments() {
CSS components can be used with arguments.
CSS components can be used with arguments.
} css windVaneRotation(degrees float64) { transform: { templ.SafeCSSProperty(fmt.Sprintf("rotate(%ddeg)", int(math.Round(degrees)))) }; } templ Rotate(degrees float64) {
Rotate
} // Combine all tests. templ TestComponent() { @StyleTagsAreSupported() @CSSComponentsAreSupported() @CSSComponentsAndConstantsAreSupported() @MapsCanBeUsedToConditionallySetClasses() @KVCanBeUsedToConditionallySetClasses() @PseudoAttributesAndComplexClassNamesAreSupported() @ClassNamesAreHTMLEscaped() @CSSComponentsCanBeUsedWithArguments() @Rotate(45) }