Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added DataAttr and DataAttrs function #78

Merged
merged 1 commit into from
Nov 17, 2023
Merged

Conversation

whisk
Copy link
Contributor

@whisk whisk commented Nov 12, 2023

Issue: #73

Example usage:

Div(attrs.Props{attrs.DataAttr("theme"): "cupcake"}, Text("foobar"))
// <div data-theme="cupcake">foobar</div>
Div(attrs.DataAttrs(map[string]string{"theme": "cupcake", "foobar": "baz"}), Text("foobar"))
// <div data-theme="cupcake" data-foobar="baz">foobar</div>

@whisk whisk changed the title added DataAttr function added DataAttr and DataAttrs function Nov 12, 2023
@@ -0,0 +1,20 @@
package attrs_test
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be package attrs then you can remove the attrs. from usage in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

attrs/utils.go Outdated
}

// Return Props of data attributes build from given name-value pairs
func DataAttrs(pairs map[string]string) Props {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea on also adding a way to add multiple considering these may be less unique that other attributes! What do you think about introducing a reusable type named KeyValueMap or something similar, to avoid constantly writing map[string]string? It could streamline things for users. However, I'm a bit cautious about adding complexity that might make the library harder for developers to grasp. What do you think? Is the trade-off worth it?

attrs/utils.go Outdated

import "strings"

// Return name for a data attribute
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go convention is to start comments with the function name. It's helps godoc generate documentation. Can we change the comments to // DataAttr returns the name for a data attribute. please?

attrs/utils.go Outdated
return builder.String()
}

// Return Props of data attributes build from given name-value pairs
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same note on comment here. Thanks!

attrs/utils.go Outdated
}

// DataAttrs returns Props of data attributes build from given name-value pairs
func DataAttrs(pairs map[string]string) Props {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2023-11-17 at 5 54 54 AM

We might need to only have the DataAttr and not DataAttrs function. Without some sort of props merge I'm not sure this will work and may be confusing to the developer. Let's just simplify with the single DataAttr method for now. Sorry I didn't catch this earlier. Thanks.

Copy link
Owner

@chasefleming chasefleming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks @whisk !

@chasefleming chasefleming merged commit d20f39d into chasefleming:main Nov 17, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants