Skip to content

Version 0.11.0

Compare
Choose a tag to compare
@chasefleming chasefleming released this 04 Nov 22:25
· 201 commits to main since this release
25fdd90

This update introduces refactoring to the handling of attributes and styles within the elem-go library to resolve naming conflicts and improve the overall structure.

⚠️ Breaking Changes

Below are the breaking changes and examples of how to update your code accordingly:

1. Refactoring elem.Attrs to attrs.Props

To avoid naming conflicts with the HTML attribute names and provide a clearer distinction, elem.Attrs has been renamed to attrs.Props. This change emphasizes that these are properties for elements rather than direct attributes.

Old Usage:

div := elem.Div(elem.Attrs{
    attrs.ID:    "content",
    attrs.Class: "main-content",
})

New Usage:

div := elem.Div(attrs.Props{
    attrs.ID:    "content",
    attrs.Class: "main-content",
})

Action Required: Replace all instances of elem.Attrs with attrs.Props.

2. Refactoring elem.Style to styles.Props

To differentiate style properties from other attributes and ensure they are treated distinctly within the library, elem.Style has been refactored to styles.Props. This allows for a more modular approach to styling elements.

Old Usage:

style := elem.Style{
    styles.BackgroundColor: "#fff",
    styles.Color:           "#000",
}

New Usage:

style := styles.Props{
    styles.BackgroundColor: "#fff",
    styles.Color:           "#000",
}

Action Required: Replace all instances of elem.Style with styles.Props.

3. Deprecation of ApplyStyle and Introduction of ToInline

The ApplyStyle method, which was used to set style attributes directly on elements, has been deprecated to promote a more streamlined API. We are introducing the ToInline method for the styles.Props type to convert style properties to inline CSS strings more explicitly.

Old Usage with ApplyStyle:

divStyle := elem.Style{
    styles.BackgroundColor: "#f4f4f4",
    // ...other styles
}

div := elem.Div(elem.Attrs{
    attrs.Style: elem.ApplyStyle(divStyle),
})

New Usage with ToInline:

divStyle := elem.Style{
    styles.BackgroundColor: "#f4f4f4",
    // ...other styles
}

div := elem.Div(styles.Props{
    attrs.Style: divStyle.ToInline(),
})

Action Required: Migrate all usages of ApplyStyle to use the ToInline method on styles.Props and set the resulting string with the attrs.Style key when defining element attributes.