Add utility functions for enhanced attrs and styles functionality#167
Add utility functions for enhanced attrs and styles functionality#167Snehadas2005 wants to merge 4 commits into
Conversation
chasefleming
left a comment
There was a problem hiding this comment.
Thank you for the additions! I think the merge method and validity checkers might not fit the scope of the library. Can we remove those and just keep the CSS helpers? Those are very useful and work well with this.
| } | ||
|
|
||
| // MergeDataAttrs creates a Props map with multiple data attributes. | ||
| func MergeDataAttrs(dataAttrs map[string]string) Props { |
There was a problem hiding this comment.
I'm not sure this is necessary.
The current API already handles this use case cleanly with the existing DataAttr() helper and Props type.
For creating multiple data attributes:
userAttrs := attrs.Props{
attrs.DataAttr("user-id"): "123",
attrs.DataAttr("user-name"): "john",
attrs.DataAttr("role"): "admin",
}If you need to combine data attributes with other attributes:
buttonAttrs := attrs.Merge(
attrs.Props{
attrs.Class: "user-button",
attrs.ID: "user-123",
},
attrs.Props{
attrs.DataAttr("user-id"): "123",
attrs.DataAttr("role"): "admin",
},
)Or combining multiple attribute sets:
finalAttrs := attrs.Merge(
baseAttrs,
attrs.Props{
attrs.DataAttr("user-id"): "123",
attrs.DataAttr("user-name"): "john",
},
)| } | ||
|
|
||
| // Calc returns a CSS calc() function string. | ||
| func Calc(expression string) string { |
There was a problem hiding this comment.
These CSS helpers are great. These would fit nicely in the library.
| } | ||
|
|
||
| // IsValidHexColor validates if a string is a valid hex color. Supports 3 or 6 digit hex codes. | ||
| func IsValidHexColor(color string) bool { |
There was a problem hiding this comment.
Unfortunately, I don't think this fits the scope of the library.
There was a problem hiding this comment.
Ok, I will make changes accordingly. I will just keep the CSS part, and the rest of them will be restored to the initial one.
There was a problem hiding this comment.
I had made changes, kindly check
| @@ -0,0 +1,38 @@ | |||
| package main | |||
There was a problem hiding this comment.
Can you remove this too please?
Add new utility functions to improve developer experience when working with data attributes and CSS functions.
Proposed Changes
attrspackageMergeDataAttrs: Create multiple data attributes from a map in one gostylespackageCalc: CSS calc() function wrapperMin: CSS min() function wrapperMax: CSS max() function wrapperClamp: CSS clamp() function for responsive valuesIsValidHexColor: Validate hex color format (#RGB or #RRGGBB)IsValidRGBColor: Validate RGB color formatBenefits
Testing
Documentation
I had worked on this contribution under the label of Hacktoberfest 2025.